Skip to content

fix(pending): hold a message whose page left mid-send or before it was listed - #4106

Merged
devswha merged 1 commit into
mainfrom
fix/pending-lease-findings
Nov 18, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/pending-lease-findings

Conversation

@devswha

@devswha devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner

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

  1. 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 PendingInputs.hold had marked on its way. Nothing was typed (the next attempt failed with pending_lease_lost), but until the next turn's end the row said it still waited. It is now held with the reason hold gave. Only a connection's own message is affected; a first message's retry is as before.
  2. A first message was typed on its own although its page had left since the request. 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, in between got its message typed later: nothing was listed yet for holdRequested to hold.
  3. The same during the launch. The create routes called queueFirstMessage only 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. 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. 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) and SKILL.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.ts against the isolated test herdr: 133 pass, 1 fail. The failure is sends over Claude's grey suggestion while the viewport is scrolled into the history, an immediate send through submitText, which this PR does not touch. It passed in the run before the last change and 3 of 3 times alone afterwards.
  • Each new test was run against the code without its fix and fails there: 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, sends role observe then interact over the real socket, and expects the create answer to say held.
  • The model: PendingLease.cfg and the six broken-* configs through pstack /statechart (TLC 1.7.4). A scratch change that removed the authority delete from holdPending was caught by following the skill, and the path it reported typed the message on the real code.
  • Not run: bun run check full, browser regressions (no UI change), Windows and macOS jobs.

Review

Two adversarial passes by Codex gpt-6.2-astra on the local commit before this push; the findings and what became of each are in the first comment.

Not changed, listed for later

  • A first message whose page is already gone is published as queued and then as held, in two frames.
  • A queue request typed at once behind an omp whose startup window ends between two reads can be queued without a second lease check. Nothing is typed.
  • A message sent at once that is queued after all behind a starting omp takes its lease in the pane's lane, not when its frame comes.
  • A switch to watching and back while the server still reads the create request's body is not seen: the request counts from when the route has read it.

🤖 Generated with Claude Code

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

devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Adversarial review: Codex gpt-6.2-astra, two passes, before the push

Run read-only on the local commit (codex exec -s read-only). Each finding was checked in the code before anything was changed.

Pass 1, on the first version (hold in queueFirstMessage only)

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.

@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
    • Pending messages are held for Send if the originating page leaves or stops attending before delivery, instead of being sent unexpectedly.
    • A workspace’s first message is held when its requesting page or pane becomes unavailable during creation or launch.
  • Tests
    • Added coverage for message handling across page, pane, and agent-launch lifecycle changes.
  • Documentation
    • Added guidance and a model for checking pending-message lease behavior.

The change tracks first-message requests across workspace creation and pending delivery. It also adds tests for lease-related timing cases, a TLA+ model of message and connection behavior, and tools for checking the model against covered server files.

Changes: Pending Message Lease Handling

Layer / File(s) Summary
First-message request flow
server/pending-input.ts, server/workspace-routes.ts, server/dispatch.ts, server/core/server-core.ts, server/workspace-routes.test.ts, server/pending-input.contract.test.ts
Workspace routes create a first-message ask before workspace creation, bind it to the root pane, and queue the message after agent launch. Tests check request ordering and verify that a requester who leaves during launch has the message held as unattended.
Pending-message lease and fault tracking
server/core/pending.ts, server/core/pending-left-lease.test.ts, changelog.d/pending-left-lease.md
Pending delivery records requester departures and pane faults before a first message is listed. Queueing applies those events to the message, and retry handling preserves a lease-loss error. Tests cover queued messages and first messages across departure, pane restart, and ended-pane cases.
Lease model and verification tools
.claude/skills/verify-pending-lease/PendingLease.tla, .claude/skills/verify-pending-lease/PendingLease.cfg, .claude/skills/verify-pending-lease/broken-*.cfg, .claude/skills/verify-pending-lease/SKILL.md, .claude/skills/verify-pending-lease/covered.*, .claude/skills/verify-pending-lease/view.ts
The TLA+ model represents connection, attachment, lease, queue, and send actions, and defines safety properties. TLC configurations check the properties and broken variants. The skill guide, coverage tracker, and state formatter support model verification.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Suggested reviewers: jpcarranza94

Merge Risk: Minimal · up to 0fb63

The change holds a pending message whose sender's page left mid-send or before the message was listed, instead of typing it automatically. No blocking issue was found in the supplied changes. The only remaining open items are documented limitations and unrun full CI jobs, which are normal pre-merge checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a fix to pending-message handling that holds a message when its page leaves mid-send or before the message is listed. The changeset matches this, covering the deferred…
Description check Passed The description follows the template's two required sections. The Change section explains the problem, the three fixed orders, and the resulting behavior, and the Validation section lists the commands…
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: a fix to pending-message handling that holds a message when its page leaves mid-send or before the message is listed. The changeset matches this, covering the deferred-send hold in server/core/pending.ts and first-message ask tracking in the workspace routes. The title is specific and does not include a file list or vague terms.

Full details: Description check

Explanation

The description follows the template's two required sections. The Change section explains the problem, the three fixed orders, and the resulting behavior, and the Validation section lists the commands run, their results, and what was skipped, including the one failing contract test. The description includes an extra Added and Review section and does not link an issue, which the template asks for only for features. The new skill is a feature-like addition, so a linked issue could be expected, but the repository's template wording makes that optional.

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 4954078 and 0fb633c.

Files selected for processing: 21

  • .claude/skills/verify-pending-lease/PendingLease.cfg
  • .claude/skills/verify-pending-lease/PendingLease.tla
  • .claude/skills/verify-pending-lease/SKILL.md
  • .claude/skills/verify-pending-lease/broken-keep-authority.cfg
  • .claude/skills/verify-pending-lease/broken-keep-requester.cfg
  • .claude/skills/verify-pending-lease/broken-list-after-leave.cfg
  • .claude/skills/verify-pending-lease/broken-no-hold-on-leave.cfg
  • .claude/skills/verify-pending-lease/broken-requeue-lost-lease.cfg
  • .claude/skills/verify-pending-lease/broken-retry-after-typing.cfg
  • .claude/skills/verify-pending-lease/covered.blobs
  • .claude/skills/verify-pending-lease/covered.sh
  • .claude/skills/verify-pending-lease/view.ts
  • changelog.d/pending-left-lease.md
  • server/core/pending-left-lease.test.ts
  • server/core/pending.ts
  • server/core/server-core.ts
  • server/dispatch.ts
  • server/pending-input.contract.test.ts
  • server/pending-input.ts
  • server/workspace-routes.test.ts
  • server/workspace-routes.ts

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

@devswha
devswha merged commit 7c8999f into main Nov 18, 2026
24 checks passed
@devswha
devswha deleted the fix/pending-lease-findings branch November 18, 2026 04:58
@devswha

devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

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 0fb633ca0, without --admin.

What stood behind the merge at that head:

  • Required checks green on GitHub (Fast checks, Integration and browser, Native Windows install, Hook kill tests).
  • CodeRabbit reviewed it: no actionable comments, no threads.
  • Codex gpt-6.1-terra (xhigh), fresh checkout, the merge pass's review brief: no findings, CLEAR. It could not install dependencies in its sandbox, so it ran only server/pending-input.test.ts.
  • The two Codex gpt-6.2-astra passes before the push, in the comment above.
  • A fresh Opus review of the same head was still running at the merge; its findings, if any, follow here and are fixed forward.

@devswha

devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

The Opus review of head 0fb633ca0 finished after the merge: CLEAR, two LOW findings, both reproduced by the reviewer and neither typing anything.

  • A pane that ends while queueFirstMessage reads the launched process's start still gets its first message listed, held as pane_not_found, and that record is never discarded. Fixed in the follow-up PR linked below, with a test.
  • The dispatchPending change also holds a queued message on its way when the pane's attach restarts, not only when its sender leaves. Same end state as before, one step sooner. The changelog entry is corrected in the same follow-up.

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

devswha added a commit that referenced this pull request Nov 18, 2026
…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]>
devswha added a commit that referenced this pull request Nov 18, 2026
…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]>
devswha added a commit that referenced this pull request Nov 18, 2026
#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]>
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