Skip to content

refactor(sessions): stop chat work by a recorded cause, not by a changed id - #200326

Merged
obviyus merged 3 commits into
mainfrom
obviyus/identity-stop-cause
Nov 17, 2026
Merged

obviyus merged 3 commits into
mainfrom
obviyus/identity-stop-cause

Conversation

@obviyus

@obviyus obviyus commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Work was stopped by inference. Two checks compared ids that change on their own and treated a change as a stop:

  • Typed Stop refused. A chat.send "/stop" (queue mode other than steer) had to see the same session id and, with an empty view, an empty transcript. A client that had not loaded history yet sent "/stop" during a running turn: the Gateway answered "active branch changed; review and retry" and the turn kept running.
  • Retained send fenced by revision. A sessions_send held during a plugin reload replayed with the target's lifecycle revision and transcript id pinned. A reset was caught only because it rotates the revision ("Target session lifecycle changed before retained send."). A compaction successor of the target changed the transcript id, so the replay was refused even though the chat was the same.

Why This Change Was Made

A stop is a recorded act with a cause, on the existing stop paths. No new service.

  • Typed Stop stops the chat's work as it is when the Gateway receives it. Deleted: the stop branch of assertExpectedLeafActive, assertExpectedLeafActiveAsync, and the beforeAbort hook in the chat abort runtime. Work that starts after the Stop is not captured, so it is not cancelled.
  • Retained sends are addressed by chat key. Reset and delete stop them in their shared runtime cleanup (clearSessionResetRuntimeState) with the cause reset or deleted. The replay reports { status: "not_delivered", stopCause }. Deleted: the lifecycle-revision compare and its option, the replay's transcript-id pin, and the "refused target incarnation" check. Retained sends are held through WeakRef, so a handoff that never replays does not keep them.
  • config/session-identity-allowlist.txt: 6587 → 6584 pins on current main.

Accepted edge: a reset that lands after the replay has started does not stop that replay. A started request may finish, as before.

Production code (src, extensions, without tests): +73 / −127.

User Impact

  • A typed "/stop" stops the running turn even if the client's view is empty or behind.
  • A Stop does not cancel a turn, a replacement chat or a child started after it.
  • A reset or delete of the target stops a held send, with the cause in the result.
  • A held send to a compacted target is no longer refused for the new transcript id.

Evidence

Base = merge base 726a8dd49857, head = this PR.

Journey Tier Base Head
Turn 1 runs a 45 s foreground exec; client sends chat.send "/stop" with expectedLeafEntryId: null, queue mode followup; then sends turn 2 at once ocx src scratch Gateway, real Claude model Stop refused (active-leaf-changed); turn 1 not stopped Stop ok, turn 1 aborted; turn 2 (started after the Stop) final with the expected reply
Caller holds a reloading plugin, sends to its child (held), child is reset before replay real Gateway, real plugin reload, scripted model (scratch variant of server.plugin-reload-send-continuation.product.test.ts) error: "Target session lifecycle changed before retained send."; child got 0 sends not_delivered, stopCause: "reset"; child got 0 sends

Tests:

  • chat.stop-cascade.test.ts: a Stop with a stale leaf and another session id stops the chat's work; after a parent replacement or branch, the original child is cancelled and the successor's runs and child are not.
  • sessions-send-self-hold.test.ts: a reset of the target settles the held send once with stopCause: "reset" and never replays it.
  • server.plugin-reload-send-continuation.product.test.ts (resume, followup, failed reload) passes on head.
  • server-worker-placement-cancel.test.ts revoked worker Stop authority in a microtask after the first check and relied on an await that this change removes. It now revokes before the effect's own check.

server.plugin-reload-send-revocation.product.test.ts times out the same way on base and head locally.

Gates: oxfmt, oxlint, pnpm tsgo:core, pnpm check:test-types, import-cycle checks, check:session-identity-ratchet, and ocx test on the Stop, abort, chat-send, self-hold and reset-cleanup suites. Local review: complete, no findings.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Nov 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head c1cf663a51e22d8fef71f8f1487f45d289e74461, but the PR head is now c28f7ccd15781af2634338d554f1ca5f827a231c. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-17T00:48:05.374Z sha c1cf663 :: needs changes before merge. :: [P2] Update the worker cancellation test for synchronous admission

@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 17, 2026
obviyus and others added 3 commits November 17, 2026 07:25
…ged id

Typed Stop no longer compares the sender's leaf or session id. It stops the
chat's work as it is when the Gateway receives it; work that starts after the
Stop is not captured and is not cancelled.

A send retained during a plugin reload is addressed by its chat key. Reset and
delete stop it through their shared runtime cleanup with the cause "reset" or
"deleted", so the replay no longer compares the target's lifecycle revision or
transcript id.

Co-authored-by: obviyus <[email protected]>
@obviyus
obviyus force-pushed the obviyus/identity-stop-cause branch from c28f7cc to fb1d0cd Compare November 17, 2026 02:02
@obviyus
obviyus merged commit 307e88c into main Nov 17, 2026
130 checks passed
@obviyus
obviyus deleted the obviyus/identity-stop-cause branch November 17, 2026 02:16
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 307e88c.

  • Bug: a typed "/stop" was refused when the sender's view was empty or behind ("active branch changed"), and a held sessions_send was fenced by the target's revision and transcript id.
  • Fix: Stop stops the chat's work as it is at receipt; reset and delete stop held sends by chat key with a recorded cause (reset / deleted).
  • Proof: real-model Gateway journey (base: Stop refused, turn kept running; head: turn stopped, the turn started after the Stop completed), real plugin-reload reset journey (head: not_delivered, stopCause: reset), local review clean on the exact head, CI green.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…ged id (openclaw#200326)

## What Problem This Solves

Work was stopped by inference. Two checks compared ids that change on their own and treated a change as a stop:

- **Typed Stop refused.** A `chat.send` "/stop" (queue mode other than steer) had to see the same session id and, with an empty view, an empty transcript. A client that had not loaded history yet sent "/stop" during a running turn: the Gateway answered "active branch changed; review and retry" and the turn kept running.
- **Retained send fenced by revision.** A `sessions_send` held during a plugin reload replayed with the target's lifecycle revision and transcript id pinned. A reset was caught only because it rotates the revision ("Target session lifecycle changed before retained send."). A compaction successor of the target changed the transcript id, so the replay was refused even though the chat was the same.

## Why This Change Was Made

A stop is a recorded act with a cause, on the existing stop paths. No new service.

- **Typed Stop** stops the chat's work as it is when the Gateway receives it. Deleted: the `stop` branch of `assertExpectedLeafActive`, `assertExpectedLeafActiveAsync`, and the `beforeAbort` hook in the chat abort runtime. Work that starts after the Stop is not captured, so it is not cancelled.
- **Retained sends** are addressed by chat key. Reset and delete stop them in their shared runtime cleanup (`clearSessionResetRuntimeState`) with the cause `reset` or `deleted`. The replay reports `{ status: "not_delivered", stopCause }`. Deleted: the lifecycle-revision compare and its option, the replay's transcript-id pin, and the "refused target incarnation" check. Retained sends are held through `WeakRef`, so a handoff that never replays does not keep them.
- `config/session-identity-allowlist.txt`: 6587 → 6584 pins on current `main`.

Accepted edge: a reset that lands after the replay has started does not stop that replay. A started request may finish, as before.

Production code (`src`, `extensions`, without tests): +73 / −127.

## User Impact

- A typed "/stop" stops the running turn even if the client's view is empty or behind.
- A Stop does not cancel a turn, a replacement chat or a child started after it.
- A reset or delete of the target stops a held send, with the cause in the result.
- A held send to a compacted target is no longer refused for the new transcript id.

## Evidence

Base = merge base `7683f1bdbebd`, head = this PR.

| Journey | Tier | Base | Head |
|---|---|---|---|
| Turn 1 runs a 45 s foreground exec; client sends `chat.send` "/stop" with `expectedLeafEntryId: null`, queue mode followup; then sends turn 2 at once | `ocx src` scratch Gateway, real Claude model | Stop refused (`active-leaf-changed`); turn 1 not stopped | Stop ok, turn 1 `aborted`; turn 2 (started after the Stop) `final` with the expected reply |
| Caller holds a reloading plugin, sends to its child (held), child is reset before replay | real Gateway, real plugin reload, scripted model (scratch variant of `server.plugin-reload-send-continuation.product.test.ts`) | `error`: "Target session lifecycle changed before retained send."; child got 0 sends | `not_delivered`, `stopCause: "reset"`; child got 0 sends |

Tests:
- `chat.stop-cascade.test.ts`: a Stop with a stale leaf and another session id stops the chat's work; after a parent replacement or branch, the original child is cancelled and the successor's runs and child are not.
- `sessions-send-self-hold.test.ts`: a reset of the target settles the held send once with `stopCause: "reset"` and never replays it.
- `server.plugin-reload-send-continuation.product.test.ts` (resume, followup, failed reload) passes on head.
- `server-worker-placement-cancel.test.ts` revoked worker Stop authority in a microtask after the first check and relied on an await that this change removes. It now revokes before the effect's own check.

`server.plugin-reload-send-revocation.product.test.ts` times out the same way on base and head locally.

Gates: oxfmt, oxlint, `pnpm tsgo:core`, `pnpm check:test-types`, import-cycle checks, `check:session-identity-ratchet`, and `ocx test` on the Stop, abort, chat-send, self-hold and reset-cleanup suites. Local review: complete, no findings.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Backport #200326 from 307e88c.

Typed Stop cancels captured current work despite stale or empty sender history while preserving live authority and successor isolation. Reset/delete explicitly settle matching retained sends as not_delivered with their cause. Remove obsolete incarnation fences without changing the logical task/run/source guards.

Accepted edge: reset after replay starts does not retract an already started request; existing cancellation owns it.

Proof: five Stop plus four retained-send baseline failures, 67 owner and 146 worker sibling tests, and 105 assembled parent tests passed. Parent reviewed the complete change; one missing-braces lint finding repaired without behavior change. Worker live reload probe has an unclassified baseline gap; no live-model success claimed. Publication held.

Co-authored-by: RomneyDa <[email protected]>
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 19, 2026
…stage 2)

Catches the pure continuation candidate bc7e568 up to openclaw/openclaw
main 41bdde2 (fetched 2026-11-19T14:32:59Z),
2,996 upstream commits past the old merge base 401a1de. Merge commit only;
rerere disabled, so every resolution was made here.

80 conflicted paths (77 content, 3 modify/delete), each recorded with base,
ours and theirs blobs and its reason in the lane's stage2-conflicts.md:
- 8 take upstream whole: the openclaw#197153 pg16-smoke cherry-pick (6909b64) now
  ships upstream (ci.yml, ci-build-manifest, ci-workflow-planning test), the
  Control UI settings child moved onto runDistArtifactChild, the canary
  worker target and two active-facts migration tests.
- 3 deleted with upstream: session-fork and update-candidate-canary suites
  whose production paths upstream removed; cwd-split folded away (openclaw#198916),
  its one continuation case rehomed to attempt.continuation-tools.test.ts.
- One-owner cutovers where upstream now owns a fork extraction: the
  requester-origin projection and replacement-text helpers (openclaw#200533) replace
  the fork's byte-identical copies in user-turn-transcript.metadata.ts.
- Ports into fork-extracted owners: removalReason in the queued-start plan
  and collector-group sweep (openclaw#199868), the async prepared-pricing usage
  diagnostic, the announce flow types, and the session-delivery codec, which
  gains upstream's mediaCandidate kind, reviewedTaskId and their schemas
  (openclaw#198227), importing its retention type from the leaf types module.
- Transcript repair (openclaw#201304, post-b894): upstream's payload-free adapter
  kernel carries the fork's continue_delegate attachment redaction through a
  payload-adapter-only fact and a withBlock update.
- Reset cleanup: upstream's process and retained-send stops (openclaw#199079,
  openclaw#200326) with the fork's continuation-aware reason as the single input;
  the chat reset's retention adapter wraps upstream's stopSessionResetWork,
  the Gateway preemption keeps stopSessionResetSubagents as upstream does.
- Schema: upstream owns agent 42 (tool usage) and 43 (pending-input
  endings) and is at 43; 44 is unused upstream. Continuation's recipient
  authority moves 42 -> 44: version constants, step order, historical
  schemas, witness additive table and version set, backup scope, PostgreSQL
  ladder (V43 = current minus the authority table) and port descriptor.
  package.json schemaVersions state 40, agent 44.
- Generated outputs regenerated, never hand-merged: config baseline,
  gateway validators, postgres schema catalogs, worker-access inventory.
- Compile follow-through for upstream's delivery-union narrowing and its
  readSessionDelivery callers.

Refs openclaw#129388
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…ged id (#200326)

Work was stopped by inference. Two checks compared ids that change on their own and treated a change as a stop:

- **Typed Stop refused.** A `chat.send` "/stop" (queue mode other than steer) had to see the same session id and, with an empty view, an empty transcript. A client that had not loaded history yet sent "/stop" during a running turn: the Gateway answered "active branch changed; review and retry" and the turn kept running.
- **Retained send fenced by revision.** A `sessions_send` held during a plugin reload replayed with the target's lifecycle revision and transcript id pinned. A reset was caught only because it rotates the revision ("Target session lifecycle changed before retained send."). A compaction successor of the target changed the transcript id, so the replay was refused even though the chat was the same.

A stop is a recorded act with a cause, on the existing stop paths. No new service.

- **Typed Stop** stops the chat's work as it is when the Gateway receives it. Deleted: the `stop` branch of `assertExpectedLeafActive`, `assertExpectedLeafActiveAsync`, and the `beforeAbort` hook in the chat abort runtime. Work that starts after the Stop is not captured, so it is not cancelled.
- **Retained sends** are addressed by chat key. Reset and delete stop them in their shared runtime cleanup (`clearSessionResetRuntimeState`) with the cause `reset` or `deleted`. The replay reports `{ status: "not_delivered", stopCause }`. Deleted: the lifecycle-revision compare and its option, the replay's transcript-id pin, and the "refused target incarnation" check. Retained sends are held through `WeakRef`, so a handoff that never replays does not keep them.
- `config/session-identity-allowlist.txt`: 6587 → 6584 pins on current `main`.

Accepted edge: a reset that lands after the replay has started does not stop that replay. A started request may finish, as before.

Production code (`src`, `extensions`, without tests): +73 / −127.

- A typed "/stop" stops the running turn even if the client's view is empty or behind.
- A Stop does not cancel a turn, a replacement chat or a child started after it.
- A reset or delete of the target stops a held send, with the cause in the result.
- A held send to a compacted target is no longer refused for the new transcript id.

Base = merge base `726a8dd49857`, head = this PR.

| Journey | Tier | Base | Head |
|---|---|---|---|
| Turn 1 runs a 45 s foreground exec; client sends `chat.send` "/stop" with `expectedLeafEntryId: null`, queue mode followup; then sends turn 2 at once | `ocx src` scratch Gateway, real Claude model | Stop refused (`active-leaf-changed`); turn 1 not stopped | Stop ok, turn 1 `aborted`; turn 2 (started after the Stop) `final` with the expected reply |
| Caller holds a reloading plugin, sends to its child (held), child is reset before replay | real Gateway, real plugin reload, scripted model (scratch variant of `server.plugin-reload-send-continuation.product.test.ts`) | `error`: "Target session lifecycle changed before retained send."; child got 0 sends | `not_delivered`, `stopCause: "reset"`; child got 0 sends |

Tests:
- `chat.stop-cascade.test.ts`: a Stop with a stale leaf and another session id stops the chat's work; after a parent replacement or branch, the original child is cancelled and the successor's runs and child are not.
- `sessions-send-self-hold.test.ts`: a reset of the target settles the held send once with `stopCause: "reset"` and never replays it.
- `server.plugin-reload-send-continuation.product.test.ts` (resume, followup, failed reload) passes on head.
- `server-worker-placement-cancel.test.ts` revoked worker Stop authority in a microtask after the first check and relied on an await that this change removes. It now revokes before the effect's own check.

`server.plugin-reload-send-revocation.product.test.ts` times out the same way on base and head locally.

Gates: oxfmt, oxlint, `pnpm tsgo:core`, `pnpm check:test-types`, import-cycle checks, `check:session-identity-ratchet`, and `ocx test` on the Stop, abort, chat-send, self-hold and reset-cleanup suites. Local review: complete, no findings.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 307e88c)
Release adaptation: Retain baseline task-run and branch-navigation admission guards; remove only obsolete Stop leaf recheck and retained transcript identity. Keep deleted identity allowlist deleted.:
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 853a66f5867f4d940ecdc71f0f14f838f0ab473e)
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Release adaptation: combine #200191 and #200326 using canonical307e88 hadTask/expectTargetTask replay admission, retaining explicit reset/delete stop settlement. Independent source review and 26 focused tests pass; targeted type-aware lint and formatting pass.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant