Skip to content

End a local code review when its agent is gone; Send never pretends - #3698

Merged
backnotprop merged 11 commits into
mainfrom
fix/review-ends-when-agent-gone
Nov 26, 2026
Merged

backnotprop merged 11 commits into
mainfrom
fix/review-ends-when-agent-gone

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

In a local code review (plannotator review), if the agent that asked for it quits, Send used to report success, archive the feedback and delete the draft, with nobody to receive it. Now Send refuses when nobody can receive the decision, and the person's comments are never lost.

What changes

  • Send asks first (Bun and Pi servers). startReviewServer takes agentPresence ("here" | "gone" | "away" | "no-session"). /api/feedback asks it on every Send, before it archives or settles anything. Gone answers 410 agent_gone, away answers 409 agent_away (Retry is kept), no-session answers 410 no_session. In each case nothing is archived, decided or deleted. The PR platform's status post (platform: true) is never refused. The shared rule is in packages/shared/review-agent-gone.ts.
  • What Send asks, per launch. The CLI watches its agent (apps/hook/server/review-agent-watch.ts). For a review read through a pipe, Send probes stdout (EPIPE). For a Claude Code mod launch, Send answers gone as soon as the Claude Code process named in the lease no longer runs and nobody holds the lease (released at session end, or not renewed for 20 s, the mod's own stale-lease time). A fresh lease or a running process is "here", and a resume that takes the lease again is "here" at the next Send. One window remains: a Claude Code process that crashed without releasing its lease can still take a Send in the first 20 s; that decision is delivered if the session is resumed.
  • The page says so and keeps everything. Once the agent is surely gone (for a mod launch: the lease unchanged for 2 minutes and its process gone, so a quick resume is waited out), the server sends { type: "agent-gone", gone: true } on the event stream to every open tab. Once it has said either way, every stream that opens later (a reload, a reconnect after sleep) hears where things stand, gone or back. The page changes nothing: no cover, no done screen, the comments stay on screen. A notice at the bottom shows the reason with Copy feedback. A reconnect that hears "gone" again does not bring back a notice the person closed. The draft keeps saving, so a reload brings the comments back through the existing Draft Recovered dialog. When a mod session comes back (a resume takes the lease again), the server sends gone: false: the notice goes away, so does a "not sent" toast from a Send refused because the agent was gone, and Send works again.
  • The review ends only when nobody has it open. A local review ends once its agent is gone AND no tab has held the event stream for 2 minutes (counted in looks, so a machine that slept does not end it). It then exits 3 and keeps the draft for the next review of the same changes. A decision always wins. PR reviews never end this way, since they can still post to the platform.
  • The mod. It re-arms a stalled launch timer from every hook. A review open across /clear or an in-process /resume stays with its conversation. Exit 3 is reported as an end, not as a crash.
  • Pi and OpenCode's in-process server die with the agent's process. Pi says "away" between sessions. OpenCode with no session says "no-session".

Docs: code-review.md ("When the agent that asked for a review is gone"), claude-code-mod.md (Detached launch), environment.md (PLANNOTATOR_TEST_REVIEW_NO_TAB_MS, sandbox only), and the /api/feedback row in server-and-storage.md.

New person-facing words (not yet approved)

They are all in packages/shared/review-agent-gone-words.ts. The mod keeps a copy of its one line, because its folder imports nothing from outside it; apps/hook/hooks/mod/review-agent-gone.test.ts fails if the copy, the exit code or the stale-lease time drift from the shared ones.

  • Notice, shown as soon as the page hears it (and the toast reason after a refused Send): "The agent that asked for this review is gone. Your comments are kept."
  • Toast reasons under "Feedback not sent" / "Approval not sent" (titles unchanged): the line above, plus "No agent session can receive this right now. Your comments are kept." and "This review has no agent session to send to. Your comments are kept."
  • Server refusal error: "The agent that asked for this review is gone. Nothing was sent; your comments are kept." / "No agent session can receive this right now. Nothing was sent; your comments are kept." / "This review has no agent session to send to. Nothing was sent; your comments are kept."
  • CLI stderr at the end: "Plannotator: the agent that asked for this review is gone, so the review ends. Its draft is kept."
  • Mod log (exit 3): "The review of ended while no Claude Code session was open for it. Your comments are saved as a draft; open a review of the same changes to get them back."

Tests

  • packages/server/review-agent-gone.test.ts and its Pi mirror apps/pi-extension/server/review-agent-gone.test.ts. Core case: agent gone → Send refused, draft kept, nothing archived. Both fail with the refusal taken out. The Bun file also checks that a tab connecting after the agent came back hears gone: false, and that a review never said to be gone tells a new tab nothing.
  • apps/hook/server/review-agent-watch.test.ts (including the mod launch's Send answer: released lease and process gone → refused at once; fresh lease with the process gone, a resume taking over → sent; process still running → sent; a stale held lease → refused after 20 s), apps/hook/server/review-agent-gone-cli.test.ts (real process tree: the tab hears it, the review stays for the tab and a reload, ends once the tab is closed, and the next review restores the draft), apps/hook/hooks/mod/review-agent-gone.test.ts.
  • packages/ui/utils/sendFailure.agentGone.test.ts, packages/ui/hooks/useExternalAnnotations.seam.test.tsx, packages/review-editor/components/AgentGoneNotice.dom.test.tsx, packages/review-editor/App.agentGone.test.tsx (including: the agent back after a refused Send takes the "not sent" toast down; a reconnect keeps a closed notice closed, a new time gone shows it again).

A local review's server now quits once the agent that asked for it is gone
(the parent that reads stdout, or the Claude Code mod's launch lease after
two minutes), keeping its draft so the comments come back when the same
review is opened again. PR reviews stay, since they can still post to the
platform.

Both review servers take an agentPresence probe: Send and Approve to a gone
agent answer 410 agent_gone and archive, decide and delete nothing. The page
says the review ended in one line with Copy feedback, and a refused send
says the agent is gone.
A changed parent is only a suspicion: the review ends only when a write to
its stdout fails with EPIPE, so a backgrounded launch that is still read
lives. A Claude Code mod review ends only when its lease stamp stopped
moving on the CLI's own clock and the Claude Code pid the lease now names
no longer runs. The mod re-arms a stalled launch timer, and /clear or an
in-process /resume hands open code reviews to the new session.

Send asks the host live on every try. Pi between sessions answers away
(409, Retry kept); OpenCode with no session says so instead of gone. A
decision always wins over a pending end. The ended page saves its draft,
then shows the done screen with Copy feedback, so no edit is lost.
…unfinished text

A review open across /clear or an in-process /resume stays with the
conversation that asked for it again: the pid check already keeps it open,
and its decision waits for that conversation.

The ended screen is its own: it never closes the tab and never says to go
back to the agent. Text typed into a comment box but not added yet is kept
as a general comment, in the draft and in Copy feedback, before the screen
shows.

On macOS the stdout probe is a zero-length write, which adds nothing to the
output; elsewhere it stays one newline, documented with the head case.
…agent-gone

# Conflicts:
#	apps/pi-extension/vendor.sh
#	docs/agent-guides/code-review.md
#	packages/review-editor/App.tsx
…page says not sent

The server tests now save a line comment and a global comment with an
attached image and check the draft is exactly the same after a Send to a
gone agent (Bun and Pi). The page test sends a global comment to a gone
agent: no sent screen, Feedback not sent with the agent-gone reason, no
Retry, and the comment still on the page; a live agent still gets the
sent screen. Name Forgejo among the platforms in the guide.
…and keeps every comment

The page no longer covers itself with an ended screen. The server tells
every tab, and every tab opened later, that the agent is gone (and that it
is back), the draft keeps saving, and a local review ends only once no tab
has had it open for two minutes. The words are in one file,
packages/core/review-agent-gone-words.ts.
… passes its own reason

@plannotator/ui ships against the published @plannotator/core, which has no
review-agent-gone-words, so the UI keeps its copies of the three refusal
codes (pinned by a test) and the review page hands the toast its reason.
…shed core

The UI package smoke compares core's whole export list with the published
@plannotator/core, and the new ./review-agent-gone-words export made it fail.
The words file moves unchanged to packages/shared (private, not smoke-checked);
both servers, the CLI and the review page import it from there, and Pi vendors
it from the shared list.
…agent takes the stale not-sent toast down; every new stream hears where things stand
…nded-work

# Conflicts:
#	apps/pi-extension/vendor.sh
@backnotprop
backnotprop marked this pull request as ready for review November 26, 2026 20:49
@backnotprop
backnotprop merged commit ea1b0ea into main Nov 26, 2026
74 checks passed
yermakoffivan pushed a commit to yermakoffivan/plannotator that referenced this pull request Nov 27, 2026
…d Pele 1.13

core 0.25.35 carries what merged after 0.25.34 went to npm: exact-phrase
search in inbox-search (words in double quotes, backnotprop#4117, backnotprop#4124) and the
agent-gone event in external-annotation's ExternalAnnotationEvent (backnotprop#3698).
No exports subpath changes.

ui handles that agent-gone event, so its pin follows and core goes first.
ui 0.67.0 is a minor: DiagramSourceAcceptContext lets a host refuse a fence
by its source before any engine runs (backnotprop#4146), DIAGRAM_REFUSED_RESULT is
exported, Pele 1.13.0 with the inline fit changes (backnotprop#4113), the agent-gone
send failures (backnotprop#3698) and the plan header seams (backnotprop#3905). README and HANDOFF
name the new pair and the order (core first), and the hook and Pele notes
now name ui 0.67.0 instead of "the first ui after 0.66.0".

bun.lock is bun install's own output: the two package version lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:e2e Run the full browser suite (Inbox window e2e) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant