Repository navigation
fix(gateway): continuation turns keep the admitted owner grant - #206665
Conversation
A session-event turn (durable exec wake after a restart, scheduler turn, tool handoff) bound owner authority only when its turn kind matched, so an owner's own Control UI session lost owner-only tools (portal) after a Gateway restart. The admitted grant now decides for every entry kind; the ownerContinuation flag and the portal tool's local owner refusal are gone. The owner-only gate's refusal comes from the cause table. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Continuation E2E: real isolated Gateway from source, real model ( Durable exec wake after a Gateway restart (the owner starts
Head, same harness, other entry kinds (all reach the owner path, none refused): typed owner turn, live exec-completion wake, restart-resume of an interrupted turn. Limit: the model keeps filling the optional |
|
|
One-admission E2E on head |
|
Codex review: needs changes before merge. What this changesContinuation turns inherit their requester's admitted owner grant, and non-owner tool refusals use the shared refusal table. Example: A Control UI owner backgrounds sleep 30, restarts the Gateway, and requests portal.open from the completion turn.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this maintainer-authored PR fixes a real continuation-authority failure, but leaves a reload-handoff test expecting the superseded ownership rule. Reviewed head: Before merge
Findings
Agent review detailsHow this fits togetherGateway admission turns authenticated requester facts into a grant; session events carry that grant into command authorization and the agent's tool execution gate. flowchart TD
A[Requester identity] --> B[Operator admission]
B --> C[Admitted grant]
C --> D[Continuation event context]
D --> E[Tool execution gate]
E --> F[Gateway operation]
E --> G[Non-owner refusal]
Technical reviewBest possible solution: Every continuation should consume its requester's admitted grant through the existing execution gate. Do we have a high-confidence way to reproduce the issue? Current main visibly drops an admitted owner's authority when an exec wake lacks ownerContinuation; the supplied isolated Gateway comparison exercises that refusal before the fix and passes the owner gate afterward. Is this the best way to solve the issue? Using admission as the single owner decision removes redundant state and preserves requester identity; the remaining repair is to align the reload-handoff regression with that contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d407ba340e8e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -40, Tests +30, Other 0. Total -10 across 26 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 27, 2026, 7:44 AM ET / 12:44 UTC. |
An admin-scoped operator source is the owner on a resumed turn; the sender flag alone no longer narrows or grants it. Co-authored-by: obviyus <[email protected]>
|
One-admission E2E on head CI round 1 had one red, ours: |
|
Landed as 6ef7508. Bug: continuation turns in the owner's own session (durable exec wake after a restart, tool handoff, scheduler turn) dropped the admitted owner grant at a turn-kind gate, so |
## Problem The rule "check authority one time, when work starts" was one bullet inside root `AGENTS.md` "Choose good compromises". New changes still add post-start authority re-checks (`assertCurrent()`-style re-reads, tool-time `senderIsOwner` refusals, refusal text outside the cause table). These give one person different answers depending on how or when a turn started (#203464), for example `portal` refused in an owner's turn after a Gateway restart (#206665). The one-admission work found 242 such refusal strings in 186 files. ## Change Docs and agent instructions only. No runtime code. - Root `AGENTS.md`: new top section **Decide authority once**. It names the owner (`decideOperatorAdmission` in `src/gateway/operator-admission.ts`, frozen `TurnGrant`), the post-start checks that need explicit maintainer buy-in, the allowed fences (revision, `expectedHead`, `requestId`, compare-and-swap, abort signal), the accepted trade-off (a revoked person's started turn finishes) and the incidents. The old bullet, the duplicate "Security boundaries" authority bullet and a duplicate review pointer are removed. The file stays under 20,000 characters (19,961). - `src/gateway/AGENTS.md`: new **Operator Admission** section: grant fields, continuation re-admission, tool gate, refusal cause table, how to add a permission (admission fact + `decideTurnGrant` field + matrix cell in `operator-admission.table.test.ts`), and the two boundary lints whose allowlists only shrink. The "live-authority checks" line under Run Authority now says liveness fences, which never re-read authority. - `src/agents/AGENTS.md`: tools consume the turn's `TurnGrant` and add no owner, scope or authority check of their own. - Review route: `docs/reference/pull-request-review-flow.md` tells every review route to report a post-start authority re-check as P1; `pr-simplify` applies the new root section. - `scripts/lib/no-operator-permission-read.mjs`: comment points at the new section name. ## Impact Contributors and agents see the rule first in root `AGENTS.md`, with the owner and file pointers. Reviews flag new mid-run authority re-checks as P1. ## Evidence - `pnpm check:agents-md-size`: 29 files within 20,000 chars. - `pnpm docs:check-links`: 0 broken. - `oxfmt --check` on the 6 changed files: clean. - `git diff --check`: clean. Co-authored-by: Ayaan Zaidi <[email protected]>
…law#206665) ## Problem In the owner's own Control UI session, a turn the Gateway starts for that session (a background `exec` completion after a Gateway restart, a scheduler turn, a tool handoff whose sender flag was unset) lost the owner's authority. The model then got `portal needs the owner's authority, and this turn was not started by the owner` and told the owner to "send any message" to get it back. The same person got a different answer depending on how the turn started. Root cause: `buildSessionEventContext` (`src/auto-reply/reply/session-event-context.ts`) bound the command-owner authority only when the admitted grant said owner **and** the turn kind was `restart`, a scheduled run, or the target carried an `ownerContinuation` flag. Only the live same-session exec notifier and some tool handoffs set that flag. A durable exec wake (`captureOwedRequesterTarget`, used for a process restored after a restart and for stored owed rows) re-admits the requester through `restoreGatewayQueuedOperatorRecovery`, gets `grant.owner === true`, and then lost it at this gate: `senderIsOwner` became `false`, owner-only tools were refused. Observed on main (`46674419098b`, real isolated Gateway, real model, token-auth Control UI owner session): after `gateway.restart.request`, the wake for the interrupted command ran with the admitted owner grant but `senderIsOwner: false`, and its tool surface treated it as a non-owner turn. ## Fix The admitted grant is the only producer of the owner decision for a session-event turn (`decideOperatorAdmission` → `grant.owner`). Turn kind no longer narrows it. - `session-event-context.ts`: bind owner authority when `operatorAuthority.grant.owner`; no turn-kind condition. - Delete the `ownerContinuation` flag and every producer and reader: `session-event-target.ts` (scope field, option, reader, batch check), `bash-tools.exec-notify.ts`, `session-tool-handoff.ts` (and the `senderIsOwner` pass-through in `github-publish-tool.ts`, `session-project-tool.ts`, `sessions-send-self-hold.ts`), `cron-job-turn-target.ts`. - `portal-tool.ts`: delete the local `senderIsOwner === false` refusal. The turn's owner-only tool gate (`resolveTurnToolSurface` → `gateAgentToolExecution`, and the HTTP/loopback `ownerOnlyDeny`) already refuses a non-owner call without a conversation worker. - The owner-only gate's refusal comes from the cause table: new `owner-only` cause in `src/gateway/operator-refusal.ts` with a next step ("Ask the Gateway owner to do it."). The text no longer says "this turn was not started by the owner", which led the model to ask the owner to send another message. Production: +14 / −54. Decisions recorded (standing authority): - A completion that a requester's command routed to another chat (`cross-session` row in `bash-tools.exec-notify.owner-continuation.test.ts`) now runs with that requester's admitted grant, like every other continuation. Before, it already carried that grant for control-plane tools; only the sender flag differed. Test row updated. - A scheduler turn about a job (`cron`, `cron_failure_repair`) now takes the owner bit from its restored source's grant (admin scope), not from the extra `automationAdmin` delegation flag. The `automations` capability itself is unchanged. - No widening beyond the recorded principal's own grant: a member's or guest's continuation still has `owner: false` and gets the cause-table refusal. Other tools that still refuse locally on `senderIsOwner` (outside this PR, OA2 PR 6 sweep): `src/agents/tools/conversation-tools.ts:71`, `session-project-tool.ts:67`, `sessions-tool.ts:194,387`, `openclaw-delegate-tool.ts:293`, `extensions/codex/src/{command-diagnostics.ts:63,native-plugin-tool.ts:46,native-thread-tool.ts:166,supervision-tools.ts:706}`, `extensions/discord/src/actions/handle-action.guild-admin.ts:64,77`, `extensions/imessage/src/actions.ts:291`, `extensions/matrix/src/tool-actions.ts:348,422`, `extensions/visitor-access/src/tools.ts:84`, `extensions/whatsapp/src/agent-tools-login.ts:41`. ## User impact After a Gateway restart, the owner's session can open portals and use other owner-only tools again from the automatic completion turn. A real non-owner continuation is refused with "I did not run portal. It needs the Gateway owner's authority, and this turn does not run with it. Ask the Gateway owner to do it." ## Evidence - Regression: `src/gateway/owed-exec-requester.test.ts` reads the woken turn's own owner decision (the context the session event builds, as commands and owner tools read it) for `exec`, `restart` and `tool_handoff` on the same admitted target. Red on the merge base (admin and configured channel owner cells: `owner: { exec: false, restart: true, tool_handoff: false }`), green on head. Member cell stays `owner: false`. - Matrix note in `src/gateway/operator-admission.table.test.ts` points at those continuation cells. - E2E: see the comment below (real isolated Gateway, real model, owner Control UI session, `gateway.restart.request`; plus the one-admission Q/R/S run). Co-authored-by: Ayaan Zaidi <[email protected]>
…#206706) ## Problem The rule "check authority one time, when work starts" was one bullet inside root `AGENTS.md` "Choose good compromises". New changes still add post-start authority re-checks (`assertCurrent()`-style re-reads, tool-time `senderIsOwner` refusals, refusal text outside the cause table). These give one person different answers depending on how or when a turn started (openclaw#203464), for example `portal` refused in an owner's turn after a Gateway restart (openclaw#206665). The one-admission work found 242 such refusal strings in 186 files. ## Change Docs and agent instructions only. No runtime code. - Root `AGENTS.md`: new top section **Decide authority once**. It names the owner (`decideOperatorAdmission` in `src/gateway/operator-admission.ts`, frozen `TurnGrant`), the post-start checks that need explicit maintainer buy-in, the allowed fences (revision, `expectedHead`, `requestId`, compare-and-swap, abort signal), the accepted trade-off (a revoked person's started turn finishes) and the incidents. The old bullet, the duplicate "Security boundaries" authority bullet and a duplicate review pointer are removed. The file stays under 20,000 characters (19,961). - `src/gateway/AGENTS.md`: new **Operator Admission** section: grant fields, continuation re-admission, tool gate, refusal cause table, how to add a permission (admission fact + `decideTurnGrant` field + matrix cell in `operator-admission.table.test.ts`), and the two boundary lints whose allowlists only shrink. The "live-authority checks" line under Run Authority now says liveness fences, which never re-read authority. - `src/agents/AGENTS.md`: tools consume the turn's `TurnGrant` and add no owner, scope or authority check of their own. - Review route: `docs/reference/pull-request-review-flow.md` tells every review route to report a post-start authority re-check as P1; `pr-simplify` applies the new root section. - `scripts/lib/no-operator-permission-read.mjs`: comment points at the new section name. ## Impact Contributors and agents see the rule first in root `AGENTS.md`, with the owner and file pointers. Reviews flag new mid-run authority re-checks as P1. ## Evidence - `pnpm check:agents-md-size`: 29 files within 20,000 chars. - `pnpm docs:check-links`: 0 broken. - `oxfmt --check` on the 6 changed files: clean. - `git diff --check`: clean. Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
In the owner's own Control UI session, a turn the Gateway starts for that session (a background
execcompletion after a Gateway restart, a scheduler turn, a tool handoff whose sender flag was unset) lost the owner's authority. The model then gotportal needs the owner's authority, and this turn was not started by the ownerand told the owner to "send any message" to get it back. The same person got a different answer depending on how the turn started.Root cause:
buildSessionEventContext(src/auto-reply/reply/session-event-context.ts) bound the command-owner authority only when the admitted grant said owner and the turn kind wasrestart, a scheduled run, or the target carried anownerContinuationflag. Only the live same-session exec notifier and some tool handoffs set that flag. A durable exec wake (captureOwedRequesterTarget, used for a process restored after a restart and for stored owed rows) re-admits the requester throughrestoreGatewayQueuedOperatorRecovery, getsgrant.owner === true, and then lost it at this gate:senderIsOwnerbecamefalse, owner-only tools were refused.Observed on main (
39b6a89d2984, real isolated Gateway, real model, token-auth Control UI owner session): aftergateway.restart.request, the wake for the interrupted command ran with the admitted owner grant butsenderIsOwner: false, and its tool surface treated it as a non-owner turn.Fix
The admitted grant is the only producer of the owner decision for a session-event turn (
decideOperatorAdmission→grant.owner). Turn kind no longer narrows it.session-event-context.ts: bind owner authority whenoperatorAuthority.grant.owner; no turn-kind condition.ownerContinuationflag and every producer and reader:session-event-target.ts(scope field, option, reader, batch check),bash-tools.exec-notify.ts,session-tool-handoff.ts(and thesenderIsOwnerpass-through ingithub-publish-tool.ts,session-project-tool.ts,sessions-send-self-hold.ts),cron-job-turn-target.ts.portal-tool.ts: delete the localsenderIsOwner === falserefusal. The turn's owner-only tool gate (resolveTurnToolSurface→gateAgentToolExecution, and the HTTP/loopbackownerOnlyDeny) already refuses a non-owner call without a conversation worker.owner-onlycause insrc/gateway/operator-refusal.tswith a next step ("Ask the Gateway owner to do it."). The text no longer says "this turn was not started by the owner", which led the model to ask the owner to send another message.Production: +14 / −54.
Decisions recorded (standing authority):
cross-sessionrow inbash-tools.exec-notify.owner-continuation.test.ts) now runs with that requester's admitted grant, like every other continuation. Before, it already carried that grant for control-plane tools; only the sender flag differed. Test row updated.cron,cron_failure_repair) now takes the owner bit from its restored source's grant (admin scope), not from the extraautomationAdmindelegation flag. Theautomationscapability itself is unchanged.owner: falseand gets the cause-table refusal.Other tools that still refuse locally on
senderIsOwner(outside this PR, OA2 PR 6 sweep):src/agents/tools/conversation-tools.ts:71,session-project-tool.ts:67,sessions-tool.ts:194,387,openclaw-delegate-tool.ts:293,extensions/codex/src/{command-diagnostics.ts:63,native-plugin-tool.ts:46,native-thread-tool.ts:166,supervision-tools.ts:706},extensions/discord/src/actions/handle-action.guild-admin.ts:64,77,extensions/imessage/src/actions.ts:291,extensions/matrix/src/tool-actions.ts:348,422,extensions/visitor-access/src/tools.ts:84,extensions/whatsapp/src/agent-tools-login.ts:41.User impact
After a Gateway restart, the owner's session can open portals and use other owner-only tools again from the automatic completion turn. A real non-owner continuation is refused with "I did not run portal. It needs the Gateway owner's authority, and this turn does not run with it. Ask the Gateway owner to do it."
Evidence
src/gateway/owed-exec-requester.test.tsreads the woken turn's own owner decision (the context the session event builds, as commands and owner tools read it) forexec,restartandtool_handoffon the same admitted target. Red on the merge base (admin and configured channel owner cells:owner: { exec: false, restart: true, tool_handoff: false }), green on head. Member cell staysowner: false.src/gateway/operator-admission.table.test.tspoints at those continuation cells.gateway.restart.request; plus the one-admission Q/R/S run).