Repository navigation
refactor: simplify state and process worker lifecycles - #169648
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThis PR consolidates private state publication, worker transport, wake scheduling, event dispatch, and child-process lifecycle code under existing owners. Example: A heartbeat callback for agent main is running when its handler is replaced.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it contains useful maintainer-directed consolidation with explicitly accepted lifecycle tradeoffs. No definite introduced defect was established, and the earlier merge conflict is resolved. Priority: P3 Before merge
FindingsNone. Agent review detailsHow this fits togetherGateway runtime owners submit database operations, queued wakes, and process requests; these subsystems return installed state facts, wake results, command output, and cleanup outcomes. flowchart TD
A[Gateway runtime] --> B[State workers]
A --> C[Wake queue]
A --> D[Process supervisor]
B --> E[Shared publication owner]
C --> F[Admitted callbacks]
D --> G[Spawn broker and native children]
Technical reviewBest possible solution: Retain the consolidation and accepted tradeoffs while satisfying the existing landing gates. Do we have a high-confidence way to reproduce the issue? This is a refactor; inspection established its changed lifecycle contracts, without running target code or claiming a reproduced product defect. Is this the best way to solve the issue? Reusing the existing publication, framing, output, and type owners is a reasonable simplification, and the maintainer explicitly records the behavior changes it accepts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4375c939e05c. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1029, Tests -277. Total -1306 across 59 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 12, 2026, 5:48 AM ET / 09:48 UTC (Revision 5). |
37b279c to
b752933
Compare
|
fb9b578 to
e66f82f
Compare
e66f82f to
555ccfc
Compare
Exact-head CI attribution and inherited-red landingReviewed/pushed head: Every failed check is individually attributed:
The independent scheduled-main run tested
No failing test or directly implicated subject is changed by this PR. Source inspection separately identifies existing admission validation and notification/coalescing behavior; retained security and preview tests are not removed or relaxed. The out-of-scope admission owner issue has been reported to the coordinator. Additional local clean-main replay was attempted in the original 4/6-file selections. Its first setup lacked newer main's PR-owned proof remains: 139 affected tests passed after the conflict-only rebase; core production/state test types, targeted lint, formatting, runtime cycles 0 and Madge cycles 0. Independent review is scoped-clean through P2. The known local renderer suppression inventory failure also reproduces on clean main and is untouched. No CI rerun or green-chasing push was used. Net production reduction: 1,029 LOC (+464 / -1,493). No config, protocol, SDK, schema, durability, retention, permission or dependency change. Phase E standalone session memory and its factory/registry/expiry/federation/tests are untouched. Landing under the coordinator-authorized inherited-main-red exception, pinned to the exact reviewed head above. This does not describe the failed CI as green. |
* refactor: consolidate state and process worker infrastructure * fix: preserve goal error decoding after main integration * fix(infra): preserve unstarted wakes and align lifecycle coverage
First-parent upstream e099f44..285369b (88 commits). Stops before openclaw#169648 (fp#649) and openclaw#169414 (fp#650), which each add conflicts and are steps 64 and 65. Conflicts: - session-entry-patch-source.ts: upstream removed the native-source commit guard arm (every main-thread patch now goes through the worker); kept our afterPersistInTransaction arm on the native writer (its closure cannot cross into the worker). - subagent-spawn-request.ts: import union (our recipient-authority binding, upstream's SessionEntry type). - openclaw-agent-participants-migration.test.ts: upstream removed the "missing aggregate count" case and the "absent" scenario; removed the case from our copy, kept our fresh-install schema-27 shape case. - status-text.ts: upstream's async fallback-model read beside our continuation status line import. - SDK budgets, config baseline and worker inventory regenerated. Auto-merged files carrying continuation overlay (40) keep it byte-for-byte. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…absorb: step 64 openclaw#169648 "simplify state and process worker lifecycles", isolated as its own step. The session-event wake queue drops handler generations: replacing the handler no longer aborts admitted work (it owns its settlement); a stopped runner hands an unstarted wake to its successor as "preempted" instead of "disabled". Conflicts: - session-event-wake.ts: took upstream's handler-snapshot dispatch and kept our trusted-continuation routing mark on the request before it; ActiveWake's `generation` removal ported into our split session-event-wake.types.ts. - heartbeat-runner-scheduler.ts: upstream's preempted/disabled split, with our runHeartbeatOnceCore default (the fork's continuation-aware wrapper supplies runOnce). Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Reduces duplicated private worker infrastructure and speculative lifecycle machinery in state, infra, and process execution.
User Impact
Normal storage, command execution, and streaming behavior stays intact. No config, CLI, Gateway protocol, plugin SDK, schema, durability, retention, or permission change is intended. Already-running wake callbacks finish under their captured handler; unstarted work selects the current handler.
Why This Change Was Made
GitHub authority receipts now share the existing state-domain publication owner rather than maintaining parallel transaction capture, rollback, supersession, and settlement code. GitHub-specific row/key restrictions, presentation-field scrubbing, byte limits, and live publication authority remain at the adapter. The state worker's operation types derive from its actual lazy-loader table instead of a second manually maintained inventory. Execa's own result types replace a parallel conditional-type implementation.
Private error/admission/bootstrap schema mirrors, impossible return-path reordering, historical receipt replay, and handler-replacement generations are removed. Process control framing and stdout use existing owners. Native child cleanup, current execution authority, original input FIFO/reordering, output limits, and write-capable work settlement remain.
Net production reduction after conflict-only rebase and CI correction: 1,029 LOC (+464 / -1,493), excluding tests, fixtures, test support, generated files, and declarations. This is PR 2 of the w09 campaign; the first cleanup is already on main. Ancillary edits outside the three lane directories remove three private declarations orphaned by this cutover and narrow one directly coupled error-payload type annotation. The coordinator explicitly authorized these deletion-only follow-through edits; tests outside the lane prove retained consumers.
Best-effort tradeoffs accepted
cfba0ab68f7case uses a synthetic delayed field assignment; #106495 carried the helper forward. Normal emitted exit codes stay exact; ambiguous shims retain their existing fallback result.CommandSpawnOptionstype and already normalizes invocation/environment and forcesshell:false. Native descriptors, streams, inherited output, and unsupported shells retain their explicit handling; invalid internal options fail in the operation/serializer.The relay's nonce-matched retirement response is replaced by natural exit after the same anchor reaping and parent-lineage release. This is consolidation, not permission to lose cleanup: force delivery failures remain recorded until actual extinction or the hard deadline, and a late exit cannot turn failed cleanup into success.
Evidence
All tests/builds use task-owned HOME, OpenClaw state/config, and XDG directories. No live Gateway or real operator state is used. Local proof uses
node scripts/run-vitest.mjs ... --maxWorkers=1through that isolated environment.81a4679dec8b7fc0fb137df0a5b085a93d4977c7for an unchanged JSON control-character regex; this PR adds no production lint suppression.check-changedstopped on four inherited UI type errors, precisely the errors fixed by #169439 in319ec991d02a343014c40b1e623897502ab41d5b. The UI files are untouched. All preceding changed checks passed (format, safety/line-cap/SQLite/mock/timeout ratchets, plugin boundaries, wrapper guard, configuration baseline). Remaining applicable lint/structural checks were run separately; exact-head hosted CI remains the landing gate.The real-process lifecycle tests exceed the five-second target because they prove native process-group extinction, inherited pipe closure, and failed signal delivery. They retain existing deadlines, transport parameterization, and assertions; no cheaper mocked layer proves these OS contracts. Exact-head hosted CI remains the cross-platform gate.
The retained tests caught and drove fixes for suspended-handler selection, bounded control-frame search, decoder disposal, and forced-retirement error recording. After the second conflict rebase, the MCP fault fixture is unchanged from main's corrected disconnect-boundary fixture; its six real-process fault cases pass against this cleanup. No timeout, retry, skip, or lint suppression was added to make proof pass.
Review also retained the existing synchronous task-port liveness check: a retire-on-error worker can close its task channel while another native handle keeps it alive, so synchronous task servicing must reject without waiting for a JavaScript close callback. Both native task-port files are unchanged. The shared publication lifecycle retains invalidation when the GitHub-specific publisher throws, now covered by the synchronous regression. Final independent review after both repairs is scoped-clean through P2.
Conflict-only rebase onto
acba98bf6231aee87f8ee86444fb74672dd9bcd8: preserved main's new physical database identity fields and simpler local error hydration. The affected error/admission/wake/Goal/session-storage and lint-suppression suites passed across four configurations (749.67s wrapper wall on the loaded local host). Production types plus state/infra test types, targeted lint, runtime cycles, and Madge cycles passed. A missing Goal enum export detected during integration was repaired before pushing. The final restoration also received a clean independent review. No CI rerun or green-chasing push was used.First exact-head CI and correction
Run
38212881368testedb7529339d0ceac83359f55aff13c4de63bca35a1and completed with five failing test jobs plus the downstream CI gate. All five are attributable to this PR; none is claimed inherited. All 224 exact-head check runs were enumerated, with no cancelled or unfinished checks.114691167692(checks-node-changed-compact-large-8-1): stale replacement/replay expectations plus a real stopped-before-execution wake being consumed as disabled. The scheduler now returns the existing retryable preempted result after stop/abort during lazy loading; global disable remains disabled.114691167708(checks-node-changed-compact-small-15): the bridge test expected callback mutation of runId to reroute the current event. Removed only that synthetic case under the documented fixed-cohort policy.114691167825(checks-node-changed-compact-large-8-2): the cleanup fault fixture mocked the retired timers/promises route. It now injects the same rejection at the actual sleep owner; error identity, cleanup settlement and no-unhandled-rejection assertions remain.114691168021(checks-node-changed-compact-large-21): the heartbeat replacement fixture awaited replay before releasing the original lazy load, creating a circular wait under finish-once semantics. It now releases the original callback and proves fresh work uses the replacement. The health cases passed in the original job.114691168042(checks-node-changed-compact-small-20-1): obsolete abort/replay expectations left synthetic callbacks unfinished and contaminated later fake-clock cases. Updated those expectations and guaranteed fixture release while retaining the four-slot bound, same-target ordering, explicit abort and actual settlement.114693708607(openclaw/ci-gate) failed downstream of those five jobs.The corrected selection passed all five Vitest configurations, including the complete three-file Gateway selection, heartbeat and event siblings, process cleanup, bridge, and lint-suppressions (519.52s wrapper wall). Core production, infra-test and Gateway-test types, targeted lint, runtime cycles (0) and Madge cycles (0) passed. A fresh independent review of the eight-file correction is scoped-clean through P2. No timeout, retry, skip, suppression, dependency or schema change was added. Hosted CI on the new exact head remains the landing gate; the failed run was not rerun.
The restarted local changed-check attempts passed conflict markers, line-cap, suppression/env-count and assertion ratchets, then were intentionally stopped during the repository-wide SQLite worker scan. Selecting the correction base still traverses the whole repository. These incomplete attempts are not claimed passing; the original changed-check evidence above, the first run's successful policy checks, and the correction's focused proof are retained. The final formatter pass changed whitespace only in two tests.
Second conflict-only rebase
GitHub reported the pushed correction head
fb9b578b2400532e56159041df82c6194b92e5c9CONFLICTING. Rebased onto2b4c2a10bb4, producinge66f82f97fbf51d24a50312b3591983bc62f262f. The one manual conflict keeps main's complete MCP fixture, including6f990462290's retained-POSIX selection and actual disconnect-boundary fault injection. Main's newer validation-cache logic also remains intact. Range-diff shows no production patch change; net production remains -1,027 LOC. The correction commit replayed unchanged; its P2 review and formatter-only follow-through remain recorded above.Rebase-focused runtime proof passed 94 tests across three configurations (591.19s wrapper wall): 53 validation-cache cases (239.92s suite), 35 relay/cleanup cases (26.89s), and all six real-process MCP fault cases (79.90s). Core production types, agent-root and state test graphs, targeted lint, formatting and diff checks passed. Runtime and Madge cycles are both zero. Main added a pinned renderer dependency; syncing the unchanged frozen lockfile resolved the local missing-dependency prerequisite without changing manifests or lockfiles.
The mandatory lint-suppression test fails identically on this branch and a clean checkout of main
fdbe95f5d1d68c160d8d281560b7ea43894bf00d: unexpectedsrc/gateway/control-ui-public-session-card-render.ts|no-control-regex|1, introduced by #169527. Renderer and allowlist test blobs are identical in both trees and neither is changed by this PR. The clean-main run completed 2 passing/1 failing cases (38.25s suite); its earlier missing UI-workspace dependency link was repaired before that reproduction. No allowlist expansion or suppression was added. Hosted CI on the final exact head remains required; any inherited-failure exception will enumerate and attribute every failed job after completion.Third conflict-only rebase
GitHub reported
e66f82f97fbf51d24a50312b3591983bc62f262fCONFLICTING. Rebased onto96681719c825ed836326ce7c2726162be3254733, producing555ccfc1b5e3244773bec2c893111fc3cc51e1bb. Main's encoding change added two fields to the removed duplicate schema decoder. The reviewed typed-receipt path carries the complete schema facts directly, includingtextEncoding; the owner, admission and payload implementation from main remain intact. The resolved module is byte-identical to the prior reviewed module; range-diff changes only those two additional deleted mirror lines, with the correction commits replayed unchanged. Net production reduction is now 1,029 LOC.Affected proof: 139 tests passed across validation-cache, worker-admission, schema-facts and transcript-payload files (129 infra cases / 663.97s suite; 10 payload cases / 14.69s suite). The worker-admission case explicitly verifies transferred UTF-8 encoding. Worker precompilation took 404.175s under heavy shared-host load. Core production types, state test types, targeted lint, formatting and diff checks passed; runtime and Madge cycles are both zero. Mandatory lint-suppressions again reports only the same untouched renderer entry (2 passing/1 failing, 122.60s suite). Main's newer renderer/Knip export-accounting fix does not repair that suppression inventory; no baseline was expanded here. No CI rerun or push solely for green was requested.
Final exact-head CI: inherited-main-red exception
CI 38230162973 completed on
555ccfc1b5e3244773bec2c893111fc3cc51e1bb. All 142 check runs were enumerated: 94 success, 44 skipped, 1 neutral, 3 failure, no cancelled/incomplete checks.security-fastand all seven Security High checks passed. Every failing job is attributed individually:114749919813, changed compact-large-9: two canonical user-admission cases inworker-turn-detached-context.test.ts, exactly matching protected-main job 114736777003.114749919784, changed compact-large-11: committed transcript preview undefined versusFresh committed previewinsessions-read-cache.test.ts, exactly matching protected-main job 114736776831.114754786412, CI gate: downstream aggregate of those two Node test roots, not another product failure.That independent main run tested
292a9887dbbf0cd1e1439b07a1c6a608abadc690before this head was pushed. The nine traced test/direct-subject files are byte-identical on that main, current-main snapshot2500d81145d9754c9e3a0957d7c9c925f1811a4d, and this PR. The CI classifier's unknown result was only a compact-job-name mismatch. No failing test or directly implicated authority, transcript-notification, preview/backfill or launcher owner is changed here. The admission owner issue was reported to the coordinator; retained security and feature tests were not removed or relaxed.An additional full-selection local main reproduction first encountered a missing newer-main dependency, repaired by a private frozen install, then an unrelated cold-start timeout in
github-publication-boundaries.test.ts. After the independent main CI matches and unchanged source were established, the redundant replay was stopped and its owned processes joined. It is incomplete, not passing proof. No timeout, retry, skip or suppression was changed. Landing uses the coordinator-authorized inherited-red exception pinned to the exact head, not a claim of green CI. Phase E standalone session memory and its factory/registry/expiry/federation/tests remain untouched.