Skip to content

fix(runtime): record a turn a quit cuts off as interrupted, not as a Stop (ATO-1688) - #1761

Closed
sosidudku1 wants to merge 3 commits into
mainfrom
fix/ato-1688-interrupted-turn
Closed

sosidudku1 wants to merge 3 commits into
mainfrom
fix/ato-1688-interrupted-turn

Conversation

@sosidudku1

@sosidudku1 sosidudku1 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes ATO-1688 (agent side). Reported in Discord: a chat working in the background was killed when the desktop app quit, and after relaunch the chat gave no sign that its reply had been cut off.

Cause

serve closes its HTTP server before runtime.shutdown(). Closing drops the connections, which aborts the turns on them. A turn that unwound in that moment ran its normal cancel path and wrote its end as a plain cancelled with the error it had before, the same as a person pressing Stop. That overwrote the interrupted stand-in shutdown writes (or came before it), so interruptedChatTurn (ATO-448) saw no interrupted ending: no "reply was cut off" line and no Continue in the desktop, no /resume hint in the TUI.

Change

  • createRuntimeLifecycle gets beginShutdown() and isStopping(). Only beginShutdown sets it: a host that stops its own turn and then calls shutdown (the TUI's quit) keeps that turn's own end, as before.
  • AgentRuntime.beginShutdown?() (optional), wired in bootstrap.ts. serve calls it first thing in its teardown, before it drops the connections.
  • runtime-turn-service.ts: a chat turn that ends cancelled while the host is stopping is saved with INTERRUPTED_TURN_ENDING (transcript kept as the turn wrote it, progress marker kept as for any cancel). A thrown turn aborted while stopping is released with INTERRUPTED_TURN_ENDING instead of the prior error. A person's Stop with the host running is unchanged. A durable task's turn (checkpoint.taskId) keeps its own end: the task runner runs it again, and Continue on its chat would have nothing to continue.

Tests

  • runtime-lifecycle.test.ts: isStopping from beginShutdown on, and not from shutdown alone.
  • runtime-turn-service.test.ts: cancelled while stopping ends interrupted with its transcript; a Stop, with the host running or only shutting down, stays a plain cancel; a task turn keeps its own end; a thrown abort while stopping is released interrupted.

The desktop half (quit dialog, sidebar) is the companion PR on rel/xp-build, which also carries this commit.

Verification

  • Reviewer, then a skeptic on its findings, then fixes (2 rounds). Confirmed and fixed: shutdown alone set the flag and broke the TUI-quit contract pinned in bootstrap-turn-status.test.ts, bootstrap-task-lifecycle.test.ts; task turns got a Continue offer that could not continue.
  • Round 2 skeptic: no findings at or above confidence 80. The new tests fail with each fix line reverted.
  • Not covered by a unit test: serve calling beginShutdown before handle.close() (one line in serve-command.ts).

…Stop (ATO-1688)

serve dropped its connections before runtime.shutdown, which aborted the
turns on them. A turn that unwound in that moment wrote its own end as a
plain cancel, over the shutdown's interrupted stand-in, so the chat
reopened with no word that its reply was cut off and no Continue.

The runtime now has beginShutdown (called by serve before it drops the
connections) and isStopping; a turn that ends cancelled while the host
stops ends with INTERRUPTED_TURN_ENDING, transcript kept as written.
…r a task's (ATO-1688)

Review: shutdown alone set the flag, so a host that stops its own turn
and then shuts down (the TUI's quit, and the tests that pin it) had that
end overwritten. Now only beginShutdown sets it. A durable task's turn
keeps its own end: the task runner runs it again, and Continue on its
chat would have nothing to continue. Tests drive isStopping directly.
@sosidudku1

Copy link
Copy Markdown
Collaborator Author

Merged into main via #1764 (all commits are in main). GitHub did not mark it merged because of the outage during the merge.

@sosidudku1 sosidudku1 closed this Nov 25, 2026
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