Repository navigation
fix(pending): hold a message whose page left mid-send or before it was listed - #4106
Conversation
…s listed Three orders of events that a TLA+ model of the pending-message lease, and a review of the first fix, found and the tests had not reached: - A queued message whose sender left the pane during its automatic send went back to "queued" when that send was only put off (agent_blocked): dispatchPending retried whatever hold() had marked on its way. Nothing was typed, but the row said it still waited. It is now held with the reason hold() gave. - queueFirstMessage looked its page up, awaited herdr, and then listed the message as queued while asking only whether the page was still connected. A page that switched to watching and back, or opened the pane and left it, during those awaits got its first message typed on its own later. - The create routes called queueFirstMessage only after the workspace was made and the agent launched, which may take a minute: the same could happen during all of it. The create routes now take the request first (askFirstMessage), before the pane is made. holdRequested and holdPendingPane mark a request that is not listed yet, and its message is then listed held: for a page that left or stopped typing, and for a pane whose terminal restarted. A pane that ended meanwhile gets no message. The model, its configs and a project skill that says when and how to run it are in .claude/skills/verify-pending-lease. Each rule has a config that breaks the code it guards. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Adversarial review: Codex
|
| Finding | Severity | Outcome |
|---|---|---|
| First-message tracking started only after the agent launch: a page that switched to watching and back during it still got its message typed | High | Fixed. askFirstMessage is taken by the create routes before the pane is made. Contract test at the route with the launch held; it fails with the route as it was. |
Pane-wide holds (holdPendingPane) missed a request not listed yet: an attach restart during the lookup, or a pane that ended |
Medium | Fixed. The fault is kept on the request: listed held with it, or no message for a pane that ended. Unit tests. |
| A first message whose page is gone is published queued, then held | Low | Not changed (it was so before). Listed in the PR. |
| The "opened the pane and left it" test never opened the pane | Low | Fixed. |
The model's Init assumed the result of the race it claimed to check |
High | Fixed. The model starts at the request; FirstListed lists the message from what holdRequested and holdPendingPane recorded, and the rule is stated on the page not having left since the request. |
| An immediate submit that turns into a queued one takes its lease in the lane | Medium | Not changed: a message sent at once is outside this check. Listed in SKILL.md and the PR. |
TypeNowWaits requires a lease check the code can skip for omp at a 1 ms boundary |
Medium | Not changed: nothing is typed, only the row. Listed in SKILL.md and the PR. |
Attach merges claim and membership |
Medium | Not changed in the model; SKILL.md says what that folds together and why no hold is lost. |
covered.sh --record could leave a corrupt record; check mode wrote objects |
Medium, Low | Fixed. |
| The drift check left out helpers that make guarded writes | Medium | Fixed. composer.ts, opencode-skill-attach.ts and workspace-routes.ts are covered. |
| Three promises worded too widely | Low | Fixed in SKILL.md and the changelog fragment. |
The first fix (no re-queue after a lost lease) and its test were checked and found correct.
Pass 2, on the version with askFirstMessage
| Finding | Severity | Outcome |
|---|---|---|
| A page could attach and leave the new pane before the route learned its id (herdr may tell of the pane before its create call answers) | High | Fixed. A request without a pane yet keeps what happens to each pane and counts it at at(). Unit tests, failing without it. |
| A switch to watching and back while the request's body is still being read is not seen | High | Not changed. The request counts from when the route has read it; the body read is under a millisecond and the order is not one a person can produce. Listed in the PR and SKILL.md. |
| A later attach fault could overwrite a pane's end | Medium | Fixed. A pane's end is kept, and checked before and after the lookup. Unit test. |
The route test passed with ask() after the create call |
Low | Fixed, and checked: it now fails with the route asking after create. |
covered.sh --record went on after a failed write |
Low | Fixed. |
Checked and found correct in pass 2: holds are scoped to the right page and pane once the pane is known; concurrent and retried create requests get their own request objects; no leak in asking on any exit of the route; queueFirstMessage called with a plain id behaves as before apart from the new holds.
The fixes of pass 2 were not reviewed a third time; they are covered by the tests named above.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
|
Merged by the session that opened it, on the maintainer's word ("you do it", then his choice to go past the local merge guard for this one merge), not by the merge pass. Squash-merged at the reviewed head What stood behind the merge at that head:
|
|
The Opus review of head
It also ran the new tests (46 of 46), mutated each fix to see its tests fail, and checked the route's exits for leaks in |
…last read (#4107) ## What Follow-up to #4106, from the Opus review of its head that was still running when it merged. Two LOW findings, both reproduced by the reviewer; nothing was typed in either. 1. **A pane that ended during the last read still got its first message listed.** `queueFirstMessage` checked for an ended pane before reading the launched process's start (`processStartedAtAsync`), which is awaited when herdr does not show that process in front yet. A pane that ended during that read had its message listed after all, held as `pane_not_found`. `holdPendingPane` had already run with nothing to discard, so the record stayed until the server restarted, and the create answer said `held: "pane_not_found"`. The check now comes after the last await, so the request is refused as #4106 said it would be. 2. **#4106 did not say that an attach restart is held too.** Its `dispatchPending` change holds a queued message on its way whenever `hold()` marked it, which `holdPendingPane` also does on an attach restart. The end state is the same as before (held, nothing typed), one step sooner. No code change: the changelog entry now names it. `.claude/skills/verify-pending-lease/covered.blobs` is recorded again for the changed `pending.ts`. The model is unchanged: it does not cover a pane that ends (listed under "Not covered" in the skill), and the change touches nothing else. ## Validation - `bun run check fast`: green (unit: 18,613 pass, 0 fail). - The new test in `server/core/pending-left-lease.test.ts` holds the read of the launched process's start, ends the pane, and expects the request to be refused with nothing listed. It fails on `main` and passes here. - Not run: contract tests, browser regressions (no UI change), `check full`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.2 <[email protected]>
…4109) ## What The small gaps that the reviews of #4106 found and that PR listed for later, each with a test that fails without its fix. Nothing was typed into a terminal in any of them except the third. 1. **A first message nobody will send on its own was listed as queued, then as held.** Other pages attached to its pane saw it as waiting for a moment. `PendingInputs.enqueue` takes the reason and lists the message held at once. 2. **A queue request typed at once could be queued without a check.** When omp's start ran out before the wait's first poll, the wait's last process read came after its last check, and the `pending_wait` that followed queued the message for a page that had left, or past its deadline. The wait's own check (lease, discard, deadline) is made once more after the wait. 3. **A chat message sent at once, then queued behind a starting omp, took its lease in the pane's lane.** A page that left the pane and came back while its frame waited there got a new lease, and the message was sent on its own later. The lease is now the one taken as the frame comes. The verify-pending-lease skill drops the assumption and the "not covered" lines these were (its model is unchanged), and says of a held copy's resend (`resend_id`) that it is a present user's own send under `authorizeSocket`, by design. AGENTS.md: one line of #4108 rewrapped. ## Validation - `bun run check fast`: green. - `bun test server/pending-input.contract.test.ts server/opencode-first-message.contract.test.ts` against the isolated test herdr: 134 pass, 0 fail (run before the last two small fixes below; the unit tests ran after them). - Each new test fails with its fix taken out: `server/core/pending-left-lease.test.ts` (two), `server/core/pending-omp-start.test.ts` (three cases). - Not run: `check full`, browser regressions (no UI change). ## Review Codex `gpt-6.2-astra`, read-only, on the commit before this push: CLEAR, two mediums and one low, all three taken: - a requester that closes as it is told of the first listing stayed registered (a regression of fix 1): asked about again after the listing, with a test; - discard and the deadline were not checked after omp's last process read (older than this PR): fix 2 now repeats the wait's whole check, with a test for the deadline; - the skill overstated what `Submit` stands for: its text says which immediate sends it covers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.2 <[email protected]>
#4117) ## What A second project verification skill, `.claude/skills/verify-turn-gate`, beside `verify-pending-lease` (#4106). It checks the chat queue's turn gate: once the queue has typed a message and its Enter, it gives out no further message of that pane until statuses that came after that Enter have shown the turn to start and to finish. A break types the next queued message into the turn the previous one started, where the agent takes it as a mid-turn steer or merges it into the wrong turn. No product code changes. - `explore.ts`: a breadth-first explorer that uses the real `PendingInputs` class (`server/pending-input.ts`) as its step function. Every step calls the class's own methods; states are deduplicated by its saved fields. The callers' order of calls and their `await` points, the agent and herdr are described beside it, and `SKILL.md` maps each described step to its code. - `check.ts`: 22 runs, about two and a half to four minutes: 7 that must hold, 7 edited copies of the class that must each break their rule, 5 findings and 3 known limits that must break. - `covered.sh` / `covered.blobs`: the covered files by git blob id, as in `verify-pending-lease`. - `SKILL.md`: when a change touches the gate, how to run the check, how to tell a real bug from a wrong check, what to update on an intended change, what it assumes and what it leaves out. Why not TLA+ this time: the class is synchronous and has no I/O, so a model would be a second implementation to keep in step with it. The explorer runs the class itself. ## What it found Five orders in today's code, none fixed here. Each was replayed on the real code with herdr faked (`createPendingDelivery`, `PendingInputs`, `interruptCodexSteering`; the real collector and status hub handlers for the fourth). None was observed on a live herdr; all need a narrow timing. 1. **A Send now as the turn ends.** The last read before the Enter says working, so the gate waits for a ready status alone. The turn has ended when the Enter lands, the ended turn's ready completes the gate, and the next queued message is typed as the Send now's own turn begins (`X, Enter, Y, Enter`). 2. **Status events that arrive late.** A snapshot can answer ahead of events herdr sent before it. The old turn's `working` and `idle` events, applied after the next Enter, pass for the new turn. 3. **A second Send now during a Codex restart.** It replaces the restart gate (ready, work, ready) with one that waits for ready alone; the interruption's ready completes it and a third message is typed. 4. **An older ready snapshot told as a baseline.** A collector reconcile tells the queue a ready reading taken before the turn's `working` event. The queue is offered the next message early; in the explored space no key follows, because the send re-reads the pane at work. 5. **A message sent to the queue right behind the queue's Enter** is typed at once: that submit asks `pending.waiting`, not the gate. The user did press Send for it. The main runs hold only with these five left out; `SKILL.md` says how to fold each back in once it is fixed. ## Not covered Whether the status told is right (`CompletionTracker`, `restingClaude`, `queueStatus`), first messages, omp's start, agent-only messages, Grok's second Enter, `close`, several panes, liveness. Three limits of status evidence are shown as runs that break: an Enter that lands long after `committing`, an Enter the agent keeps in its own queue past the turn's end, and a turn something else starts. ## Validation - `bun .claude/skills/verify-turn-gate/check.ts`: 22 lines `ok`, exit 0 (run twice, by the session that built it and again by the session that opened this PR). - The skill was followed once on a scratch break of the real code (`hold()` made to delete the gate): `covered.sh` flagged the file, the check exited 1 with five runs `WRONG` and a path, and that path played on the class offered the next message. After `git checkout` it was back to all `ok`. - The five findings: 7 replay tests on the real code pass today, which is the bad outcome (kept outside the repo: they assert the bug). - `covered.sh` after the rebase onto main: no covered file changed. - `bun run check fast`: passed on this head. - Review: one read-only Codex pass on the tree before the last round of changes; its points and what was done with each are in the session's report (the older-baseline and queue-send findings came from it). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <[email protected]>
What
A pending chat message (queued for the agent's next turn, held for Send now, or a new workspace's first message) may be typed only while the page it waits on is still attached to the pane and may still type. A TLA+ model of that lease, checked with TLC over every order of events, and an adversarial review of the first fix found three orders the tests had not reached. This PR fixes them and adds the model as a project skill.
Fixed
queuedwhen that send was only put off (agent_blocked).dispatchPendingretried whateverPendingInputs.holdhad marked on its way. Nothing was typed (the next attempt failed withpending_lease_lost), but until the next turn's end the row said it still waited. It is now held with the reasonholdgave. Only a connection's own message is affected; a first message's retry is as before.queueFirstMessagelooked its page up, awaited herdr, and then listed the message as queued while asking only whether the page was still connected. A page that switched to watching and back, or opened the pane and left it, in between got its message typed later: nothing was listed yet forholdRequestedto hold.queueFirstMessageonly after the workspace was made and the agent launched, which may take a minute.The create routes now take the request first (
askFirstMessage), before the pane is made.holdRequestedandholdPendingPanemark a request that is not listed yet, and its message is then listed held: for a page that left or stopped typing, and for a pane whose terminal restarted. What happens to a pane before the route learns which pane herdr made is kept and counted once it does. A pane that ended meanwhile gets no message.Added
.claude/skills/verify-pending-lease/: the model (PendingLease.tla), its TLC configs, a view that puts the result in plain words,covered.sh(lists covered files that changed since the model was last confirmed, by git blob id, so a squash merge keeps the record) andSKILL.md, which says when a change is covered, how to run the check, how to tell a real bug from a wrong model, and what the model leaves out.Five rules hold on this branch over 1,182,451 states (about 80 s): nothing is typed after the lease is lost; a first message is typed on its own only by its page, and not once that page has left since the request; a message is pasted and entered once; a first message whose page left is held; a queued message whose sender left is held. Six
broken-*configs each undo one piece of the code in the model and break the rule that guards it, two of them the fixes above.Validation
bun run check fast: green (unit: 18,612 pass, 0 fail).bun test server/pending-input.contract.test.ts server/opencode-first-message.contract.test.tsagainst the isolated test herdr: 133 pass, 1 fail. The failure issends over Claude's grey suggestion while the viewport is scrolled into the history, an immediate send throughsubmitText, which this PR does not touch. It passed in the run before the last change and 3 of 3 times alone afterwards.server/core/pending-left-lease.test.ts(the three orders, the pane not yet known, an attach restart, an ended pane, and controls that must still be typed),server/workspace-routes.test.ts(the request is taken before the pane is made), and one contract test that holds the stand-in launch, sendsroleobserve then interact over the real socket, and expects the create answer to say held.PendingLease.cfgand the sixbroken-*configs through pstack/statechart(TLC 1.7.4). A scratch change that removed the authority delete fromholdPendingwas caught by following the skill, and the path it reported typed the message on the real code.bun run check full, browser regressions (no UI change), Windows and macOS jobs.Review
Two adversarial passes by Codex
gpt-6.2-astraon the local commit before this push; the findings and what became of each are in the first comment.Not changed, listed for later
🤖 Generated with Claude Code