Skip to content

A pane revived by hand takes the conversation its new agent reports - #632

Merged
pallaoro merged 7 commits into
mainfrom
messages-queue-behind-a-pane-whose-agent-quit
Dec 1, 2026
Merged

pallaoro merged 7 commits into
mainfrom
messages-queue-behind-a-pane-whose-agent-quit

Conversation

@pallaoro

Copy link
Copy Markdown
Member

Follow-up to #584.

The bug

Since #584, a Start in 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() in packages/server/src/sessions.ts never 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 (launch in engine.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-typed claude has 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 Start in a stopped pane, 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:

  • any other event, and a Start with no reported id, leave the id alone;
  • a Start in 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() in peer-messages.ts, and it only runs for a launch that never came up, which is not this path.

Verified

  • New tests in 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.
  • End to end with a real engine, PTY daemon and hook server against a stand-in claude: an agent quits, its pane stays a shell, claude --session-id <new id> typed into it reports Start, and the row now carries the new id. 10/10 checks with the earlier quit-pane checks.
  • bun test in packages/server: 1113 pass, 1 fail. The failure is the computeGitStatus squash-merge test, which cannot spawn git in 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 --noEmit clean; Biome clean on the changed files.

Not covered

  • An Antigravity pane revived by hand on another conversation: the hook handler drops Antigravity events whose id differs from the row's before this runs, so that pane stays a shell to Ateam.
  • OpenCode reports no Start, so a hand-run OpenCode keeps the old id; it has no restart door while its listener polls.

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
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
pallaoro merged commit 77ae181 into main Dec 1, 2026
1 check passed
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.
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