Skip to content

refactor(gateway): decide what a turn may do once, as a turn grant - #204756

Merged
obviyus merged 1 commit into
mainfrom
refactor/oa2-turn-grant
Nov 24, 2026
Merged

obviyus merged 1 commit into
mainfrom
refactor/oa2-turn-grant

Conversation

@obviyus

@obviyus obviyus commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The same person got a different answer depending on how the turn started:

Fix

This is OA2 PR 1b. It builds on the lint guard from #204823. Admission now decides what a turn may do, and the Control UI entry kinds read that decision.

  • TurnGrant (owner, skillAuthoring, questionReplace, commands) is a frozen field on AdmittedRunOperatorAuthority. Only decideTurnGrant(scopes) in src/gateway/operator-admission.ts produces it.
    • Every authority constructor calls it: replay decide, fresh Gateway admission, channel capture and continuation narrowing.
    • It is in memory only, so no schema changes. A replay admits again from its recorded source.
  • Owner tools (dangerous-tools.ts) and the transcript owner stamp (chat-user-turn-recorder.ts) read grant.owner, which is operator.admin in the admitted scopes.
  • Commands: chat.send puts the grant on the command context as TurnGrant.
    • grant.commands === "all" (operator.admin) passes commands.allowFrom, per Ayaan's decision. Non-admins keep the list and its visible refusal.
    • TurnGrant is trusted only on the internal provider, like GatewayClientScopes.
    • Docs are updated (tools/slash-commands, gateway/config-channels/commands).
  • Skill authoring: deleted isHumanTurn, canPrepareSkillAuthoring and the agent RPC internal-start list. grant.skillAuthoring decides.
    • The client checks stay: in-process runtime callers carry no attributed person.
    • Workspace authoring reads grant.owner instead of re-reading the role mid-turn.
    • Also deleted the mid-preparation "requester changed" scope re-check.
    • skill-library-authoring.ts leaves ADMISSION_FILES.
  • Question replacement: deleted the Control UI client-id, turnKind, provenance and internal re-entry gates. grant.questionReplace plus the request shape (steer, non-command, pending question) decide.
  • Lint allowlists shrink:
    • ADMISSION_FILES 63 → 62;
    • turn-kind flags 24 → 21 (chat-send-input-dispatch, chat-send-agent-dispatch.types, skill-library-authoring);
    • owner producers 53 → 52 (chat-user-turn-recorder);
    • capability provenance 5 → 4 (chat-send-question-replacement).
  • Matrix: the admission table's real-Gateway after-start rows now also check the grant at fresh admission and at saved-source replay. Cells: Control UI token, password, OpenClaw ID owner, Tailscale, Tailscale device and trusted proxy; CLI via Gateway; Discord linked identity.
    • KNOWN_DIVERGENT is shrink-only, with a ceiling. Its one entry: a linked Discord sender gets its role's scopes while the same person over Tailscale gets identityScopes. PR 2 fixes it.

Decisions (recorded, not asked)

  • Owner: grant.owner is operator.admin in the admitted scopes. Saved channel and parent-bound command ownership stays in requesterOwner, read only by scheduled occurrences, until PR 2 (verified configured channel owner) and PR 4 (parent-bound sources). The round-2 review of the earlier head found that putting that fact in the grant would give owner-only tools to a read/write channel command owner.
  • Internal starts: same-person internal starts (agent RPC internal events, approval follow-ups, re-entries with handler options) now get the grant their admission produced. The skill tool shape is already stable per session, so the provider request does not change. The client checks still exclude in-process runtime callers.
  • Read-only steer: a read-only client no longer replaces a pending question (questionReplace needs operator.sessions.write).
  • Narrowing: a continuation that narrows scopes re-derives its grant from the narrowed scopes.
  • Deferred: grant.automations (the cron-creator classifier) and moving the fresh-turn decision out of operator-run-authority.ts go in a later PR. prActions comes with PR 3.

User impact

  • An admin on Control UI or WebChat can run slash commands even when commands.allowFrom does not list it.
  • A steer from any client with session write (native app, system-provenance turn, reconnect) can replace an ordinary pending question.
  • Same-person internal turns no longer get the false "Skill authoring needs a fresh message" refusal.
  • Owner tools, the transcript owner stamp and workspace skill authoring follow one admission decision.

Evidence

  • Production lines: src (non-test) +109 / −110.
  • Red on base 23e252373e9b (head tests run against base code): question replacement from a native app, a system-input turn, and the read-only case; /status for an admitted admin outside commands.allowFrom. All four fail on base and pass on head.
  • Matrix: on the earlier head, all 8 cells passed and the one KNOWN_DIVERGENT cell still diverged. The admission table also passed.
  • E2E one-admission-e2e/run.sh: Q, R and S all pass. Q: queued input refused visibly. R: a running turn finishes. S: Stop cancels.
  • Z5 reconnect skill case: turns A, B and C each list skill_library.
  • Z1 [Bug]: New owner input after Control UI reconnect loses cron management authority despite current admin authentication #167867 case: turns A, B and C each see scope=gateway total=3.
  • Failing on base too (not ours): subagent-registry.requester-wake.e2e (6 receipt cases time out) and reef-shutdown.gateway.

@clawsweeper

clawsweeper Bot commented Nov 24, 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 docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: aca8f967362f5efe5e55cf381f19226185b61af7
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/admitted-run-operator-authority.types.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/operator-run-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/skill-library-authoring.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/security/dangerous-tools.ts: Controls product security checks or trust decisions. Check whether the change weakens detection, protection, or remediation.

Carefully review these changes before merging.

@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. P2 Normal backlog priority with limited blast radius. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 24, 2026
@clawsweeper

clawsweeper Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR adds an admission-owned turn grant for owner tools, commands, skill authoring, and pending-question replacement.

Example: An admitted operator.admin Control UI client sends /status with commands.allowFrom set to {"*": ["someone-else"]}.

  • Before: The command receives a policy refusal.
  • After: The admitted administrator bypasses that allowlist and receives status.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The direction is justified, but caller migration is incomplete, a consumer regression fails, and changed user behavior has only automated-test evidence.
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) 2 actionable review findings remain.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Equivalent authenticated input receives different command, authoring, and question behavior depending on its entry path.
Reason: The maintainer-authored direction consolidates decisions in the existing authority owner and explicitly scopes channel and other entry-kind follow-ups.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep open: this maintainer-authored PR consolidates admission decisions usefully, but incomplete caller migration and a failing consumer test block merge.

Priority: P2
Reviewed head: 10929dbd152a6d955f4e03b29326f5bd03c6707d

Before merge

  • Migrate every constructor to the required turn grant (P2) - Making grant required leaves three direct createAdmittedRunOperatorAuthority callers unmigrated: scripts/perf/turn-participants-measure.ts:29, scripts/perf/harness-tool-authority-measure.ts:86, and scripts/perf/reply-tool-authority-measure.ts:46. Their object literals have no grant, so they no longer satisfy the constructor parameter and fail the scripts TypeScript program, which includes scripts/**/*; exact-head CI also reports the script-types leaf failing. Derive grants with the shared producer at these callers, as the changed benchmark already does.
  • Migrate the ACP transcript fixture to admitted ownership (P2) - The owner stamp now requires admission.operatorAuthority.grant.owner, but the ACP provenance case in chat.directive-tags.test.ts still supplies createScopedCliClient(["operator.admin"]), which has scopes but no admitted authority, and expects senderIsOwner:true. Exact-head CI fails at line 4189 with precisely that missing field. Update this consumer fixture to exercise an admitted administrator and preserve the ACP ownership assertion under the new contract.

Findings

  • [P2] Migrate every constructor to the required turn grant — src/agents/admitted-run-operator-authority.types.ts:53
  • [P2] Migrate the ACP transcript fixture to admitted ownership — src/gateway/server-methods/chat-user-turn-recorder.ts:153-155

Tests

  • Missing end-to-end proof: Provide redacted Gateway output showing the administrator allowlist bypass, native/system-provenance multipart-question replacement, and grant-based authoring/tool behavior; redact credentials, IPs, phone numbers, and private endpoints.
Agent review details

How this fits together

Gateway admission turns authenticated principal facts and scopes into run authority; chat, command, question, and tool owners consume its grant.

flowchart TD
  A[Authenticated request] --> B[Admission and scope checks]
  C[Saved requester source] --> B
  B --> D[Admitted authority and turn grant]
  D --> E[Commands and owner tools]
  D --> F[Skill authoring]
  D --> G[Pending question replacement]
Loading

Technical review

Best possible solution:

Keep the grant on the existing admission authority, complete constructor and consumer migration, and preserve the saved-source format.

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

Current-main source shows the administrator allowlist denial and native/system-provenance question exclusions; the author reports base-failing/head-passing tests, but this read-only review ran no reproduction.

Is this the best way to solve the issue?

The existing admission authority is the appropriate owner for these decisions, and the maintainer-authored PR explicitly accepts the changed command and narrowing behavior.

Full review comments:

  • [P2] Migrate every constructor to the required turn grant — src/agents/admitted-run-operator-authority.types.ts:53
    Making grant required leaves three direct createAdmittedRunOperatorAuthority callers unmigrated: scripts/perf/turn-participants-measure.ts:29, scripts/perf/harness-tool-authority-measure.ts:86, and scripts/perf/reply-tool-authority-measure.ts:46. Their object literals have no grant, so they no longer satisfy the constructor parameter and fail the scripts TypeScript program, which includes scripts/**/*; exact-head CI also reports the script-types leaf failing. Derive grants with the shared producer at these callers, as the changed benchmark already does.
    Confidence: 0.99
  • [P2] Migrate the ACP transcript fixture to admitted ownership — src/gateway/server-methods/chat-user-turn-recorder.ts:153-155
    The owner stamp now requires admission.operatorAuthority.grant.owner, but the ACP provenance case in chat.directive-tags.test.ts still supplies createScopedCliClient(["operator.admin"]), which has scopes but no admitted authority, and expects senderIsOwner:true. Exact-head CI fails at line 4189 with precisely that missing field. Update this consumer fixture to exercise an admitted administrator and preserve the ACP ownership assertion under the new contract.
    Confidence: 0.98

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 b99d3787909e.

Provenance checked

  • Saved-source owner classification keeps the original intent (3ad2cce: Admit saved requesters when work starts using current principal facts and captured scope ceilings.)
  • Skill-library preparation and workspace authority changes intended behavior with a stated reason (baff85b: Combine library preparation while checking requester continuity; later worker-backed checks retained current profile authority. This PR explicitly replaces mid-turn policy reads with admitted facts.)
  • Configured command allowlists changes intended behavior with a stated reason (7f5ec42: Make Gateway denials visible while preserving the existing allowlist boundary and leaving the administrator bypass for an owner decision.)
  • Pending-question replacement changes intended behavior with a stated reason (691d0cd: Typed replies continue the asking run while preserving child-session, credential, and form boundaries; this PR replaces client and provenance exclusions with session-write admission.)
  • Model-policy intersection keeps the original intent (b4a8576: Share captured/current model-policy intersection without changing its membership semantics; this PR relocates the implementation unchanged.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +29, Tests +229, Docs +7, Other +267. Total +532 across 45 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 17 137 108 +29
Tests 21 293 64 +229
Docs 2 23 16 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 5 270 3 +267
Total 45 723 191 +532

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.

Review metrics

Metric Value Why it matters
Production versus test/support changes Production +406/-111; tests/support +293/-64 Counts cover src, scripts, and test; most production growth is the 256-line static boundary rule, while behavioral coverage reuses existing admission fixtures.

Labels

Label changes:

  • add P2: This is a bounded admission consistency improvement with concrete caller and regression-fixture repairs needed before merge.
  • 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:

  • P2: This is a bounded admission consistency improvement with concrete caller and regression-fixture repairs needed before merge.
  • 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 24, 2026, 11:38 AM ET / 16:38 UTC.

@obviyus

obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

E2E verdict (one-admission run.sh, head production code 10929dbd152a):

{
 "pass": true,
 "prefix": "HEAD",
 "sessionKey": "agent:main:one-admission-9801cbd2",
 "models": [
  "gpt-5.5-2026-04-23"
 ],
 "relayStatuses": [
  200
 ],
 "checks": [
  {
   "id": "R.running-turn-finishes",
   "pass": true,
   "detail": {
    "state": "final",
    "toolEnds": 3,
    "toolEndsAfterRevoke": 3
   }
  },
  {
   "id": "Q.queued-input-refused-visibly",
   "pass": true,
   "detail": {
    "accepted": true,
    "providerRequestsWithQueuedMarker": 0,
    "visibleRefusalInTranscript": true
   }
  },
  {
   "id": "S.stop-cancels",
   "pass": true,
   "detail": {
    "abort": {
     "ok": true,
     "aborted": true,
     "runIds": [
      "35e52660-f2f7-465f-b3d0-a2a9c015bc50"
     ]
    },
    "state": "aborted",
    "requestsWithStopMarker": 1
   }
  }
 ],
 "elapsedMs": 61420
}

@obviyus

obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Stopped under the two-CI-round rule.

  • Round 1 (10929dbd152a): perf-script fixtures without grant, and the ACP owner-stamp fixture. Both are fixed in round 2. subagent-registry.requester-wake.e2e also failed; it fails on base 23e252373e9b too.
  • Round 2 (0690b48e0833): ci-node-test-plan expects 4 isolated Gateway groups and got 5, because the new matrix file joined gatewayServerIsolatedTestFiles. Local review round 2 also found a real P1: the channel and parent-bound command-owner fact in grant.owner widened owner-only tools.
  • Fixed locally but not pushed (070b5f74c4): grant.owner is the admin scope only, and requesterOwner is restored for scheduled occurrences. Typecheck passes; matrix, table, cron and boundary tests pass.

Proposed split:

  1. Lint rule plus shrink-only allowlist tests and the planted fixture (tooling only).
  2. TurnGrant plus Control UI consumers, with 070b5f74c4. Fold the matrix cases into operator-admission.table.test.ts so the CI node-test plan keeps its 4 groups.

decideTurnGrant in operator-admission.ts is the only producer of the frozen
TurnGrant on the admitted operator authority. Control UI turns read it for
owner tools, skill authoring, question replacement and commands.allowFrom;
the isHumanTurn, client-id, turn-kind, provenance and internal-start
branches are gone, and workspace skill authoring no longer re-reads the
live role mid-turn. The turn grant matrix runs in the admission table's
after-start rows. Lint allowlists and ceilings shrink with the removed
readers.

Co-authored-by: obviyus <[email protected]>
@obviyus
obviyus force-pushed the refactor/oa2-turn-grant branch from 0690b48 to aca8f96 Compare November 24, 2026 19:13
@obviyus

obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

E2E on the exact head aca8f967362f (one-admission run.sh): Q queued input refused visibly, R running turn finishes, S Stop cancels. All pass.

Z5 reconnect skill case: turns A, B (after reconnect) and C each list skill_library. Z1 #167867 case: turns A, B and C each see scope=gateway total=3. Both on the same head.

{
  "pass": true,
  "prefix": "HEAD",
  "sessionKey": "agent:main:one-admission-7dfadcab",
  "models": [
    "gpt-5.5-2026-04-23"
  ],
  "relayStatuses": [
    200
  ],
  "checks": [
    {
      "id": "R.running-turn-finishes",
      "pass": true,
      "detail": {
        "state": "final",
        "toolEnds": 3,
        "toolEndsAfterRevoke": 3
      }
    },
    {
      "id": "Q.queued-input-refused-visibly",
      "pass": true,
      "detail": {
        "accepted": true,
        "providerRequestsWithQueuedMarker": 0,
        "visibleRefusalInTranscript": true
      }
    },
    {
      "id": "S.stop-cancels",
      "pass": true,
      "detail": {
        "abort": {
          "ok": true,
          "aborted": true,
          "runIds": [
            "513e6ac9-7b6f-4727-b2b2-aead77464731"
          ]
        },
        "state": "aborted",
        "requestsWithStopMarker": 1
      }
    }
  ],
  "elapsedMs": 54464
}```

@obviyus
obviyus merged commit 63e0742 into main Nov 24, 2026
241 of 242 checks passed
@obviyus
obviyus deleted the refactor/oa2-turn-grant branch November 24, 2026 20:19
@obviyus

obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 63e0742. Admission now produces one frozen turn grant, and Control UI turns read it for owner tools, skill authoring, question replacement and commands.allowFrom for admins. The isHumanTurn, client-id, turn-kind, provenance and internal-start gates are deleted (src +109/−110). Proof on the exact head:

obviyus added a commit that referenced this pull request Nov 24, 2026
…4904)

## Problem

The same person got a different answer depending on how the turn started (OA2 PR 2, channels).

- A Discord or Telegram sender listed in `commands.ownerAllowFrom` got owner-only commands and tools, but no operator authority. Their channel turns ran as System. `github_publish` and other operator tools then refused them ("Inspecting your PR requires your verified linked GitHub account."), while the same owner's Control UI turn passed. The owner cannot fix this by linking: a channel identity cannot be bound to the reserved owner profile.
- A linked channel sender got its role's scopes (`operator.admin` in the matrix fixture), while the same person over Tailscale got their `gateway.auth.identityScopes` capped by role. This was the one `KNOWN_DIVERGENT` cell left by #204756.
- Channel ingress decided owner status itself (`message-access/runtime.ts` read `isConfiguredCommandOwner` and `prepareCommandOwnerAuthority`).

## Fix

- **Admission decides the channel sender.** `src/gateway/operator-admission.ts` now owns the channel sender decision:
  - `prepareChannelSenderAdmission(sender, getConfig)` gathers the link, the operator profile and the command-owner policy once at ingress. `message-access/runtime.ts` only hands over `ChannelSenderFacts` (`verified` or `asserted`). It leaves the turn-flag allowlist.
  - `decideChannelOwnerPrincipal(config, sender)`: a **verified** sender in the global `commands.ownerAllowFrom` (wildcard stripped) is the owner principal: owner profile, `operator.admin`, the same grant as the owner's Control UI turn. A sender whose link already yields an operator profile keeps that profile's grant and its recoverable source (round-1 review: scheduled plugin commands and restart need that source). Asserted channels (Signal, WhatsApp, ...) are excluded and keep today's owner-only commands and tools.
- **Every start re-checks it.** The admitted authority records the sender as `channelOwner`. Queued and continued work re-admits through `decideOperatorAdmission`, which refuses when the sender left `commands.ownerAllowFrom`, like a revoked linked requester. The authority records no durable source, so restart recovery keeps today's path for these turns (session principal).
- **Linked senders:** `resolveLinkedOperatorScopes` uses the socket rule: the verified login's `identityScopes`, capped by role; the role's scopes only when no identity scopes apply.
- **Consumers:** `channel-command-user-turn.ts` reads `grant.owner` (leaves the owner-producer allowlist).
- **Matrix** (`operator-admission.table.test.ts`): `KNOWN_DIVERGENT` is empty and deleted. New channel cells: configured Discord owner → owner grant (`owner`, `commands: "all"`); allowlisted unlinked guest → no grant; linked person → the Tailscale person's grant.
- **Lint allowlists shrink:** turn flags 21 → 20 (`message-access/runtime.ts`), owner producers 52 → 51 (`channel-command-user-turn.ts`).
- Docs: `gateway/config-channels/commands.md` states the owner rule.

## Decisions (recorded, not asked)

- **Owner rule** (Ayaan, recorded in ONE-ADMISSION-PLAN): verified sender + global `commands.ownerAllowFrom` = owner principal. Everyone in that list gets owner power, including operator tools and PR actions; that list is by definition the owners. Channel/context allowlists never qualify.
- **Owner removed while a message is queued:** the queued message is refused at start (same as a revoked linked requester), instead of running without owner power. Rare and visible; the sender sends again.
- **Not in this PR** (kept, cut less): the channel cron-creator mint (`get-reply-run.cron-requester.ts`; needs `grant.automations`), Telegram/Discord native slash-command allowlist composition (a list-membership fact, read before any turn exists), `github_publish` requester re-checks (PR 3), restart/durable sources for channel owners (PR 4). `channel-operator-authority.ts` stays in `ADMISSION_FILES`: its live-identity checks still read role policy.

## User impact

- A Discord or Telegram owner configured in `commands.ownerAllowFrom` gets the same permissions in the channel as in the Control UI, with no Control UI step.
- A linked channel sender gets the same scopes as that person over the Control UI.

## Evidence

- **Production lines:** `src` + `extensions` (non-test) +139 / −93. Not net negative: the owner principal is new behavior Ayaan asked for (decision recorded in the one-admission plan). The gather/decide move out of `message-access/runtime.ts` is net zero; the rest is the decision, its replay re-check and the `channelOwner` fact.
- **Matrix, head** (`operator-admission.table.test.ts`, real Gateway, 5 boots): 151/151 passed, including the channel owner cell, the guest cell and the linked-person cell.
- **Red on base `48f162d64bc8`** (head tests against base code): linked-person cell fails (`fresh: { owner: true }` vs the Tailscale person's `owner: false`); configured-owner cell fails (base admits the configured owner with no operator authority, so its queued work is never re-admitted against the owner list).
- **Pre-push:** one `ocx test` call over 151 importer/touched files: 1 failure, `chat-send-pending-input-withdrawal.test.ts` "settles queued input (restart, restart, discard: false)", which also fails on base `48f162d64bc8` (not ours). `pnpm tsgo:core`, `pnpm tsgo:test`, oxlint, boundary-guard lint and oxfmt clean. `pnpm check:changed`: all lanes ok after removing a now-unused export it flagged.
- **E2E:** `one-admission-e2e/run.sh` on heads `e329c508d869`, `a804c9d7c2de` and `6177d4488f81`: Q (queued input refused visibly), R (running turn finishes) and S (Stop cancels) all pass (`verdict.json` + `results.jsonl` kept in the task proof directory).
- **Discord ingress proof:** the matrix channel rows run the real Discord identity declaration (`verified`), the real `message-access/runtime.ts` ingress and the real host context builder against a real Gateway, queue and agent run. A live Discord QA-bot run was not used: QA-bot readiness passed, but in this PR nothing user-visible in Discord differs between a configured owner on base and on head (owner-only tools and `/status` already worked there through the owner flag). The visible difference, `github_publish` for a Discord owner, lands with PR 3, which owns the live Discord run.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…penclaw#204756)

## Problem

The same person got a different answer depending on how the turn started:

- A Control UI steer from a native app, or one sent with system provenance, could not replace a pending question.
- An `operator.admin` client outside `commands.allowFrom` was refused slash commands (openclaw#198259).
- Skill authoring read `isHumanTurn` on chat.send and a list of internal start kinds on the agent RPC. Same-person internal turns got the false refusal "Skill authoring needs a fresh message".
- Workspace skill authoring re-read the live role in the middle of a turn.

## Fix

This is OA2 PR 1b. It builds on the lint guard from openclaw#204823. Admission now decides what a turn may do, and the Control UI entry kinds read that decision.

- **`TurnGrant`** (`owner`, `skillAuthoring`, `questionReplace`, `commands`) is a frozen field on `AdmittedRunOperatorAuthority`. Only `decideTurnGrant(scopes)` in `src/gateway/operator-admission.ts` produces it.
  - Every authority constructor calls it: replay `decide`, fresh Gateway admission, channel capture and continuation narrowing.
  - It is in memory only, so no schema changes. A replay admits again from its recorded source.
- **Owner tools** (`dangerous-tools.ts`) and the **transcript owner stamp** (`chat-user-turn-recorder.ts`) read `grant.owner`, which is `operator.admin` in the admitted scopes.
- **Commands:** chat.send puts the grant on the command context as `TurnGrant`.
  - `grant.commands === "all"` (`operator.admin`) passes `commands.allowFrom`, per Ayaan's decision. Non-admins keep the list and its visible refusal.
  - `TurnGrant` is trusted only on the internal provider, like `GatewayClientScopes`.
  - Docs are updated (`tools/slash-commands`, `gateway/config-channels/commands`).
- **Skill authoring:** deleted `isHumanTurn`, `canPrepareSkillAuthoring` and the agent RPC internal-start list. `grant.skillAuthoring` decides.
  - The client checks stay: in-process runtime callers carry no attributed person.
  - Workspace authoring reads `grant.owner` instead of re-reading the role mid-turn.
  - Also deleted the mid-preparation "requester changed" scope re-check.
  - `skill-library-authoring.ts` leaves `ADMISSION_FILES`.
- **Question replacement:** deleted the Control UI client-id, `turnKind`, provenance and internal re-entry gates. `grant.questionReplace` plus the request shape (steer, non-command, pending question) decide.
- **Lint allowlists shrink:**
  - `ADMISSION_FILES` 63 → 62;
  - turn-kind flags 24 → 21 (`chat-send-input-dispatch`, `chat-send-agent-dispatch.types`, `skill-library-authoring`);
  - owner producers 53 → 52 (`chat-user-turn-recorder`);
  - capability provenance 5 → 4 (`chat-send-question-replacement`).
- **Matrix:** the admission table's real-Gateway `after-start` rows now also check the grant at fresh admission and at saved-source replay. Cells: Control UI token, password, OpenClaw ID owner, Tailscale, Tailscale device and trusted proxy; CLI via Gateway; Discord linked identity.
  - `KNOWN_DIVERGENT` is shrink-only, with a ceiling. Its one entry: a linked Discord sender gets its role's scopes while the same person over Tailscale gets `identityScopes`. PR 2 fixes it.

## Decisions (recorded, not asked)

- **Owner:** `grant.owner` is `operator.admin` in the admitted scopes. Saved channel and parent-bound command ownership stays in `requesterOwner`, read only by scheduled occurrences, until PR 2 (verified configured channel owner) and PR 4 (parent-bound sources). The round-2 review of the earlier head found that putting that fact in the grant would give owner-only tools to a read/write channel command owner.
- **Internal starts:** same-person internal starts (agent RPC internal events, approval follow-ups, re-entries with handler options) now get the grant their admission produced. The skill tool shape is already stable per session, so the provider request does not change. The client checks still exclude in-process runtime callers.
- **Read-only steer:** a read-only client no longer replaces a pending question (`questionReplace` needs `operator.sessions.write`).
- **Narrowing:** a continuation that narrows scopes re-derives its grant from the narrowed scopes.
- **Deferred:** `grant.automations` (the cron-creator classifier) and moving the fresh-turn decision out of `operator-run-authority.ts` go in a later PR. `prActions` comes with PR 3.

## User impact

- An admin on Control UI or WebChat can run slash commands even when `commands.allowFrom` does not list it.
- A steer from any client with session write (native app, system-provenance turn, reconnect) can replace an ordinary pending question.
- Same-person internal turns no longer get the false "Skill authoring needs a fresh message" refusal.
- Owner tools, the transcript owner stamp and workspace skill authoring follow one admission decision.

## Evidence

- **Production lines:** `src` (non-test) +109 / −110.
- **Red on base `d96b6e90fee5`** (head tests run against base code): question replacement from a native app, a system-input turn, and the read-only case; `/status` for an admitted admin outside `commands.allowFrom`. All four fail on base and pass on head.
- **Matrix:** on the earlier head, all 8 cells passed and the one `KNOWN_DIVERGENT` cell still diverged. The admission table also passed.
- **E2E `one-admission-e2e/run.sh`:** Q, R and S all pass. Q: queued input refused visibly. R: a running turn finishes. S: Stop cancels.
- **Z5 reconnect skill case:** turns A, B and C each list `skill_library`.
- **Z1 openclaw#167867 case:** turns A, B and C each see `scope=gateway total=3`.
- **Failing on base too (not ours):** `subagent-registry.requester-wake.e2e` (6 receipt cases time out) and `reef-shutdown.gateway`.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…nclaw#204904)

## Problem

The same person got a different answer depending on how the turn started (OA2 PR 2, channels).

- A Discord or Telegram sender listed in `commands.ownerAllowFrom` got owner-only commands and tools, but no operator authority. Their channel turns ran as System. `github_publish` and other operator tools then refused them ("Inspecting your PR requires your verified linked GitHub account."), while the same owner's Control UI turn passed. The owner cannot fix this by linking: a channel identity cannot be bound to the reserved owner profile.
- A linked channel sender got its role's scopes (`operator.admin` in the matrix fixture), while the same person over Tailscale got their `gateway.auth.identityScopes` capped by role. This was the one `KNOWN_DIVERGENT` cell left by openclaw#204756.
- Channel ingress decided owner status itself (`message-access/runtime.ts` read `isConfiguredCommandOwner` and `prepareCommandOwnerAuthority`).

## Fix

- **Admission decides the channel sender.** `src/gateway/operator-admission.ts` now owns the channel sender decision:
  - `prepareChannelSenderAdmission(sender, getConfig)` gathers the link, the operator profile and the command-owner policy once at ingress. `message-access/runtime.ts` only hands over `ChannelSenderFacts` (`verified` or `asserted`). It leaves the turn-flag allowlist.
  - `decideChannelOwnerPrincipal(config, sender)`: a **verified** sender in the global `commands.ownerAllowFrom` (wildcard stripped) is the owner principal: owner profile, `operator.admin`, the same grant as the owner's Control UI turn. A sender whose link already yields an operator profile keeps that profile's grant and its recoverable source (round-1 review: scheduled plugin commands and restart need that source). Asserted channels (Signal, WhatsApp, ...) are excluded and keep today's owner-only commands and tools.
- **Every start re-checks it.** The admitted authority records the sender as `channelOwner`. Queued and continued work re-admits through `decideOperatorAdmission`, which refuses when the sender left `commands.ownerAllowFrom`, like a revoked linked requester. The authority records no durable source, so restart recovery keeps today's path for these turns (session principal).
- **Linked senders:** `resolveLinkedOperatorScopes` uses the socket rule: the verified login's `identityScopes`, capped by role; the role's scopes only when no identity scopes apply.
- **Consumers:** `channel-command-user-turn.ts` reads `grant.owner` (leaves the owner-producer allowlist).
- **Matrix** (`operator-admission.table.test.ts`): `KNOWN_DIVERGENT` is empty and deleted. New channel cells: configured Discord owner → owner grant (`owner`, `commands: "all"`); allowlisted unlinked guest → no grant; linked person → the Tailscale person's grant.
- **Lint allowlists shrink:** turn flags 21 → 20 (`message-access/runtime.ts`), owner producers 52 → 51 (`channel-command-user-turn.ts`).
- Docs: `gateway/config-channels/commands.md` states the owner rule.

## Decisions (recorded, not asked)

- **Owner rule** (Ayaan, recorded in ONE-ADMISSION-PLAN): verified sender + global `commands.ownerAllowFrom` = owner principal. Everyone in that list gets owner power, including operator tools and PR actions; that list is by definition the owners. Channel/context allowlists never qualify.
- **Owner removed while a message is queued:** the queued message is refused at start (same as a revoked linked requester), instead of running without owner power. Rare and visible; the sender sends again.
- **Not in this PR** (kept, cut less): the channel cron-creator mint (`get-reply-run.cron-requester.ts`; needs `grant.automations`), Telegram/Discord native slash-command allowlist composition (a list-membership fact, read before any turn exists), `github_publish` requester re-checks (PR 3), restart/durable sources for channel owners (PR 4). `channel-operator-authority.ts` stays in `ADMISSION_FILES`: its live-identity checks still read role policy.

## User impact

- A Discord or Telegram owner configured in `commands.ownerAllowFrom` gets the same permissions in the channel as in the Control UI, with no Control UI step.
- A linked channel sender gets the same scopes as that person over the Control UI.

## Evidence

- **Production lines:** `src` + `extensions` (non-test) +139 / −93. Not net negative: the owner principal is new behavior Ayaan asked for (decision recorded in the one-admission plan). The gather/decide move out of `message-access/runtime.ts` is net zero; the rest is the decision, its replay re-check and the `channelOwner` fact.
- **Matrix, head** (`operator-admission.table.test.ts`, real Gateway, 5 boots): 151/151 passed, including the channel owner cell, the guest cell and the linked-person cell.
- **Red on base `4061fdbf46e5`** (head tests against base code): linked-person cell fails (`fresh: { owner: true }` vs the Tailscale person's `owner: false`); configured-owner cell fails (base admits the configured owner with no operator authority, so its queued work is never re-admitted against the owner list).
- **Pre-push:** one `ocx test` call over 151 importer/touched files: 1 failure, `chat-send-pending-input-withdrawal.test.ts` "settles queued input (restart, restart, discard: false)", which also fails on base `4061fdbf46e5` (not ours). `pnpm tsgo:core`, `pnpm tsgo:test`, oxlint, boundary-guard lint and oxfmt clean. `pnpm check:changed`: all lanes ok after removing a now-unused export it flagged.
- **E2E:** `one-admission-e2e/run.sh` on heads `e329c508d869`, `a804c9d7c2de` and `6177d4488f81`: Q (queued input refused visibly), R (running turn finishes) and S (Stop cancels) all pass (`verdict.json` + `results.jsonl` kept in the task proof directory).
- **Discord ingress proof:** the matrix channel rows run the real Discord identity declaration (`verified`), the real `message-access/runtime.ts` ingress and the real host context builder against a real Gateway, queue and agent run. A live Discord QA-bot run was not used: QA-bot readiness passed, but in this PR nothing user-visible in Discord differs between a configured owner on base and on head (owner-only tools and `/status` already worked there through the owner flag). The visible difference, `github_publish` for a Discord owner, lands with PR 3, which owns the live Discord run.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot added a commit that referenced this pull request Nov 25, 2026
…204904)

Bounded release port of the linked-sender scope rule from #204904: a linked
channel sender now gets the verified login's gateway.auth.identityScopes capped
by its role, and the role's scopes only when no identity scopes apply, the same
rule as a socket connection. Previously the role's scopes won outright, so a
linked maintainer whose identity only grants operator.write still received
channel operator.admin.

Release adaptation for 2026.11.11: #204904 also moves channel-sender admission
into the one-admission turn grant (#204756) and makes commands.ownerAllowFrom
channel senders the owner principal. That architecture is absent here and the
owner principal is new privilege behavior, so both are excluded. Adds a
regression test in operator-role-policy.test.ts.

(cherry picked from commit e2a9a6d)

Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
## Problem

Fixes #198259. On a Gateway with `gateway.auth.mode=password` and `commands.allowFrom: {"*": [...]}`, the owner's Control UI `/status` (and every other text command) returned `started`, then a final with no assistant message. The command gate (`rejectUnauthorizedCommand`) replied only to native commands; every other denial was silent. Thirteen commands (`/status`, `/help`, `/commands`, `/skill`, `/context`, `/usage`, `/fast`, `/session`, `/diagnostics`, `/agents`/`/subagents`, `/tts`, `/whoami`, `/restart`, `/update`) also set `silentUnauthorized`, which dropped the native refusal too.

## Fix

- `command-gates.ts` is the one owner of the denial outcome:
  - Gateway clients (Control UI, WebChat, CLI) get a refusal that names the policy and the next step: add the Gateway user profile ID to `commands.allowFrom`, or move the `"*"` entries to per-channel keys so Control UI commands follow operator access.
  - Native commands get the existing refusal for every command.
  - Text commands from external channel senders stay silent, so strangers in shared chats get no reply. This is the recorded intentional non-outcome.
- Deleted the `silentUnauthorized` option and its 13 uses.
- Docs (`docs/tools/slash-commands.md`): password/token Control UI clients have no user identity, and how to keep their commands available.

Supersedes the denial part of #198874 (draft, maintainer edits off). Thanks @RomneyDa for the first cut of the visible WebChat refusal.

## Owner identity: no change (policy question)

The issue asks that the password owner (`gateway-owner`) pass `commands.allowFrom`. The docs are not silent here: since #144601 they say "A shared owner profile used only for attribution does not grant this access." Every holder of the shared password or token gets that profile, so making it matchable would admit them all. This PR keeps that rule and does not add an owner bypass. The documented route for the reporter: list channel senders under per-channel keys and omit `"*"`; Control UI commands then follow operator scopes.

Open policy question for @obviyus: should `operator.admin` Gateway clients pass `commands.allowFrom` (today the list is the only authority when set)? Default kept: no.

## User impact

- Control UI owner denied by `commands.allowFrom`: sees why and what to change, instead of nothing.
- Native `/status`, `/help` and the others from a denied sender: see "You are not authorized to use this command." instead of no response (Discord shows "did not respond" otherwise).
- External channel text senders: unchanged (silent).

## Evidence

- Red on base `e24a2eecffb7`, green on head: `commands-info.test.ts` "denied /status" (Control UI owner refusal names `commands.allowFrom`; native refusal). Silence for external text senders and the per-channel-key route pass on both.
- Pre-push: touched tests + importers of every changed source (15 files), `tsgo:core`, `tsgo:test`, oxfmt, oxlint.
- Head E2E `9f42a4647b`, isolated password-auth Gateway from source, Control UI client (`operator.admin`, password), `chat.send /status`:
  - `commands.allowFrom: {"*": ["someone-else"]}` (the issue config): base `736ec651c262` gave `started`, then a final with no assistant message; head replies with the refusal that names `commands.allowFrom`.
  - `commands.allowFrom: {"telegram": ["someone-else"]}` (the documented route): `/status` returns the full status card.
- One-admission E2E on head (queued refusal, running turn finishes, Stop cancels): Q, R, S pass.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 7f5ec42)

Companion audit: The approval context follow-up f57a179 is separately selected. #204756 is a main-only authority refactor, #205780 adds the /context budget card, and #207006 changes loop test scaffolding; none is needed for baseline denial. #144601 verified-sender matching is already an ancestor of the pinned baseline.

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 docs Improvements or additions to documentation gateway Gateway runtime 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 security-sensitive-changed size: M 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