Skip to content

refactor(gateway): flatten HTTP request stages - #127264

Merged
vincentkoc merged 1 commit into
mainfrom
refactor/gateway-http-stage-callables
Aug 21, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
refactor/gateway-http-stage-callables

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

The gateway HTTP router still wrapped every ordered request stage in a { run } object even though the stage contract no longer carries metadata. This residue from the earlier route-staging consolidation adds structure without owning behavior and makes the canonical short-circuit flow harder to scan.

This is part of an explicitly maintainer-authorized, bounded refactor campaign.

Why This Change Was Made

The gateway HTTP request router now owns one canonical array of callable stages and invokes each callback directly. Admission remains an explicit wrapper only for admitted stages.

The change removes the object shell from the initial probe, MCP app, plugin-auth, and plugin-dispatch stages while preserving:

  • exact stage order and first-true short-circuit behavior
  • false fallthrough and exception propagation to the existing outer 500 handler
  • admitted versus non-admitted execution
  • plugin auth before plugin dispatch with the same captured mutable state
  • the pre-config liveness fast path

No routes, error policy, tests, docs, changelog, config, protocol, or public surface changed. Production LOC is +55/-65 (net -10); tests are +0/-0.

Open PR #119446 adds cfg: configSnapshot inside the unchanged plugin authorization call. Its exact one-line semantic delta remains compatible with this callable flow; the deterministic combined resolution contains both changes and no additional behavior.

User Impact

No user-visible behavior changes. This only removes obsolete internal routing structure from the gateway HTTP owner.

Evidence

  • pnpm format src/gateway/server-http.ts
  • node scripts/run-vitest.mjs src/gateway/server-http.request-trace.test.ts - 14 passed
  • node scripts/run-vitest.mjs src/gateway/server-http.mcp-app-admission.test.ts - 8 passed
  • node scripts/run-vitest.mjs src/gateway/server-http.probe.test.ts - 58 passed
  • node scripts/check-changed.mjs -- src/gateway/server-http.ts - passed on Blacksmith Testbox tbx_01m0jg1wdx5jajp6225n3s9yqh
  • Blacksmith run: https://github.com/openclaw/openclaw/actions/runs/32499461145
  • git diff --check
  • autoreview: clean, no accepted/actionable findings
  • signed head: 0a1c4c117b80f48e56fe1519cbcce61e2fa1f6a0

AI-assisted: yes.

@vincentkoc vincentkoc self-assigned this Aug 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 21, 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 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 12:08 PM ET / 16:08 UTC.

ClawSweeper review

What this changes

The PR changes the gateway HTTP router from { run } stage objects to direct callable stages without changing routing behavior.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still uses wrapper objects and stage.run() for this router; the PR cleanly removes that metadata-free indirection while preserving stage order, returns, admission, and plugin auth-before-dispatch flow. It is a maintainer-owned draft, so normal review is appropriate.

Priority: P3
Reviewed head: 0a1c4c117b80f48e56fe1519cbcce61e2fa1f6a0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative router cleanup with no supported correctness or security finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal refactor is not subject to the external-contributor real-behavior-proof gate.
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 refactor is not subject to the external-contributor real-behavior-proof gate.
Evidence reviewed 6 items Current main still has the wrapper contract: Current main defines stages as objects with a run callback and invokes stage.run(), so the cleanup is not already implemented.
Direct diff preserves the routing closures: The only PR-owned change replaces wrapper construction and invocation with the same callbacks; the MCP admission closure and paired plugin authorization/dispatch callbacks remain ordered identically.
Caller and admission sibling checked: Gateway runtime construction calls this router, while plugin dispatch independently uses the same HTTP admission helper; the refactor retains the router-side admission boundary.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/server-http.mcp-app-admission.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs src/gateway/server-http.mcp-app-admission.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127264-4VhjAR/target$ node scripts/run-vitest.mjs src/gateway/server-http.mcp-app-admission.test.ts
node scripts/run-vitest.mjs src/gateway/server-http.mcp-app-admission.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127264-4VhjAR/target

 ✓  gateway-server-isolated  ../../src/gateway/server-http.mcp-app-admission.test.ts (4 tests) 76ms











































Assertions:

  • PASS expect_output: server-http.mcp-app-admission.test.ts

How this fits together

Gateway HTTP requests enter one ordered router, where probe, core, plugin, and Control UI handlers either claim the request or fall through. Claimed work produces the response; unclaimed requests reach startup readiness and then the final 404.

flowchart LR
A[HTTP request] --> B[Gateway router]
B --> C[Ordered route stages]
C --> D{Stage claimed request?}
D -->|yes| E[HTTP response]
D -->|no| F[Startup readiness]
F --> G[503 or 404 response]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -10. Total -10 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 55 65 -10
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 55 65 -10

Review metrics

Metric Value Why it matters
Production versus test LOC production −10 net; tests 0 The patch deletes internal wrapper structure without adding a test-only or runtime surface.

Technical review

Best possible solution:

Retain the direct-callable representation, preserving the existing stage order and admission wrappers, once the draft is ready for normal maintainer review.

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

Not applicable: this is a behavior-neutral refactor; direct source comparison and existing boundary tests establish the preserved contract.

Is this the best way to solve the issue?

Yes: representing a metadata-free stage as its callable directly is the narrowest maintainable cleanup and keeps the existing admission wrapper explicit.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a small behavior-neutral internal gateway cleanup.
  • 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 refactor is not subject to the external-contributor real-behavior-proof gate.

Label justifications:

  • P3: This is a small behavior-neutral internal gateway cleanup.
  • 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 refactor is not subject to the external-contributor real-behavior-proof gate.

Evidence

What I checked:

  • Current main still has the wrapper contract: Current main defines stages as objects with a run callback and invokes stage.run(), so the cleanup is not already implemented. (src/gateway/server-http.ts:140, 8531da19930d)
  • Direct diff preserves the routing closures: The only PR-owned change replaces wrapper construction and invocation with the same callbacks; the MCP admission closure and paired plugin authorization/dispatch callbacks remain ordered identically. (src/gateway/server-http.ts:140, 0a1c4c117b80)
  • Caller and admission sibling checked: Gateway runtime construction calls this router, while plugin dispatch independently uses the same HTTP admission helper; the refactor retains the router-side admission boundary. (src/gateway/server-runtime-state.ts:295, 8531da19930d)
  • Existing behavior tests cover the affected invariants: Focused tests cover probe precedence before stalled stages, MCP admission closure/fallthrough/error release, and plugin gateway-auth runtime scope handoff; the PR changes none of these tests. (src/gateway/server-http.mcp-app-admission.test.ts:55, 8531da19930d)
  • History provenance: Available current-main blame attributes the existing stage helper lines to the recorded source snapshot commit; the local history is limited, so this supports routing rather than a strong feature-origin claim. (src/gateway/server-http.ts:140, 9c3335a1a43b)
  • Release-tree check: The local object database does not contain the supplied latest-release tree; the current-main comparison independently establishes that this cleanup remains needed.

Likely related people:

  • Peter Steinberger: The available blame and file history attribute the existing request-stage helper to the recorded current-main snapshot commit; limited retained history makes this a routing signal rather than definitive ownership. (role: current-main history contributor; confidence: low; commits: 9c3335a1a43b; files: src/gateway/server-http.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.

@vincentkoc
vincentkoc marked this pull request as ready for review August 21, 2026 16:43
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer landing preflight is complete for exact head 0a1c4c117b80f48e56fe1519cbcce61e2fa1f6a0.

  • Repository-native review artifacts validate with no findings.
  • Exact-head CI run 32504403594 is green; scripts/pr prepare-run 127264 passed in hosted_exact_or_recent_parent mode.
  • The prior focused Testbox and Crabbox evidence covered 158/158 tests on each backend, with 27/27 changed gates. The cancelled lease wrapper run 32499461145 was not treated as a green GitHub gate.
  • Current main is 781ded80d62499dc123a97e4eb534ce13791e034; src/gateway/server-http.ts remains blob 56fef2a249c271e383f608ad81935fd0d8314127, and the current synthetic merge-tree applies cleanly.
  • The latest exact-head ClawSweeper review has no findings and Before merge: None; there are no review conversations.

Proceeding with the repository-native squash landing workflow.

@vincentkoc
vincentkoc merged commit 081810c into main Aug 21, 2026
302 checks passed
@vincentkoc
vincentkoc deleted the refactor/gateway-http-stage-callables branch August 21, 2026 17:00
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: 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