Interrupt a running Anthropic session before archiving it - #71465
Open
kaxil wants to merge 1 commit into
Open
Conversation
kaxil
force-pushed
the
anthropic-interrupt-before-archive
branch
from
August 11, 2026 19:58
ca5d7c3 to
7977439
Compare
kaxil
marked this pull request as ready for review
August 11, 2026 20:00
kaxil
force-pushed
the
anthropic-interrupt-before-archive
branch
from
August 11, 2026 21:03
7977439 to
360e983
Compare
kaxil
force-pushed
the
anthropic-interrupt-before-archive
branch
from
August 11, 2026 21:33
360e983 to
89b5c74
Compare
The API refuses to archive **or** delete a session while its status is ``running``, rejecting both with a 400. ``AnthropicAgentSessionOperator`` treats archiving as best-effort teardown on every failure path, so a session that will not stop on its own is left behind with no way to release it -- and it keeps accruing ``active_seconds``, which the SDK describes as the duration the session's runtime cost is priced on. Observed directly: two sessions halted by a $0.01 budget sat at status ``running`` for over 40 minutes with model spend frozen at the ceiling while ``active_seconds`` kept climbing. ``archive`` and ``delete`` both returned 400. Sending ``user.interrupt`` moved them to ``idle`` immediately, after which archiving succeeded. ``AnthropicHook.archive_session`` now interrupts and retries when the first archive attempt fails, and ``interrupt_session`` exposes the event on its own. The retry is bounded, so an unarchivable session still surfaces its error rather than looping. This is reachable well beyond budgets -- any session still working when a task fails, times out, or is killed hits the same 400 -- but a budget halt makes it routine, because that is a session which has stopped spending without stopping. The interrupt-then-archive sequence was verified by hand against the live API on two genuinely stuck sessions. Its wiring through ``archive_session`` is covered by unit tests rather than a live run.
kaxil
force-pushed
the
anthropic-interrupt-before-archive
branch
from
August 11, 2026 21:42
89b5c74 to
4196cb2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The API refuses to archive or delete a session while its status is
running, rejectingboth with a 400.
AnthropicAgentSessionOperatortreats archiving as best-effort teardown onevery failure path, so a session that will not stop on its own is left behind with no way to
release it -- and it keeps accruing
active_seconds, which the SDK describes as theduration the session's runtime cost is priced on.
Evidence
Two sessions halted by a $0.01 budget sat at status
runningfor over 40 minutes. Modelspend was frozen at the ceiling, but
active_secondskept climbing across successivesamples (777 to 838 seconds over one 60-second window). Both
archiveanddeletereturned400. Sending
user.interruptmoved them toidleimmediately, after which archivingsucceeded.
Solution
AnthropicHook.archive_sessionnow interrupts and retries when the first archive attemptfails, and
interrupt_sessionexposes the event on its own. The retry is bounded, so asession that genuinely cannot be archived still surfaces its error rather than looping.
This is reachable well beyond budgets: any session still working when a task fails, times
out, or is killed hits the same 400. A budget halt just makes it routine, because that is a
session which has stopped spending without stopping.
Scope
The interrupt-then-archive sequence was verified by hand against the live API on two
genuinely stuck sessions. Its wiring through
archive_sessionis covered by unit testsrather than a live run.