Skip to content

fix(pending): close four edges of a chat message queued behind a starting omp - #4157

Merged
devswha merged 1 commit into
mainfrom
fix/pending-lows
Nov 19, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/pending-lows

Conversation

@devswha

@devswha devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner

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 in server/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:

  1. A page that left the pane and came back while its frame waited. fix(pending): keep the queue out of the turn before it, keep same-text held messages apart, and re-read a typed answer before its Enter #4143 took the lease as the frame arrives, so such a page's frame was refused. A frame whose pane was not ready yet as it came still took its lease in the pane's lane, so it was queued under the page's new attach. Such a frame is now noted on its way with the mechanism a create request's first message uses (askFirstMessage / holdRequested). If its page left meanwhile, it is refused with pending_lease_lost, the same as a frame that was ready on arrival. A page that stayed while its attach became ready is still queued.
  2. The same frame arriving twice. That branch kept no record of the frame's id, so the frame arriving again after its message was discarded or sent made a second row, typed at its turn. The queued reply is now recorded in the connection's 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.
  3. The 45 s submit deadline.
    • The branch asked no deadline before it queued, so a frame that waited past the deadline in the lane was accepted. It now answers submit_timeout, as the queue request and the plain send beside it do.
    • 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 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, as composer.ts counts 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

  • The six replay tests, now with their fixed expectations, fail on main's code and pass with the fix. The two tests that bound the fix pass on both:
    • a page that was ready as its frame came, then left and came back, is refused;
    • a page that stayed while its attach became ready is queued.
  • Two more tests come from the reviews: a copy of the frame that arrives before the first copy's turn while omp reports in between, and the skills path's deadline (in 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.
  • The pending suites (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 fast passed on 4d0087a (on old-desktop through dori heavy): workflow syntax, generated files, typecheck, build and unit tests all ok.
  • Reviews: omo code review, and Codex gpt-6.2-sol-fast at xhigh through the team proxy. The findings and how each was resolved are in a PR comment.

…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]>
@devswha

devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Review findings and how each was resolved

Two reviews ran before this PR was opened.

omo code review (Claude Opus 5.5) of the first version

Verdict: APPROVE, with nothing HIGH.

  • MEDIUM, fixed. A frame that arrives again before the first copy's turn in the pane's lane could still be typed twice. The record lookup ran only on arrival, and omp could report between the two turns. The lookup now runs inside the frame's own turn, where the choice between queueing and typing is made. Test: "types once a chat message sent at once whose frame comes again before its turn, when omp reports between the two". It fails against the first version and passes now.
  • LOW, kept. The paste-deadline test's mock re-implements herdrRpc's guard contract: ask the guard once connected, throw cancelled. The skills path had no deadline test; it has one now, from the Codex finding below.
  • LOW, kept. The harness's eventually polls. That comes from the existing harness, and it is needed because the production omp wait polls on real timers.
  • LOW, fixed. The commit title said three edges where the body lists four.

Codex review (gpt-6.2-sol-fast, xhigh, through the team proxy) of the second version

  • HIGH, not introduced here and not part of this change. "A waiting message can send after its socket closes."
    • This is the plain send-at-once path, submitText in composer.ts, which this PR leaves unchanged. A scratch test shows main does the same for any send-at-once frame that waits in the pane's lane, with or without omp.
    • The page settles a send that a disconnect cut short as disconnected: "Not confirmed: the pane did not confirm this message. Check the terminal before sending it again" (src/lib/compose.ts:169). So the send the user made before the drop is the documented uncertain case. It is not a draft or a queued message sent automatically after a disconnect.
    • Queued and held messages are unchanged: they still need a live lease.
  • MEDIUM, fixed. On an OpenCode message with skills, typeWithSkills asks its guard before any write. That check counted as typed, so the new deadline check was skipped for the real first write. A write now counts as typed only once its guard lets it go, as composer.ts counts it. Test: "types no OpenCode skill once the deadline passed while the first write's herdr connection opened" in pending-birth-guard.test.ts. It fails without the fix and passes with it.
  • MEDIUM, kept. A receipt pushed out of the connection's 256-entry request book lets the same frame be typed again. That needs a client that replays an old frame after 256 newer requests on the same socket.
    • The shipped page never replays a frame (src/lib/ws.ts submitRequest).
    • A send-at-once frame that was never queued has no receipt at all on main.
    • So this degrades to main's behaviour for every send-at-once frame.
  • LOW, kept. A deadline that passes during a partial socket write of the paste request reports submit_changed rather than submit_timeout. That is herdrRpc's existing reading of a guard refusal partway through a write, and the lease guard already hits it the same way.
  • LOW, kept. A replayed send-at-once frame whose queued row was discarded is answered ok: true without pending, after the row's discard outcome is published. That is the shape the queue branch already gives a replay. Answering it differently would need a new WS error code, which is a contract change. The shipped page never replays a frame.

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.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Prevented messages from being queued or typed after their send deadline, including when the page leaves and returns while an agent is starting.
    • Prevented duplicate requests from re-sending messages or restoring messages that were discarded.
    • Messages that cannot be sent before the deadline are now reported as not sent.

Pending message delivery now tracks repeated submit frames and page leases while a submission waits during OMP startup. Skill and paste writes also check the submit deadline, including when a paste connection opens after the deadline.

Changes: Pending message delivery

Layer / File(s) Summary
Submit tracking and startup queue
server/core/pending.ts, server/pending-requests.ts, server/core/pending-omp-start.test.ts
Submit frames use fingerprints and recorded replies to avoid duplicate queueing or typing. Queued submissions track page leases, and startup-wait handling checks whether the page left and whether the deadline expired. Tests cover duplicate frames, page changes, and queued outcomes.
Deadline-guarded writes
server/core/pending.ts, server/core/pending-birth-guard.test.ts, server/core/pending-omp-start.test.ts, changelog.d/pending-omp-start-edges.md
Skill and paste writes check authorization and the submit deadline. Tests cover deadline expiry before a guarded write, while a paste connection opens, and while a submission waits in the lane. The changelog records these delivery cases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: jpcarranza94, jimbb

Merge Risk: Minimal · up to 4d008

This change tightens how chat messages queued behind a starting agent are handled. It refuses messages after the page leaves or the send deadline passes, and it avoids retyping duplicate frames. No merge-blocking risk was found. One rare replay edge case is already documented by the author.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: fixing four edge cases for a chat message queued behind a starting omp in the pending delivery path. The raw summary and objectives confirm the changes cover these edg…
Description check Passed The description follows the template's two required sections. The Change section explains the three problem areas and their fixes, covering the lease, duplicate frames, and the 45 s submit deadline. T…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: fixing four edge cases for a chat message queued behind a starting omp in the pending delivery path. The raw summary and objectives confirm the changes cover these edges: lease loss on page leave, duplicate frames answered from the request book, submit deadline checks, and the paste write deadline. The title is specific and accurate, though the phrase "four edges" is terse and relies on context.

Full details: Description check

Explanation

The description follows the template's two required sections. The Change section explains the three problem areas and their fixes, covering the lease, duplicate frames, and the 45 s submit deadline. The Validation section lists the commands run, the test counts, and the results, including flaky-test notes. It does not link an issue, but the template only asks for one for features, and this is a fix. It also does not mention the contract-test coverage the template asks for on HTTP/WS changes. The changes touch the pending delivery path, which may use WS frames, so that gap is minor but worth a check. The changelog reference is also absent from the description, though the raw summary shows a changelog.d entry exists.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 288f732 and 4d0087a.

Files selected for processing: 5

  • changelog.d/pending-omp-start-edges.md
  • server/core/pending-birth-guard.test.ts
  • server/core/pending-omp-start.test.ts
  • server/core/pending.ts
  • server/pending-requests.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@devswha

devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

On hold: #4158 reverts #4143, whose turn gate made main's pending-input contract tests flaky under load (runs 44338954162, 44342237591). This PR builds on the code #4143 added in server/core/pending.ts. It is reworked against main once the gate is fixed and re-landed.

@devswha devswha added the hold Not merged until the owner says so label Nov 18, 2026
devswha added a commit that referenced this pull request Nov 18, 2026
…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]>
@devswha

devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Re-checked on today's main, after #4158 reverted #4143

This branch was built on #4143, and its CI ran before the revert, so I checked it again against main 7de4a00 (no #4143):

  • git merge-tree of this PR onto main: clean. Of changelog.d/, only README.md and this PR's own fragment remain, so none of the fragments the 0.5.5 release folded into CHANGELOG.md come back.
  • Main with this PR merged: typecheck ok. server/core/pending-omp-start.test.ts 76 pass, server/core/pending.test.ts 79, server/pending-requests.test.ts 4, server/pending-input.test.ts 63.
  • This PR's pending-omp-start.test.ts against main's code without the fix: 7 fail (claim 1: 1, claim 2: 3, claim 3: 3).

All three claims are still real on main without #4143, and this fix does not depend on #4143's queue turn gate.

@devswha

devswha commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

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).

@devswha devswha removed the hold Not merged until the owner says so label Nov 19, 2026
@devswha
devswha merged commit 80f3b17 into main Nov 19, 2026
23 checks passed
@devswha
devswha deleted the fix/pending-lows branch November 19, 2026 05:28
@devswha

devswha commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head 4d0087a28. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit reviewed this head.

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.

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