Skip to content

refactor(gateway): admit the agent RPC turn before its owner bit - #205263

Merged
obviyus merged 1 commit into
mainfrom
refactor/oa2-agent-rpc-admission
Nov 25, 2026
Merged

obviyus merged 1 commit into
mainfrom
refactor/oa2-agent-rpc-admission

Conversation

@obviyus

@obviyus obviyus commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The agent RPC turn decided its own owner bit before admission ran (OA2 PR 6f, follow-up (ii) of #205232).

  • prepareAgentRunDispatch recorded the user turn first and ran admission (retainAgentTurnOperatorRun) afterwards. Only private completions were admitted first.
  • So agent-run-user-turn.ts had no admitted grant and decided owner locally: hasGatewayAdminScope(client) plus four requester-origin shape rules. That is a second owner producer next to decideTurnGrant.
  • Result: any client that carried operator.admin was owner on agent turns, admitted or not. Example: a subagent spawned from an unadmitted System turn with a model override carries [operator.admin] only to allow the override, and its child turn became owner.

Fix

  • agent-run-admission-phase.ts: every agent turn is admitted before its input is recorded (the private-completion path, generalized). The System-turn source choice reads the request's input provenance. The second admission block after input recording is deleted.
  • prepareAgentRunUserTurn takes senderIsOwner = the admitted grant's owner. The transcript stamp and the run use it.
  • Deleted resolveRuntimeSenderIsOwner (the admin-scope and origin-shape rules).

Decisions (recorded, not asked)

  • Cut less (Fable 5.2): the commands.ownerAllowFrom match for a requester origin from a channel (prepareCommandOwnerAuthority, :449-465 on base) stays. Asserted-identity channel owners (iMessage, SMS, IRC, Tlon, Slack relay, A2A, Feishu) have no admitted grant. Their own channel turn keeps owner through command-auth.ts (DESIGN §10 fork 2A). Without this match, their subagent and completion turns would silently lose owner-only tools. It is the same decision command-auth.ts makes for the channel turn, not a second implementation. Because of it, agent-run-user-turn.ts stays in OWNER_PRODUCER_FILES, and the allowlist does not shrink in this PR.
  • Accepted behavior change (unadmitted turns only): a synthetic System client that holds operator.admin without an admitted operator authority is no longer owner on agent turns. Its admin scope authorizes the model override only. This matches MATRIX (SYS → owner ✗). Real socket clients (shared-token CLI, paired admin device, authenticated admin profile), inherited admitted callers and verified-channel owners get the same answer as before: the grant's owner bit.
  • An admission refusal now happens before the input is recorded. The RPC caller gets the same error (INVALID_REQUEST). A returned result still records its "could not start under your current access" notice.

User impact

  • openclaw agent (Gateway mode) and the Control UI give the same owner answer for the same credential, from the same grant.
  • No change for admitted turns. Unadmitted System agent turns lose owner-only tools.

Evidence

  • Production (src, non-test): +40 / −64 (3 files).
  • Owner cells in agent.owner-policy.test-support.ts (run by agent.test.ts): admitted admin CLI → owner; admitted write CLI → not owner; authenticated admin/write profile; admitted operator continuation; configured asserted channel owner → owner; unadmitted admin-scoped CLI and unadmitted System admin → not owner (red on base: base answered owner from the scope).
  • Pre-push: one ocx test call over the touched tests and importers of the changed files; pnpm tsgo:core, pnpm tsgo:test; oxfmt/oxlint on changed files.
  • E2E (one-admission run.sh Q/R/S) on the exact head: results in a follow-up comment.

Every agent turn is admitted before its input is recorded; the run and
transcript take the admitted grant's owner bit. Deleted the admin-scope
and requester-origin shape rules. Asserted channel owners keep the
commands.ownerAllowFrom match (no grant).

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

clawsweeper Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S labels Nov 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels Nov 25, 2026
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on the exact head 0f83921b7b2a:

  1. One-admission Q/R/S (isolated Gateway, real openai/gpt-5.5): verdict.json pass: true.
    • Q queued-input-refused-visibly: pass (visible refusal, 0 provider requests with the queued marker).
    • R running-turn-finishes: pass (3 tool ends after revoke, final state).
    • S stop-cancels: pass (aborted, 1 request with the stop marker).
  2. openclaw agent (Gateway mode, shared token) uses an owner-only tool: isolated token-mode Gateway, tools.allow: [read, automations]. The agent RPC turn ([ws] res ✓ agent, run 0844268f…) called automations (list) and replied AUTOMATIONS_OK 0. The owner bit came from the admitted grant.

Local review on this head: complete, "patch is correct", no findings.

@obviyus
obviyus merged commit 1c83c39 into main Nov 25, 2026
140 checks passed
@obviyus
obviyus deleted the refactor/oa2-agent-rpc-admission branch November 25, 2026 10:10
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 1c83c39. The agent RPC turn is now admitted before its input is recorded, and its owner bit is the admitted grant's owner; the admin-scope and origin-shape rules are gone. Asserted channel owners keep the commands.ownerAllowFrom match. Proof: CI green on the exact head, local review clean, E2E Q/R/S pass, openclaw agent with the shared token used the owner-only automations tool (#205263 (comment)).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
…nclaw#205263)

## Problem

The `agent` RPC turn decided its own owner bit before admission ran (OA2 PR 6f, follow-up (ii) of openclaw#205232).

- `prepareAgentRunDispatch` recorded the user turn first and ran admission (`retainAgentTurnOperatorRun`) afterwards. Only private completions were admitted first.
- So `agent-run-user-turn.ts` had no admitted grant and decided owner locally: `hasGatewayAdminScope(client)` plus four requester-origin shape rules. That is a second owner producer next to `decideTurnGrant`.
- Result: any client that carried `operator.admin` was owner on `agent` turns, admitted or not. Example: a subagent spawned from an unadmitted System turn with a model override carries `[operator.admin]` only to allow the override, and its child turn became owner.

## Fix

- `agent-run-admission-phase.ts`: every `agent` turn is admitted before its input is recorded (the private-completion path, generalized). The System-turn source choice reads the request's input provenance. The second admission block after input recording is deleted.
- `prepareAgentRunUserTurn` takes `senderIsOwner` = the admitted grant's `owner`. The transcript stamp and the run use it.
- Deleted `resolveRuntimeSenderIsOwner` (the admin-scope and origin-shape rules).

## Decisions (recorded, not asked)

- **Cut less (Fable 5.2):** the `commands.ownerAllowFrom` match for a requester origin from a channel (`prepareCommandOwnerAuthority`, `:449-465` on base) stays. Asserted-identity channel owners (iMessage, SMS, IRC, Tlon, Slack relay, A2A, Feishu) have no admitted grant. Their own channel turn keeps owner through `command-auth.ts` (DESIGN §10 fork 2A). Without this match, their subagent and completion turns would silently lose owner-only tools. It is the same decision `command-auth.ts` makes for the channel turn, not a second implementation. Because of it, `agent-run-user-turn.ts` stays in `OWNER_PRODUCER_FILES`, and the allowlist does not shrink in this PR.
- **Accepted behavior change (unadmitted turns only):** a synthetic System client that holds `operator.admin` without an admitted operator authority is no longer owner on `agent` turns. Its admin scope authorizes the model override only. This matches MATRIX (SYS → owner ✗). Real socket clients (shared-token CLI, paired admin device, authenticated admin profile), inherited admitted callers and verified-channel owners get the same answer as before: the grant's owner bit.
- An admission refusal now happens before the input is recorded. The RPC caller gets the same error (`INVALID_REQUEST`). A returned result still records its "could not start under your current access" notice.

## User impact

- `openclaw agent` (Gateway mode) and the Control UI give the same owner answer for the same credential, from the same grant.
- No change for admitted turns. Unadmitted System `agent` turns lose owner-only tools.

## Evidence

- Production (`src`, non-test): +40 / −64 (3 files).
- Owner cells in `agent.owner-policy.test-support.ts` (run by `agent.test.ts`): admitted admin CLI → owner; admitted write CLI → not owner; authenticated admin/write profile; admitted operator continuation; configured asserted channel owner → owner; **unadmitted admin-scoped CLI and unadmitted System admin → not owner (red on base: base answered owner from the scope)**.
- Pre-push: one `ocx test` call over the touched tests and importers of the changed files; `pnpm tsgo:core`, `pnpm tsgo:test`; oxfmt/oxlint on changed files.
- E2E (one-admission run.sh Q/R/S) on the exact head: results in a follow-up comment.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Release adaptation: Use the stable retained custody runner for direct and one-way completion; preserve shared operator scope without attributing mixed-requester batches to one person.

Companion audit: #207030 changes the newer announcement owner and is not needed; keep stable standalone delivery, deadline and row fencing. #205263 is a downstream separate lane row.

(cherry picked from commit 50a6774)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Release adaptation: Share the stable worker-prepared lineage model across typed chat, image input and agent run admission; keep stop and explicit provider/model independent of parent lookup. Preserve inherited provider facts in the stable chat configuration witness and first-send native consent.

Companion audit: #205263 is downstream; #207557 standalone execution does not own these stable entry points.

(cherry picked from commit 27fe9c3)

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 gateway Gateway runtime impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant