Skip to content

fix(desktop): ask before a quit cuts off working chats; keep them findable (ATO-1696, ATO-1688) - #1762

Closed
sosidudku1 wants to merge 5 commits into
rel/xp-buildfrom
fix/ato-1688-desktop-quit-live-turns
Closed

sosidudku1 wants to merge 5 commits into
rel/xp-buildfrom
fix/ato-1688-desktop-quit-live-turns

Conversation

@sosidudku1

@sosidudku1 sosidudku1 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes ATO-1696 and the desktop side of ATO-1688. Reported in Discord (Desktop 0.0.9): "I lose chats a lot in the background in the desktop view", and quitting the app silently killed a chat that was still working.

What changes for the person

  • Quit asks when a chat is still working. before-quit asked only about queued messages (ATO-135). It now also asks when a turn is running, in the chat on screen or one left in the background: "A chat is still working" / "N chats are still working", "Quitting now stops its reply before it is done.", Quit / Cancel. With queued messages too it is one dialog that names both. Same exceptions as the queue question (smoke, first-run probe, an update's install, the last window closing off macOS without a tray). Cancel keeps the app and the turn running. Text and counting: main/quit-question.ts.
  • A working chat stays findable. A chat with a turn running or an approval waiting stays on the chat list past the Load more cut (pageWithBusy in renderer/chat-list.js). Before, an older chat working a long turn slid behind Load more as newer chats were stored.
  • Collapsed projects and folders show it too. A collapsed group draws no rows, so a chat working inside it had no mark anywhere. Its header now shows the running pulse, or the amber dot when a chat there waits on an approval.
  • After relaunch the cut-off chat says so. The ATO-448 line now reads "The last reply was cut off before it finished: the app quit or the agent restarted." with its Continue button. For it to show after a quit, the agent must record the quit's cancel as interrupted: that is fix(runtime): record a turn a quit cuts off as interrupted, not as a Stop (ATO-1688) #1761 (base main), cherry-picked here (two commits) so this branch works on its own. The desktop's quit now also ends the agent first and drops the turns' streams once it has gone (AgentClient.stopNow on close()); before, it dropped them first and the agent saw each turn's request vanish before it knew it was stopping. A restart keeps the old order.

Why ask rather than keep the turn running

The turn runs inside atag serve, a child of the app, so it cannot outlive a full quit. Keep Running (tray) already lets the app live with no window. So the quit warns, the way it already does for queued messages, and a turn cut off anyway (Quit pressed) is offered to continue after relaunch.

Tests

Verification

  • Reviewer, then a skeptic on its findings, then fixes (2 rounds). Confirmed and fixed: the desktop dropped turn streams before signalling the agent (race that lost the interrupted ending); the Pinned block count once busy rows are kept past the cut; the agent-side items listed in fix(runtime): record a turn a quit cuts off as interrupted, not as a Stop (ATO-1688) #1761.
  • Round 2 skeptic: no findings at or above confidence 80. Quit time bounds still hold (SIGTERM grace 4 s and kill wait inside the quit's 10 s close bound).
  • Not covered by a unit test: the new order in AgentClient.stopNow and the collapsed-group dot (renderer only). Worth a look in the combined run: quit with a chat working, Cancel keeps it running; Quit, relaunch, the chat shows the cut-off line with Continue.

…dable (ATO-1696, ATO-1688)

- before-quit asked only about queued messages (ATO-135). It now also
  asks when a chat is still working: "N chats are still working",
  Quit / Cancel, one dialog when there are both (main/quit-question.ts).
- A chat working or waiting on an approval stays on the chat list past
  Load more's cut (chat-list.js pageWithBusy).
- A collapsed project or folder shows the running or approval dot on
  its header, since it draws no rows.
- The ATO-448 offer line now names a quit as well as a restart.
…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.

(cherry picked from commit f6068f4)
…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.

(cherry picked from commit 10f775b)
…ms (ATO-1688)

Review: stopNow aborted every turn's request before the SIGTERM (or the
Windows stand-in's end), so the agent could end a turn as a person's
Stop before it knew it was stopping. close() now ends the agent first
and drops the streams once it has gone; a stream the agent's shutdown
broke reads as the app ending the turn, not a transport failure. A
restart keeps the old order. Also: the Pinned block counts only the
pinned rows the page drew, not busy rows kept past the cut.
@sosidudku1

Copy link
Copy Markdown
Collaborator Author

Merged into rel/xp-build via #1763 (all commits are in rel/xp-build). 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