Skip to content

fix(scheduler): abort queued wake inject on cancel; purge goal-check on terminal cancel - #21

Draft
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/bc-4f735225-e19c-432b-9610-15700f08b124-a391
Draft

fix(scheduler): abort queued wake inject on cancel; purge goal-check on terminal cancel#21
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/bc-4f735225-e19c-432b-9610-15700f08b124-a391

Conversation

@cursor

@cursor cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

1. Queued agent_wake inject permanently lost on session cancel

  • Impact: Scheduled / goal wakes silently stopped after terminal cancel if the inject was still queued (not yet dispatched). poll_due_wakes never retried because the wake stayed staged=True.
  • Root cause: _dispatch_loop skipped cancelled queued requests without calling _finalize_agent_wake_delivery(confirmed=False). Only _run_and_route had the abort path.
  • Trigger: Due wake → inject_turn enqueues + _mark_staged → user cancels before dispatch dequeues → skip at dispatch with no abort → wake stuck staged forever.

2. Terminal cancel flushed staged goal-check wakes

  • Impact: User Ctrl+C / dashboard cancel during a running turn could immediately re-inject a staged goal-check wake in finally, restarting auto-continue right after abort.
  • Root cause: cancel_session_tasks did not purge _PENDING_BY_SESSION goal-check entries; flush_pending_wakes_for_session still delivered them when inflight hit zero.
  • Trigger: Long turn in flight → goal-check wake staged (inflight>0) → terminal cancel → finally flush delivers wake inject.

Fix

  • Call _finalize_agent_wake_delivery(request, confirmed=False) when dispatch skips a cancelled queued request.
  • Call cancel_pending_wakes(session_id, label="goal-check") at the start of cancel_session_tasks.

Validation

  • tests/test_kernel_runtime.py::test_cancel_dispatch_skip_aborts_agent_wake_delivery
  • tests/test_kernel_runtime.py::test_terminal_cancel_does_not_flush_staged_goal_check
  • Existing test_cancel_skip_aborts_agent_wake_delivery still passes
Open in Web View Automation 

…on terminal cancel

When cancel_session_tasks skipped a queued agent_wake inject at dispatch,
the wake stayed staged and poll_due_wakes never retried it. Call
_finalize_agent_wake_delivery(confirmed=False) on the dispatch skip path.

Terminal cancel also flushed staged goal-check wakes from the pending
queue after the user aborted the session. Purge goal-check wakes at
cancel start so flush_pending_wakes cannot resurrect them.

Co-authored-by: Yuxuan Liu <Osc-7@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant