Repository navigation
refactor(gateway): simplify session and reload bookkeeping - #168980
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 simplifies bookkeeping for Gateway session projections, config reloads, channel teardown, Talk cleanup, and desktop processes. Example: While a WhatsApp reload drains active work, another config.patch changes selfChatMode from true to false.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep this PR open: the maintainer-approved simplification is useful, but the previously reported reload-drain dependency cycle still blocks merge. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherGateway owners consume configuration writes and session events, apply runtime changes, present authorized session views, and settle channel and process lifetimes. flowchart TD
A[Config writes and session events] --> B[Gateway owners]
B --> C[Serialized config application]
B --> D[Resident session projection]
C --> E[Active work drain]
E --> F[Channel and process lifetimes]
D --> G[Authorized client replies]
Technical reviewBest possible solution: Retain the simplification while allowing queued config requests to end their predecessor's drain without abandoning committed runtime work. Do we have a high-confidence way to reproduce the issue? Source establishes the successor-request cycle through application-receipt waits, root accounting, and serialized reload execution; no target code was executed. Is this the best way to solve the issue? The accepted bookkeeping reductions fit repository policy, but serialization still needs a drain escape for requests awaiting that same queue. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 38f456226f62. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -746, Tests -1788. Total -2534 across 58 files. Added test files: 0. View PR surface stats
Review metrics
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 11, 2026, 10:07 AM ET / 14:07 UTC (Revision 5). |
f74889f to
5335389
Compare
4d7caf4 to
923cc70
Compare
Remove repeated filesystem probes from generation observations while retaining captured database identity, row lifecycle checks, mutation invalidation, and recipient authorization. Best-effort tradeoffs accepted: an out-of-band database replacement before the projection owner observes it no longer gets an additional per-event filesystem veto. The owner observes it on refresh or restart. The probes originated in e0d8000 (#154069); no production incident requiring the repeated probes was identified. Proof: 23 unchanged topology and incognito tests pass; 49 baseline owner/broadcaster tests pass; independent P2 review is clean. No tests or lint suppressions changed. The lint-suppression inventory test has two unrelated existing entries missing from its allowlist. Full changed-check was stopped in the broad assertion scan; focused validation is recorded in the lane ledger.
Retain measured caches, row and recipient authority, and bounded reads while removing speculative physical witnesses, supersession retries, reentrant refresh guards, and post-consumption validation. Best-effort tradeoffs: optional previews and display attribution may retain older same-session facts until their next publication; catalog acquisition errors are returned instead of replayed. External file replacement is observed by the owning runtime. No schema or protocol change.
Remove registry metadata replay and in-flight watcher-echo reconciliation. Serialized config application leaves newer observations queued and keeps physical source checks, credential validation, caller authority, and shutdown settlement. Best-effort tradeoffs: a read does not expand its routing inventory when another database is registered, and a queued config finishes before the newer observation. Keep failed credential activation rollback coverage while dropping only supersession choreography.
Use one pending channel stop, one Talk cleanup promise, direct diagnostic snapshots, and existing process lifetime state. Keep strict caller settlement, ingress handoff, explicit effect authority, bounded resources and ordinary shutdown joins. Best-effort tradeoffs: rare mid-read status changes refresh next time; internal impossible clocks and synthetic reentrant cleanup no longer have dedicated machinery. The recorded failed-reload recovery remains intact. Includes strict-join regression coverage.
923cc70 to
8c72a3c
Compare
|
Exact-head CI attribution for Run 38145324909 is terminal. It tested GitHub merge
The cancelled This uses the coordinator-authorized inherited-only admin exception, pinned to the exact reviewed head. These failures remain recorded as failures, not relabeled green. No test expectation, timeout, retry, skip, suppression or scanner policy was weakened to release a gate. Final focused proof: 21 actor/incognito/history/row tests pass; production and affected Gateway test types pass; scoped lint/format pass; runtime and Madge cycles are zero. SDK comparison: no named public export or signature changes. Net production reduction is 746 lines against the rebase base; the PR body contains all best-effort tradeoffs and the 15-row KEEP re-evaluation. |
…168980) * refactor(gateway): trust owned database identity for queued events Remove repeated filesystem probes from generation observations while retaining captured database identity, row lifecycle checks, mutation invalidation, and recipient authorization. Best-effort tradeoffs accepted: an out-of-band database replacement before the projection owner observes it no longer gets an additional per-event filesystem veto. The owner observes it on refresh or restart. The probes originated in 81c57e5 (openclaw#154069); no production incident requiring the repeated probes was identified. Proof: 23 unchanged topology and incognito tests pass; 49 baseline owner/broadcaster tests pass; independent P2 review is clean. No tests or lint suppressions changed. The lint-suppression inventory test has two unrelated existing entries missing from its allowlist. Full changed-check was stopped in the broad assertion scan; focused validation is recorded in the lane ledger. * refactor(gateway): simplify projection and catalog snapshot ownership Retain measured caches, row and recipient authority, and bounded reads while removing speculative physical witnesses, supersession retries, reentrant refresh guards, and post-consumption validation. Best-effort tradeoffs: optional previews and display attribution may retain older same-session facts until their next publication; catalog acquisition errors are returned instead of replayed. External file replacement is observed by the owning runtime. No schema or protocol change. * refactor(gateway): apply captured config and source snapshots once Remove registry metadata replay and in-flight watcher-echo reconciliation. Serialized config application leaves newer observations queued and keeps physical source checks, credential validation, caller authority, and shutdown settlement. Best-effort tradeoffs: a read does not expand its routing inventory when another database is registered, and a queued config finishes before the newer observation. Keep failed credential activation rollback coverage while dropping only supersession choreography. * refactor(gateway): share teardown and simplify optional lifecycle guards Use one pending channel stop, one Talk cleanup promise, direct diagnostic snapshots, and existing process lifetime state. Keep strict caller settlement, ingress handoff, explicit effect authority, bounded resources and ordinary shutdown joins. Best-effort tradeoffs: rare mid-read status changes refresh next time; internal impossible clocks and synthetic reentrant cleanup no longer have dedicated machinery. The recorded failed-reload recovery remains intact. Includes strict-join regression coverage. * fix(gateway): preserve retry ingress through channel handoff * fix(gateway): preserve cleanup timing and backfill progress * refactor(gateway): remove unused background-work predicate * test(gateway): remove obsolete catalog loader import * refactor(gateway): preserve reload contracts without stale fences * fix(gateway): preserve native publication and fixture lifetimes * refactor(gateway): check desktop authority at command dispatch * refactor(gateway): reconcile live contracts after rebase * test(gateway): align retained coverage with simplified lifetimes
9e90500 backported the #169249 state-lease change (cleanup releases through the worker writer queue, needed by #173225's native-cleanup test) without #169249's reload fixture adaptation. Release now settles after an awaited worker round trip, so fixtures that drove sequential reloads with one vi.advanceTimersByTimeAsync(0) wake hung for 120s. Port the b1cadee fixture changes to the terminal, restart-sequence and operator model-policy tests: drive reloads through a scheduler clock and join each wake. Apply the same join to the release-only watcher handoff test (removed on main by #168980). Assertions are unchanged. Adapted from b1cadee (#169249).
What Problem This Solves
Reduces Gateway complexity spent defending speculative config, catalog and display-read interleavings.
User Impact
Normal session, channel, Talk and desktop features remain. Authorization at private-row presentation and external effects, durable writes, shutdown settlement and resource bounds stay in place. Optional previews and attribution can briefly show older same-session facts; a failed catalog acquisition reports its existing error instead of replaying indefinitely. A queued config observation is applied after the current serialized transaction rather than cancelling it mid-flight.
Why This Change Was Made
The Gateway had overlapping ownership mechanisms around work already owned by a serialized queue, a pending promise, a current process pair or a final authorization check. This cut removes that duplicate state while retaining measured caches and the minimal checks needed by ordinary concurrent requests. It also removes tests whose only contract was a deliberately forced, now-accepted interleaving; kept security, data and shutdown tests are not weakened.
Best-effort tradeoffs accepted
e0d80000067, perf(sessions): publish transcript projections off thread #154069): synthetic replacement/finalizer interleavings, not a reported user incident. Logical mutation/current-row checks remain; an out-of-band replacement is observed by the next owner refresh.3d903819c56): prior evidence was CI/harness failures in perf(gateway): stream append deltas to every client #158587/perf(gateway): reduce stalls when many sessions start #159102, not a human actual-use report. Read routing is captured once, while physical-target and caller checks remain.a4cc77c355f5): forced observations during an active serialized transaction. Later observations remain queued; lease/credential checks and validated persisted snapshots remain authoritative.Evidence
Pre-rebase
node scripts/check-changed.mjs --base origin/mainpassed atf74889f79dc3dc94c18900335c3d97efcc39d1f2, including all 28 dependent test-type graphs, core and extension production/test typechecks, all three Knip scans (zero findings), changed-file/extension lint, ratchets, and webhook/pairing guards. Extension lint emitted one non-failing max-lines warning in untouchedextensions/crabbox/src/crabbox-worker-provider.ts.Candidate:
8c72a3cea17e559938fa951c2d9ef199d70424bd, rebased only after GitHub reported CONFLICTING, onto7dd5b520d4757cafdad089abb0fe44a7ce6c691d. Net production reduction: 746 lines (510 added, 1,256 removed; tests, test-support, fixtures, generated files and declarations excluded). This uses the campaign's 500–999 honest-pass exception; the coverage log below records all original KEEP decisions rather than padding the cut. Three formerly unused async approval types now have consumers in newer main; their definitions are restored exactly, without ignores.The final test-fixture and cleanup reviews are scoped-clean through P2. Full-branch review raised two documented best-effort tradeoffs (mid-read transcript rewrite and registry remapping), declined with retained authority/target checks identified. A later review suggested guarding same-ID identity replacements; that was declined after verifying that production emits replacement only when the session ID changes and emits reset for same-ID lifecycle changes. Reset invalidation remains intact. Final-content proof includes 32 Talk-registry/transcription/backfill tests, 87 channel-presence policy tests, 7 targeted realtime shutdown/final-write tests, 14 catalog tests, and the selected archived-residency test passing; production core typechecking passes. Earlier candidate proof also passed all 95 channel cases, 31 history-worker cases and 8 source-routing cases. The channel exhaustion regression failed at the intended retained-route assertion before its correction and passes afterward. Runtime and Madge import cycles are both zero; the final pre-push lint-suppression suite passed all 3 tests in 29.98 seconds (38.35 seconds wrapper). The 50-file core lint pass found one unused test import; its removal passes focused lint. Catalog test wall time was 303.95 seconds (346.60 seconds wrapper); archived-residency was 332.45 seconds. No CI-time claim is made yet.
Before rebase, all three Knip export scans passed with zero findings and all 13 SDK transcript-runtime tests passed. The refreshed SDK comparison on production-identical head
53353895b0d749886ed07b884131bd2a3d10eb39completed with digestb86f9b78: 150 dependency-closure-affected exports and two internal whole-module declaration differences, with no named export additions/removals or public signature changes. Async approval definitions now match main exactly. Final core/Gateway/infra types, targeted lint, zero runtime/Madge cycles, and all three lint-suppression tests pass (9.24 seconds Vitest, 12.14 seconds wrapper).The broad Gateway run was interrupted when its Testbox job was cancelled, after 8,360 passing case lines and twelve failed case lines; it has no complete-suite summary. The subsequent projection run completed 22 files with 136 passes and four failures. One failure pinned forged inode reuse and is removed; the catalog case now preserves observable refreshed model facts without demanding intermediate cache eviction. The two remaining failures exposed a real same-stack publication regression: native row facts were published and then erased by an identity notice. A per-row idempotency check fixes it without global fences. All 25 tests in the affected three projection files then passed, keeping the native/worker create, replacement and reset matrix unchanged.
The coordinator authorized test-only updates to the heartbeat-owned reload/runtime-service tests. Obsolete stale-config, watcher-handoff and duplicate-idle fixtures are removed; direct shutdown, receipt settlement, publication failure and model-refresh recovery coverage remains. The cron child-handoff fixture reset admission while replacement startup was still detached and used a virtual scheduler it never advanced. It now retains the helper lifetime through completion, uses the host-timer adapter and explicitly joins the real child; its original one-child, persisted-disable and 10-second assertions stay and pass. Two ordinary install/RPC timeouts from the interrupted broad run remain unqualified. No timeout was raised or skip/retry added.
The first rebase was required by a named pre-existing UI test-root budget failure, not main drift. It kept main's async account descriptions and prepared native session ownership. The budget was not raised. The unchanged 8,193-row category performance case timed out locally under host load and passed on Testbox in 6,890 ms.
After PR creation, GitHub reported CONFLICTING. The conflict-only rebase onto
50cf629016e248cdea5fac810c8fc6b194155e01retained main's new committed transcript-fact reuse from #168719 and this lane's timer simplification. Core and Gateway-root types pass. Across the affected seven projection files, 76 retained cases pass; one obsolete variant was removed after it deliberately discarded an exact committed owner fact and substituted a broad profiles invalidation during a held worker reply (#155767). Real owner, profile, membership-revocation and accepted-fact coverage stays. The desktop authority check now runs once immediately before dispatch; all 11 process tests pass, and focused independent review is clean. Final integration review of the live type restoration and synthetic-test cleanup is clean through P2.The conflict-proof Testbox request remained queued without a host for ten minutes and was stopped. Native status is completed with no IP; the wrapper retains a claim/key because the request has no GitHub-run association. It ran no proof. Local focused proof is used instead.
Seven retained-memory cases in the untouched
server-plugin-reload.recovery.test.tsfailed locally and reproduced on clean main snapshotf8fe56a999119cf87f46af99cfd463ac6f4bfe97with the same assertions:held-close:Plugin first is retiringinstead of successful cleanup.failed-close: wrong error class instead ofPluginInstanceUnavailableError.pending,initialized, andseparate-registry:recoveringinstead ofreloading(three cases).checkpointandrestartfailure:recoveringinstead ofreloading(two cases).The baseline run reports 7 failed, 1 passed, 103 filtered-out cases in 550.72 seconds. These inherited failures remain failures; no timeout, retry, skip, or expectation was changed for them. The initial baseline attempt failed before collecting tests because package-local dependency links were absent; that setup error is not counted as baseline proof.
The initial scope review mistakenly treated synthetic PR reproductions as real incidents. This pass re-evaluated all 15 KEEP rows: 8 flipped to removal/minimal keepers, 7 retain explicit security, durability, shutdown, bounded-resource or measured-performance justification. The detailed coverage ledger is maintained with the lane.
Exact-head CI and test-only follow-up
Run 38126904478 tested
53353895b0d749886ed07b884131bd2a3d10eb39and failed. All check runs were enumerated; there were no cancellations. The follow-up changes only tests, and all 112 focused cases across the seven affected/sibling files passed in four sequential shards (1,180.10 seconds wrapper). Fresh independent review is clean through P2.checks-node-compact-small-1checks-node-changed-compact-small-1-1f442662cabdunder Bun. Main subsequently fixed the fixture in 952c102 by explicitly invalidating facts. The final branch preserves that test byte-for-byte, including positive keyed reads, unchanged siblings, no main-thread SQL, and subsequent clean-row reuse.checks-node-changed-compact-small-9checks-node-changed-compact-small-19checks-node-changed-compact-large-21checks-node-changed-compact-large-14checks-node-changed-extensions-bundle-25e30a97b9207d19ac4eb2aaa3922e7f811b5292f, run 38137511377, job 114464519186. Both steering test files and the executed steering/transcript-write owners are unchanged. The peer's delivered-command additions are outside these paths. The same six failures include missing acceptance, a completed-answer timeout and database-closing teardown cascade. The precise deadlock cause remains unresolved; passing local replays are not claimed as a fix.openclaw/ci-gateNo CI rerun was requested. The necessary test-only repair receives a new exact-head run; unqualified failures are not relabeled as main-red.
The subsequent exact-head run 38135696717 at
4d7caf4119d7922b14cf51b7d51b50bbcae5efe7had two failed test jobs and the aggregate gate, with no cancellations: job 114459199610 was the over-strict zero-worker-read expectation corrected above; job 114459199622 was the independently qualified steering failure; gate 114461165617 aggregated them. The final conflict-only rebase preserves main's repaired row-read test and new live borrowed-turn self-reload refusal, and keeps the existing simplification where main independently removed a source assertion.Conflict-integration proof: the four-file reload/activation/recovery/row run completed with 215 passed and three retained-memory failures (825.82 seconds wrapper). All three reproduce on clean rebase main
6781784f3714b2914a04ed3003ded6f7870dab2e: separate-registry watcher restart, early checkpoint failure, and early restart failure expectreloadingbut observerecovering. The focused baseline completed with three failures and 108 filtered cases in 280.44 seconds; no expectation was weakened. The corrected, current-main row test independently passes all five cases (186.62 seconds wrapper). Fresh isolated review accepts that correction. The two remaining full-branch review suggestions are declined: Talk synchronous reentrant shutdown is explicitly best-effort and no production cleanup callback initiates it; desktop host/request/abort authority is already checked immediately before dispatch.The required lint-suppression suite reports two passes and one inventory mismatch, repeated identically on clean
6781784f371(44.28 seconds candidate / 32.42 seconds baseline). Reported drift is in untouched state/test-utils and Solid HTML files; this lane changes neither those files nor the suppression test and adds no suppression. The inventory is not widened. Madge reports zero cycles.At conflict-repair publication, core production types and all three Gateway test-type graphs pass, and runtime value cycles and Madge cycles are both zero. The broader 28-graph changed check and refreshed SDK API comparison are still running locally; their previous-head results above are not presented as fresh-head completion. Hosted CI will be observed on exactly
923cc70b5a8c03c0c80dd299a4455caf4dac15abbefore landing. Refreshed heartbeat exclusions have no production overlap with this lane; only the already-authorized test overlaps remain.The next conflict-only integration supersedes that publication: main #169100 moved row preparation into
session-row-database-facts.tsand added actor-fact reuse. This branch retains that implementation, moving only the existing global revision-fence and repeated registry-wait removal into the new owner. Main #168991's history replacement guard/test deletions remain; the obsolete row-test correction commits are dropped and the current-main row test is unchanged. Fresh isolated P2 integration review is clean; all 21 selected actor, incognito, history-lifecycle and keyed-row tests pass (220.71 seconds wrapper), core production and Gateway-root/methods test types pass, and runtime/Madge cycles are zero. The preceding changed check passed all pre-type gates and 14 test-type graphs; it was interrupted for the required conflict repair, not reported complete. The SDK comparison completed at production-equivalent pre-move heada87ef2f546d76581f8efed056dbe213ccfe4c327against6781784f371: digestb5f709b8, 150 closure-affected exports, two internal whole-module declaration differences, no named export additions/removals or public signature changes. This final integration preserves main's internal module move and introduces no new public surface.The repair's changed-file check ran on Testbox against the verified candidate source. All selected type graphs (28 core and three root-test), Knip scans (zero entries), lint and guard commands emitted passing results. The wrapper itself exited 1 during cleanup when its GitHub run read failed; that exit remains recorded. Native status was completed with no IP, and a subsequent cleanup reconciliation succeeded. The separate pre-push suppression suite passed all three cases (8.86 seconds, 11.50 seconds wrapper). Production is identical to the previous zero-cycle/API-checked head.
Coverage log: all 15 original KEEP decisions re-evaluated
session-row-projection-generation.tssession-row-projection-catalog.tsreplacement retentionsession-row-projection-catalog.tsdirty symbolssession-row-projection-backfill.tssession-row-projection-materialize.ts/ projection ownerserver-channels.tssession-utils-store-sources.tsThe eight flips are event-generation observation, catalog replacement fencing, catalog revision symbols, backfill interruption/revision checks, materializer global generations, plugin/channel pause choreography, per-account redundant lifecycle state, and source-registry rediscovery. Both previously deferred candidates—Talk reentry and idle-task duplicate checks—were also implemented. Existing tests and synthetic repros are used as proof tools, not as evidence of a real incident.