Skip to content

refactor: simplify private state and process transports - #169379

Merged
steipete merged 1 commit into
mainfrom
deslop/w09-state-infra-process-20261011
Oct 11, 2026
Merged

steipete merged 1 commit into
mainfrom
deslop/w09-state-infra-process-20261011

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Removes duplicate private-worker schemas and unused recovery machinery from the state, snapshot, and process infrastructure.

User Impact

Normal storage and terminal behavior is unchanged. No config, CLI, Gateway protocol, plugin SDK, persisted schema, retention, or permission changes. Queue accounting now conservatively measures nested command data, so unusually large requests can meet the existing byte limit earlier.

Why This Change Was Made

Private state/snapshot/PTY channels already have typed, version-matched senders. Their second hand-written schema mirrors grow with every command and duplicate the real input/authorization boundaries. The state reader's byte estimator had another command-by-command copy of the same contract; it now measures captured values structurally.

The native-resource broker now joins concurrent close requests through one promise and rejects reuse of an attachment ID that no current client reconnects. Snapshot allocation errors still reach their callers, known directories still get cleaned, and native children still settle; a missing allocation receipt no longer permanently poisons shutdown. The private allocation-error class used only by that removed poison path is gone; wire messages and contention markers stay unchanged.

Best-effort tradeoffs accepted

  • Malformed private state-read requests now fail at their consumer rather than a second schema. The sole sender is the typed state-read pool. #153508 introduced the mirror with worker delegation, not a human report of malformed private frames. External validation, current authority, and database admission remain.
  • Malformed private snapshot commands/replies now fail at their consumer. #160946 and #164046 describe synthetic lifecycle tests, not an actual malformed-frame incident. Native child/file input validation, host reader fences, and cleanup remain.
  • A broken version-matched PTY peer no longer gets a bespoke invalid-message decoder error. #140876 and #145749 address terminal startup/output, not malformed private IPC. Launch authorization and parent-loss cleanup remain.
  • Reattaching an existing native-resource ID closes the new socket. #160946 added replay support, but the actual client retries only before connect and never reconnects a lost attachment. A new resource lifetime is the recovery path.
  • Extra concurrent close requests join the same close instead of receiving an artificial per-origin observer-capacity error. #168587 supplied synthetic lifecycle coverage; actual parent/worker callers already coalesce requests. Each request still receives its own receipt and native close happens once.
  • If a child creates a temporary snapshot directory but fails before reporting its path, that unreported directory may leak until temporary-file cleanup. #161372 and fix: retain shared-state snapshots through worker failures #160946 exercised injected post-creation failures; linked #144592 is an architecture task, not a user incident. The allocation still fails visibly; shutdown joins the child and cleans all known directories instead of retaining a permanent poison record.

Evidence

Net production reduction: 1,310 lines (+141 / -1,451), excluding tests, fixtures, test support, generated files, and declarations. Tests reduce by 136 lines; no new skips, retries, timeouts, or lint suppressions. The only ancillary production path outside state/infra/process removes the private plugin-blob predicate orphaned by deleting the reader mirror; its public command/reply types are unchanged.

  • Pre-change state baseline: 40 tests passed in two files.
  • Integrated focused proof: 178 passed, five existing Windows-only skips, 19 files, five configurations. Wrapper wall time 1,022.02 seconds, including compiled prerequisites and real native processes. No Windows runtime claim from this Mac.
  • Final standalone changed tests with node scripts/run-vitest.mjs <file> --maxWorkers=1: state reader 34 passed, 657.49s wall (435.971s shared cold-worker compilation); native snapshot resource 10 passed, 464.51s wall (279.394s cold compilation). These are existing native-boundary suites, not new per-test boots; actual test execution is a small fraction of the loaded-host wall time. The retained real-allocation test proves native close precedes resource close. Hosted CI seconds will be recorded when available.
  • Plugin-blob owner coverage: 17 passed, three files, 329.49s wrapper wall.
  • Final worker-protocol proof after deleting the private allocation-error class: 15 passed, 320.06s wall. Final production types and the affected infra test graph pass.
  • Core production and all 28 test-type graphs passed. Runtime import cycles: 0. Madge cycles: 0.
  • Lint-suppression gate: three tests passed.
  • Changed-check coverage is composed: all selected type graphs and pre-export guards passed; targeted lint on every remaining changed TypeScript file passed. The normal broad run reached export scanning, then its two large Knip scans timed out at the unchanged 600-second limit. Serial production/full-tree attempts also hit that bound after the first serial scan identified the now-removed orphan class. The script export scan passed with zero entries. Whole-core lint was stopped after 13 minutes without a verdict, then replaced by supported targeted lint. The repository-wide legacy-store scan was stopped after ten minutes without a verdict; its canonical analyzer passes on all 11 changed production files. These are recorded local coverage limits, not green full-scan claims; exact-head hosted CI remains the landing gate.
  • Independent final P2 review: scoped-clean, no actionable findings.

All runtime/test/build commands used task-owned HOME, OpenClaw paths, and XDG directories. No real operator state, live Gateway, or deployment was used.

The coverage ledger also records retained candidates: migration witnesses and schema/integrity validation, real parallel-reader lifetimes, write-capable shutdown settlement, kernel process-tree cleanup, execution authorization, and bounded-resource protections. These are not removed merely to increase the deletion total.

Remove duplicate schemas from typed private worker channels and replace per-command byte accounting with one structural path. Coalesce native resource close and remove unused reattachment and unknown-allocation poison state while retaining execution authority, bounded queues, known-directory cleanup, and native child settlement.
@clawsweeper

clawsweeper Bot commented Oct 11, 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.

@steipete
steipete marked this pull request as ready for review October 11, 2026 21:35
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR removes duplicate private-message validators, simplifies request byte accounting, and consolidates native-resource closure.

Example: Shutdown after a snapshot allocation reports ENOENT without reporting its directory.

  • Before: Uncertain allocation custody can permanently reject cleanup.
  • After: Cleanup joins native child closure and removes known directories; an unreported temporary directory may remain.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is coherent and has no actionable finding; reported native-boundary tests support confidence without establishing shipped-entry-point proof.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal refactor is outside the contributor proof gate; reported native-boundary runs support it, while the inspected UI images do not demonstrate these transport changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes
User problem: Private infrastructure duplicates transport schemas and retains recovery machinery unused by its actual clients.
Reason: The maintainer owns this direction, explicitly records the behavioral tradeoffs, and substantially reduces code within the existing ownership boundaries.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-owned refactor removes duplicate private transport machinery with explicit, source-supported tradeoffs; no actionable introduced defect was found.

Priority: P3
Reviewed head: 1e6838f195e4cdcaaae7e6b5fe8f6da557360681

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied current-head shipped CLI or Gateway demonstration exercises concurrent resource closure or shutdown after an unreported allocation.
Agent review details

How this fits together

Gateway storage readers and terminal hosts send captured commands over private worker transports; workers return database results, terminal events, and resource-cleanup receipts.

flowchart LR
A[Gateway callers] --> B[Typed worker transports]
B --> C[Shared state reader]
B --> D[Snapshot staging]
D --> E[Native resource broker]
E --> F[SQLite child and temporary files]
A --> G[Node PTY helper]
Loading

Technical review

Best possible solution:

Retain one typed private transport per owner while preserving external validation, live launch authority, bounded admission, and confirmed native cleanup.

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

This is a refactor rather than a reported bug; source inspection confirms the changed lifecycle paths, but this review executed no target code.

Is this the best way to solve the issue?

The simplification fits the existing owners, and the documented tradeoffs match the actual private senders and retained cleanup checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 670ad6a9b0fc.

Provenance checked

  • Private shared-state request validation and accounting changes intended behavior with a stated reason (c69b8b9: The team-admin delegation change carried a detailed worker request mirror; earlier fleet worker history also contains isReadRequest. This PR explains why typed private senders no longer need that mirror or command-specific byte estimates.)
  • Snapshot allocation uncertainty and private native framing changes intended behavior with a stated reason (9c93bc3: Retained snapshot reads preserved native custody through failures; the later contention repair distinguished definite refusal from unknown allocation. This PR explicitly accepts unreported-directory leakage while retaining known-directory fences and native settlement.)
  • Broker attachment replay and close observers changes intended behavior with a stated reason (9c93bc3: The retained-resource broker supported replay and per-origin close observations. Current clients never reconnect after attachment, and the replacement promise preserves the native-close owner added by fix: finish shutdown without disabling V8 compilers #168587.)
  • Private PTY message decoders changes intended behavior with a stated reason (b420450: The Node helper restored Bun terminal startup and output; subsequent supervisor integration retained launch authority. This PR removes only the duplicate private decoder and explains the malformed-peer tradeoff.)
  • Plugin blob private command predicate keeps the original intent (76b636d: The predicate supported shared-worker blob reads and is orphaned by removal of the reader mirror; public command and reply types remain unchanged.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9c93bc3 adds src/process/spawn-broker/resource-server.ts:119 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9c93bc347cec; files: src/process/spawn-broker/resource-server.ts)
  • RoboClaw: Raw commit 98813c2 adds src/process/spawn-broker/resource-server.ts:129 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 98813c23905e; files: src/process/spawn-broker/resource-server.ts)

PR surface

Source -1310, Tests -136. Total -1446 across 15 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 12 140 1450 -1310
Tests 3 50 186 -136
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 190 1636 -1446

Review metrics

Metric Value Why it matters
Production versus test LOC Production +140/-1,450; tests +50/-186 The verified reduction removes duplicate validators and recovery state without adding another production owner.

Labels

Label changes:

  • add P3: This is an internal simplification with accepted edge-case tradeoffs and no demonstrated urgent user-facing regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This is an internal simplification with accepted edge-case tradeoffs and no demonstrated urgent user-facing regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 11, 2026, 5:42 PM ET / 21:42 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Exact-head CI disposition

Reviewed head: 1e6838f195e4cdcaaae7e6b5fe8f6da557360681 (source tree c5cc2ca4f90dd5b33b2e760e30b7f0484f46c61d). Net production reduction: 1,310 LOC. No source changes after the signed, independently reviewed commit.

CI 38176980643 is failed/cancelled, not green. The exhaustive 206-check census has 70 successes, 122 skips, one neutral, three failures, and ten cancellations. Security-fast and all seven applicable Security High categories passed; dependency and security-sensitive reviews passed. No substantive PR review findings are present.

Every failed job and observed failing case

  • 114581618203 — UI 1/7: chat-scroll.e2e.test.ts:395, “overlays the scroll-to-bottom affordance without shrinking the transcript” (initial button visible, expected false), plus chat-history-prepend-anchor.e2e.test.ts:116, both shared=false/true manual=true prepend cases (“Show earlier” never enabled). Independent main run 38172718771, head 24af217792a07f3f15373f3add4bb20ac0bc94b9, reproduces the same cases in jobs 114568737693 and 114568737610.
  • 114581618121 — UI 4/7: chat-follow-maintenance.e2e.test.ts:155, “keeps following across concurrent row contraction, streaming growth and session navigation” (330 versus ≤2). The same main run reproduces that exact assertion in 114568737709.
  • 114582583661 — openclaw/ci-gate: aggregate failure from the UI jobs, not a separate product failure.

The cancelled 114581618143 — UI 2/7 had already reported the two dark/light chat-position-rail.e2e.test.ts:442 failures (1 versus 0) and the retained-draft board-mcp-app.e2e.test.ts:579 failure (empty versus “Keep this unsaved dashboard note”). Main reproduces the rail cases in 114568737704. The board case independently reproduces in scheduled main run 38180826485, job 114592980204, head 3be41182be9b09709f3e6c038c46aeb7d633841d, with the same assertion. A clean-main Testbox control at dcd6491869d5ef7a08b85d9600f63a1c32faa440 also reproduced the board case (136 passed / one failed). These browser-only mocked-Gateway paths and their UI sources are outside this PR's changes. Passing candidate replay is additional coverage, not a claim to have repaired those inherited failures.

Every cancelled job and replacement proof

Remote provider: blacksmith-testbox, lease tbx_01m4pgxdtrtqddsgm9x2je2wfy, run 38180113014. The wrapper binds source head and verifies the materialized carrier's exact source tree. All runtime commands use isolated HOME, OpenClaw state/config, and XDG directories.

  • 114581618143 — UI 2/7: exact original include inventory, actual shard 2/6, three workers: 29 files / 137 tests passed. Command: OPENCLAW_UI_E2E_SKIP_REAL_GATEWAY=1 OPENCLAW_VITEST_INCLUDE_FILE=<original inventory> OPENCLAW_VITEST_MAX_WORKERS=3 node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner --maxWorkers 3 --shard 2/6.
  • 114581618184 — UI 7/7: canonical pnpm test:e2e:browser-extension: passed, including Chromium bootstrap, pairing, paused-tab revocation, existing-session and launcher proof.
  • 114581618498 — Node small 1-1: exact original tooling group via scripts/ci-run-node-test-shard.mts, unchanged bun-compatible policy, concurrency one: 280 passed / one existing skip.
  • 114581618449 — Node large 24: the original CI positively completed its two-file/32-test group. Six other groups replayed successfully (147 tests). One two-file Bun group could not start because the Testbox image lacked Bun (spawn bun ENOENT); its exact-runtime follow-up is recorded below. No runtime-policy change, skipped tests, or passing claim for that failed launch.
  • 114582205333 — extension lint 3: node --import ./scripts/tsx.mjs scripts/run-oxlint-shards.mts --only=extensions --extension-stripe=3/3 --extension-roots-json '["extensions/codex","extensions/slack","extensions/telegram"]' --threads=1: passed. This original stripe resolves to Slack only.
  • 114581872876 — production types: core passed both original CI and local proof; missing ui and extensions graphs independently passed locally (43.8s / 59.2s).
  • 114581872845 / 114581872828 / 114581872938 / 114581872866 — core test-type stripes 2/3/4/5: all 28 original core-test graphs passed locally; all four missing root partitions independently passed (tooling 39.0s, scripts 55.3s, e2e 42.0s, other 35.5s).

The initial combined remote command exits 1 because the clean-main control intentionally exposed its inherited failure and Bun was absent. Its candidate UI, six Node groups, small tooling, browser-extension and Slack-lint phases passed individually. This is not represented as an all-green remote run.

The PR body retains the full focused proof, clean independent review, zero runtime/Madge cycles, and local broad-scan limitations: large Knip scans reached the unchanged 600s limit; full lint/legacy-store scans produced no verdict; supported changed-file lint and canonical changed-file analysis passed. No CI rerun, empty push, timeout increase, retry, skip, or suppression was added to manufacture green.

Pinned Bun prerequisite follow-up

Staged the exact checksum-pinned runtime with /bin/bash scripts/stage-openclaw-bun.sh <temporary directory> linux x64, then replayed only original agentic-gateway-methods-hosted-4 through the same shard owner and runtime policy: two files / nine tests passed, 34.79s test-wrapper wall time. Source tree was reverified before execution. No production dependency or pin changes. This completes the missing large-24 inventory: 32 tests in the original CI receipt, 147 in the six replayed groups, and nine in the pinned-Bun group.

The documented campaign inherited-failure exception is selected for the exact reviewed head. No failed or cancelled result is reclassified as green; no rerun or source push was used to change the check status.

@steipete
steipete merged commit 5889e62 into main Oct 11, 2026
195 of 209 checks passed
@steipete
steipete deleted the deslop/w09-state-infra-process-20261011 branch October 11, 2026 23:23
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
)

Remove duplicate schemas from typed private worker channels and replace per-command byte accounting with one structural path. Coalesce native resource close and remove unused reattachment and unknown-allocation poison state while retaining execution authority, bounded queues, known-directory cleanup, and native child settlement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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