Repository navigation
feat(gateway): chat.send expectedLeafEntryId precondition keeps stale panes off switched branches - #113073
Merged
Conversation
steipete
marked this pull request as ready for review
July 23, 2026 15:57
steipete
force-pushed
the
claude/chat-send-expected-leaf
branch
from
July 23, 2026 19:04
85a20f4 to
f492663
Compare
… panes off switched branches
steipete
force-pushed
the
claude/chat-send-expected-leaf
branch
from
July 23, 2026 19:21
f492663 to
459272c
Compare
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jul 24, 2026
… panes off switched branches (openclaw#113073)
obviyus
added a commit
that referenced
this pull request
Nov 16, 2026
… and stop refusing on captured ids (#200191) ## What Problem This Solves Work was stopped by inference: a check captured an id that changes on its own (a transcript id, lifecycle revision, run id, generation or displayed leaf), and later treated "it changed" as "it was revoked". Users saw: - A message queued in Control UI during a turn was refused as "switched branches" once the turn ended. The sender's leaf was one entry behind the new reply, and a send without a session id needed an exact leaf match. - `sessions_send` to a task session was refused with "Task resume differs from the captured communication owner." after the task moved to a new run (exec wake, yield, follow-up) or was compacted. - A requester-wake failure notice for a lost subagent batch was pinned to the requester's old transcript and refused as `session-rebound` after a reset or compaction successor. - Deleting a chat left its queued outbound replies in the durable queue, so a chat recreated with the same key could receive them. - Every delivery, queue, wake and session-event API took a `SessionDeliveryGeneration` with a transcript id and revision, so any new caller could pin a chat to an id again. ## Why This Change Was Made Make the bad state hard to express and guard the rest: - **`ChatRef`** (`src/sessions/chat-ref.ts`) is the only durable chat address: agent id, store path and session key, branded. `chatRef()` copies only the address, so ids in rows queued by older builds never travel with it. Delivery, queue, wake, cron delivery, memory audience and session-event APIs take a `ChatRef`. `SessionDeliveryGeneration` and `SessionGenerationFacts` are deleted. - **`TranscriptLease`** (`src/config/sessions/transcript-lease.ts`) is the only way to hold one transcript. Live writers (cron root, fork, subagent control, restart resume, a scheduled occurrence) acquire it with a private pin. It refuses to serialise. - **One prefix rule for sends:** a send is admitted while the sender's leaf is on the active path; an empty view is a prefix of every path. A rewind, branch switch or reset away from the leaf still refuses it (#113073 holds). Deleted: the exact-match branch, `activePathNavigationMoved` and its reader, the send's own session-id fence, and the test-only relation reader. `activePathRelation` becomes `onActivePath`. - **Task sends follow the chat:** `sessions_send` continues the task's current run. The `previousRunId` / `generation` / `childSessionId` compares, the retained-task pins and the target-incarnation compare are deleted. It refuses only when the task ended or was cancelled, the chat was deleted, or another session controls the task. - **Lost-run notice by key**, and **delete purges queued sends** (a send that already started stays with its recovery owner). - **Guard:** `check:session-identity-ratchet` counts, per file outside `src/config/sessions/`, any `===`/`!==` on a session id, run id, generation, lifecycle revision or leaf id, the `expectedSessionId` / `expectedLifecycleRevision` pin names, and refusal strings ("differs from the captured", "no longer active", "changed before", "was replaced"). Existing hits are listed in `config/session-identity-allowlist.txt`, which may only shrink. Kept on purpose: - **Typed Stop** keeps its incarnation fence (an empty view must still be empty, and the session id must match), so a Stop never cancels work that started after it. It moves to a recorded stop cause in the next change. - **Memory grants** hold the incarnation they were minted in through a transcript lease: a reset revokes the grant, a compaction successor keeps it. This is the narrower authority and matches the memory audience's own tests. - Knowledge partitions, the deep-research job store and GitHub publication rows key on transcript ids in stored rows; changing them needs a data migration and is left for a separate decision. Production code (`src`, `extensions`, without tests): +524 / −602. ## User Impact - A message queued during a turn is sent when the turn ends. - A pane that still shows a branch another client switched away from is still refused, and the message is parked as not sent. - A send to a task session reaches its current run after wakes, yields and compaction; a send to a cancelled task is refused with a reason. - Deleting a chat drops its unsent queued replies. - Rows queued by older builds still deliver. A row queued by this build and replayed by an older build has no transcript id; the older build treats it as unavailable and retries it until its retry budget ends. ## Evidence Base = merge base `edbc5bcea9b6`, head = this PR. | Journey | Tier | Base | Head | |---|---|---|---| | Control UI: queue a message during a held turn, release the turn (send carries only the displayed leaf) | Control UI E2E, real Gateway, scripted provider (`ui/src/e2e/chat-send-leaf-ancestor.real-gateway.e2e.test.ts`) | `chat.send` ok=false, message parked "Not sent" | `chat.send` ok=true, reply "Flag mentioned." | | Control UI: pane still shows Plan C, another client switches to the Plan B tip, pane sends | same | refused, no provider request | refused, no provider request | | Compaction successor while a background exec runs, then a next turn | `ocx src` scratch Gateway, real Claude model | exec wake lands in the successor transcript; next turn runs | same | | Queue an outbound reply, delete the chat, recreate the key | `ocx src` scratch Gateway | 1 queued reply still pending | 0 pending | | Reaction, then edit a later message | `ocx src` scratch Gateway | reaction still listed | reaction still listed | | Plant `entry.sessionId === saved` in a new file | `check:session-identity-ratchet` | — | fails: `src/sessions/chat-ref.ts: 1 > 0` | The task-send fix is proven by unit tests only: a send to an owned task after its run id and generation advanced, with a stale resume binding, is delivered (fails on base), and a send after the task is killed is refused. Real-Gateway journeys with a real Claude model (spawn a task, then send after an exec wake, after compaction, after cancel, or while the task is busy so the send is held and released) did not reproduce the refusal on base: base delivered in each. The live refusal needs the in-process resume binding of a retained self-hold replay, which these journeys do not reach. Gates: oxfmt, oxlint, `pnpm tsgo:core`, `tsgo:ui`, `tsgo:scripts`, `pnpm check:test-types`, and `ocx test` on the lease, session store, outbound queue, subagent registry, cron, memory audience, session events, chat send and Stop, `sessions_send`, restart resume and UI E2E inventory suites. `test/plugins/deep-research-routing.gateway.test.ts` fails the same way on `main` (CI run 43939332007, job 133553190527); this PR does not touch it. Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 17, 2026
… and stop refusing on captured ids (openclaw#200191) ## What Problem This Solves Work was stopped by inference: a check captured an id that changes on its own (a transcript id, lifecycle revision, run id, generation or displayed leaf), and later treated "it changed" as "it was revoked". Users saw: - A message queued in Control UI during a turn was refused as "switched branches" once the turn ended. The sender's leaf was one entry behind the new reply, and a send without a session id needed an exact leaf match. - `sessions_send` to a task session was refused with "Task resume differs from the captured communication owner." after the task moved to a new run (exec wake, yield, follow-up) or was compacted. - A requester-wake failure notice for a lost subagent batch was pinned to the requester's old transcript and refused as `session-rebound` after a reset or compaction successor. - Deleting a chat left its queued outbound replies in the durable queue, so a chat recreated with the same key could receive them. - Every delivery, queue, wake and session-event API took a `SessionDeliveryGeneration` with a transcript id and revision, so any new caller could pin a chat to an id again. ## Why This Change Was Made Make the bad state hard to express and guard the rest: - **`ChatRef`** (`src/sessions/chat-ref.ts`) is the only durable chat address: agent id, store path and session key, branded. `chatRef()` copies only the address, so ids in rows queued by older builds never travel with it. Delivery, queue, wake, cron delivery, memory audience and session-event APIs take a `ChatRef`. `SessionDeliveryGeneration` and `SessionGenerationFacts` are deleted. - **`TranscriptLease`** (`src/config/sessions/transcript-lease.ts`) is the only way to hold one transcript. Live writers (cron root, fork, subagent control, restart resume, a scheduled occurrence) acquire it with a private pin. It refuses to serialise. - **One prefix rule for sends:** a send is admitted while the sender's leaf is on the active path; an empty view is a prefix of every path. A rewind, branch switch or reset away from the leaf still refuses it (openclaw#113073 holds). Deleted: the exact-match branch, `activePathNavigationMoved` and its reader, the send's own session-id fence, and the test-only relation reader. `activePathRelation` becomes `onActivePath`. - **Task sends follow the chat:** `sessions_send` continues the task's current run. The `previousRunId` / `generation` / `childSessionId` compares, the retained-task pins and the target-incarnation compare are deleted. It refuses only when the task ended or was cancelled, the chat was deleted, or another session controls the task. - **Lost-run notice by key**, and **delete purges queued sends** (a send that already started stays with its recovery owner). - **Guard:** `check:session-identity-ratchet` counts, per file outside `src/config/sessions/`, any `===`/`!==` on a session id, run id, generation, lifecycle revision or leaf id, the `expectedSessionId` / `expectedLifecycleRevision` pin names, and refusal strings ("differs from the captured", "no longer active", "changed before", "was replaced"). Existing hits are listed in `config/session-identity-allowlist.txt`, which may only shrink. Kept on purpose: - **Typed Stop** keeps its incarnation fence (an empty view must still be empty, and the session id must match), so a Stop never cancels work that started after it. It moves to a recorded stop cause in the next change. - **Memory grants** hold the incarnation they were minted in through a transcript lease: a reset revokes the grant, a compaction successor keeps it. This is the narrower authority and matches the memory audience's own tests. - Knowledge partitions, the deep-research job store and GitHub publication rows key on transcript ids in stored rows; changing them needs a data migration and is left for a separate decision. Production code (`src`, `extensions`, without tests): +524 / −602. ## User Impact - A message queued during a turn is sent when the turn ends. - A pane that still shows a branch another client switched away from is still refused, and the message is parked as not sent. - A send to a task session reaches its current run after wakes, yields and compaction; a send to a cancelled task is refused with a reason. - Deleting a chat drops its unsent queued replies. - Rows queued by older builds still deliver. A row queued by this build and replayed by an older build has no transcript id; the older build treats it as unavailable and retries it until its retry budget ends. ## Evidence Base = merge base `2c94bae9c3ea`, head = this PR. | Journey | Tier | Base | Head | |---|---|---|---| | Control UI: queue a message during a held turn, release the turn (send carries only the displayed leaf) | Control UI E2E, real Gateway, scripted provider (`ui/src/e2e/chat-send-leaf-ancestor.real-gateway.e2e.test.ts`) | `chat.send` ok=false, message parked "Not sent" | `chat.send` ok=true, reply "Flag mentioned." | | Control UI: pane still shows Plan C, another client switches to the Plan B tip, pane sends | same | refused, no provider request | refused, no provider request | | Compaction successor while a background exec runs, then a next turn | `ocx src` scratch Gateway, real Claude model | exec wake lands in the successor transcript; next turn runs | same | | Queue an outbound reply, delete the chat, recreate the key | `ocx src` scratch Gateway | 1 queued reply still pending | 0 pending | | Reaction, then edit a later message | `ocx src` scratch Gateway | reaction still listed | reaction still listed | | Plant `entry.sessionId === saved` in a new file | `check:session-identity-ratchet` | — | fails: `src/sessions/chat-ref.ts: 1 > 0` | The task-send fix is proven by unit tests only: a send to an owned task after its run id and generation advanced, with a stale resume binding, is delivered (fails on base), and a send after the task is killed is refused. Real-Gateway journeys with a real Claude model (spawn a task, then send after an exec wake, after compaction, after cancel, or while the task is busy so the send is held and released) did not reproduce the refusal on base: base delivered in each. The live refusal needs the in-process resume binding of a retained self-hold replay, which these journeys do not reach. Gates: oxfmt, oxlint, `pnpm tsgo:core`, `tsgo:ui`, `tsgo:scripts`, `pnpm check:test-types`, and `ocx test` on the lease, session store, outbound queue, subagent registry, cron, memory audience, session events, chat send and Stop, `sessions_send`, restart resume and UI E2E inventory suites. `test/plugins/deep-research-routing.gateway.test.ts` fails the same way on `main` (CI run 43939332007, job 133553190527); this PR does not touch it. Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa
added a commit
that referenced
this pull request
Nov 19, 2026
… and stop refusing on captured ids (#200191) ## What Problem This Solves Work was stopped by inference: a check captured an id that changes on its own (a transcript id, lifecycle revision, run id, generation or displayed leaf), and later treated "it changed" as "it was revoked". Users saw: - A message queued in Control UI during a turn was refused as "switched branches" once the turn ended. The sender's leaf was one entry behind the new reply, and a send without a session id needed an exact leaf match. - `sessions_send` to a task session was refused with "Task resume differs from the captured communication owner." after the task moved to a new run (exec wake, yield, follow-up) or was compacted. - A requester-wake failure notice for a lost subagent batch was pinned to the requester's old transcript and refused as `session-rebound` after a reset or compaction successor. - Deleting a chat left its queued outbound replies in the durable queue, so a chat recreated with the same key could receive them. - Every delivery, queue, wake and session-event API took a `SessionDeliveryGeneration` with a transcript id and revision, so any new caller could pin a chat to an id again. ## Why This Change Was Made Make the bad state hard to express and guard the rest: - **`ChatRef`** (`src/sessions/chat-ref.ts`) is the only durable chat address: agent id, store path and session key, branded. `chatRef()` copies only the address, so ids in rows queued by older builds never travel with it. Delivery, queue, wake, cron delivery, memory audience and session-event APIs take a `ChatRef`. `SessionDeliveryGeneration` and `SessionGenerationFacts` are deleted. - **`TranscriptLease`** (`src/config/sessions/transcript-lease.ts`) is the only way to hold one transcript. Live writers (cron root, fork, subagent control, restart resume, a scheduled occurrence) acquire it with a private pin. It refuses to serialise. - **One prefix rule for sends:** a send is admitted while the sender's leaf is on the active path; an empty view is a prefix of every path. A rewind, branch switch or reset away from the leaf still refuses it (#113073 holds). Deleted: the exact-match branch, `activePathNavigationMoved` and its reader, the send's own session-id fence, and the test-only relation reader. `activePathRelation` becomes `onActivePath`. - **Task sends follow the chat:** `sessions_send` continues the task's current run. The `previousRunId` / `generation` / `childSessionId` compares, the retained-task pins and the target-incarnation compare are deleted. It refuses only when the task ended or was cancelled, the chat was deleted, or another session controls the task. - **Lost-run notice by key**, and **delete purges queued sends** (a send that already started stays with its recovery owner). - **Guard:** `check:session-identity-ratchet` counts, per file outside `src/config/sessions/`, any `===`/`!==` on a session id, run id, generation, lifecycle revision or leaf id, the `expectedSessionId` / `expectedLifecycleRevision` pin names, and refusal strings ("differs from the captured", "no longer active", "changed before", "was replaced"). Existing hits are listed in `config/session-identity-allowlist.txt`, which may only shrink. Kept on purpose: - **Typed Stop** keeps its incarnation fence (an empty view must still be empty, and the session id must match), so a Stop never cancels work that started after it. It moves to a recorded stop cause in the next change. - **Memory grants** hold the incarnation they were minted in through a transcript lease: a reset revokes the grant, a compaction successor keeps it. This is the narrower authority and matches the memory audience's own tests. - Knowledge partitions, the deep-research job store and GitHub publication rows key on transcript ids in stored rows; changing them needs a data migration and is left for a separate decision. Production code (`src`, `extensions`, without tests): +524 / −602. ## User Impact - A message queued during a turn is sent when the turn ends. - A pane that still shows a branch another client switched away from is still refused, and the message is parked as not sent. - A send to a task session reaches its current run after wakes, yields and compaction; a send to a cancelled task is refused with a reason. - Deleting a chat drops its unsent queued replies. - Rows queued by older builds still deliver. A row queued by this build and replayed by an older build has no transcript id; the older build treats it as unavailable and retries it until its retry budget ends. ## Evidence Base = merge base `edbc5bcea9b6`, head = this PR. | Journey | Tier | Base | Head | |---|---|---|---| | Control UI: queue a message during a held turn, release the turn (send carries only the displayed leaf) | Control UI E2E, real Gateway, scripted provider (`ui/src/e2e/chat-send-leaf-ancestor.real-gateway.e2e.test.ts`) | `chat.send` ok=false, message parked "Not sent" | `chat.send` ok=true, reply "Flag mentioned." | | Control UI: pane still shows Plan C, another client switches to the Plan B tip, pane sends | same | refused, no provider request | refused, no provider request | | Compaction successor while a background exec runs, then a next turn | `ocx src` scratch Gateway, real Claude model | exec wake lands in the successor transcript; next turn runs | same | | Queue an outbound reply, delete the chat, recreate the key | `ocx src` scratch Gateway | 1 queued reply still pending | 0 pending | | Reaction, then edit a later message | `ocx src` scratch Gateway | reaction still listed | reaction still listed | | Plant `entry.sessionId === saved` in a new file | `check:session-identity-ratchet` | — | fails: `src/sessions/chat-ref.ts: 1 > 0` | The task-send fix is proven by unit tests only: a send to an owned task after its run id and generation advanced, with a stale resume binding, is delivered (fails on base), and a send after the task is killed is refused. Real-Gateway journeys with a real Claude model (spawn a task, then send after an exec wake, after compaction, after cancel, or while the task is busy so the send is held and released) did not reproduce the refusal on base: base delivered in each. The live refusal needs the in-process resume binding of a retained self-hold replay, which these journeys do not reach. Gates: oxfmt, oxlint, `pnpm tsgo:core`, `tsgo:ui`, `tsgo:scripts`, `pnpm check:test-types`, and `ocx test` on the lease, session store, outbound queue, subagent registry, cron, memory audience, session events, chat send and Stop, `sessions_send`, restart resume and UI E2E inventory suites. `test/plugins/deep-research-routing.gateway.test.ts` fails the same way on `main` (CI run 43939332007, job 133553190527); this PR does not touch it. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 8d581e9) Release adaptation: Direct backport; retain baseline event-handoff fixes and adopt ChatRef plus transcript leases consistently. Follow-up disposition: Active-path admission and requester-event changes retained; focused regression proof recorded in lane report. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 6191c103b746aa121f5d88f570f760064c6da731)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
The last known cross-client race in the rewind/fork feature set (deliberate follow-up from that work): tab A displays branch X of a session; tab B switches the session's active branch to Y; tab A sends — the message lands on Y, a branch the sender never saw. Confirmed live twice on an isolated dev gateway, including the subtle failure mode where a first-cut guard based on the client's latest branch fetch was defeated because background branch refreshes race ahead of what the pane renders.
Why This Change Was Made
Adds an additive
chat.sendprecondition anchored to what the user actually sees:expectedLeafEntryIdonChatSendParamsSchema;chat.history's session info now carriesactiveLeafEntryId(both additive, no version bump).details.reason: "active-leaf-changed"); param absent → unchanged behavior; fresh session with a claimed leaf → rejected as stale.User Impact
A message typed against one branch can no longer silently land on another. The sender gets an explicit review-and-resend prompt with their draft intact; other clients (iOS/Android) can adopt the same additive param independently.
Evidence
transcript_events); display-derived v2 verified — typed rejection shown, composer restored, view resynced, zero server-side writes; immediate resend after resync landed with its reply on the current branch.chatBranchesrefresh cannot change what a send attaches; focused runs green (233 gateway/core, 4 protocol, 420 UI).docs/gateway/protocol.md,docs/web/webchat.md).