Skip to content

refactor(gateway): simplify scope checks and tool dispatch - #154120

Merged
steipete merged 2 commits into
mainfrom
codex/simplify-scope-policy
Sep 20, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/simplify-scope-policy

Conversation

@steipete

@steipete steipete commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Related: #153979

What Problem This Solves

Maintainer-requested simplification of the background-continuation scope fix: built-in Gateway tools unnecessarily imported the plugin loader, and scope checks carried redundant wrappers and branches.

User Impact

No permission or user-visible behavior change. Background continuations retain their existing read access through operator.write; identity, session access, cancellation, and execution-lifetime checks remain in force. No migration or configuration change is required.

Why This Change Was Made

Built-in tools now import their existing dispatcher directly. The shared scope predicate expresses exact grants, admin, and write implications once; role namespace checks no longer construct synthetic authorization requests. Event authorization keeps its existing plugin and public-event rules with fewer branches.

The continuation regression now calls the actual GitHub identity tool through each of sessions_send, subagent_announce, and subagent_settle, removing the duplicate method axis. Independent scope and lifecycle tests remain. Net reduction: 40 production lines, 22 test lines, and 4 documentation lines.

Evidence

  • Independent Codex review: no actionable P0–P2 findings.
  • Before/after adapter and continuation suites passed: 30 cases before, 29 after (one redundant session-list continuation row removed while all three ingress paths now cover the actual identity tool).
  • Timing observation on the same checkout/runtime: combined wall time 27.68s → 20.36s; maximum RSS 4.47 → 3.91 GiB. Continuation suite 22.76s → 15.79s; adapter suite 1.13s → 0.76s. These are single local observations, with different continuation cases, not a performance guarantee.
  • All 423 focused tests passed across scope compatibility, method authorization, broadcast delivery, in-process dispatch, continuation identity lookup, cancellation/committed outcomes, and update-tool routing.
  • Full pnpm build passed, including plugin control-plane loading checks.
  • Full node scripts/check-changed.mjs passed for the architecture cleanup: formatting, production/test type checks, lint, unused-export checks, and runtime import-cycle checks (0 cycles).
  • The first broader test invocation overlapped the build and correctly refused a changing compilation input tree. It passed after the build finished; no test assertion, timeout, or retry policy changed.

CI fixture repair

The first CI run exposed an existing order-dependent Claw archive test introduced in #153973. An earlier installer test restores fs-safe through configureFsSafeNative, whose explicit mode takes precedence over FS_SAFE_NATIVE_MODE. The Claw test's environment override therefore failed to disable native writes, bypassing its JavaScript close-error spy. The fixture now selects and restores its mode through the same configuration owner, retaining the rejection, single-close, and empty-directory assertions.

On Linux, the Claw test and its full file passed alone. Running src/skills/lifecycle/install-download.test.ts before src/claws/project.test.ts in one worker reproduced the exact CI failure: 58 passed, 1 failed, 1 existing skip. After the repair, that original order passes on Linux and macOS: 59 passed, 1 existing skip. A temporary Vitest sequencer fixed the order explicitly; no runner configuration was committed.

Linux proof used configured Blacksmith Testbox tbx_01m30f2c7casje5c9c135x1e21, prepared run, the existing test/vitest/vitest.unit-src.config.ts, and --maxWorkers=1 --no-file-parallelism. Wrapper exit status was 0. Targeted lint and a fresh independent P0–P2 review of the fixture repair passed. The previously failing hosted job is now green.

@clawsweeper

clawsweeper Bot commented Sep 20, 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 agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 20, 2026
@steipete
steipete marked this pull request as ready for review September 20, 2026 22:20
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 46b319477d89fd3d3fef7424e5e22c3021fb422f
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/method-scopes.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/shared/operator-scope-compat.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 20, 2026, 7:03 PM ET / 23:03 UTC (Revision 3).

ClawSweeper review

What this changes

Simplifies Gateway permission checks and built-in tool routing, consolidates continuation tests, and repairs filesystem test configuration isolation.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-requested cleanup remains distinct from the merged scope consolidation. No actionable correctness or security findings remain at the reviewed head.

Priority: P3
Reviewed head: 46b319477d89fd3d3fef7424e5e22c3021fb422f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable simplification with relevant validation and no supported blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored cleanup preserves the Gateway dispatcher and permission semantics, so the external-contributor proof gate does not apply; reported continuation, revocation, broadcast, and fixture tests remain supplemental validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored cleanup preserves the Gateway dispatcher and permission semantics, so the external-contributor proof gate does not apply; reported continuation, revocation, broadcast, and fixture tests remain supplemental validation.
Evidence reviewed 9 items Pinned introduction and review continuity: Reviewed the merge-base-to-head changes at the pinned original head. The only change after the first reviewed head is the filesystem fixture repair; the previous completed review retained no findings. The stale test-merge reference was not used to infer removal of base-branch work.
Equivalent permission decisions: The rewritten predicate preserves operator namespace rejection, exact grants, admin implication, and write-to-read/Talk implication. Role-prefix validation preserves whitespace and empty-role behavior. Existing scope tests retain denial coverage for admin, approvals, pairing, Talk secrets, and unknown scopes.
Dispatcher identity and lifetime preserved: The former server-plugins imports re-export the same dispatcher and context getter. The removed boolean helper itself returns Boolean(getInProcessGatewayRequestContext(resolver)); direct calls preserve resolver precedence, unavailable-context rejection, scope attenuation, and commit guards. This does not materially change authority or introduce a dependency on the Codex runtime.
Findings None None.
Security None None.

How this fits together

The Gateway checks operator permissions before dispatching tool requests and sending events to connected clients. Built-in agent tools use its in-process dispatcher, which retains caller identity, session access, and execution-lifetime checks.

flowchart LR
  A[Built-in agent tools] --> B[In-process Gateway dispatcher]
  C[Caller identity and grants] --> B
  B --> D[Shared scope checks]
  D --> E[Authorized method handler]
  F[Gateway events] --> G[Recipient scope checks]
  D --> G
  G --> H[Connected clients]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -40, Tests -22, Docs -4. Total -66 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 4 26 66 -40
Tests 7 23 45 -22
Docs 1 2 6 -4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 51 117 -66

Review metrics

None.

Technical review

Best possible solution:

Keep one shared scope policy and route built-in tools directly through the existing dispatcher while preserving its authorization and lifetime contracts.

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

Not applicable to the behavior-preserving refactor. The incidental fixture failure has a documented original-order reproduction, but this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: removing re-export indirection and redundant permission branches keeps the existing owners and avoids adding a parallel authorization path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3ec1caf958cc.

Labels

Label justifications:

  • P3: This is bounded internal cleanup with preserved permission behavior and a focused test-isolation repair.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored cleanup preserves the Gateway dispatcher and permission semantics, so the external-contributor proof gate does not apply; reported continuation, revocation, broadcast, and fixture tests remain supplemental validation.

Evidence

What I checked:

  • Pinned introduction and review continuity: Reviewed the merge-base-to-head changes at the pinned original head. The only change after the first reviewed head is the filesystem fixture repair; the previous completed review retained no findings. The stale test-merge reference was not used to infer removal of base-branch work. (46b319477d89)
  • Equivalent permission decisions: The rewritten predicate preserves operator namespace rejection, exact grants, admin implication, and write-to-read/Talk implication. Role-prefix validation preserves whitespace and empty-role behavior. Existing scope tests retain denial coverage for admin, approvals, pairing, Talk secrets, and unknown scopes. (src/shared/operator-scope-compat.ts:8, 46b319477d89)
  • Dispatcher identity and lifetime preserved: The former server-plugins imports re-export the same dispatcher and context getter. The removed boolean helper itself returns Boolean(getInProcessGatewayRequestContext(resolver)); direct calls preserve resolver precedence, unavailable-context rejection, scope attenuation, and commit guards. This does not materially change authority or introduce a dependency on the Codex runtime. (src/gateway/server-plugin-in-process-dispatch.ts:452, 46b319477d89)
  • Event filtering remains equivalent: Explicit plugin scopes still take precedence; unclassified plugin events still require write; worker clients remain excluded; public events and operator-only guarded events retain their previous decisions. Session filtering and queued-delivery revalidation are unchanged. (src/gateway/server-broadcast.ts:172, 46b319477d89)
  • Current main and release comparison: The fetched main retains the pre-PR implementation across the changed production owners and filesystem fixture. The supplied merged scope-consolidation PR establishes related prior work, not a replacement for this simplification. The v2026.9.5 scope source also retains the older implementation, so no shipped-fix or redundancy claim is made. (src/shared/operator-scope-compat.ts:10, 3ec1caf958cc)
  • Filesystem fixture repair: The test now selects JavaScript filesystem operations through the configuration owner and restores the previous effective mode in finally. It retains error identity, single-close, and empty-output-directory assertions. The captured PR body reports the original installer-before-Claw order failing before the repair and passing afterward on Linux and macOS. (src/claws/project.test.ts:115, 46b319477d89)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-20T22:31:48.419Z sha abb7d2f :: needs changes before merge. :: none
  • reviewed 2026-09-20T22:53:57.393Z sha 46b3194 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit a342c69 into main Sep 20, 2026
219 checks passed
@steipete
steipete deleted the codex/simplify-scope-policy branch September 20, 2026 23:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

roboclaw-bot added a commit that referenced this pull request Sep 20, 2026
Reuse the exact owner fix from a342c69 (#154120). The installer predecessor restores explicit fs-safe native configuration, which outranks the environment flag; the close-failure fixture must set and restore the same owner rather than changing the environment alone.

Reproduced the exact CI failure with the installer-before-Claw order (58 passed,1 failed,1 existing skip). After repair all59cases pass with1skip; this host subsequently refuses temporary-namespace cleanup with EACCES, recorded separately rather than counting an exit0. Canonical Claw file alone passes28with1skip and exit0; the owning PR also has Linux/macOS order proof and a green hosted job. Independent scoped P0-P2 review clean. No production or permission changes.

Co-authored-by: steipete <[email protected]>
roboclaw-bot added a commit to VACInc/openclaw that referenced this pull request Sep 21, 2026
Preserve Telegram and foreground-delivery changes while retaining the canonical Claw test repair from openclaw#154120.

Co-authored-by: VACInc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…154120)

* refactor(gateway): simplify scope checks and tool dispatch

* test(claws): isolate close-failure native configuration
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 maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant