Skip to content

fix(gateway): detached work keeps its origin's authority when the parent chat is edited - #200176

Merged
obviyus merged 3 commits into
mainfrom
obviyus/identity-authority-facts
Nov 16, 2026
Merged

obviyus merged 3 commits into
mainfrom
obviyus/identity-authority-facts

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Scope

This is the first slice of "authority from saved facts". It moves accepted work onto the saved-facts path and fixes the user-visible bug. The next slice deletes the machinery this makes redundant: the subagent completion custody map, the store-replaced suspend path, the remaining parent-authority reads for detached children, the follow-up queue's silent cancel, the cron occurrence authority and the duplicated restore glue.

What Problem This Solves

Editing a message in a chat stopped every subagent that chat had started, and dropped their results. The people involved still had access; nothing had revoked it.

How it happened: accepted work that outlives its request (a child run, a subagent completion, a node event) reused the live authority object of the request that accepted it. For a child, that object also checked the parent chat.send's admitted input, which asserts that the parent chat's transcript revision has not changed. An edit (sessions.rewind plus a new send) changes that revision. So at its next boundary the child failed with source_authority_refused / "admitted run authority is no longer active | session changed before chat.send", its exec calls failed with "tool invocation authority is no longer active", and its completion failed with "requester settle wake failed: session changed before chat.send".

The bug class: detached work held a closure over a live owner (request, turn or run) as its authority. When that owner ended or its target changed, the work lost authority although nothing revoked it.

Why This Change Was Made

Accepted work now carries values, not the accepting closure. captureGatewayOperatorContinuation restores the work's authority from the origin's saved facts (the operator recovery snapshot that restart recovery already uses) and checks it against current policy. The accepting request, turn or run is no longer part of the chain.

  • One path: captureGatewayOperatorContinuation (in operator-run-recovery.ts) replaces the independentContinuation flag. It is used for accepted agent turns (retainGatewayOperatorRun: child launches, sent turns), subagent completion custody (captureOperatorToolGatewayContinuationContext) and node event sources.
  • Deleted: the continuationAuthorities map, bindGatewayOperatorContinuationAuthority and the independentContinuation parameter. The restored authority in restart recovery is now one object instead of a policy object plus a claim wrapper.
  • A source without saved facts (unavailable in the recovery codec) keeps its live authority, as before.
  • Continuations of one origin keep its opaque source identity, so sibling children still settle as one completion batch. The accepted work still retains the inherited object for its lifetime, because other holders of that object (for example the queued input's transcript write) keep using it; its checks no longer gate the work.
  • No schema, stored-row or protocol change. Production delta: −3 lines (+60 / −63).

Security model

  • Revokes authority now: a change of the origin's policy: paired device revoked, shared Gateway token or password rotated (shared-secret generation), profile identity or email binding changed, role assignment or role policy changed, access grant ended, OpenClaw ID membership changed. These are the checks restart recovery already runs, with the same revocation subscriptions, so a refusal arrives at the same boundaries as before (each authority check: admission, model request, tool call).
  • No longer revokes: the accepting request ending, the parent turn ending or being replaced, and an edit or new message in the parent chat.
  • Explicit stops are unchanged: Stop / chat.abort cancels descendants; reset (/new, /reset) stops controlled subagents, as docs/concepts/session-controller.md documents; delete stops them during lifecycle cleanup.
  • Ceiling: the restored authority is the saved snapshot's scopes intersected with the caller's scopes (the same narrowing as before) and the current role; the model policy is the intersection of the saved and the current policy. Saved facts are captured only from a live host-issued authority (captureQueuedOperatorRecoverySource asserts it current first) and decoded by the strict codec. Work can never hold more than its origin had when it was accepted, and less if policy tightened since.

User Impact

  • A subagent keeps running and its result reaches the parent chat when the person edits or resends a message in that chat.
  • Revoking access still stops the work: rotating the Gateway token cancels a running child at once.

Evidence

Real agent on an isolated source Gateway (ocx src, scratch state, port and HOME, scrubbed env), Claude Opus through the shared Claude proxy. base = merge base edbc5bce, head = this PR.

Journey base head
J1: parent spawns a child and yields; the person sends a second message, then edits it (sessions.rewind + resend) while the child runs child refused (source_authority_refused, "session changed before chat.send"); completion dropped (delivery=not_required); parent never gets the result child finishes; parent replies parent-got child-final; registry delivery=delivered
J2: child running; the operator rotates gateway.auth.token child cancelled ("operator source authority is no longer active") child cancelled within a second of the reload ("Restart recovery operator authority changed; start a new user turn."; the restored authority reuses the restart-recovery messages); no further tool call ran
J3: input A queued behind a busy turn, then human message B A and B both run (busy-done a-ack b-ack) A and B both run (busy-done a-ack b-ack)
J1b: parent spawns two children and yields; the person edits a later message; both children settle as one batch both children refused (source_authority_refused); no result both finish; parent replies parent-got one-final two-final
J4: cron occurrence; job edited mid-run occurrence finishes (cron-done) occurrence finishes (cron-done)
Parent gets a new message / chat.abort + new message while a child runs (yielded and busy shapes) child survives, completion delivered child survives, completion delivered

The first journey matches the production incident: the transcript there shows a user message, a leaf (branch) event and the resent message, and every running child of that chat failed in the same second.

/new while the parent is yielded on a running child stops the child on both arms. That is the documented reset behavior (reset stops controlled subagents), so this PR keeps it.

Not covered by E2E: role downgrade and device revocation for a running child (the scratch Gateway uses shared-token owner auth). Unit tests cover device revocation and email reassignment of retained child authority (operator-run-recovery.test.ts, operator-run-cancellation.test.ts).

Gates: oxfmt, oxlint on changed files, pnpm tsgo:core, pnpm check:test-types, import-cycle and madge checks, ocx test on the operator-run authority, cancellation and recovery suites, in-process dispatch suites, requester pause authority, session restart resume and src/agents/subagents/.

…ent chat is edited

A child run, a subagent completion and a node event reused the live
authority object of the request that accepted them. That object also
checked the requester chat.send's admitted input, so editing (rewinding)
the parent chat revoked every running child and dropped its completion,
although nothing had revoked the person's access.

Accepted work now restores its authority from the origin's saved facts
(the recovery snapshot that restart recovery already uses), checked
against current policy: device, shared-secret generation, profile, role
and access grant. The accepting request, turn or run is not part of it.
A source without saved facts keeps its live authority.

The continuation map and the independentContinuation flag are deleted;
captureGatewayOperatorContinuation is the one path.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 16, 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.

@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. labels Nov 16, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head d66666509f91b25aa261fddf09d6467aeba8c777, but the PR head is now 270c3e42fea62b9f2c1a5df909b8b3f696a0ab33. 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-16T17:21:27.892Z sha d666665 :: needs changes before merge. :: [P1] Preserve replay guard custody through detached chat execution

@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 5fc3d2274e84269023873af378c1abb54a466cdd
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/operator-run-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/nodes.invoke-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-plugin-in-process-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: checks-node-changed-compact-large-20 fails in one test this PR does not touch.

  • Failing test: test/plugins/deep-research-routing.gateway.test.ts > "admits browser research through the real Gateway session gate, recovers acceptance, and denies cross-session/reset reads", line 839 (expected true to be false).
  • The same assertion fails at line 839 on the merge base edbc5bce, and on current main 3c512c583018, both run locally with ocx test test/plugins/deep-research-routing.gateway.test.ts. This PR changes no deep-research or session view-state code.
  • Exact-head proof: real-Gateway E2E on 5fc3d227 (see the PR body), and a clean local review on the same head.

@obviyus
obviyus merged commit f4fa17a into main Nov 16, 2026
122 of 125 checks passed
@obviyus
obviyus deleted the obviyus/identity-authority-facts branch November 16, 2026 17:59
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in f4fa17a.

  • Bug: editing a message in a chat stopped every subagent that chat had started, and dropped their results. Detached work reused the accepting request's live authority, and that authority checked the parent chat's transcript revision.
  • Fix: accepted work restores its authority from the origin's saved facts, checked against current policy. Device, token, profile, role and grant changes still revoke it.
  • Proof:
    • A real-Gateway E2E with Claude Opus covered the edit journey with one child and with two batched children. Base: refused. Head: delivered.
    • Token rotation still cancels a running child.
    • Queued-input and cron journeys behave the same as before.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…ent chat is edited (openclaw#200176)

## Scope

This is the first slice of "authority from saved facts". It moves accepted work onto the saved-facts path and fixes the user-visible bug. The next slice deletes the machinery this makes redundant: the subagent completion custody map, the store-replaced suspend path, the remaining parent-authority reads for detached children, the follow-up queue's silent cancel, the cron occurrence authority and the duplicated restore glue.

## What Problem This Solves

Editing a message in a chat stopped every subagent that chat had started, and dropped their results. The people involved still had access; nothing had revoked it.

How it happened: accepted work that outlives its request (a child run, a subagent completion, a node event) reused the live authority object of the request that accepted it. For a child, that object also checked the parent `chat.send`'s admitted input, which asserts that the parent chat's transcript revision has not changed. An edit (`sessions.rewind` plus a new send) changes that revision. So at its next boundary the child failed with `source_authority_refused` / "admitted run authority is no longer active | session changed before chat.send", its exec calls failed with "tool invocation authority is no longer active", and its completion failed with "requester settle wake failed: session changed before chat.send".

The bug class: detached work held a closure over a live owner (request, turn or run) as its authority. When that owner ended or its target changed, the work lost authority although nothing revoked it.

## Why This Change Was Made

Accepted work now carries values, not the accepting closure. `captureGatewayOperatorContinuation` restores the work's authority from the origin's saved facts (the operator recovery snapshot that restart recovery already uses) and checks it against current policy. The accepting request, turn or run is no longer part of the chain.

- One path: `captureGatewayOperatorContinuation` (in `operator-run-recovery.ts`) replaces the `independentContinuation` flag. It is used for accepted agent turns (`retainGatewayOperatorRun`: child launches, sent turns), subagent completion custody (`captureOperatorToolGatewayContinuationContext`) and node event sources.
- Deleted: the `continuationAuthorities` map, `bindGatewayOperatorContinuationAuthority` and the `independentContinuation` parameter. The restored authority in restart recovery is now one object instead of a policy object plus a claim wrapper.
- A source without saved facts (`unavailable` in the recovery codec) keeps its live authority, as before.
- Continuations of one origin keep its opaque `source` identity, so sibling children still settle as one completion batch. The accepted work still retains the inherited object for its lifetime, because other holders of that object (for example the queued input's transcript write) keep using it; its checks no longer gate the work.
- No schema, stored-row or protocol change. Production delta: −3 lines (+60 / −63).

## Security model

- **Revokes authority now:** a change of the origin's policy: paired device revoked, shared Gateway token or password rotated (shared-secret generation), profile identity or email binding changed, role assignment or role policy changed, access grant ended, OpenClaw ID membership changed. These are the checks restart recovery already runs, with the same revocation subscriptions, so a refusal arrives at the same boundaries as before (each authority check: admission, model request, tool call).
- **No longer revokes:** the accepting request ending, the parent turn ending or being replaced, and an edit or new message in the parent chat.
- **Explicit stops are unchanged:** Stop / `chat.abort` cancels descendants; reset (`/new`, `/reset`) stops controlled subagents, as `docs/concepts/session-controller.md` documents; delete stops them during lifecycle cleanup.
- **Ceiling:** the restored authority is the saved snapshot's scopes intersected with the caller's scopes (the same narrowing as before) and the current role; the model policy is the intersection of the saved and the current policy. Saved facts are captured only from a live host-issued authority (`captureQueuedOperatorRecoverySource` asserts it current first) and decoded by the strict codec. Work can never hold more than its origin had when it was accepted, and less if policy tightened since.

## User Impact

- A subagent keeps running and its result reaches the parent chat when the person edits or resends a message in that chat.
- Revoking access still stops the work: rotating the Gateway token cancels a running child at once.

## Evidence

Real agent on an isolated source Gateway (`ocx src`, scratch state, port and HOME, scrubbed env), Claude Opus through the shared Claude proxy. base = merge base `2c94bae9`, head = this PR.

| Journey | base | head |
|---|---|---|
| J1: parent spawns a child and yields; the person sends a second message, then edits it (`sessions.rewind` + resend) while the child runs | child refused (`source_authority_refused`, "session changed before chat.send"); completion dropped (`delivery=not_required`); parent never gets the result | child finishes; parent replies `parent-got child-final`; registry `delivery=delivered` |
| J2: child running; the operator rotates `gateway.auth.token` | child cancelled ("operator source authority is no longer active") | child cancelled within a second of the reload ("Restart recovery operator authority changed; start a new user turn."; the restored authority reuses the restart-recovery messages); no further tool call ran |
| J3: input A queued behind a busy turn, then human message B | A and B both run (`busy-done a-ack b-ack`) | A and B both run (`busy-done a-ack b-ack`) |
| J1b: parent spawns two children and yields; the person edits a later message; both children settle as one batch | both children refused (`source_authority_refused`); no result | both finish; parent replies `parent-got one-final two-final` |
| J4: cron occurrence; job edited mid-run | occurrence finishes (`cron-done`) | occurrence finishes (`cron-done`) |
| Parent gets a new message / `chat.abort` + new message while a child runs (yielded and busy shapes) | child survives, completion delivered | child survives, completion delivered |

The first journey matches the production incident: the transcript there shows a user message, a `leaf` (branch) event and the resent message, and every running child of that chat failed in the same second.

`/new` while the parent is yielded on a running child stops the child on both arms. That is the documented reset behavior (reset stops controlled subagents), so this PR keeps it.

Not covered by E2E: role downgrade and device revocation for a running child (the scratch Gateway uses shared-token owner auth). Unit tests cover device revocation and email reassignment of retained child authority (`operator-run-recovery.test.ts`, `operator-run-cancellation.test.ts`).

Gates: oxfmt, oxlint on changed files, `pnpm tsgo:core`, `pnpm check:test-types`, import-cycle and madge checks, `ocx test` on the operator-run authority, cancellation and recovery suites, in-process dispatch suites, requester pause authority, session restart resume and `src/agents/subagents/`.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Bounded backport of f4fa17a (#200176). Restore accepted detached work through the existing saved-source owner while retaining current policy, device revocation, scope ceilings and original source identity. Remove the alternate continuation map and flag.

Parent independent review complete; unchanged worker proof: genuine committed-parent-edit regression red, 95 owner tests and 42 Stop/reset tests green. Parent canonical scoped typed lint passed across eight files. No live-model rewind E2E qualification claimed. Publication held.

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

P1 High-priority user-facing bug, regression, or broken workflow. security-sensitive-changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant