Skip to content

fix(gateway): resume session-scoped operators after restart - #179579

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-restart-recovery-missing-operator-write-20260919
Oct 21, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-restart-recovery-missing-operator-write-20260919

Conversation

@steipete

@steipete steipete commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #179564, whose PR head did not advance after its branch was updated and which GitHub refused to reopen. This PR uses the same branch; the earlier CI findings are repaired and recorded below.

What Problem This Solves

Fixes interrupted turns repeatedly failing restart recovery with missing scope: operator.write when their original caller was admitted with operator.sessions.write.

User Impact

Session-only operators, including trusted-proxy users and delegated parent continuations, can resume their own interrupted work without receiving broader permissions. Confirmed revocation records a visible interruption instead of repeatedly deferring the same input. Saved final replies and other unfinished recovery obligations remain preserved.

Why This Change Was Made

Recovery already persists the original operator authority and revalidates its current profile, role, device, and access grant. Its internal agent dispatch omitted the existing exact-session binding used by other session continuations. Bind the captured session/run/lifecycle before dispatch, retaining the original scopes and normal own-session checks.

Classify definitive authorization loss separately from storage, lifecycle, and temporarily unavailable policy failures. Route denied pre-admission recovery through the existing guarded notice/settlement owner. No schema, permission, or configuration changes.

Evidence

  • Regression reproduced the exact missing-scope rejection for trusted-proxy and delegated session-only callers before the binding change; broad-write recovery succeeded.
  • 76 focused tests passed across operator-run-recovery.test.ts, server-instance-runtime.operator-recovery.test.ts, and server-instance-runtime.native-restart-recovery.test.ts. Coverage includes cold authority restoration, retained scopes, revocation, cron-owned interruption, exact claims, repeated recovery without duplicate turns/notices, and saved-final preservation. The recovery/router and persistence boundaries are real; the model/turn executor is stubbed.
  • Last owning-boundary run: 38 tests / 2 files, 67.76 s including compilation; authority-restoration run: 38 tests / 1 file, 65.92 s including compilation. This is correctness evidence, not a performance comparison; no latency or GC claim.
  • Targeted core typecheck, changed-file lint/format, export collision guard, and 22 closure checks passed. Final independent autoreview was clean at P0/P1. The simplification pass reuses the existing guarded settlement owner and preserves saved delivery custody.
  • CI caught a stale child-completion consumer of the old access-denied error. The original exact-head run failed subagent-registry.completion-authority.test.ts at “revalidates revoked grant for a cold-loaded interrupted child batch without widening the parent”; local replay reproduced 91 passing / 1 failing. The restoration owner now recognizes the typed definitive denial as well as a live access denial. The unchanged 92-test file passes after the fix (88.74 s including compilation). Changed-file lint/format and an additional independent P0/P1 review passed.
  • A second selected CI shard caught changed revocation wording in requester and automation consumers (3 failures reproduced locally). Recovery now preserves the established public error message and its cause while retaining the typed denial. The two failing files plus the main restart regression pass: 38 tests, 95.80 s including compilation. Changed-file lint/format and a further independent P0/P1 review are clean.
  • Production LOC delta: +105. Growth is the required typed denial/settlement behavior; the fix reuses existing authority, session-binding, and recovery-state owners rather than introducing storage or a parallel recovery path.

A full isolated Gateway/model restart is not yet verified. Production acceptance remains the next operator-coordinated restart. Production grants and configuration were not changed; incident logs alone do not identify each original caller's authentication method.

Inherited CI failure

On head c1331a7695ee36567da649011b27ea2420f65edf, CI run 39620783593, job 119294018629 (checks-node-changed-compact-small-4) fails both cases in src/gateway/server-methods/chat.reset-visible-yield.test.ts before Gateway startup: agents.defaults: Unrecognized key: "heartbeat". The same single file on unchanged main parent 5d2d946899a8a1e2160758487a0ceb34118a9329 fails both cases with the identical configuration error (57.55 s including compilation). The fixture still sets the field removed by #179387; this PR changes neither that fixture nor the agent-default schema. CI tested merge 717e03d7a32b68832fbce02cfd90bf8eed3c0eaa, whose parents are that baseline and this exact PR head. No CI rerun was requested.

The cancelled one-second security-review job was superseded by GitHub concurrency before any steps ran; the required openclaw/security-sensitive-review and dependency-review statuses passed.

Final CI run 39620783593 completed with only the inherited test-shard failure and its aggregate gate failure. The gate log (job 119303715083) confirms all other selected job groups passed, including build, production/test types, lint, docs, UI e2e, security-fast, and PostgreSQL conformance. CodeQL run 39620783387 completed successfully. GitHub retained stale pending rows for some jobs despite the completed workflow results; no rerun was requested. GitHub's independent code review also completed on the exact head with no findings.

Bind recovery to its captured session without broadening persisted operator scopes. Record definitive authorization loss with the existing guarded interruption notice, preserving pending delivery and other recovery custody.
@steipete
steipete marked this pull request as ready for review October 21, 2026 14:53
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 21, 2026
@steipete
steipete force-pushed the steipete/perf-micro-restart-recovery-missing-operator-write-20260919 branch from 7901aa2 to c1331a7 Compare October 21, 2026 14:53
@clawsweeper

clawsweeper Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T15:03:52.813556Z c1331a7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete merged commit 8e590f2 into main Oct 21, 2026
212 of 219 checks passed
@steipete
steipete deleted the steipete/perf-micro-restart-recovery-missing-operator-write-20260919 branch October 21, 2026 15:16
@steipete

Copy link
Copy Markdown
Contributor Author

Landed under the authorized inherited-failure exception. On head c1331a7695ee36567da649011b27ea2420f65edf, CI run 39620783593, job 119294018629, fails both cases in src/gateway/server-methods/chat.reset-visible-yield.test.ts with agents.defaults: Unrecognized key: "heartbeat". Running only that file on unchanged main parent 5d2d946899a8a1e2160758487a0ceb34118a9329 reproduced the same two failures. This PR changes neither the fixture nor the agent-default schema. The actual CI merge commit 717e03d7a32b68832fbce02cfd90bf8eed3c0eaa has that baseline and the reviewed head as its two parents. No CI rerun was requested.

The focused recovery/authority proof passes, and the final independent review is clean. The one-second cancelled security-review job was superseded by concurrency before executing; it is distinct from the passing required security statuses. A real-model sandbox restart and production acceptance remain unverified; the next production restart must use the existing operator coordination. No production grants, configuration, or lifecycle were changed.

Final CI run 39620783593 completed with only the inherited test-shard failure and its aggregate gate failure. The gate log (job 119303715083) confirms all other selected job groups passed, including build, production/test types, lint, docs, UI e2e, security-fast, and PostgreSQL conformance. CodeQL run 39620783387 completed successfully. GitHub retained stale pending rows for some jobs despite the completed workflow results; no rerun was requested. GitHub's independent code review also completed on the exact head with no findings.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…#179579)

* fix(gateway): resume session-scoped operators after restart

Bind recovery to its captured session without broadening persisted operator scopes. Record definitive authorization loss with the existing guarded interruption notice, preserving pending delivery and other recovery custody.

* fix(agents): settle definitive recovery denials in child cohorts

* fix(gateway): preserve recovery revocation error context
@jonathanlindsay

Copy link
Copy Markdown
Contributor

Could this be backported to 2026.10.10 before the stable cut?

On 2026.10.10-beta.2 (unchanged in v2026.10.10-beta.3 and on release/2026.10.10 today: GatewayOperatorRecoveryAuthorizationError is not in src/infra/restart-recovery-errors.ts there), a trusted-proxy user whose role grants operator.sessions.write but not operator.write loses her own conversation for good when her turn is interrupted:

  1. Gateway restart mid-turn. Her turn is inside the model call; the Gateway stops and starts again. Every recovery dispatch fails GatewayClientRequestError: missing scope: operator.write ([main-session-restart-recovery] failed to resume interrupted main session <key>), and every message she sends afterwards ends Error: Restart recovery failed: <key>. See Gateway logs.
  2. Role change in the turn's first second. An admin calls users.setRole for her about 400 ms after her sessions.create {message} (or chat.send) is acknowledged. The Gateway closes her connection (4001 operator role changed) and the session row keeps the turn as started with no end. Recovery then fails Restart recovery operator identity changed., her messages end Restart recovery failed: <key> three times, then SessionRestartRecoveryTombstoneError: Session "<key>" ended during restart recovery. The same role change at other moments behaves well.

Repro (stock, no plugins): gateway.auth.mode: "trusted-proxy" with allowLoopback: true; gateway.roles.definitions with r-member: { scopes: ["operator.read", "operator.sessions.write"], sessions: { others: "none" }, agents: ["a1"] } and r-room: { scopes: ["operator.read", "operator.write"], sessions: { others: "view" }, agents: "*" }; one agent a1 on a fake OpenAI-compatible provider. A user connects through the proxy headers with her own signed device (approved with device.pair.approve), is given r-member with users.setRole, reconnects, and sends sessions.create { key: "agent:a1:direct:<email>", agentId: "a1", message: "..." }. Then either stop and start the Gateway while the model holds the response, or users.setRole her to r-room about 400 ms after the acknowledgement. Reconnect and chat.send to the same key.

Expected: her next message runs. Actual: "Restart recovery failed" on every message. This PR fixes both on main; without it, 2026.10.10 stable strands the conversation of every session-only operator whose turn meets a Gateway restart. I didn't find it in the open PRs against release/2026.10.10 (#180270, #180157).

RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
When main-session restart recovery found that its recorded operator source no longer matched the session or interrupted input, it threw a generic error that bypassed the rejected-recovery settlement owner. The recovery stayed retryable, so every later user message re-ran it and failed with 'Restart recovery failed' until sessions.reset. Ownership loss is now a typed GatewayOperatorRecoveryOwnershipError handled by the existing guarded settlement (pre-admission rejection with an applied reservation rollback): one interruption notice, the stale recovery is retired, and new messages run normally. Pending replies, harness completions and independent runs keep their recovery protection.

Fixes #180802

(cherry picked from commit 50f795a)

Release adaptation: stable lacks the rejected-recovery settlement owner from #179579 and restart-recovery-errors.ts, so this adds a minimal settleRejectedRestartRecovery (ownership errors only, applied rollback, no accepted dispatch) that retires the stale recovery through the existing finishDelegatedRestartRecovery path, plus the typed GatewayOperatorRecoveryOwnershipError. The gateway runtime test is main-only; an equivalent case was added to main-session-restart-recovery.test.ts.
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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants