Skip to content

fix(gateway): prevent mismatched core command payload types - #130241

Merged
steipete merged 3 commits into
mainfrom
codex/fix-107499-gateway-typed-payloads
Aug 26, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/fix-107499-gateway-typed-payloads

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #107499

What Problem This Solves

Gateway core RPC handlers accepted broadly typed payload records, which let command names, validators, and handler payloads drift apart without a compile-time failure.

Why This Change Was Made

Add a type-only, schema-derived core method payload map and one canonical validated handler adapter. Migrate board, conversation, portal, command-listing, log, and UI-command methods to inferred payloads while preserving open request envelopes, dynamically registered plugin methods, existing validation order, and standard invalid-request responses. No protocol version, plugin SDK, or wire contract changes.

User Impact

Gateway and plugin behavior is unchanged; core protocol mistakes are caught during typechecking instead of being masked by unsafe assertions.

Evidence

  • Regression-first proof: both new typed-handler tests failed on the previous code because the validated method adapter did not exist.
  • Focused Gateway proof: 8 files, 116 tests passing, including malformed payload rejection, board capability boundaries, portal access, conversation behavior, and runtime plugin method dispatch.
  • Compile-time negative case rejects pairing a conversation method with the UI command validator.
  • Independent structured review: clean, no actionable findings.
  • Production LOC: +857/-843, net +14; tests: +73/-0.
  • Hosted clean-environment changed gate is running; required PR CI will verify the exact pushed head.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete steipete closed this Aug 26, 2026
@steipete steipete reopened this Aug 26, 2026
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete steipete closed this Aug 26, 2026
@steipete steipete reopened this Aug 26, 2026
@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 Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 1:46 PM ET / 17:46 UTC.

ClawSweeper review

What this changes

Adds a schema-derived payload map and shared validator adapter for 19 selected core Gateway RPC handlers, replacing local post-validation payload casts.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer-led landing: the PR introduces a coherent typed validation boundary not present on current main, but its closing reference would resolve a broader architecture issue while many core handlers remain outside this migration.

Priority: P3
Reviewed head: 62010e1ec0595774c2b43f8c04c6126d00eab696
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The implementation cleanly centralizes an existing validation invariant with targeted source coverage; the remaining blocker is linked-issue scope, not a patch defect.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal type-safety refactor is exempt from the external-contributor real-behavior-proof gate; the PR body also records focused Gateway test evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal type-safety refactor is exempt from the external-contributor real-behavior-proof gate; the PR body also records focused Gateway test evidence.
Evidence reviewed 7 items Current main lacks the typed boundary: Current main has only the generic validation helper; it does not define the method-to-schema adapter added by this PR.
Canonical typed adapter: The adapter validates the raw payload with the existing validator before invoking the typed handler, preserving the established invalid-request path.
Schema ownership map: The new type map explicitly binds the 19 migrated board, conversation, command, log, portal, and UI methods to their existing protocol payload types.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/gateway/server-methods/validation.test.ts

Result: FAIL (partial) — step 2 expect_output typed gateway method validation: expected terminal output was not visible within 30 seconds: "typed gateway method validation"

$ node --import tsx scripts/test-projects.mts src/gateway/server-methods/validation.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130241-2x6iQd/target

 ✓  gateway-methods  ../../src/gateway/server-methods/validation.test.ts (2 tests) 73ms

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  17:47:08
   Duration  1.79s (transform 1.26s, setup 754ms, import 676ms, tests 73ms, environment 0ms)

[test] passed 1 Vitest shard in 6.73s
$ node --import tsx scripts/test-projects.mts src/gateway/server-methods/validation.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130241-2x6iQd/target

 ✓  gateway-methods  ../../src/gateway/server-methods/validation.test.ts (2 tests) 38ms

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  17:47:16
   Duration  958ms (transform 425ms, setup 352ms, import 393ms, tests 38ms, environment 0ms)

[test] passed 1 Vitest shard in 5.89s

Assertions:

  • FAIL expect_output: typed gateway method validation

How this fits together

Gateway RPC requests are authorized and dispatched through an open registry whose handlers receive generic request records. The new adapter validates selected core requests against protocol schemas before passing a statically typed payload to their handlers, while plugin methods remain dynamically registered.

flowchart LR
  A[Gateway RPC request] --> B[Authorization and dispatch]
  B --> C[Open method registry]
  C --> D[Core schema validator]
  D --> E[Typed core handler]
  C --> F[Dynamic plugin handler]
  E --> G[Gateway response]
  F --> G
Loading

Decision needed

Question Recommendation
Should this targeted migration close #107499, whose stated scope covers all protocol commands, or should the issue remain open for the un-migrated core handlers? Keep the architecture issue open: Replace the closing reference with a partial-progress reference and retain the issue for the remaining core handler migrations.

Why: The patch is technically coherent for its selected methods, but only maintainers can decide whether that subset satisfies the architecture issue's intended scope.

Before merge

  • Resolve merge risk (P1) - The linked architecture issue requests strict typing across protocol commands, but this PR maps 19 selected methods while other core handlers retain generic validation plus local casts; merging with its current closing reference could prematurely close the remaining work.
  • Resolve merge risk (P1) - Production code is net +14 lines after separating tests and the assertion baseline; the increase is the explicit type-only ownership map and adapter, so it should remain the canonical migration pattern rather than a parallel validation style.
Agent review details

Security

None.

PR surface

Source +14, Tests +76, Other -4. Total +86 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 9 842 828 +14
Tests 2 81 5 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 5 -4
Total 12 924 838 +86

Review metrics

Metric Value Why it matters
Production versus test LOC production +842/-828 (net +14); tests +81/-5; assertion baseline +1/-5 The net production growth is the type-only map and shared adapter; the handler changes otherwise consolidate repeated validation.

Root-cause cluster

Relationship: partial_overlap
Canonical: #107499
Summary: This PR explicitly targets the canonical architecture issue but implements only a selected subset of its all-command scope.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep this adapter as the canonical pattern for the named methods, but retain [Architecture] Enforce strict typings for command payloads in packages/gateway-protocol #107499 for the remaining core-handler migration unless maintainers explicitly redefine that issue's scope.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep this adapter as the canonical pattern for the named methods, but retain #107499 for the remaining core-handler migration unless maintainers explicitly redefine that issue's scope.

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

Yes, at source level: current main dispatches generic payload records and selected handlers validate then cast locally, so a method-validator mismatch can evade compile-time checking.

Is this the best way to solve the issue?

Yes for the listed handler families: a single validator adapter binds runtime validation and static payload ownership without changing the wire contract; its scope should not silently stand in for the broader migration request.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is an internal type-safety and maintainability refactor with no demonstrated user-visible regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal type-safety refactor is exempt from the external-contributor real-behavior-proof gate; the PR body also records focused Gateway test evidence.

Label justifications:

  • P3: This is an internal type-safety and maintainability refactor with no demonstrated user-visible regression.
  • 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: This maintainer-authored internal type-safety refactor is exempt from the external-contributor real-behavior-proof gate; the PR body also records focused Gateway test evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Commit 8416469 introduced the generic validator and conversation handlers that this PR refactors. (role: introduced the current validation pattern and recent Gateway contributor; confidence: high; commits: 841646999444; files: src/gateway/server-methods/validation.ts, src/gateway/server-methods/conversations.ts, packages/gateway-protocol/src/schema/agent.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Decide whether the linked architecture issue remains open for un-migrated core handlers before landing.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer decision on the review's rank-up move: this PR should close #107499. It establishes the requested canonical schema-derived core-command typing boundary, rejects method/validator mismatches at compile time, and migrates 19 representative methods across board, conversations, commands, logs, portals, and UI. The public request envelope and dynamic plugin methods intentionally remain open, and agent/chat methods retain their owner-specific prevalidation and normalization ordering; converting every unrelated handler indiscriminately would weaken those contracts. Future compatible owner migrations can reuse this same canonical adapter without keeping the foundational architecture request open.

The +14 production-line delta is justified by the required type-only protocol ownership map and shared adapter; the same change removes 18 grandfathered unsafe assertions. Exact-head CI passed, including the full Gateway-methods shard and the deterministic setup-admission cleanup fix. The bot's separate reported live-verification failure was its output-string assertion: its own attached terminal output shows the focused regression tests passing twice.

@steipete
steipete merged commit 3601020 into main Aug 26, 2026
205 checks passed
@steipete
steipete deleted the codex/fix-107499-gateway-typed-payloads branch August 26, 2026 18:08
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

* fix(gateway): enforce schema-typed core request handlers

* fix(gateway): preserve protocol and type safety guards

* test(gateway): await setup admission owner settlement
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

[Architecture] Enforce strict typings for command payloads in packages/gateway-protocol

1 participant