Repository navigation
refactor(placement): move lifecycle and grant preparation to workers - #166444
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: blocked before merge. Reviewed October 7, 2026, 10:33 AM ET / 14:33 UTC (Revision 13). ClawSweeper reviewWhat this changesMoves session placement lifecycle operations and standing-approval preparation into existing database workers while preserving released synchronous plugin interfaces. Merge readiness⛔ Blocked before merge - 3 items remain The refactor remains necessary, and no actionable code or security defect was found. The updated evidence resolves the previous SQL-budget and local typecheck blockers; inherited-red CI still requires native landing admission. Priority: P2 Review scores
Verification
How this fits togetherSession placement decides where OpenClaw runs a session and coordinates moves, retirement, and prepared workers. Gateway requests and approval decisions enter this subsystem; committed placement facts and authorization checks feed subsequent worker launches and session cleanup. flowchart TD
A[Gateway session request] --> B[Current caller authority]
B --> C[Placement database worker]
C --> D[Transaction and commit checks]
D --> E[Committed placement facts]
E --> F[Worker launch or session cleanup]
G[Standing approval preparation] --> H[Final node transport authorization]
E --> H
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one worker owner for placement persistence, preserve live final-effect guards and released SDK adapters, and leave the remaining read-caller migration to the stacked follow-up. Do we have a high-confidence way to reproduce the issue? Not applicable as a standalone bug report; current-main source establishes the native SQLite preparation paths this refactor targets, and the recorded worker comparisons exercise the replacement paths. Is this the best way to solve the issue? Yes. The branch extends existing database workers, keeps transactions synchronous, and preserves authority checks and shipped SDK contracts rather than introducing another persistence owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cb04039f21de. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
…tion Merge main at 520db50 without rebasing. Read pending-input profile facts from their current owner when sharing consumers run, preserving valid collected input after non-revoking profile changes and retaining final revocation checks. Extend the existing placement SDK compatibility record and type assertions for the released synchronous Gateway contracts. No schema, stored-data, retention, or environment-name changes.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…rrors Invalidate the embedded placement cache when its physical database owner retires, keeping previously retained stores revoked. Return an explicit no-change receipt when conditional move cancellation loses its local generation so the original abort remains visible and no stale intent is deleted or published. Restore the canonical ordering of worker test paths. Existing user-flow regression assertions remain unchanged; the internal conditional cancellation test now asserts false and preserved intent.
Model the asynchronous placement readers, move lookup, and retirement methods consumed by the worker cutover. Preserve existing destination, recovery publication, and session-event assertions.
Merge eb1b48c without rebasing to include the independently landed fresh-borrower config-generation repair and retained integrity proof. The placement PR patch remains byte-identical relative to the new baseline. Fresh P2 integration review is clean; post-integration type, behavior, and SQL gates remain bound to the merged tree.
|
@clawsweeper re-review |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
One upstream commit (openclaw#166444, placement lifecycle and grant preparation moved to workers). The only conflict is the generated docs/reference/database-schemas/worker-access-inventory.md, regenerated from the merged tree with `node scripts/database-worker-inventory.mjs --write` (`--check` is current). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Jhynq2GVpzuVQQieebEubg
…scope Upstream openclaw#166444 (af18444) moved `latestEntry` into the prepare step, where it exists only when no maxLines trim is requested. The feature's post-trim release of staged post-compaction delegates fell back to that name and broke typecheck (TS2448/TS18048). It now falls back to the row this request read before the lifecycle fence (`entry`) and skips the release when no row exists. Gates: tsgo core clean. Canonical runner: server.sessions.compaction(.continuation, -read-errors) 20+5+6, sessions-sharing(.authority) 15+4, subagent-spawn.attachments/authority/claim-handoff 26+4+6. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Jhynq2GVpzuVQQieebEubg
…nt row 9a37d5b fell back to the request's pre-fence `entry` when the post-trim current-row read failed or no longer matched the compacted session (session id, lifecycle revision, work-start). Before upstream openclaw#166444 that fallback was a row read under the lifecycle fence; afterwards it was not. A stale row could then reach the delegate release with its compaction count. Review: 🌻 Elliott and 🕯 Emeric, independently. The release now runs only from the row read after the trim. Without one, the staged delegates stay staged. Fossil: server.sessions.compaction.continuation.test.ts "keeps delegates staged when the post-trim row no longer matches" replaces the session row right after the real trim (trim seam spreads the real module). Patch-coupled: with the fallback restored it fails (release runs, delegate count 0); with this change the suite passes 6/6. The gateway-server test typecheck shard is clean; the mock-export ratchet is unchanged at 559. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Jhynq2GVpzuVQQieebEubg
…penclaw#166444) * refactor(placement): run lifecycle and grant preparation in workers * test(placement): retain lifecycle boundaries in worker fixtures * test(placement): align startup and recovery owner lifetimes * perf(placement): avoid single-query projection transactions * fix(placement): retire cached stores and preserve move cancellation errors Invalidate the embedded placement cache when its physical database owner retires, keeping previously retained stores revoked. Return an explicit no-change receipt when conditional move cancellation loses its local generation so the original abort remains visible and no stale intent is deleted or published. Restore the canonical ordering of worker test paths. Existing user-flow regression assertions remain unchanged; the internal conditional cancellation test now asserts false and preserved intent. * test(placement): update worker lifecycle fixture contracts Model the asynchronous placement readers, move lookup, and retirement methods consumed by the worker cutover. Preserve existing destination, recovery publication, and session-event assertions. * fix(sdk): keep final grant consumption out of deprecation metadata The consume method remains the synchronous final authorization boundary and has no async replacement. Keep its compatibility type assertion while removing the incorrect deprecated-surface marker. * fix(gateway): settle concurrent placement retirement Treat an already-absent placement as a completed worker retirement while preserving state, generation, and live-claim fences. Keep released synchronous retirement strict and avoid publishing a fabricated state change. * fix(gateway): keep retirement absence checks in worker * test(gateway): bind retirement regression to its placement owner * test(gateway): let recovery fixture settle work before closing
What Problem This Solves
Placement moves, prepared-environment binding, retirement, and standing-grant preparation still perform SQLite work on the Gateway thread. Awaited persistence must preserve live authority, accepted-write ordering, and successful session deletion when orphan cleanup retires the same placement first.
User Impact
Placement and approval preparation use the existing database workers while retaining revocation and cancellation behavior. No schema, persisted-format, retention, durability, configuration, or environment-variable changes are introduced. Released synchronous SDK signatures remain available; worker failures do not fall back to native persistence. Remaining ordinary getter and policy-preparation callers stay in stacked PR #166445.
Why This Change Was Made
The placement actor owns move/bind/retirement writes, and the approval reader prepares joined grant facts. Transactions remain synchronous. Physical ownership and live authorization are checked after waits and immediately before commit; accepted writes retain FIFO settlement through shutdown. Placement mutations with unknown outcomes are never replayed. New abandonment intents check the live runner against transaction-local source facts, while callers joining an existing durable intent retain its original decision.
The landing repairs preserve refreshed profile authority, invalidate the embedded fallback placement cache when its database owner retires, and keep conditional Move cancellation from replacing the original Stop error. Retirement recognizes an already-absent row inside the worker transaction without publishing a fabricated transition. Present rows still require the exact state, generation, and null claim fields; the released synchronous method remains strict. Successful retirement adds no SQL. The recovery test now uses its existing asynchronous session/Gateway-home cleanup owner instead of closing SQLite prematurely in a competing hook.
Released Gateway/SDK surfaces were checked against
v2026.10.1-beta.1andv2026.9.8. Optional async companions, compatibility records, and type assertions preserve callers until the next SDK major. Standing-grantconsumeremains the permanent synchronous final transport guard, not a deprecated preparation API.Retained authority boundaries and follow-up debt
Cross-store reset retirement stays synchronous at
src/gateway/worker-environments/session-placement-lifecycle.ts:146andsrc/gateway/session-reset-service.ts:816. Destructive worktree cleanup retains narrow live reconciliation reads atsrc/agents/worktrees/owner-protection.ts:82; final standing-grant consumption retains its joined native query atsrc/gateway/operator-approval-placement-grants.ts:185. Sharing grants retain pre-existing short indexed reads of the other agent-store owner atsrc/gateway/session-sharing-worker-grant.ts:149, with source admission prepared before the placement transaction. These guards do not rediscover same-database maintenance admission while its writer lock is held.Overlap stays focused on these owners: #166102, #165901, #165921, and the entry/auth/binding/discovery/worktree/transcript/profile work. Improvements from #166053 and #166054 remain intact. No other PR branch is changed.
Evidence
Published head:
1b0647535c9cb1a931d0a61f4647ce371362ef36, tree13f5ff68d3922fa545e8f08dec85355d049bedd6. Real GitHub conflicts required a merge of main892911ba; the later integration adds main1b395594318bbd0db6f2467f35b10cc8ac1d30d0to consume its exact fixes for the remaining inherited failures. Both integrations use merge commits. GitHub confirms the published head is mergeable. The second merge had no conflicts, and the PR patch and review context remain byte-identical to the clean two-pass P2 review. The source interaction audit found no actionable issue: transcript retries retain their existing idempotent ledger recovery and recheck live placement/source authority before persistence and acknowledgment.All 15 integration gate groups pass on this exact head: core types; all 27 test type graphs (1447.24s); worker retry/live acknowledgment; startup/channel status; Doctor/update; the repaired publication E2E; all four import/build-graph contracts; Madge; formatting; lint; worker/mock/timeout ratchets; and diff validation. Fresh proof across 16 runtime/import files passed 273 cases; the public E2E uses two reporters and is counted once. The fresh local SDK report also passes. ClawSweeper completed this exact head at 12:57 UTC with no actionable code or security findings. Its then-pending local test-type and inclusive SQL requirements are now complete. All 25 focused SQL flows and all three warmed-turn pairs pass against integrated main
1b395594, including maintenance/background work. Warmed all-thread counts are 2268.1→2242.8, 2279.7→2233.4, and 2276.5→2251.4; the median falls from 2276.5 to 2242.8, while host-thread counts remain 28. All workload phases report zero SQL execution or preparation errors. The completed run retains 452 traces and compiled-runtime/source identities; all measured processes stopped and source copies are clean. Exact-head CI remains independently inherited red as described below; landing still requires the native exception admission. Previous-source checks below remain historical evidence.d45e1ec6afa772292925e45edabe26636b59acbd, treebd04566667c7da92dc44593e0679330543db6269, with ordered parents main86b83b74b4c68e147277b022b517c0d8b5322c16and this PR head. The run completed with 92 successful jobs, 23 skipped jobs, two failed roots and their downstream failed aggregate, with no cancellations in this CI run. The root failures are fourserver.sessions-send-owner-continuation.test.tscases that end before private requester/plugin authority gates, andserver.channels.test.ts:100expects a boolean WhatsAppconfiguredfield but receivesundefined. Both job logs were retained once. The same two tests also fail in scheduled main CI atccadf6ace8757f188fe9e40fbbf39d71ccf0928c; both test files are byte-identical on that main revision, the actual CI base, and the tested merge. Five unchanged runs per file on main and five on the tested merge reproduce both failures. The channel test supplies its configured-state fixture through hooks that main no longer calls for non-probing status. One diagnostic run per revision exposed the same requester-owner capability rejection before plugin execution in the continuation family. The exact early gate varies, not every failed case prints the underlying error, and printed successful receipts belong to the passing child-error sibling. The fixture and relevant authority/invocation owners are unchanged across the compared revisions. These are independently inherited failures; the completed evidence is prepared for the native inherited-failure exception without weakening assertions or rerunning CI for green.3106f46f): 16 of 17 gate groups passed: all 424 focused/import/compatibility cases across 37 files, core types, 26 of 27 test type graphs, Madge, lint, format, and worker/mock/timeout ratchets. The sole failure was the unchanged UI font fixture's obsoletesignalargument; current integrated main contains its one-line fix.1b0647535c9cb1a931d0a61f4647ce371362ef36versus integrated main1b395594318bbd0db6f2467f35b10cc8ac1d30d0is checked and its renderer completed successfully, digest0179d1d95c492e53f431e79d9c9936f1d40ce1d6948bbd8292c7869fb41f9365. The full diff is identical to the previously audited3106f46freport, including all 181 affected export records across 30 entrypoints and all 33 distinct declaration-change records. Changes are reachable declarations only; no direct exported declaration or entrypoint is added, removed, or changed. Integration introduces no new reachable callable change; released synchronous contracts and optional async companions remain compatible.5937396fgave four passes and one exact retirement failure; all fiveeb1b48c5baseline runs passed. The test-only worker-queue regression then failed with that exact error while the archive-publication phase passed (56.201s). Repair624075e4passed all three full suites withpnpm test <file> --maxWorkers=1: deletion lifecycle 132.250s, real abandonment 97.102s, and reclaim/retirement fences 80.195s. Worker retirement also preserves strict claim/state/generation rejection and clears local conflict state after peer retirement.d215c779, including those three full suites, lint, production types, four Gateway test graphs, import boundaries, Madge, and the ratchet. The checked SDK report is bound to production commitbf25462da5cd, digest7767152bd270dd60da0af296f8c66f664e8483b4937ebc0c778c44d397c08ca0: 181 reachable exports across 30 entrypoints, no export/entrypoint additions or removals. The only delta from the preceding report is an internal retirement-option name; public signatures are unchanged. The subsequent commits through93f59e77change tests only; this qualification does not cover the later main integration or claim a new SDK render.624075e4merged with main5077ad4f: 89 successful jobs, 23 skipped jobs, five failed roots, and the downstream failed aggregate; no cancellations. The PR-caused unbound-method lint is fixed. Recovery passed all five main runs and failed all five tested-merge runs at the premature synchronous cleanup; the exact failing merge plus the minimal fixture repair passes all eight cases (79.49s), and actual93f59e77passes all eight (79.76s). Its scoped lint (17.98s), Gateway-server type graph (4.08s), formatting, and diff checks also pass. ClawSweeper completed624075e4with no findings; that is prior-head review evidence only.a2e44be9(2 failed/10 passed, 136.723s). The update CLI diagnostic expectation also fails on scheduled main. X publication's unchanged anonymous-reader assertion returns 503 instead of 200 on both main and the tested merge: main runs passed[1]and failed[2,3,4,5]; merge runs passed[1,4]and failed[2,3,5]. All five runs per side used clean pinned sources and the same command. A source audit found all scoped Doctor and update test, producer, and diagnostic-renderer files byte-identical to the earlier independent qualification, main5077ad4f, integrated main892911ba, and candidate3106f46f. These records now remain historical attribution evidence: current integrated main contains the exact Doctor fix0dc209168731, update diagnostic fix19cc8e6568f2, and stable-public-read fixture fixd641ea18101f, alongside the UI type fix1d10375ee563. Final CI must exercise those fixes; this candidate does not claim an inherited-failure exception for the old failures. Recovery was PR-exposed and is not classified as inherited.The attempted
93f59e77SQL run was superseded by the required conflict integration after completing only the old baseline's stop/handoff family (69.692s). Its raw traces, source identities, and interruption receipt are preserved. No candidate samples, warmed-turn samples, or candidate-versus-main comparison were produced by that run; it supplies no passing SQL qualification. The current exact-head comparison above supplies the required integrated-source qualification.The
5937396fstrict SQL no-growth gate failed and remains disclosed. Commentary counted four extra periodic-checkpoint statements over ten observations (+0.4 each); the pooled 30-observation control remained +4 total (+0.1333 each). Background and maintenance statements remain counted. A baseline raw-auditSQLITE_BUSYrecovered through the existing owner retry and remains in the evidence. The current exact-head comparison now passes all 25 flows and all three warmed pairs against integrated main. The old failure remains historical evidence; no samples, maintenance statements, or thresholds were excluded to obtain the current pass.Original failures and earlier proof retained
The original CI failure was PR-caused: sharing preparation retained initial profile facts instead of the pending-input owner's refreshed facts. It failed on all five PR runs and passed on all five baseline runs; the unchanged regression now passes, including subsequent revocation. Original fail-fast cancellations were downstream fallout.
Fallback-cache and Move-cancellation regressions likewise failed all five original-PR Linux runs while all five baseline runs passed. Stale async fixtures and a test-path ordering error were repaired. Earlier agent-admission failures reproduced on both main and PR; main's borrower repair resolved the representative case. Mac timeout noise was retained and proof moved to isolated Linux without weakened deadlines. Main fixed the earlier
CallBriefexport failure in #166147.Earlier passing checks are not substituted for final-head gates. Integrated
de6e0a7fpassed 101 behavior cases across 11 files (551.359s), planner/import boundaries, production types, all 27 core-test type graphs (402.045s), Madge, and CI. Earlier owner-only SQL grew by +5.5/+2.9/+1.5 statements per warmed turn and failed. A later8c6d5cecseries passed all 25 flows and warmed pairs: main-thread 28→28, all-thread median 2442.9→2397.9, no SQL errors. Neither supersedes the newer no-growth failure. The broader target of fewer than 500 statements per warmed turn remains unmet.The published-driver cell passed from published
2026.9.8to the earlier persistence-owner source, proving readiness, durable/incognito preservation, and service cleanup. It is retained update-path evidence, not final validation of the subsequent repairs.Release-note context: move placement and approval preparation off the Gateway thread while preserving released SDK compatibility, live abandonment authority, and deletion completion when orphan cleanup has already retired the placement.