Repository navigation
A pane revived by hand takes the conversation its new agent reports - #632
Merged
Merged
Conversation
An agent that quits leaves its pane open as a shell, its session `stopped` on a live PTY (pty/agent-quit.ts). The peer messenger still took that pane for the task's live agent, found it busy (holdsWork is true for every status but idle) and queued every message to the task for as long as the tab stayed open, telling the sender "its agent is busy". list_peers called it idle. - liveAgentSession() skips a `stopped` pane, as liveAgentIds, liveTabOn, applyAgentQuit and sessionAlive already do: such a task gets its agent started in a new tab with the message, and the shell is left alone. - A Start in a `stopped` pane is an agent the user ran there again by hand: sessionStatusAfter() makes it `idle`, and the card is redrawn. Kept `stopped`, it would have been skipped while its listener was already waiting, and a message would have started a second agent. - A `stopped` pane whose listener is asking still counts: OpenCode reports no Start, and Claude's listener can ask before its Start is recorded.
…-a-pane-whose-agent-quit # Conflicts: # packages/server/test/peer-messages.test.ts
…-a-pane-whose-agent-quit # Conflicts: # packages/server/test/peer-messages.test.ts
…-a-pane-whose-agent-quit # Conflicts: # packages/server/src/peer-messages.ts # packages/server/test/peer-messages.test.ts
…-a-pane-whose-agent-quit
Since #584 a Start in a pane whose agent quit (`stopped`) makes it an idle agent again. Its row kept the conversation id of the agent that quit: adoptReportedConversation never replaces an id, and never adopts one for Claude. A restart (the user's own words to a Claude with no mod, or a Codex with no listener) then killed the hand-run agent and its shell and reopened the conversation that quit. On a Start in a `stopped` pane, the row now takes the id the agent reports. Any other event, and a Start in a pane whose agent is still there (a resume or a compaction), leave the id as before.
…-a-pane-whose-agent-quit
pallaoro
added a commit
that referenced
this pull request
Dec 1, 2026
An agent that quits leaves its pane open as a shell, its session `stopped` on a live PTY (pty/agent-quit.ts). Each place that cares wrote its own test of that, and each one that missed it was a bug (#584 queued every message behind such a pane; #632 had to add one more). - runsAgent(session, listening) in protocol/session-tabs.ts is the one answer: not a shell row, and not `stopped` unless its message listener is asking (an agent run again by hand: OpenCode sends no Start). - liveAgent(session, isLive, listening) in pty/agent-quit.ts adds "not ended and its terminal is open" for callers holding the PTY daemon. - Moved onto them: taskSessionAgents, createSessionInCallerTask, liveTabOn, applyAgentQuit, sessionAlive, tileSessions, the peer messenger (liveAgentSession, addressedSession, the asking-tab check), adoptReportedConversation, the browser relay check, the Mac link's task-session check, and the Start handler in the engine. - A guard test fails on any other comparison of a session's `status` with "stopped" outside session-tabs.ts. Behaviour changes, both small: - sessionAlive (the board organizer's and triage's "does a live agent own this card") no longer counts a plain shell tab as a live agent. A shell row is never `stopped`, so a task with only a shell open read as having a live agent. - The browser relay check also refuses a shell row, which holds no relay token. Which agent's conversation a row holds (engine launch target, restore) is a different question and still reads `agentId`; the comments say so. Tests: runsAgent, liveAgent, sessionAlive, the quit-pane browser case and the guard. Run against a real engine and PTY daemon with the quit-pane harness: 10/10.
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.
Follow-up to #584.
The bug
Since #584, a
Startin a pane whose agent quit (stopped) makes the pane an idle agent again: the user ran an agent there by hand. But the session row kept the conversation id of the agent that quit.adoptReportedConversation()inpackages/server/src/sessions.tsnever replaces an id already on the row, and never adopts one for Claude, because Ateam names Claude's conversations itself.A restart resumes the row's id (
launchinengine.ts). So when a restart was the door, the hand-run agent and the pane's shell were killed and the conversation that quit was reopened in their place, with the message. The hand-run conversation stayed on disk but was no longer open. The doors that restart are the user's own words to a Claude with no Ateam mod polling (a hand-typedclaudehas none) and a Codex with no listener. Messages from the Lead and other agents to a hand-run Claude go to its listener and were not affected.The fix
On a
Startin astoppedpane, the row takes the conversation id the agent reports (adoptReportedConversation, now passed the event type by the hook handler). Every other case keeps today's rule:Startwith no reported id, leave the id alone;Startin a pane whose agent is still there (a resume or a compaction) leaves it alone.The only code that reads "id equals terminal id" is
forgetConversation()inpeer-messages.ts, and it only runs for a launch that never came up, which is not this path.Verified
packages/server/test/spawn-resume.test.ts("in a pane whose agent quit"). Two of them fail on main; the two that guard the other cases pass on main and here.claude --session-id <new id>typed into it reportsStart, and the row now carries the new id. 10/10 checks with the earlier quit-pane checks.bun testinpackages/server: 1113 pass, 1 fail. The failure is thecomputeGitStatussquash-merge test, which cannot spawngitin this machine's test environment; it does not touch this code and passed on CI for Deliver messages to a task whose agent quit but whose tab is still open #584.tsc --noEmitclean; Biome clean on the changed files.Not covered
Start, so a hand-run OpenCode keeps the old id; it has no restart door while its listener polls.