Skip to content

refactor(gateway): table-drive lazy method registration - #118232

Merged
steipete merged 4 commits into
mainfrom
refactor/gateway-method-table
Aug 2, 2026
Merged

steipete merged 4 commits into
mainfrom
refactor/gateway-method-table

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway method policy and lazy dispatch ownership were maintained in separate hand-written lists. That duplication had already allowed advertised methods to ship without a dispatch route, and every new method required synchronized edits across multiple files. Several terminal handler catches also returned raw String(error) text instead of using the WebSocket dispatch backstop's safer redaction.

Why This Change Was Made

The canonical core method table now carries a handler-family column for all 330 lazy-routed methods. A single typed 69-family module map builds the lazy handlers while retaining one-import-per-family caching, deterministic descriptor order, and the existing missing-handler runtime invariant. The two residual method-name arrays and the 715-line registration duplicate are deleted; server-methods.ts drops from 1,158 to 486 lines and its max-lines grandfathering is removed.

Ten terminal, single-response catches now delegate failures to the authenticated WebSocket backstop, which emits UNAVAILABLE after applying formatForLog redaction. Three superficially similar paths remain deliberately local: worktree snapshot errors and board validation errors have structured outcomes, while chat send owns early acknowledgements and lifecycle cleanup. No current in-process call site targets the ten changed methods; generic raw in-process dispatch would receive a rejected handler error rather than a synthesized protocol response.

The per-request registry rebuild for callers without an owning attached registry remains unchanged. That fallback is intentional for #94127 so late process-root plugin methods remain visible.

AI-assisted change; the final Codex autoreview reported no accepted/actionable findings.

User Impact

There is no intended visible behavior change in successful requests. Maintainers now add a core method's policy and lazy owner in one row, preventing advertised-but-unknown drift. Unexpected failures on the affected WebSocket methods are redacted consistently before being returned.

The proposed four test-suite file renames were intentionally omitted: each file carries a grandfathered max-lines suppression, and renaming would require baseline path replacements forbidden by this cleanup fleet's shrink-only baseline rule.

Evidence

  • Automated semantic comparison against origin/main: all 350 method names, scopes, release metadata, visibility/startup/write flags, and ordering are unchanged; all 330 lazy methods retain their prior family; 69 loader import/export selectors are unchanged.
  • node scripts/run-vitest.mjs src/gateway/server-methods-list.test.ts src/gateway/server-methods/lazy-core-handlers.test.ts src/gateway/server-methods/models.test.ts src/gateway/server-methods/worktrees.test.ts — 4 files, 55 tests passed.
  • node scripts/run-vitest.mjs src/gateway/server/ws-connection/authenticated-request-dispatch.server.test.ts src/gateway/method-scopes.test.ts src/gateway/methods/registry.test.ts src/gateway/methods/core-descriptors.since.test.ts src/gateway/server-methods.plugin-gateway-dispatch.test.ts src/gateway/server.models-voicewake-misc.test.ts — 6 files, 173 tests passed.
  • node scripts/check-changed.mjs --dry-run — correctly selected core, coreTests, and tooling lanes.
  • node scripts/check-changed.mjs — broader remote gate could not start because no approved Crabbox provider was ready.
  • Hosted PR CI: run 30769789621 passed at head 87429b5b766b491a934134e9d90b43bd5e2d0196, including build, lint, production/test types, protocol, and package-boundary checks.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted — TruffleHog clean; Codex gpt-5.6-sol high-reasoning review clean, no actionable P0 findings.
  • git diff --check — clean.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime labels Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 22:03
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 6:31 PM ET / 22:31 UTC.

ClawSweeper review

What this changes

The PR moves lazy core gateway-method ownership into the canonical descriptor table, derives cached lazy handlers from that table, and lets selected terminal handler failures reach the authenticated WebSocket redaction backstop.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this maintainer-labeled PR open for explicit maintainer review. The branch’s descriptor-table ownership model is a coherent replacement for duplicated method-name and lazy-loader lists, and the authenticated WebSocket dispatcher already owns the redacted terminal-error response path; no concrete patch defect was found. The branch is behind current main, so merge should wait for a rebase or exact-current-base validation refresh.

Priority: P2
Reviewed head: 87429b5b766b491a934134e9d90b43bd5e2d0196
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The patch has a strong ownership model, focused validation evidence, and no supported correctness or security finding; only the normal current-base refresh remains before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-labeled internal gateway refactor is outside the external-contributor live-proof gate; focused gateway test evidence and successful exact-head CI are available in the PR context.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-labeled internal gateway refactor is outside the external-contributor live-proof gate; focused gateway test evidence and successful exact-head CI are available in the PR context.
Evidence reviewed 7 items Canonical ownership is type-checked: The PR defines the handler-family loader map with satisfies Record<CoreGatewayHandlerFamily, CoreGatewayHandlerModuleLoader>, so every family named by the descriptor-table union must have a loader and no loader can use an unrecognized family.
Lazy handlers derive from the same descriptor data: The core handler map is generated by grouping descriptor-table method names by family, then building cached lazy handlers for each family; this removes the separate handwritten method arrays while retaining the existing missing-handler invariant.
Descriptor table remains the source of method metadata: The PR converts the core table to typed rows, derives normalized method specs from those rows, and exposes the family-to-method grouping from that same normalized table.
Findings None None.
Security None None.

How this fits together

Gateway clients send authenticated RPC requests to the WebSocket dispatcher, which authorizes a method through a registry and invokes its lazily loaded handler. Core method metadata controls what is advertised and authorized, while handler-family ownership determines which module supplies the method at runtime.

flowchart LR
  Client[Authenticated gateway client] --> Dispatch[WebSocket request dispatcher]
  Dispatch --> Registry[Method registry and authorization]
  Registry --> Table[Canonical core method table]
  Table --> Families[Handler-family mapping]
  Families --> Lazy[Lazy module loader]
  Lazy --> Handler[Core request handler]
  Handler --> Response[Protocol response or redacted failure]
Loading

Decision needed

Question Recommendation
Should this maintainer-labeled, broad gateway refactor be accepted after its branch is refreshed against current main and its exact-head checks are green? Refresh and merge: Rebase or update the branch, confirm exact-head gateway and full CI checks, then merge the canonical-table refactor.

Why: The code path is technically coherent, but the protected maintainer label requires an explicit human merge decision for a large central gateway ownership refactor.

Before merge

  • Add real behavior proof - Not applicable: This maintainer-labeled internal gateway refactor is outside the external-contributor live-proof gate; focused gateway test evidence and successful exact-head CI are available in the PR context.
  • Resolve merge risk (P1) - The branch is behind current main; merge should use a rebase or an exact-current-base validation refresh so the large registry refactor is checked against intervening gateway changes.
Agent review details

Security

None.

PR surface

Source -724, Tests -6, Other +8. Total -722 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 9 666 1390 -724
Tests 1 3 9 -6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 29 21 +8
Total 12 698 1420 -722

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/gateway/methods/core-descriptors.ts, vector/embedding metadata: scripts/check-protocol-since.mjs. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one canonical core method table that owns method policy and lazy handler family, retain authenticated dispatch as the sole fallback owner for terminal error redaction, then merge only after current-base validation is refreshed.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one canonical core method table that owns method policy and lazy handler family, retain authenticated dispatch as the sole fallback owner for terminal error redaction, then merge only after current-base validation is refreshed.

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

Not applicable: this PR is an internal refactor rather than a report of a separately reproducible user defect. Its relevant verification is preservation of registry dispatch and terminal failure handling, for which the PR supplies focused tests and exact-head CI evidence.

Is this the best way to solve the issue?

Yes. Consolidating policy metadata and lazy-handler ownership into one typed source is a better fix than preserving synchronized method arrays, because the loader map is checked against the table-derived family union and dispatch keeps its existing canonical error boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a1c2009b91b9.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a substantial but non-emergency gateway reliability and maintainability refactor with no demonstrated successful-request regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-labeled internal gateway refactor is outside the external-contributor live-proof gate; focused gateway test evidence and successful exact-head CI are available in the PR context.

Evidence

What I checked:

  • Canonical ownership is type-checked: The PR defines the handler-family loader map with satisfies Record<CoreGatewayHandlerFamily, CoreGatewayHandlerModuleLoader>, so every family named by the descriptor-table union must have a loader and no loader can use an unrecognized family. (src/gateway/server-methods.ts:172, 87429b5b766b)
  • Lazy handlers derive from the same descriptor data: The core handler map is generated by grouping descriptor-table method names by family, then building cached lazy handlers for each family; this removes the separate handwritten method arrays while retaining the existing missing-handler invariant. (src/gateway/server-methods.ts:230, 87429b5b766b)
  • Descriptor table remains the source of method metadata: The PR converts the core table to typed rows, derives normalized method specs from those rows, and exposes the family-to-method grouping from that same normalized table. (src/gateway/methods/core-descriptors.ts:505, 87429b5b766b)
  • Terminal failures already have one authenticated dispatch owner: The authenticated dispatcher catches an unhandled request failure, logs formatForLog(err), and returns an UNAVAILABLE response using the same redacted text; allowing single-response handlers to reject reaches that canonical backstop. (src/gateway/server/ws-connection/authenticated-request-dispatch.ts:167, 87429b5b766b)
  • Feature-history provenance: Blame attributes both the existing authenticated-dispatch backstop and this branch’s descriptor-derived lazy-handler assembly to Peter Steinberger, showing the refactor is aligned with the current gateway ownership path rather than introducing a parallel dispatcher. (src/gateway/server-methods.ts:230, 10e9281f1e6b)
  • Exact-head validation evidence: The provided PR context reports passing hosted CI at the reviewed head, including build, lint, production/test types, protocol, package-boundary, gateway runtime-boundary, and real-behavior-proof checks; the PR body also records 228 focused gateway tests passing. (87429b5b766b)

Likely related people:

  • steipete: Peter Steinberger authored the descriptor-table refactor and the existing authenticated dispatch backstop, and recent gateway history shows sustained ownership of this registry and dispatch surface. (role: feature owner and recent area contributor; confidence: high; commits: 10e9281f1e6b, 641a4bf7b09b; files: src/gateway/server-methods.ts, src/gateway/server/ws-connection/authenticated-request-dispatch.ts, src/gateway/methods/core-descriptors.ts)

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-08-02T22:08:33.776Z sha d1daa6f :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T22:22:27.175Z sha 87429b5 :: needs real behavior proof before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 2, 2026
@steipete
steipete merged commit 0e94d23 into main Aug 2, 2026
130 of 132 checks passed
@steipete
steipete deleted the refactor/gateway-method-table branch August 2, 2026 23:08
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
)

* refactor(gateway): table-drive lazy method registration

* test(gateway): keep auth coverage outside refactor scope

* fix(ci): teach protocol guard about method rows

* fix(types): widen gateway method row policy
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Aug 21, 2026
Re-integrate upstream/main (base a3ca846 → tip 784a228, 266 commits) into the
cortex fork. Conflict resolution + keystone reconciliation summary in
RESYNC_LEDGER.md.

Foundation (lead-owned): MCP fence ENHANCE (fence sanitized publicValue + fix a
latent _meta-leak), openshell buildRemoteCommand union-trap → adopt upstream
extraction, cron completion-announce grafted onto upstream openclaw#126483 failure-
threshold rewrite, memory-core prompt-section KEEP-OURS, ui/package.json union.

Gateway/protocol second pass (split-brain repair): grafted upstream's GitHub-
identity schemas; re-grafted 37 dropped methods (openclaw#118232) + placement scopes +
handler wiring; method-scope drift (config.schema/fs.listDir/worktrees.create,
sessions.groups.*, skills.forge.*); embedded-agent type extensions;
agentHarnessStructuredInput SDK export; resolved-v1 provenance;
AgentToolResult<unknown>; cron-trigger-filter; exec-approval; copyImage icon.

GitHub-identity (adopt fully): core adopted + working; UI ported to ui/src/ui
(compiles + unit-tested); app-shell live-wire + runExternalMutation + visual
verification are the documented land-time step.

Agent-loop (merge + restore fork features): restored the fork's tool mutation-
tracking + recovery cluster (20 files) to fork-main; grafted upstream's clean
before-tool-call owner-arg change; deferred upstream intentionalTermination
hardening as a follow-up.

UI divergence: fork owns ui/src/ui; upstream's ui/src/pages restructure not
adopted (184 files kept-deleted). i18n kept-ours (fork en.ts superset).

Verification: tsgo core/extensions/test:ui/test:packages = 0 (zero new errors;
core:test/extensions:test residuals proven identical to fork-main baseline).
Behavior: cron, mcp, memory-core, agent-loop mutation-recovery green (merge
regressions fixed). Pending land-time: Linux build + behavior proof + autoreview
+ GitHub-identity UI wiring/visual.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: XL 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