Skip to content

refactor(gateway): local-host owner producers read the admitted grant - #205255

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

obviyus merged 3 commits into
mainfrom
refactor/oa2-local-host-owner

Conversation

@obviyus

@obviyus obviyus commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

OA2 PR 6a (one admission owner). Processes the operator runs on this host each decided "the sender is the owner" for themselves:

  • openclaw agent --local (and agent exec, BOOT.md, Template setup): senderIsOwner: opts.senderIsOwner ?? true.
  • openclaw message: senderIsOwner: opts.senderIsOwner !== false.
  • Codex supervision stdio MCP: a private { senderIsOwner: true } constant.
  • MCP loopback: { senderIsOwner: ownerTokenMatched }, where the alternative was a raw non-owner token that no production code ever hands out.

These were four more owner producers outside admission (OWNER_PRODUCER_FILES).

Fix

  • operator-admission.ts exports LOCAL_HOST = { grant: decideTurnGrant(["operator.admin"]) }: the local host is the owner principal, and decideTurnGrant decides its grant. The four entries read LOCAL_HOST.grant.owner.
  • agent-command-local.ts: no caller option narrows the local owner (no production caller set it). The local cron-creator capability is now gated only by operatorAuthority, because the senderIsOwner === true check is always true.
  • MCP loopback: deleted the unused raw non-owner token (nonOwnerToken in the runtime, listener and request auth). CLI backends get run-bound client grants; attach clients get attach grants. Only the in-process owner token remains, and it names the local host.
  • OWNER_PRODUCER_FILES 32 → 28 after merging main (ceiling lowered).

Decisions (recorded, not asked)

  • Worker placement stays listed (src/worker/embedded-agent.runtime.ts). The worker runs tools on a separate box for a run the Gateway admitted. The correct value is that run's grant.owner, and the worker protocol does not carry it. LOCAL_HOST there would declare every remote box an owner. Carrying the bit is a protocol change, so it is not in this PR (Fable 5.2 consult).
  • No full decideOperatorAdmission for in-process local runs. It would set operatorAuthority on CLI-local runs and change many downstream branches. It would also need the profile store in the stdio MCP and the worker. The grant comes from the same decideTurnGrant.
  • Raw non-owner MCP token deleted, not kept. Only mcp-http.ts created it and only resolveMcpSender compared it; no production path hands it to a client (CLI backends use run-bound client grants, attach uses attach grants). Deleting it closes no client route. Without it the owner-token producer could not move, and production would not be net negative.
  • Accepted risk: any file can import LOCAL_HOST and pass the owner lint. Today it has four readers; adding an import allowlist would be a new guard.

User impact

None. A local CLI user, the message CLI, the standalone Codex supervision MCP and the in-process MCP owner token stay owner.

Evidence

  • Production (src, non-test): +18 / −21.
  • One cell per entry, through the real entry function:
    • agent-command-local.test.ts: every local run reaches preparation with senderIsOwner: true; the operator run gets the local cron-creator capability.
    • message.test.ts: the message CLI dispatches with senderIsOwner: true.
    • plugin-tools-serve.test.ts: Codex supervision MCP context has senderIsOwner: true.
    • mcp-http.test.ts: a real loopback listener request with the owner token resolves tools with senderIsOwner: true.
  • test/scripts/oxlint-boundary-guards.test.ts: ceiling 28; the stale-entry check passes for the four removed files.
  • Real openclaw agent --local on an isolated profile (ocx src -- --profile e2e), real openai/gpt-5.5: the model called the owner-only sessions tool and replied LOCAL_OWNER_DONE 0; exit 0.
  • Pre-push checks: one ocx test call over 62 files (touched tests plus direct importers of every changed source; the 318-file set with test-support importers is over the 150 cap), all green. pnpm tsgo:core, pnpm tsgo:test, oxfmt and oxlint on changed files: clean. pnpm check:changed: the changelog attribution lane fails on files this PR does not touch (same as refactor(gateway): decide automations rights once, as the turn grant #205173); the rest was still running at 15 min, so CI runs it.
  • Q/R/S E2E on the exact head: see the follow-up comment.

The CLI --local run, the message CLI, the Codex supervision stdio MCP and the
in-process MCP owner token now read LOCAL_HOST.grant.owner, decided by
decideTurnGrant, instead of deciding owner status themselves. Delete the
unused raw MCP loopback non-owner token. OWNER_PRODUCER_FILES 33 -> 29;
the remote worker placement stays listed (its run's grant is not on the
worker protocol).

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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: S labels Nov 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. labels Nov 25, 2026
…st-owner

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

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on the exact head 97bf1de9def7 (isolated Gateway, real openai/gpt-5.5 through a byte relay):

  • Q queued input refused visibly: pass
  • R running turn finishes: pass
  • S Stop cancels: pass
  • Verdict pass: true, 57060 ms, models ["gpt-5.5-2026-04-23"].

Local CLI owner check: openclaw agent --local on an isolated profile (source CLI, real model). The model called the owner-only sessions tool once and replied LOCAL_OWNER_DONE 0; exit 0.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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-repro 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

This PR centralizes local-host ownership in the turn-grant owner and removes the unused raw non-owner MCP token.

Example: Run openclaw agent --local and call the sessions tool.

  • Before: The local command independently defaults senderIsOwner to true.
  • After: The command reads LOCAL_HOST.grant.owner and retains the same owner access.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The production consolidation is focused and supported by caller tracing, but exact-head validation exposes an unadapted consumer test.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored refactor preserves supported user behavior; the discussion additionally reports a local CLI owner-tool smoke run and exact-head lifecycle checks.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
Reason: The maintainer-authored direction reduces duplicate authority decisions and removes unused authentication machinery while preserving supported production behavior.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this maintainer-authored PR open: the authority consolidation is coherent, but an unchanged transcript test now fails because it still treats a local operator run as non-owner.

Reviewed head: 97bf1de9def7cabc2f74fd3a0a74c92b4caf4a61

Before merge

  • Update transcript ownership coverage for local-host admission (P2) - Forcing local sender ownership to true invalidates the existing false/external_user row in src/agents/agent-command.compaction-rotation.test.ts:350-371. Exact-head CI fails at line 365 because both opts.senderIsOwner and the transcript owner stamp are now true. The local behavior is intentional, so update its expectation and retain non-owner transcript coverage through the existing Gateway ingress entry point rather than restoring caller-side owner derivation or deleting the security contract.

Findings

  • [P2] Update transcript ownership coverage for local-host admission — src/agents/agent-command-local.ts:70
Agent review details

How this fits together

Local CLI and standalone MCP entry points prepare tool-execution contexts; Gateway MCP authentication separately maps owner tokens, run-bound client grants, and attach grants into those contexts.

flowchart TD
A[Local operator entry points] --> B[Local host principal]
B --> C[Turn grant decision]
C --> D[Tool execution context]
E[MCP bearer request] --> F[Bearer authentication]
F --> B
F --> G[Scoped client or attach grant]
G --> D
Loading

Technical review

Best possible solution:

Keep the centralized local-host grant and adapt transcript ownership coverage to distinguish local operator runs from non-owner ingress runs.

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

This is a behavior-preserving authority refactor rather than a reproduced user bug; exact-head CI independently demonstrates the obsolete local transcript expectation.

Is this the best way to solve the issue?

Reusing decideTurnGrant and deleting the unused token is the smallest coherent consolidation; production caller inspection supports retaining local owner behavior without adding another admission mechanism.

Full review comments:

  • [P2] Update transcript ownership coverage for local-host admission — src/agents/agent-command-local.ts:70
    Forcing local sender ownership to true invalidates the existing false/external_user row in src/agents/agent-command.compaction-rotation.test.ts:350-371. Exact-head CI fails at line 365 because both opts.senderIsOwner and the transcript owner stamp are now true. The local behavior is intentional, so update its expectation and retain non-owner transcript coverage through the existing Gateway ingress entry point rather than restoring caller-side owner derivation or deleting the security contract.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8616182ae3f2.

Provenance checked

  • Local agent ownership and creator capability changes intended behavior with a stated reason (9344233: This commit carried the optional owner narrowing through the graceful-restart refactor; it does not establish the narrowing's original introduction. The PR explicitly removes it because production local callers do not supply false.)
  • Message CLI ownership changes intended behavior with a stated reason (02182d5: The earlier refactor retained explicit false while defaulting the CLI to owner; current production has only the local CLI caller, and this PR explicitly assigns that principal its owner grant.)
  • MCP bearer-derived ownership keeps the original intent (fix(gateway): derive loopback owner context from token #69796: Separate bearers prevented child-controlled headers from escalating ownership; current scoped client and attach grants retain that protection after the unused raw non-owner bearer is removed.)
  • Standalone Codex supervision ownership keeps the original intent (f94a7dc: The standalone supervision server supplied trusted local owner context; the replacement obtains the same value from the shared grant decision.)
  • Owner-producer lint inventory keeps the original intent (refactor(lint): stop counting owner pass-throughs as owner producers #205206: The prerequisite distinguished owner producers from pass-throughs and explicitly left local-host producers for a subsequent change.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 63e0742 adds src/gateway/operator-admission.ts:231 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)

PR surface

Source -3, Tests -14, Other -4. Total -21 across 20 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 18 21 -3
Tests 12 13 27 -14
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 5 -4
Total 20 32 53 -21

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: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp 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: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp 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, 4:55 AM ET / 09:55 UTC.

The local-host grant names every local run's sender owner, so the case that
passed senderIsOwner: false to a local agentCommand asserted removed behavior.

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

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on head 070c431351bc (test-only change since the last comment): Q queued input refused visibly, R running turn finishes, S Stop cancels: all pass (pass: true, 58977 ms).

CI round 1 red: src/agents/agent-command.compaction-rotation.test.ts (OURS). One case passed senderIsOwner: false to a local agentCommand and expected it to be kept. That option is gone: the local-host grant names the sender. The case asserted removed behavior, so I deleted it; the owner and system-provenance cases stay. 35 importers of agent-command.ts / commands/agent.ts pass locally.

@obviyus
obviyus merged commit 71b629c into main Nov 25, 2026
144 checks passed
@obviyus
obviyus deleted the refactor/oa2-local-host-owner branch November 25, 2026 10:29
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 71b629c.

  • Bug: four local-host entries (openclaw agent --local, openclaw message, the Codex supervision stdio MCP, the in-process MCP owner token) decided owner status for themselves, outside admission.
  • Fix: they read LOCAL_HOST.grant.owner, decided by decideTurnGrant. The unused raw MCP non-owner token is deleted. OWNER_PRODUCER_FILES is now 28. The remote worker stays listed, because its run grant is not on the worker protocol.
  • Proof: CI is green on the head. The local review is clean. Q/R/S E2E pass. A real agent --local run used the owner-only sessions tool.

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

## Problem

OA2 PR 6a (one admission owner). Processes the operator runs on this host each decided "the sender is the owner" for themselves:

- `openclaw agent --local` (and `agent exec`, BOOT.md, Template setup): `senderIsOwner: opts.senderIsOwner ?? true`.
- `openclaw message`: `senderIsOwner: opts.senderIsOwner !== false`.
- Codex supervision stdio MCP: a private `{ senderIsOwner: true }` constant.
- MCP loopback: `{ senderIsOwner: ownerTokenMatched }`, where the alternative was a raw non-owner token that no production code ever hands out.

These were four more owner producers outside admission (`OWNER_PRODUCER_FILES`).

## Fix

- `operator-admission.ts` exports `LOCAL_HOST = { grant: decideTurnGrant(["operator.admin"]) }`: the local host is the owner principal, and `decideTurnGrant` decides its grant. The four entries read `LOCAL_HOST.grant.owner`.
- `agent-command-local.ts`: no caller option narrows the local owner (no production caller set it). The local cron-creator capability is now gated only by `operatorAuthority`, because the `senderIsOwner === true` check is always true.
- MCP loopback: deleted the unused raw non-owner token (`nonOwnerToken` in the runtime, listener and request auth). CLI backends get run-bound client grants; attach clients get attach grants. Only the in-process owner token remains, and it names the local host.
- `OWNER_PRODUCER_FILES` 32 → 28 after merging main (ceiling lowered).

## Decisions (recorded, not asked)

- **Worker placement stays listed** (`src/worker/embedded-agent.runtime.ts`). The worker runs tools on a separate box for a run the Gateway admitted. The correct value is that run's `grant.owner`, and the worker protocol does not carry it. `LOCAL_HOST` there would declare every remote box an owner. Carrying the bit is a protocol change, so it is not in this PR (Fable 5.2 consult).
- **No full `decideOperatorAdmission` for in-process local runs.** It would set `operatorAuthority` on CLI-local runs and change many downstream branches. It would also need the profile store in the stdio MCP and the worker. The grant comes from the same `decideTurnGrant`.
- **Raw non-owner MCP token deleted, not kept.** Only `mcp-http.ts` created it and only `resolveMcpSender` compared it; no production path hands it to a client (CLI backends use run-bound client grants, `attach` uses attach grants). Deleting it closes no client route. Without it the owner-token producer could not move, and production would not be net negative.
- **Accepted risk:** any file can import `LOCAL_HOST` and pass the owner lint. Today it has four readers; adding an import allowlist would be a new guard.

## User impact

None. A local CLI user, the `message` CLI, the standalone Codex supervision MCP and the in-process MCP owner token stay owner.

## Evidence

- Production (`src`, non-test): +18 / −21.
- One cell per entry, through the real entry function:
  - `agent-command-local.test.ts`: every local run reaches preparation with `senderIsOwner: true`; the operator run gets the local cron-creator capability.
  - `message.test.ts`: the `message` CLI dispatches with `senderIsOwner: true`.
  - `plugin-tools-serve.test.ts`: Codex supervision MCP context has `senderIsOwner: true`.
  - `mcp-http.test.ts`: a real loopback listener request with the owner token resolves tools with `senderIsOwner: true`.
- `test/scripts/oxlint-boundary-guards.test.ts`: ceiling 28; the stale-entry check passes for the four removed files.
- Real `openclaw agent --local` on an isolated profile (`ocx src -- --profile e2e`), real `openai/gpt-5.5`: the model called the owner-only `sessions` tool and replied `LOCAL_OWNER_DONE 0`; exit 0.
- Pre-push checks: one `ocx test` call over 62 files (touched tests plus direct importers of every changed source; the 318-file set with test-support importers is over the 150 cap), all green. `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on changed files: clean. `pnpm check:changed`: the changelog attribution lane fails on files this PR does not touch (same as openclaw#205173); the rest was still running at 15 min, so CI runs it.
- Q/R/S E2E on the exact head: see the follow-up comment.

Co-authored-by: Ayaan Zaidi <[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 commands Command implementations gateway Gateway runtime impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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