Repository navigation
Deliver messages to a task whose agent quit but whose tab is still open - #584
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.
pallaoro
added a commit
that referenced
this pull request
Nov 22, 2026
A message to a task whose agent quit with its tab left open as a shell is fixed in "Deliver messages to a task whose agent quit but whose tab is still open" (#584), so this change no longer carries its own version of it: the liveAgentSession filter, the Start on a stopped session, the listener's status write and their tests go back to main's.
This was referenced Nov 22, 2026
pallaoro
added a commit
that referenced
this pull request
Nov 22, 2026
#585) * Tell the Lead and the user when a message never reached a task's agent A message from the Lead chat or the user (a reply, an answer to a question) that never reached the task's agent was recorded and logged only, so the Lead went on promising an answer that could not come and the card looked done. Now, when Ateam starts an agent for such a message and that agent cannot start, quits before starting up, or is still not up after two minutes (most likely held at a prompt in its terminal), the task records it (tasks.undelivered, TaskDTO.undelivered) and its card goes to Needs You. The Lead chat that sent it shows a notice on the task, and the Lead's agent hears it with the user's next message. The Mac shows a banner once, and the task's panel shows why. The record clears once an agent of the task shows up again. The idle-archive sweep counts it as activity, so a month-old task whose conversation Claude Code dropped is not archived the hour after. A message to a task whose agent quit but whose tab is still open as a shell no longer waits on that shell for good: it starts the agent in a new tab. An agent the user starts by hand in that tab counts as up and takes it instead. * Leave the quit-tab fix to its own PR A message to a task whose agent quit with its tab left open as a shell is fixed in "Deliver messages to a task whose agent quit but whose tab is still open" (#584), so this change no longer carries its own version of it: the liveAgentSession filter, the Start on a stopped session, the listener's status write and their tests go back to main's.
…-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
pallaoro
added a commit
that referenced
this pull request
Nov 30, 2026
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.
pallaoro
added a commit
that referenced
this pull request
Dec 1, 2026
…632) * Deliver messages to a task whose agent quit but whose tab is still open 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 revived by hand takes the conversation its new agent reports 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.
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.
The bug
A message sent to a task (from the Lead, the user or another task's agent) was never delivered while that task had a tab whose agent quit and left its pane open as a shell. The sender was told "queued: its agent is busy, so it gets the message as soon as it can take it", and the message stayed pending for as long as the tab stayed open. The PTY daemon outlives app restarts and the reaper only takes
idlesessions, so that could be days.Why:
liveAgentSession()inpackages/server/src/peer-messages.tstook any non-shell session with a live PTY as the task's agent, whatever its status. A pane whose agent quit isstoppedon a live PTY (applyAgentQuit,pty/agent-quit.ts), andholdsWork()inpty/reap.tsis true for every status butidle, so the plan waswaiton every sweep.list_peersreported such a task asidleinstead ofnot_running.The fix
liveAgentSession()skips astoppedpane, asliveAgentIds(services.ts),liveTabOn(sessions.ts),applyAgentQuitandsessionAlive(loops/session-liveness.ts) already do. Such a task now gets its agent started in a new tab with the message, resuming its conversation; the shell is left open.Startin astoppedpane is an agent the user ran there again by hand.sessionStatusAfter()inengine.tskeptstoppedon aStart, so with the first change alone a message arriving before that agent's first activity would have started a second agent beside it, where before it reached the listener already waiting. It now makes the sessionidle, and the card is redrawn so its tab shows the agent again, not a shell.stoppedpane whose listener is asking for messages still counts as the task's agent: OpenCode reports noStartat all, and Claude's listener can ask before itsStartis recorded.Verified
New tests in
packages/server/test/peer-messages.test.ts("A task whose agent quit but whose tab is still open") andsession-status.test.ts. Three of them fail on main; the other two (OpenCode's listener in that pane, another busy agent of the same task) pass on main and guard against regressions from this change.End to end with a real engine, PTY daemon, hook server and launch line, against a stand-in claude that quits on cue: the agent quits and its pane stays (
stopped, PTY live); a Lead message is answered "Ateam is starting it" and resumes the conversation in a new tab with the message, no error, shell left open;claudetyped into the shell reportsStart, the session becomesidleand the card is redrawn with an agent tab; a message after that starts no second agent. 9/9 checks.bun testinpackages/server: 1029 pass, 1 fail. The failure issystem:hello handshake, which timed out at 5 s probing installed agents on a busy machine; it passes alone with a longer timeout and does not touch this code.tsc --noEmitclean. Biome is clean on the changed files except two findings inengine.ts(import order, one line wrap) that are on main already.With main merged in (Tell the Lead and the user when a message never reached a task's agent #585, A message to a task whose conversation is gone starts a new one instead of being lost #586):
bun testinpackages/server1052 pass, 0 fail (30 s per-test timeout). A message to a task whose conversation is gone starts a new one instead of being lost #586 leaves a tab whose new conversation never started open as astoppedshell; the end-to-end run of that case with the manual close of that tab removed passed 27/27: the tab stays open, the next message is answered "Ateam is starting it" and reopens the task's real conversation.Not covered
Startand has no listener, so it stays a shell to the messenger until its first turn ends; a message in that window starts the task's agent in a new tab.idle, so the reaper reclaims it like any other idle agent; before, it stayedstoppedand was never reaped.