Repository navigation
fix(pending): close four edges of a chat message queued behind a starting omp - #4157
Conversation
…ting omp From review findings on #4143 (replays by t107): - A frame whose page was not ready yet as it came took its lease in the pane's lane, so a page that left the pane and came back while the frame waited there had it queued under its new attach. Such a frame is now noted on its way (askFirstMessage / holdRequested), and refused with pending_lease_lost when its page left meanwhile, as one ready as it came already was. A page that stayed while its attach became ready is still queued. - The branch that queues a message sent at once asked no deadline: one that waited past it in the lane was accepted. It now answers submit_timeout, as the queue request and the plain send beside it do. - That branch kept no record of the frame's id, so the same frame coming again after the message was discarded or sent made a second row, typed at its turn. It now records the queued reply in the connection's request book, and a frame that comes again is answered from it. The record is asked in the frame's own turn in the pane's lane, where the choice between queueing and typing is made, so a copy that came before the first one's turn is answered from it too, even when omp reported between the two (found by the omo review of this change). - The pending path's paste was guarded by the lease alone, so a paste whose herdr connection opened past the deadline still went, about a second late. Its first write now asks the deadline too, and refuses with submit_timeout; once anything is typed, the rest and its Enter go. On an OpenCode message with skills, a write counts as typed once its guard let it go, as composer.ts counts it: typeWithSkills asks the same guard before any write, which had counted as typed and skipped the deadline (found by the Codex review of this change). Co-authored-by: sisyphus-dev-ai <[email protected]>
Review findings and how each was resolvedTwo reviews ran before this PR was opened. omo code review (Claude Opus 5.5) of the first versionVerdict: APPROVE, with nothing HIGH.
Codex review (gpt-6.2-sol-fast, xhigh, through the team proxy) of the second version
The Codex run on the first version stopped partway, with no findings, when its provider flagged the prompt. It was re-run with plainer wording on the second version. |
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
…in red (#4158) ## Why `main` went red twice in a row after #4143 (CI runs 44338954162 at ccb0253 and 44342237591 at 288f732). Each time, four `server/pending-input.contract.test.ts` cases ran out the test's 15 s wait, among them "queues any working agent and advances one message per confirmed turn" and "keeps a request that finds the agent ready behind the messages already waiting". `main` last passed at 55ec00b, #4143 itself, and the commits after it change browser tests only. The lead asked for the cause to be fixed within about 90 minutes, or for #4143 to be reverted otherwise. A safe fix needs more than that, so this reverts it. ## Cause (for the re-land) The failure trails show a queued message held with `pending_turn_unconfirmed` by #4143's turn gate at its 10 s start timeout, even though herdr had reported the turn's `working` and its end after the queue's Enter. A local trace of `PendingInputs` shows the mechanism on a passing run: 1. A collector baseline reads `working` while the queue still holds `unknown` (the pane's first baseline). The gap-closing snapshot after the subscription started records that reading as one ahead of herdr's events, owed an event (`ahead`). 2. The change happened before the subscription started, so herdr never sends it as an event. 3. For the reading's 10 s, every event counts as older than a snapshot (`overtaken`): a `done` with no matching reading leaves the reading in place. 4. A gate opened in that window takes its turn's `working` as one of those older events (`unconfirmed`). It never sees the turn start, and it holds the queue at 10 s. Whether a test lands in that window depends on runner load. Locally, with the file alone under load, all 128 cases still pass, and #4157's CI passed with this code. A fix has to tell a reading that is owed an event from one herdr will never send: a change made before the subscription, as with `blind` readings. That can't be done safely in the time asked; #4118's order B depends on the same `overtaken` rule. ## What this reopens #4118 (the five turn-gate races), #3990 (two held messages with the same words come back as one) and #3999 (a typed answer's Enter goes out with no re-read). They come back once the gate is fixed. ## Validation - `git revert` of 55ec00b applies cleanly on `main` at 288f732. - `bun run check fast` on the revert (old-desktop, through `dori heavy`): workflow syntax, generated files, typecheck, build and unit tests all ok. Co-authored-by: sisyphus-dev-ai <[email protected]>
Re-checked on today's main, after #4158 reverted #4143This branch was built on #4143, and its CI ran before the revert, so I checked it again against main 7de4a00 (no #4143):
All three claims are still real on main without #4143, and this fix does not depend on #4143's queue turn gate. |
|
Hold lifted: the 0.5.5 Release run is complete, and the lead (t10k) asked to merge the ready PRs now. This PR does not depend on #4143's queue turn gate (re-checked on main without it, see the comment above). |
|
Merged through omo code review (1 MEDIUM, fixed) and Codex gpt-6.2-sol-fast xhigh via the team proxy (1 MEDIUM fixed; its HIGH is pre-existing on main) - findings and resolutions in the PR comment; CodeRabbit reviewed. Re-verified on main without #4143. Merged on the lead's (t10k) word after the 0.5.5 Release run: merge the ready PRs now. |
Summary
Follow-up to #4143 (#4118): three LOW findings a review of #4143 raised on
server/core/pending.ts, each replayed on main by the owner's review session, are fixed here, and each replay's fixed expectation is now a regression test inserver/core/pending-omp-start.test.ts.All three sit where a chat message sent at once (
delivery: "immediate") is queued instead, because the pane's first message still waits for a starting omp:askFirstMessage/holdRequested). If its page left meanwhile, it is refused withpending_lease_lost, the same as a frame that was ready on arrival. A page that stayed while its attach became ready is still queued.PendingRequestBook, as a queue request's already is, so a frame that arrives again is answered from that record. The record is looked up in the frame's own turn in the pane's lane, where the choice between queueing and typing is made, so a copy that arrived before the first one's turn is covered too. The shipped page never resends a frame; this closes the edge for any other client.submit_timeout, as the queue request and the plain send beside it do.submit_timeout. Once anything is typed, the rest of the message and its Enter go. On an OpenCode message with skills, a write counts as typed only once its guard lets it go, ascomposer.tscounts it.Nothing typed is ever sent automatically after a disconnect, and nothing here types a message twice or reports "nothing was typed" for one that was typed.
Validation
pending-birth-guard.test.ts). Each fails without its fix.bun test server/core/pending-birth-guard.test.ts server/core/pending-omp-start.test.ts: 118 pass.bun run typecheck: clean.server/core/pending*.test.ts,server/pending*.test.ts,server/core/composer*.test.ts) pass.pending-input.contract.test.ts's "refuses a queued message arriving once Claude is idle" is flaky on main too: main's code went pass, pass, fail over three runs, and this branch went pass ×3.bun run check fastpassed on 4d0087a (on old-desktop throughdori heavy): workflow syntax, generated files, typecheck, build and unit tests all ok.