Skip to content

refactor(gateway): deslop gateway - #158228

Merged
steipete merged 5 commits into
mainfrom
deslop/l50-gateway3
Sep 25, 2026
Merged

steipete merged 5 commits into
mainfrom
deslop/l50-gateway3

Conversation

@steipete

@steipete steipete commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway request and lifecycle code repeats small parsing, projection, forwarding, and cleanup flows even after the earlier subsystem passes.

User Impact

This refactor preserves RPC names, params/results, protocol version, persisted schemas, and auth/pairing/approval decisions. Existing live-authority checks remain at their original boundaries. Two malformed-input/cancellation defects found during the sweep are fixed below. Existing config defaults, durable-secret inference, stored-state formats, retention, and update inputs are unchanged; no migration is required.

Why This Change Was Made

The changes remove 2,169 net production lines by routing equivalent flows through existing owners and removing redundant intermediate representations. The assertion ratchet is reduced by exactly 30 removed assertions across 14 files. The earlier validation-options and allow-once/allow-always consolidations remain intact.

Simplifications and rationale
  • Auth: share token/password credential selection and verification while retaining their distinct redaction, missing-config, mismatch and rate-limit semantics; use one config merge owner and canonical secret-input paths.
  • Approval delivery: construct direct/relay APNs arguments once and share notification payload emission without changing authority callbacks.
  • Session methods: reuse canonical row readiness, combine identical storage/status response handling, and share patch/patchMany lifecycle setup and error mapping.
  • Chat history: use one incremental-tail path for offset and ordinary pages while retaining the separate anchored-message reader and its pagination contract.
  • Chat turns: reuse canonical attachment, recovery, usage and transcript owners; remove forwarding wrappers and duplicated terminal-message projections.
  • Agent methods: derive request fields from the protocol schema, inline argument-only reset forwarding, and reuse existing roster/workspace helpers.
  • Session reads: consolidate physical-store selection, observer audiences/publication, companion byte budgeting and transcript metadata construction; retain lifecycle-specific checks and non-enumerable metadata handling.
  • HTTP/MCP: share tool failure envelopes, operation dispatch, icon cache settlement and observer-error handling; keep request rejection and auth boundaries unchanged.
  • Talk: share transcription event/error handling, remove a forced-consult forwarding layer, and rely on the existing base64 validator instead of repeating a decode/encode validation pass.
  • Worker environments: pass canonical artifact-transfer callbacks through adapters, consolidate workspace capture/reconcile bookkeeping and script setup, and use the shared deferred primitive for inference drains.
  • Gateway runtime: share chat-registration cleanup, media-GC loader ownership, readiness result decoration; remove redundant channel callbacks.
  • Logging and probes: use one WS renderer, shared truncation/default result fields, and the canonical credential and IP parsing owners.
  • Control UI serving: consume the existing root-state union directly, use canonical focus-route and repository-URL helpers, and remove redundant fallbacks and repeated commentary. Rendered output is unchanged.
  • Remaining method projections: reuse protocol result types, canonical base64/truncation helpers, and common preference/result construction instead of local wrappers and repeated structures.

Fixes found along the way

  • A node-worker operation that was already aborted returned before observing the supplied promise. A later rejection could become unhandled. The aborted branch now observes both promises while preserving the original abort error.
  • JSONL null rows could throw in Claude fallback-history and activity readers. The canonical row decoder now rejects non-object roots so existing malformed-row handling skips them and retains valid surrounding turns.

Evidence

All required checks are green on 9abc9a4e1cdccc1b38f478332c20b76b456ee83c: CI completed with 149 successful jobs and 17 workflow skips. OpenGrep, both CodeQL workflows, and security review also passed. Independent P2 review covered the full sweep and every corrective patch; no actionable findings remain.

Blacksmith Testbox proof of the sealed 610240d9e59c5836789d7bd637b334e6a8a2a991 candidate passed node scripts/check-changed.mjs (1,768 seconds, all 25 test-type graphs plus production types, lint, selected tests, and guards), pnpm build (654 seconds), pnpm protocol:check with zero generated drift, pnpm plugin-sdk:check-exports, and pnpm plugin-sdk:surface:check. The exact lint stripe passed; OpenGrep reported zero findings using the unchanged repository rulepack and exclusions. Its report retained 10 parser/internal partial-analysis notices.

Subsequent rebases preserved the reviewed patch and current main's authority boundaries. Exact-head CI logs confirm 478 passing cases across all ten identified rebase-contract files: auth/redaction, network attribution, HTTP probes and MCP admission, startup auth, configured-owner authority, compaction, and Team Reports scheduling. The latest rebase was entirely patch-identical. The unrelated scheduler import failure was repaired by the owning main commit 7c4866c73b31; current-head CI passed all 36 scheduler cases.

Negative controls reproduced both fixed defects on the original code. The earlier broad batch passed 7,156 cases and exposed four agent-deletion failures introduced by a null/truthiness simplification; restoring the original predicate fixed all four without changing assertions. Follow-up batches passed 965 cases across 38 files (one existing skip), 275 across 17 files, and 285 across 12 files. These batches overlap and are not an additive test count. CI also identified a stale export, a type-only cycle, and lint/security-boundary requirements; all were repaired without suppressions or weakened checks. No protocol/schema/config compatibility exception was added.

Changed-test costs on Linux Testbox

Measured with pnpm test <file> --maxWorkers=1; wall seconds include runner and worker preparation. The twelve files retain 323 test cases in total. The CI column sums logged test-case durations on the exact green head and excludes shared worker/build setup; the Testbox column is full command wall time.

Gateway test file Tests Testbox wall seconds CI case seconds
worker-environments/node-worker-abort.test.ts 1 8 0.032
node-wake-state.test.ts 8 3 0.062
cli-session-history.claude-input.test.ts 16 22 0.285
cli-session-history.test.ts 118 21 1.193
control-ui-routing.test.ts 95 8 0.125
server-http.node-workspace-transfer.test.ts 6 54 0.032
worker-environments/node-enrollment.test.ts 47 93 53.928
worker-environments/node-worker-bundle-installer.test.ts 6 18 0.139
worker-environments/node-worker-bundle-transfer-service.test.ts 2 32 0.074
worker-environments/node-worker-bundle-transfer.test.ts 1 52 0.045
worker-environments/store-endpoints.test.ts 6 7 0.029
worker-environments/worker-bootstrap-artifact-transfer.test.ts 17 39 0.597

The existing integration files above 30 seconds verify artifact transport and node-enrollment lifecycle contracts. Worker-bundle preparation dominates the transfer files; the enrollment file retains its existing lifecycle cases. The added malformed-row cases execute in milliseconds, and this change adds no per-case sleeps, retries, or Gateway boots.

Remote proof leases and cleanup

Provider: blacksmith-testbox, through scripts/crabbox-wrapper.mjs. Completed proof batches verified their source snapshots and used frozen dependencies; only one execution command ran per lease. All leases are stopped. Hosting workflow cancellation during lease cleanup is distinct from the command exit recorded below.

Lease Commands and observed result
tbx_01m3ce3d02kpsy3a98e64phbcq Original-defect controls and focused proof; hosting run was cancelled during the initial build, so that build was incomplete.
tbx_01m3cm3f9x53nejezm9k1a26h6 pnpm build passed in 512s. Broad run-vitest found the four corrected agent-deletion failures. Later prepared follow-up was cancelled before execution for rebase.
tbx_01m3csk3zfrrk0kkt00kxcxqqa Installer and 38-file follow-up passed. The changed-code run was interrupted for rebase and is not counted as passed.
tbx_01m3cwf1qx9ev71f1zbye7j97j pnpm deadcode:full passed (141s); pnpm check:architecture passed (215s, zero cycles); wake-state and 17-file integration tests passed. The changed-code run was superseded by the lint corrections.
tbx_01m3cy3qaakv0n0ge885897fts Complete candidate batch passed: exact core lint stripe, OpenGrep, 12-file follow-up, full check-changed, protocol, SDK checks, and build. Wrapper exit 0.

@clawsweeper

clawsweeper Bot commented Sep 25, 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 app: web-ui App: web-ui gateway Gateway runtime size: XL labels Sep 25, 2026
@steipete
steipete marked this pull request as ready for review September 25, 2026 17:28
@github-actions

github-actions Bot commented Sep 25, 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: 9abc9a4e1cdccc1b38f478332c20b76b456ee83c
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/auth-config-utils.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/auth-install-policy.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/auth-resolve.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/auth-surface-resolution.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/auth.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/credential-planner.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/credentials-secret-inputs.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/credentials.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/exec-approval-ios-push.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/probe-auth.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/secret-input-paths.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/server-http.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/agent-runtime-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/models-auth-status.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/startup-auth.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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 25, 2026, 4:19 PM ET / 20:19 UTC (Revision 7).

ClawSweeper review

What this changes

The branch consolidates Gateway authentication, session, chat, HTTP, worker, and Control UI handling while fixing pre-aborted worker rejection handling and malformed Claude history rows.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open under the maintainer’s review-only request. Current main lacks the two focused fixes, exact-head CI passed, and the inspected authority and delivery paths show no concrete introduced defect.

Priority: P2
Reviewed head: 9abc9a4e1cdccc1b38f478332c20b76b456ee83c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused regressions and successful exact-head CI support the cleanup, while its breadth keeps confidence at a normal reviewable level.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer PR is exempt from contributor real-behavior proof. The body records older-candidate Testbox build and checks plus successful exact-head CI; those checks are supplemental and do not claim to demonstrate every Gateway runtime path. The inspected diff changes no stored-data contract, so migration compatibility proof is not applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer PR is exempt from contributor real-behavior proof. The body records older-candidate Testbox build and checks plus successful exact-head CI; those checks are supplemental and do not claim to demonstrate every Gateway runtime path. The inspected diff changes no stored-data contract, so migration compatibility proof is not applicable.
Evidence reviewed 9 items Introduced branch scope: The pinned merge-base-to-head diff changes Gateway code and a shrink-only assertion baseline; it does not change protocol schemas, config definitions, dependencies, or documentation.
Worker cancellation fix: The pre-aborted path now observes the already-running operation through Promise.race, preserving the abort result while handling a later source rejection.
Claude history fix: The decoder rejects non-object JSON roots before fallback-history and activity readers use them; the added cases cover null and other malformed roots.
Findings None None.
Security None None.

How this fits together

The Gateway receives client requests and agent events, checks authority, and routes work to session, chat, plugin, and worker owners. Those owners return responses and events or interact with storage and external services.

flowchart LR
A[Clients and agents] --> B[Gateway requests]
B --> C[Auth and authority checks]
C --> D[Session, chat, and worker handlers]
D --> E[Storage and external services]
E --> F[Responses and events]
Loading

Before merge

  • Resolve review confidence - ClawSweeper must reach high confidence before merge readiness is known.
  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Assertion ratchet 30 assertions removed across 14 files The baseline shrinks with the refactor rather than adding a suppression.

Stored data model

Persistent data-model change detected: unknown-truncated-pull-files. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Preserve the existing Gateway wire, authority, and storage contracts while retaining the two focused regression fixes; leave landing to ordinary maintainer review.

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

Yes at source level for the two incidental defects: current main leaves a pre-aborted operation unobserved and accepts a JSONL null root as a row. This read-only review did not execute either path.

Is this the best way to solve the issue?

Yes for the inspected paths: the branch reuses existing Gateway owners and preserves the checked authority boundaries. The breadth still warrants ordinary maintainer review.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a broad Gateway cleanup with two contained defect fixes and no demonstrated urgent user outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 PR is exempt from contributor real-behavior proof. The body records older-candidate Testbox build and checks plus successful exact-head CI; those checks are supplemental and do not claim to demonstrate every Gateway runtime path. The inspected diff changes no stored-data contract, so migration compatibility proof is not applicable.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (6 earlier review cycles)
  • reviewed 2026-09-25T17:35:57.884Z sha 0cd948b8bdb18d1eed4815d6ac867b97289f731b :: blocked before merge. :: none
  • reviewed 2026-09-25T17:50:39.856Z sha 4d7e36e781c222960078e810ae08dbfc8d3cd101 :: blocked before merge. :: none
  • reviewed 2026-09-25T18:19:51.242Z sha a0f2eb2 :: blocked before merge. :: none
  • reviewed 2026-09-25T18:56:39.070Z sha 610240d9e59c5836789d7bd637b334e6a8a2a991 :: blocked before merge. :: none
  • reviewed 2026-09-25T19:16:05.711Z sha c350cdeb55a9272c48d9677f6e0517b75931a1f8 :: blocked before merge. :: none
  • reviewed 2026-09-25T19:36:48.725Z sha 9abc9a4 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 25, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Sep 25, 2026
Consolidate Gateway request, projection, auth, transport, and lifecycle
plumbing through existing owners while preserving wire and authority contracts.

Observe source-promise rejection for pre-aborted worker operations and skip
malformed Claude JSONL roots without losing surrounding valid history.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final evidence is now recorded in the PR body for head 9abc9a4e1cdccc1b38f478332c20b76b456ee83c. All required GitHub checks are green; CI finished with 149 successful jobs. The complete Testbox changed-code/build/protocol/SDK batch passed, and exact-head CI covers all ten identified rebase-contract files (478 cases).

Compatibility assessment from the complete Git diff: changed paths are confined to src/gateway/** and the shrink-only assertion ratchet. No protocol schemas/version, SQLite schema/DDL, config defaults, retention, or update input formats changed. Native schema verification and zero-drift protocol generation passed. Existing durable-secret inference and auth modes are covered by the auth/Doctor tests; no migration is needed. The earlier unknown-truncated-pull-files marker reflects an incomplete API file listing, not a stored-data change. Please assess the complete checkout diff and updated evidence.

This request is review-only. Keep the PR open and unmerged.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 25, 2026
@steipete
steipete merged commit 3272581 into main Sep 25, 2026
226 checks passed
@steipete
steipete deleted the deslop/l50-gateway3 branch September 25, 2026 21:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
* refactor(gateway): deslop gateway

Consolidate Gateway request, projection, auth, transport, and lifecycle
plumbing through existing owners while preserving wire and authority contracts.

Observe source-promise rejection for pre-aborted worker operations and skip
malformed Claude JSONL roots without losing surrounding valid history.

* refactor(gateway): keep history projection cap private

* refactor(gateway): own wake attempt types in state store

* refactor(gateway): retain named trusted proxy origin guard

* refactor(gateway): satisfy lint contracts in deslop paths
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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed 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