Repository navigation
fix(pi): settle watcher delivery on Pi accepting the follow-up - #3513
Merged
Merged
Conversation
A follow-up queued while main is streaming joins the running run without ever raising before_agent_start, so waiting on that event before clearing the successor pipeline (#3498) stalled every later actionable close: no successor started, no wake was delivered or offered to the branch, and the turn-end guard woke main to re-arm by hand after every close. The pipeline now settles once Pi accepts the follow-up. Consumption is observed at before_agent_start for an idle main and at the user message_start for a streaming main, and decides only what a replacement session (/new, /resume, /fork, reload) replays. An exhausted restoration delivers its typed failure without launching an arm past the retry bound, which the stall had hidden. The replacement-coordinator map is typed so the strict no-emit typecheck passes again. Tests: the doubles no longer raise before_agent_start for a streaming send, a portable regression drives two actionable closes while main streams and proves the successor chain plus consumption-scoped replay, and a credential-free real-SDK probe pins Pi's event contract for both the streaming and the idle follow-up. Claude-Session: https://claude.ai/code/session_01QJjTsUvKkWAwLGNoncaZ3a
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported successor-close gap is addressed by preserving the verified close during delivery and scheduling its bounded retry after settlement. Reviews (2): Last reviewed commit: "fix(pi): retry a verified successor that..." | Re-trigger Greptile |
A verified successor can exit while the wake it was started for is still being delivered, most plausibly during a branch turn that holds the settlement for minutes. Its failure close arrived while the pipeline's single-flight guard was set, so the close handler skipped the retry, and the pipeline's end no longer launched an arm, which left the live generation with no watcher and no retry timer. The close handler now records that failure when the child had reported readiness and was not retired by the restoration itself, and the pipeline runs the ordinary bounded, lock-checked retry for it once the delivery settles. A restoration started for a later pending supersedes it, and an exhausted restoration still hands repair to main without a further arm. The regression holds a branch settlement open while the verified successor exits with a failure and proves one retry watcher starts after the settlement releases, none while it is held. Claude-Session: https://claude.ai/code/session_01QJjTsUvKkWAwLGNoncaZ3a
npayette84
added a commit
to npayette84/firstmate
that referenced
this pull request
Sep 2, 2026
…contract Upstream main now settles a main delivery once Pi accepts the follow-up and observes consumption at before_agent_start for an idle main and at the user message_start for a streaming one (kunchenguid#3513), replacing the acknowledgement contract this change was built against. Presentation coalescing moves on top of that contract unchanged in behavior: sendWake keeps its WakePresentation argument next to the base's pending-record argument, sets the ordinary latch before the delivery await, rolls it back in the catch that already drops the unconsumed-wake record, and a coalesced wake never enters that map, so its pending record is finished rather than left waiting for a consumption that will never come. The base's streaming-time delivery regression drove two actionable closes through one streaming run and expected a docked row for each. Coalescing presents the second through the row already docked, so it now proves the successor chain advances without a second row and takes its unconsumed handoff wake from a later close raised after that row is consumed at message_start and its run settles. The verification record names the new base, and the counterfactual matrix was re-run there: unmodified upstream fails only the burst test, each single clearing edge fails only its own re-arm test, call-site-only urgency fails both restoration-failure tests, removing urgency fails all four failure-bypass tests, and a latch shared across generations fails only the session-replacement test.
Problem
Since #3498, the Pi watcher extension delivered an actionable wake to main and then waited for Pi's
before_agent_startcarrying that exact text before it would clear its single-flight pipeline. Pi raisesbefore_agent_startonly for a prompt that starts an idle agent. A follow-up queued while main is mid-turn is drained by the agent loop into the running run and never raises it, so the first wake that landed during a busy turn pinned the pipeline for the rest of the session: every later watcher close was enqueued and dropped, no successor started, nothing was offered to the supervision branch, and the turn-end guard woke main to re-arm by hand after every close. Task-local events then fell through to main, which narrated routine progress into the captain's chat.Proven against the installed Pi 0.84.3 binary on 2026-09-02: a follow-up sent while streaming raises
inputand a newturn_start, then a usermessage_startwith the exact text once the run reaches it, but nobefore_agent_start; the same follow-up sent while idle raisesbefore_agent_startwith the exact text.Change
sendUserMessageresolves). The successor pipeline never waits for consumption./new,/resume,/fork, reload) replays. It is now observed atbefore_agent_startfor an idle main and at the usermessage_startfor a streaming main; either finishes the pending record, and a still-unconsumed record rides the replacement handoff.finallyhad added that launch; the stall hid it in the existing hung-successor test, and a hung extra child would make the repair call reportunchanged.mainwith an implicitany).Tests
before_agent_startfor a streaming send; the live-guard doubles model the idle path Pi actually takes.test_pi_streaming_time_delivery_keeps_the_successor_chain: two actionable closes while main streams must each be followed by a successor launch and a delivered wake with nobefore_agent_start; after one is consumed at its usermessage_start, a replacement replays exactly the other, and the idle replay is consumed atbefore_agent_start.tests/fm-pi-branch-live-e2e.test.sh: the tracked extension loaded through Pi's own resource loader into a realAgentSessionwith an in-process fake provider held open mid-stream. It pins the event contract for both the streaming and the idle follow-up and proves the successor chain against the real runtime, with no credential read and no request leaving the machine.Verification
The branch-extension suite needs
FM_PI_PACKAGE_DIRat a 0.84.x install; against the globally installed 0.80.10 its first rendering-consumer case fails before any delivery case, asdocs/verification/runtime-backends.mdalready records.Review follow-up
Greptile's P1 (a verified successor closing while branch settlement or
sendUserMessageis still pending left the generation with no watcher and no retry) was reproduced with a test that holds a branch settlement open while the verified successor exits with a failure: the generation stayed at two arms after the settlement released. The close handler now records such a failure when the child had reported readiness and was not retired by the restoration itself, and the pipeline runs the ordinary bounded, lock-checked retry for it once the delivery settles. An exhausted restoration still delivers its typed failure without a further arm. Regression:test_pi_successor_failure_during_delivery_is_retried_after_delivery.Docs
docs/watcher-continuity.md,docs/pi-supervision-branch.md, and the two verification records now state delivery as "Pi accepted the follow-up" and point at the extension header, which owns the delivery-versus-consumption contract.🤖 Generated with Claude Code
https://claude.ai/code/session_01QJjTsUvKkWAwLGNoncaZ3a