Repository navigation
refactor(gateway): trust admitted client scope arrays - #182897
Conversation
Remove repeated array-shape checks after connection admission while preserving scope membership, revocation, and existing capture timing.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
|
Codex review: needs maintainer review before merge. What this changesThis PR removes repeated array-shape checks from typed Gateway scope consumers and adds malformed-scope admission coverage. Example: A WebSocket client sends scopes as "xoperator.adminx" instead of an array.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: the maintainer-directed simplification preserves admission validation, permission checks, and scope-capture timing, with no actionable introduced bug found. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway admission validates incoming connection parameters and retains authenticated client scopes; handlers and event delivery consume those scopes to authorize operations and disclosure. flowchart LR
A[Connection frame] --> B[Protocol validation]
B --> C[Authentication and scope ceilings]
C --> D[Admitted client]
E[Typed internal constructors] --> D
D --> F[Permission and live authority checks]
F --> G[RPC effects and event delivery]
Technical reviewBest possible solution: Keep scope-shape validation at admission and let typed consumers perform their existing permission and live-authority checks. Do we have a high-confidence way to reproduce the issue? No broken user behavior is claimed; source inspection confirms repeated checks on scopes already constrained by admission or typed constructors, and no target code was executed during this review. Is this the best way to solve the issue? The direct substitutions are the smallest complete simplification: they retain the existing validation owner, nullable-client behavior, authorization predicates, and capture timing without introducing another abstraction. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 61deaaef5879. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -12, Tests +19. Total +7 across 15 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 24, 2026, 5:41 PM ET / 21:41 UTC. |
Populate missing connect.scopes in the shared catalog RPC fixture after #182897 made downstream handlers trust admitted connection metadata. Preserve client identity, supplied scopes, and live scope mutations. The progress suite reproduces 15 failures on main and passes all 17 cases with the fixture repair. Five sibling files yield 38 passes and one unchanged base failure expecting CATALOG_LOADING instead of pending. Focused lint, format, Gateway-methods test types, and Codex review pass.
Remove 20 redundant array-shape checks from downstream Gateway consumers of admitted connection scopes. Keep WebSocket admission validation, permission membership, revocation, effect-time authority and scope-capture ordering with their existing owners. Add actual handshake regression coverage rejecting string-valued scopes before admission. All 416 focused owner tests and exact-head CI pass. Synthetic Gateway workload retains 3,006 SQL statements and 95 MAIN statements; no SQL or latency improvement is claimed.
Populate missing connect.scopes in the shared catalog RPC fixture after openclaw#182897 made downstream handlers trust admitted connection metadata. Preserve client identity, supplied scopes, and live scope mutations. The progress suite reproduces 15 failures on main and passes all 17 cases with the fixture repair. Five sibling files yield 38 passes and one unchanged base failure expecting CATALOG_LOADING instead of pending. Focused lint, format, Gateway-methods test types, and Codex review pass.
What Problem This Solves
Gateway connections validate optional string-array scopes at admission. Downstream handlers repeatedly call
Array.isArrayon the retained, typed value. Remove 20 of these repeated shape checks across 14 Gateway files (22 additions, 34 deletions; net -12 production lines).User Impact
No user-visible authorization change. Gateway handlers do less repeated validation after admitting a connection.
Why This Change Was Made
The WebSocket
ConnectParamsschema and admission validators remain the boundary owners. In-process constructors accept or produce typed arrays. Scope membership, revocation, per-effect authorization, nullable clients, and the original pre-/post-await capture positions are preserved. No SQL, schema, database identity, SDK surface, provider request, or configuration changes.Retained checks include untrusted token-scope normalization, unknown-valued approval-client scopes, agent-tool input decoding, and WebSocket admission. Arbitrary JavaScript violating an internal TypeScript constructor contract is not a supported input boundary; existing array operations already rely on that contract.
Acceptance rule (registered before measurement)
Use frozen SQL harness v3.1.4 with synthetic state and real loopback Gateway transport. One baseline/candidate pair with matching default options; analyze ten warm turns separately from cold/startup/restart phases. Require successful turns, spawn, cron, control RPCs, compaction, restart, and shutdown. Compare statement, worker-request, and MAIN counts, including per-operation execution-window counts; no increase caused by changed scope consumers. Report warm median, nearest-rank p95, and min–max, plus raw phase changes. Any 20% adverse metric is a stop pending disposition. No latency or CPU speed claim is made. Counts-only runs do not use the timing lock.
The frozen v3.1.4 causal hook predates the shared AsyncContext migration: causal phases are empty and requests classify as background on current main. The comparison therefore uses native warm execution windows, not causal turn counts; the frozen harness is unchanged. This limitation is recorded before the first run.
The simplification gain is 20 removed runtime array-shape checks, with no new validation owner, state, cache, copying, or fallback.
Preserved authorization checks
Admission regression
The existing
ConnectParamsSchema(packages/gateway-protocol/src/schema/frames.ts:61) owns scope shape. WebSocket admission appliesvalidateConnectParamsatsrc/gateway/server/ws-connection/message-handler.ts:286. The suspension-admission suite now sends actual connect frames with both"operator.admin"and"xoperator.adminx"as string-valued scopes, and requiresINVALID_REQUEST, socket close, and no admitted client. Downstreamincludescan therefore only receive an admitted array.Evidence
All 16 focused owner test files pass (416 tests), including both malformed string-scope connect frames, final scope-revocation checks, and the repaired session-status path. Exact-head CI 40133681144 passes production/test types, core/extension lint, source contracts, architecture/Madge, T1/dialect/worker ratchets, selected test shards, and all three PostgreSQL conformance shards. Metadata 40134106199 passes after correcting template headings; earlier failed metadata runs are superseded.
Local
check:changed --base 11c9161b4a1e5e00e3a5145c04d5ae4756d61958passes type-aware changed-file core oxlint, oxfmt, architecture/Madge (zero cycles), owner guards, and ratchets. Its three typecheck steps stop at the containment guard because the campaign mandates an internal-disk virtual store outside this external-disk worktree. No guard bypass was used; exact-head CI supplies completed type proof. The completed production, full-tree, and script export scans report the same 1,230 unique findings on exact base and candidate: zero new or resolved findings, none in changed files. Both scans exit nonzero for this identical pre-existing export debt; the comparison proves this patch adds none. The frozen baseline/candidate pair completed successfully; counts and threshold investigation are below.The first CI run caught a removed
callerScopeslocal still consumed by session-patch publication; the repair restores the original pre-await capture while removing only its redundant shape test. Independent constructor/writer audit covers all selected paths. Simplification found no new owner, wrapper, state, or test machinery. Codex P0–P2 autoreview: scoped-clean (two rounds), covering the diff and unchanged boundary/constructor context. Frozen harness hashes: 36/36 verified.Frozen count comparison
One alternating baseline/candidate pair; each run includes ten warm native execution windows. All turns, spawn, control RPCs, cron, compaction, restart and shutdown contracts passed. No latency or CPU claim. Both builds match their recorded full SHAs.
Every other warm operation is unchanged, including the transcript prepare/persist batches, pending-input reads, cache-write tracking, metadata refresh (9 SQL / 1 request), and UNKNOWN (19 / 9). No new whole-workload operation names.
20% stop investigation and disposition (2026-10-24): the first-turn, warm-04, idle-settle and restart-shutdown raw windows crossed the threshold. The maintainer accepted these as execution-phase placement under the existing attribution rule after reviewing compensating adjacent windows, unchanged total SQL/MAIN, and the absence of new operation names. This is an explicit disposition, not a latency or SQL-saving claim. Worker open (181 SQL) moved from connect to first turn; connect + first-turn totals are 485/103/0 → 483/103/0. Metadata refresh and associated native work moved from warm-03 to warm-04; their combined counts are 118/29/0 → 120/29/0. Post-compaction model-context/transcript/read bookkeeping moved into idle-settle; compaction + settle are 269/49/0 → 272/49/0. Restart shutdown includes one pending patch commit and one upstream-watch poll; whole patch-commit request count remains 39. These are execution-window observations, not causal turn attribution. The patch changes no SQL, scheduling, worker routing, caching or await positions.
Open-PR compatibility
The complete shared open-PR index (2,677 PRs, refreshed 2026-10-24 22:49 UTC) finds 31 other PRs overlapping this patch. All overlapping heads are unchanged from the completed comparison. For each pinned head below,
git merge-treeon base11c9161b4a1and candidatecbbc441ffadadds zero conflict paths or hunks. 25 already conflict with the base. The excluded plugin-host-hooks edit is absent from this PR.1ec16f56b90b37a8c13f41d078147279767aa7d517ce8456a636ce0d18d7aa973a461027e692a2097a42ee6003da2db07e285f117b8cd5a65a503ac6588af7c582875ccbb4ccb1cdc978efa59f1ce48a73e79cb2c243b9d297418b9bcd58c2a90a3c2ac0a50451e8c1ae26a524ff19f9bda8e6ac94f213a2c37c07949dcd4a94ab9dd15656f143c054b275e2bbe54f53bb721c82a7d0e2c0e8ad86ec67152d15a35e9c0f28f7eabdf4fcc3f53dbb74a5bb30483289b897744353Release-note context: internal Gateway scope handling simplification; user-visible authorization behavior is unchanged.