Skip to content

fix(claude): stop a resumed turn on cancel once its deferred call settles - #3647

Open
arun-elr wants to merge 1 commit into
kagent-dev:mainfrom
arun-elr:fix-cancel-after-ask-user
Open

arun-elr wants to merge 1 commit into
kagent-dev:mainfrom
arun-elr:fix-cancel-after-ask-user

Conversation

@arun-elr

Copy link
Copy Markdown

Fixes #3314

Canceling a task that an approval or ask-user answer resumed waited up to 30s for Claude to reach a hook and stop by itself. If Claude was in a model call or a long tool after the replayed call returned, no hook fired, so CancelTask failed with runtime cancellation cleanup failed: context deadline exceeded and the session couldn't be deleted.

Once the replayed call has its result, the rest of the turn is ordinary work:

  • consume notes when the replayed call's tool result arrives, and after that a cancel stops the process like any other turn. This also covers a cancel that started cleanup just before the result arrived.
  • Resume (and Cancel, for its own replay) then records the journal as canceled, so a restored harness doesn't read it as an unfinished replay and return ErrSessionAbandoned.
  • A cancel before the result still waits for Claude to settle the call, as before.

Tests:

  • TestDeferredReplayCancelsAfterItsCallSettles covers both orderings (result then cancel, cancel then result). Both fail on main after the 30s timeout and pass with the fix, -race -count=10.
  • TestSessionCancelAfterAskUserAnswer (e2e, all harnesses): ask, answer, hold the next model call open, cancel. On main the claude case fails with the error above; with the fix all four pass. Ran on a local kind cluster set up like CI (gvisor); the full e2e suite passed apart from TestBuiltinHarnessDefaultImages/claude, which fails locally only because I rebuilt the claude image after packaging the chart.

…tles

Canceling a task that an approval or ask-user answer had resumed waited up
to 30s for Claude to reach a hook and stop by itself. When Claude was in a
model call or a long tool after the replayed call returned, no hook fired, so
CancelTask failed with "runtime cancellation cleanup failed: context deadline
exceeded" and the session could not be deleted.

Once the replayed call has its result, the rest of the turn is ordinary work,
so the driver now stops it like any other turn and records the replay as
canceled, so a restored harness does not report the session as abandoned. A
cancel that arrives before the result still waits for Claude to settle it.

Fixes kagent-dev#3314

Signed-off-by: Arunkumar Eli <elrarun@gmail.com>
@github-actions github-actions Bot added the bug Something isn't working label Nov 11, 2026
@arun-elr
arun-elr marked this pull request as ready for review November 11, 2026 18:51
@arun-elr
arun-elr requested a review from a team as a code owner November 11, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] CancelTask fails after an ask-user answer resumed the task ("deferred continuation cannot be resumed")

1 participant