Skip to content

refactor(gateway): request entries read the owner from the request grant - #205303

Merged
obviyus merged 3 commits into
mainfrom
refactor/oa2-request-owner
Nov 25, 2026
Merged

obviyus merged 3 commits into
mainfrom
refactor/oa2-request-owner

Conversation

@obviyus

@obviyus obviyus commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

OA2 PR 6d (one admission owner). Four request entries decided "the sender is the owner" for themselves, from the connection's operator.admin scope:

  • conversations.send / conversations.turn (server-methods/conversations.ts)
  • tools.invoke RPC (server-methods/tools-invoke.ts)
  • session resource tool policy (session-resource-tool-policy.ts, MCP App and session resource methods)
  • OpenAI-compatible HTTP pre-run owner bit (openai-compatible-http.ts)

That gave the same person two answers. An agent's conversations_send / conversations_turn tool (owner-only) and plugin tools.invoke calls dispatch in process with least-privilege scopes (operator.write) and the run's admitted authority. The handler ignored the admitted grant and saw "not owner", so the owner's own agent ran the conversation turn without owner tools, while the same owner calling the same method from the Control UI was owner.

Fix

  • operator-admission.ts exports readGatewayRequestAdmission(client): the request's grant is its admitted run's grant (client.internal.operatorRunAuthority.grant), else the grant decideTurnGrant decides from the connection scopes.
  • conversations, tools.invoke and the session resource tool policy read ….grant.owner from it.
  • OpenAI-compatible HTTP: prepareOpenAiCompatibleHttpRequest returns grant = decideTurnGrant(operatorScopes) (the same request scopes the run is admitted with); /v1/chat/completions and /v1/responses session checks read grant.owner.
  • Lint: OWNER_PRODUCER_FILES 28 → 24 (four request files leave; ceiling lowered).

Decisions (recorded, not asked)

  • The admitted run's grant wins over the in-process client's least-privilege scopes. The synthetic scopes narrow which Gateway method may run, not who the requester is. Owner-only conversation tools already require an owner run, so the owner now keeps owner status in the conversation turn they started. A member run stays non-owner (cell below).
  • No full decideOperatorAdmission per RPC request. Request admission (method authorization) is OA3; this PR only removes the second owner producers. A bare socket still gets the grant its connect scopes decide, through decideTurnGrant.
  • Talk not moved (split). talk/client-tool-authority.ts stays listed. The Talk tool overlay takes the owner from resolveCommandAuthorization, which includes the commands.ownerAllowFrom match for a Talk caller without admin (client-permission-parity "uses configured ownership without admin"). Moving only the consult bit would leave consult and tools able to disagree and would make the file look migrated. Talk moves when admission represents configured owners (refactor(auto-reply): reply runs take the owner decision their commands used #205232 follow-up (i)).
  • Production lines (recorded): src non-test +21 / −16 (net +5), counting the lint allowlist net 0. The +7 is the one request-grant read in the admission owner. The cause is missing code: request entries never read the admitted grant. No flag, hook or state was added.
  • Kept: resolveOpenAiCompatibleHttpSenderIsOwner for the model-override and managed-image checks (pre-run request checks, not owner producers; OA3 seam, same as refactor(gateway): admit HTTP shared-secret requests as the owner principal #205091).

User impact

  • An owner's agent that uses conversations_turn / conversations_send, or a plugin that calls tools.invoke in process, now runs with the owner's tools, the same as the owner calling the method directly.
  • Non-owners see no change. Control UI, Talk and HTTP owners see no change.

Evidence

  • Cells (red on base 71b629c5f86e, green on head): conversations.test.ts and new tools-invoke.test.ts, each owner socket / write socket / owner run (write scopes + admitted owner authority) / member run. Base: only owner run fails (senderIsOwner: false); head: 8/8.
  • Pre-push and E2E: see comments.
  • Pre-push: one ocx test call over 55 files (touched tests + direct importers of every changed source/test-support, OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1). 1 OURS (client-permission-parity configured owner): Talk cut from this PR, green. 42 Talk handler failures (client-create-authority, talk/handlers/client, talk/handlers/index) fail identically on base 71b629c5f86e (Cannot read properties of undefined (reading 'role')): not this change. One openai-http SSE case timed out at load 74; green on rerun (112/112). After rebase: pnpm tsgo:core, pnpm tsgo:test clean; cells + lint guard green; oxfmt/oxlint clean.

conversations, tools.invoke, session resource tool policy, Talk consult and OpenAI-compatible HTTP read grant.owner from readGatewayRequestAdmission/decideTurnGrant instead of deciding owner from the admin scope. In-process calls keep their admitted run's grant. OWNER_PRODUCER_FILES 28 -> 23.

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.

ClawSweeper review complete

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

View the workflow run.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: 481fbcfb73d5349cffd1f2cf7a0010c3d8db1fc9

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

@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. labels Nov 25, 2026
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on exact head 9622cbeecbe3 (one-admission-e2e/run.sh, isolated scratch Gateway, live gpt-5.5): pass.

  • R.running-turn-finishes: pass
  • Q.queued-input-refused-visibly: pass
  • S.stop-cancels: pass

verdict.json + results.jsonl kept in the task proof directory. Live Gateway pid unchanged; live config not written.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. labels Nov 25, 2026
@clawsweeper

clawsweeper Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Gateway request handlers read ownership from the admitted run grant, falling back to a grant derived from connection scopes.

Example: An admitted owner run calls tools.invoke with operator.write request scopes.

  • Before: The handler marks the caller as non-owner, filtering owner-only tools.
  • After: The handler retains the run's owner grant while other tool policies still apply.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The production consolidation is coherent, but the added test has a deterministic CI blocker and the supplied live scenario does not establish the changed behavior.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An admitted owner's request can lose owner-only capabilities when a handler reconstructs ownership from narrower method scopes.
Reason: The maintainer-authored direction follows the existing single-admission-owner contract without adding configuration, storage, or a competing authority owner.

Merge readiness

⛔ Needs changes before merge - 2 items remain

This PR usefully centralizes request ownership, but the new mock violates the CI ratchet and GitHub now reports a merge conflict.

Reviewed head: 9622cbeecbe3ae2df573933a7c7f436b20087f5a

Before merge

  • Preserve real exports in the new tool-invocation mock (P2) - The new first-party mock returns a closed factory without importOriginal/vi.importActual pass-through or an adjacent mock-isolation explanation. scripts/check-test-mock-exports.mts rejects every new factory of this form, so this addition fails both the mock-export check and its aggregate ratchet. Preserve the real exports, or replace this mocked test with production-boundary coverage; do not expand the baseline.
  • Complete next step - The author should resolve GitHub's reported merge conflict against main.

Findings

  • [P2] Preserve real exports in the new tool-invocation mock — src/gateway/server-methods/tools-invoke.test.ts:6

Tests

  • Low-value test src/gateway/server-methods/tools-invoke.test.ts: Replace the added mock-call matrix: it asserts senderIsOwner arguments while supplying unconditional tool success, so it cannot detect owner-only tool availability remaining broken.
  • Low-value test src/gateway/server-methods/conversations.test.ts: Replace the added ownership argument matrix with production-boundary coverage; its mocked conversation sender does not exercise delivery policy or the real in-process caller.
  • Missing end-to-end proof: Provide redacted logs or terminal output from an isolated Gateway showing an admitted owner retaining owner-only capability through the changed in-process request path, with a non-owner still denied.
Agent review details

How this fits together

Gateway RPC, HTTP, session-resource, and Talk entry points translate authenticated request context into ownership facts consumed by tool and session authorization.

flowchart TD
  A[Authenticated connection] --> C[Request admission reader]
  B[Admitted run grant] --> C
  C --> D[RPC and Talk handlers]
  E[Authenticated HTTP scopes] --> F[Turn grant decision]
  F --> G[HTTP session authorization]
  D --> H[Tool and conversation execution]
Loading

Technical review

Best possible solution:

Keep the shared admission reader and consumer migration, replacing mocked argument checks with focused owner/member behavior coverage through the existing production boundary.

Do we have a high-confidence way to reproduce the issue?

An internal client carrying an owner grant and operator.write scopes produces false ownership on the base and true ownership with this patch; the supplied tests construct that input, but no shipped-entry-point reproduction of it is shown.

Is this the best way to solve the issue?

The shared admission owner is the smallest coherent location for the decision, and the HTTP change preserves its existing scope semantics; the retained Talk command-owner path is explicitly justified rather than silently removed.

Full review comments:

  • [P2] Preserve real exports in the new tool-invocation mock — src/gateway/server-methods/tools-invoke.test.ts:6
    The new first-party mock returns a closed factory without importOriginal/vi.importActual pass-through or an adjacent mock-isolation explanation. scripts/check-test-mock-exports.mts rejects every new factory of this form, so this addition fails both the mock-export check and its aggregate ratchet. Preserve the real exports, or replace this mocked test with production-boundary coverage; do not expand the baseline.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2ac011e302a3.

Provenance checked

  • Request ownership keeps the original intent (63e0742: Admission owns the frozen turn grant; continuation narrowing derives a new grant.)
  • Owner-only tool invocation changes intended behavior with a stated reason (2a21de6: fix: gate owner-only HTTP tools #90261 prevents non-owners from exposing owner-only tools through allowlists.)
  • HTTP request ownership keeps the original intent (2fc20b3: The shared HTTP adapter preserves transport authorization; both old and new owner decisions use resolveSharedSecretHttpOperatorScopes.)
  • Session-resource policy keeps the original intent (0599647: Generic session-resource admission evaluates canonical tool policy from prepared session facts.)
  • Talk authority keeps the original intent (99caa18: This commit moved existing consult authority into its current module; configured command ownership and read-only tool restrictions are retained. An older content-history search failed on an unavailable promisor blob.)
  • Owner-producer lint inventory keeps the original intent (da3479a: The inventory distinguishes owner producers from pass-through consumers and shrinks as production decisions move into admission.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 63e0742 adds src/gateway/operator-admission.ts:232 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 63e0742f9970; files: src/gateway/operator-admission.ts)
  • Vincent Koc: Raw commit 99caa18 adds src/gateway/talk/client-tool-authority.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 99caa18ecd28; files: src/gateway/talk/client-tool-authority.ts)
  • Peter Steinberger: Raw commit dc518bf adds src/gateway/server-methods/conversations.ts:115 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: dc518bfca481; files: src/gateway/server-methods/conversations.ts)

PR surface

Source +2, Tests +60, Other -6. Total +56 across 21 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 12 31 29 +2
Tests 8 67 7 +60
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 6 -6
Total 21 98 42 +56

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 25, 2026, 6:49 AM ET / 11:49 UTC.

….invoke cell mock

Talk stays an owner producer: its tool overlay owner includes the commands.ownerAllowFrom match for a Talk caller without admin. OWNER_PRODUCER_FILES ceiling 24. The tools.invoke cell mock records its isolation reason.

Co-authored-by: obviyus <[email protected]>
…owner

# Conflicts:
#	test/scripts/oxlint-boundary-guards.test.ts
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on exact head 481fbcfb73d5 (one-admission-e2e/run.sh, isolated scratch Gateway, live gpt-5.5): pass.

  • R.running-turn-finishes: pass
  • Q.queued-input-refused-visibly: pass
  • S.stop-cancels: pass

verdict.json + results.jsonl kept in the task proof directory. Live Gateway pid unchanged; live config not written.

@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: build-artifacts is red on main, not from this PR.

  • Failure: pnpm gateway:validators:check → packages/gateway-protocol/src/compiled/protocol.generated/predicates.js is stale; run pnpm gateway:validators:gen (runs 45604993121 and 45609777594, heads 9622cbeecbe3 and 481fbcfb73d5).
  • This PR changes no file under packages/ and no protocol schema.
  • Reproduced on merge base ea3c64568501 in a clean ocx base --src checkout: same error, same file.
  • ci-triage 205303: no failing test files (build step). Filed as main: gateway protocol predicates.js is stale (build-artifacts red) #205340.
  • Every other job on 481fbcfb73d5 is green.

@obviyus
obviyus merged commit 5730bde into main Nov 25, 2026
127 of 130 checks passed
@obviyus
obviyus deleted the refactor/oa2-request-owner branch November 25, 2026 12:21
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 5730bde. Bug: an owner's agent calling conversations_send/conversations_turn or an in-process tools.invoke ran as non-owner, because the handler read the least-privilege dispatch scopes instead of the run's admitted grant. Fix: conversations, tools.invoke, the session resource tool policy and OpenAI-compatible HTTP read grant.owner (owner producers 28 → 24; Talk is split out). Proof: owner-run cells red on base, green on head; Q/R/S E2E pass on the exact head; local review clean. build-artifacts was overridden as red on main (#205340).

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

## Problem

OA2 PR 6d (one admission owner). Four request entries decided "the sender is the owner" for themselves, from the connection's `operator.admin` scope:

- `conversations.send` / `conversations.turn` (`server-methods/conversations.ts`)
- `tools.invoke` RPC (`server-methods/tools-invoke.ts`)
- session resource tool policy (`session-resource-tool-policy.ts`, MCP App and session resource methods)
- OpenAI-compatible HTTP pre-run owner bit (`openai-compatible-http.ts`)

That gave the same person two answers. An agent's `conversations_send` / `conversations_turn` tool (owner-only) and plugin `tools.invoke` calls dispatch in process with least-privilege scopes (`operator.write`) and the run's admitted authority. The handler ignored the admitted grant and saw "not owner", so the owner's own agent ran the conversation turn without owner tools, while the same owner calling the same method from the Control UI was owner.

## Fix

- `operator-admission.ts` exports `readGatewayRequestAdmission(client)`: the request's grant is its admitted run's grant (`client.internal.operatorRunAuthority.grant`), else the grant `decideTurnGrant` decides from the connection scopes.
- `conversations`, `tools.invoke` and the session resource tool policy read `….grant.owner` from it.
- OpenAI-compatible HTTP: `prepareOpenAiCompatibleHttpRequest` returns `grant = decideTurnGrant(operatorScopes)` (the same request scopes the run is admitted with); `/v1/chat/completions` and `/v1/responses` session checks read `grant.owner`.
- Lint: `OWNER_PRODUCER_FILES` 28 → 24 (four request files leave; ceiling lowered).

## Decisions (recorded, not asked)

- **The admitted run's grant wins over the in-process client's least-privilege scopes.** The synthetic scopes narrow which Gateway method may run, not who the requester is. Owner-only conversation tools already require an owner run, so the owner now keeps owner status in the conversation turn they started. A member run stays non-owner (cell below).
- **No full `decideOperatorAdmission` per RPC request.** Request admission (method authorization) is OA3; this PR only removes the second owner producers. A bare socket still gets the grant its connect scopes decide, through `decideTurnGrant`.
- **Talk not moved (split).** `talk/client-tool-authority.ts` stays listed. The Talk tool overlay takes the owner from `resolveCommandAuthorization`, which includes the `commands.ownerAllowFrom` match for a Talk caller without admin (`client-permission-parity` "uses configured ownership without admin"). Moving only the consult bit would leave consult and tools able to disagree and would make the file look migrated. Talk moves when admission represents configured owners (openclaw#205232 follow-up (i)).
- **Production lines (recorded):** `src` non-test +21 / −16 (net +5), counting the lint allowlist net 0. The +7 is the one request-grant read in the admission owner. The cause is missing code: request entries never read the admitted grant. No flag, hook or state was added.
- **Kept:** `resolveOpenAiCompatibleHttpSenderIsOwner` for the model-override and managed-image checks (pre-run request checks, not owner producers; OA3 seam, same as openclaw#205091).

## User impact

- An owner's agent that uses `conversations_turn` / `conversations_send`, or a plugin that calls `tools.invoke` in process, now runs with the owner's tools, the same as the owner calling the method directly.
- Non-owners see no change. Control UI, Talk and HTTP owners see no change.

## Evidence

- Cells (red on base `1a4f4a41098c`, green on head): `conversations.test.ts` and new `tools-invoke.test.ts`, each owner socket / write socket / owner run (write scopes + admitted owner authority) / member run. Base: only `owner run` fails (`senderIsOwner: false`); head: 8/8.
- Pre-push and E2E: see comments.
- Pre-push: one `ocx test` call over 55 files (touched tests + direct importers of every changed source/test-support, `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1`). 1 OURS (`client-permission-parity` configured owner): Talk cut from this PR, green. 42 Talk handler failures (`client-create-authority`, `talk/handlers/client`, `talk/handlers/index`) fail identically on base `1a4f4a41098c` (`Cannot read properties of undefined (reading 'role')`): not this change. One `openai-http` SSE case timed out at load 74; green on rerun (112/112). After rebase: `pnpm tsgo:core`, `pnpm tsgo:test` clean; cells + lint guard green; oxfmt/oxlint clean.

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 admitted scope ceiling for persisted and runtime ownership, keeping configured requester ownership separate.

Companion audit: Requester custody and inherited-model companions are already committed. #205303 and #205451 extend the newer grant contract; not required.

(cherry picked from commit 1c83c39)

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

gateway Gateway runtime impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant