Repository navigation
perf(sessions): avoid registry waits for canonical recovery stores - #175129
Conversation
Resolve canonical per-agent ownership from its existing path contract before requesting registry rows. Fixed/shared stores and ambiguous aliases retain authoritative registry reads and refusal semantics. This removes a redundant shared-state reader dependency from restart delivery discovery without adding a cache or changing storage.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5ed73a512
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@clawsweeper re-review The branch now preserves one lazy registry snapshot per discovery pass, with a regression for multiple shared targets. The PR body includes the final packaged restart measurements and their limitations. |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR loads ownership registry rows only when target selection needs them and shares one snapshot throughout each dedupe call. Example: Restart discovery finds canonical session stores for agents main and helper while registry access is deferred.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes an unnecessary recovery dependency that remains on current main, and the corrected patch has no actionable findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherSession target discovery converts configured and discovered store paths into logical agents and physical database targets for recovery and other session readers. flowchart TD
A[Recovery discovery] --> B[Prepared store inventory]
B --> C[Discovery worker]
C --> D[Target dedupe]
D --> E[Canonical path owner]
D --> F[Lazy registry snapshot]
E --> G[Selected database targets]
F --> G
Technical reviewBest possible solution: Retain the lazy invocation-local snapshot and existing ownership checks, then land through the normal exact-head CI gate. Do we have a high-confidence way to reproduce the issue? Current-main source shows canonical recovery inventory demanding registry rows before path resolution; the supplied regression reports the expected base failure, but no target code was executed during this read-only review. Is this the best way to solve the issue? The patch removes the redundant read at its existing owner and preserves one snapshot per synchronous pass without introducing another cache or resolver. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c23b09a59fba. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +2, Tests +41, Docs +4. Total +47 across 4 files. Added test files: 0. View PR surface stats
LabelsLabel 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 Reviewed October 17, 2026, 1:37 AM ET / 05:37 UTC. |
|
Landing under the authorized inherited-failure exception for head The only failing product check is PostgreSQL conformance. PR job 117319295899 reports All other selected code checks passed. The aggregate CI gate is red because PostgreSQL conformance was canceled by the job budget. Focused inventory/dedupe/target tests passed (32 tests), including both regressions; independent review is clean and the review thread is resolved. No CI rerun was requested. This exception does not claim the PostgreSQL check passed. |
Drain retained parent shared-state handles after the Doctor child settles, including unsuccessful exits, before revoking schema admission. The next parent access must admit the resulting database schema again. This keeps updates from silently reusing admission from before Doctor migrated it, without restoring per-read schema probes removed in #175077. Refuse destructive Doctor session migration before target preparation when the shared-state database is absent but its SQLite sidecars survive. Keep legacy source and WAL bytes intact and tell the operator to restore the matching database. Canonical-path recovery retains #175129's registry-read optimization; source preservation no longer depends on that incidental read. The existing regressions reproduced on origin/main cec76b0: both Doctor exit-code cases and shared-state orphan-WAL preservation failed. After the fix all 11 cases in the two owning files pass unchanged. Core types, targeted lint, formatting, docs MDX and whitespace checks pass. Independent P2 review found no actionable P0-P2 findings. Sibling proof: 65/65 pass across Doctor authority/delegation and session recovery/restore; 186.85 s command wall. No tests or assertions changed. OAuth's same-hourly failure is covered by active PR #175069 and untouched.
…5295) Reopen cold state handles after an observed schema-owner handoff so a newer schema is refused before the first write callback. Keep warm schema admission cached as intended by #175077. Retain exact execute-refusal provenance through worker retirement and deliver the original host lifecycle error. Preserve shared preparation from #175008, native-exit joining and unknown execute settlement. Exercise registry error handling with a custom store that requires the registry after #175129. Keep every existing assertion. Before: three deterministic main failures,35passes,128.76s wall. After: all38tests pass,211.93s wall including worker rebuild; files took 92.46s/54.14s/49.98s through native --maxWorkers=1 wrapper. Targeted types/lint/format pass; P2 review scoped-clean.
…penclaw#175129) * perf(sessions): avoid registry waits for canonical recovery stores Resolve canonical per-agent ownership from its existing path contract before requesting registry rows. Fixed/shared stores and ambiguous aliases retain authoritative registry reads and refusal semantics. This removes a redundant shared-state reader dependency from restart delivery discovery without adding a cache or changing storage. * fix(sessions): reuse demanded ownership snapshot during discovery
…#175300) Drain retained parent shared-state handles after the Doctor child settles, including unsuccessful exits, before revoking schema admission. The next parent access must admit the resulting database schema again. This keeps updates from silently reusing admission from before Doctor migrated it, without restoring per-read schema probes removed in openclaw#175077. Refuse destructive Doctor session migration before target preparation when the shared-state database is absent but its SQLite sidecars survive. Keep legacy source and WAL bytes intact and tell the operator to restore the matching database. Canonical-path recovery retains openclaw#175129's registry-read optimization; source preservation no longer depends on that incidental read. The existing regressions reproduced on origin/main 65bc05f: both Doctor exit-code cases and shared-state orphan-WAL preservation failed. After the fix all 11 cases in the two owning files pass unchanged. Core types, targeted lint, formatting, docs MDX and whitespace checks pass. Independent P2 review found no actionable P0-P2 findings. Sibling proof: 65/65 pass across Doctor authority/delegation and session recovery/restore; 186.85 s command wall. No tests or assertions changed. OAuth's same-hourly failure is covered by active PR openclaw#175069 and untouched.
…nclaw#175295) Reopen cold state handles after an observed schema-owner handoff so a newer schema is refused before the first write callback. Keep warm schema admission cached as intended by openclaw#175077. Retain exact execute-refusal provenance through worker retirement and deliver the original host lifecycle error. Preserve shared preparation from openclaw#175008, native-exit joining and unknown execute settlement. Exercise registry error handling with a custom store that requires the registry after openclaw#175129. Keep every existing assertion. Before: three deterministic main failures,35passes,128.76s wall. After: all38tests pass,211.93s wall including worker rebuild; files took 92.46s/54.14s/49.98s through native --maxWorkers=1 wrapper. Targeted types/lint/format pass; P2 review scoped-clean.
What Problem This Solves
Restart delivery discovery unnecessarily requests the shared-state ownership registry even when every session store has a canonical per-agent path. A busy state reader can therefore delay discovery before pending delivery input is inspected.
User Impact
Canonical agent-store recovery no longer waits for an ownership registry lookup that cannot change the selected owner. Fixed/shared store ownership, ambiguous physical aliases, admission checks, and unreadable-registry refusal remain intact.
Why This Change Was Made
The target resolver already returns the owner encoded by canonical per-agent paths. Dedupe nevertheless requested registry rows first, forcing deferred recovery inventory through discovery, cleanup, a shared-state registry read, and a second discovery request. Demand the registry only where ownership actually depends on it, and reuse the first snapshot throughout the synchronous dedupe pass.
Production delta: +12/-10 lines. The two net additional lines preserve the existing one-registry-read-per-pass contract for fixed/shared stores while removing the unconditional read. There is no new persistent cache, schema, configuration, worker, or fallback path. Tests add 41 lines; documentation adds four.
Evidence
node scripts/run-vitest.mjs src/config/sessions/session-store-target-inventory.test.ts src/config/sessions/targets-dedupe.test.ts src/config/sessions/targets.test.ts --maxWorkers=1— 32 passed. The canonical recovery regression fails on the original implementation withsession-target-registry-requiredand passes with registry access still deferred.git diff --checkpassed. Broad validation runs in PR CI; no Testbox/Crabbox lease was allocated.Packaged Gateway measurements
Sequential Linux-rig runs used the supported
gatewayWatchruntime build, synthetic 5,000-session/6,000-run fixtures with 200 approvals, 100 cron jobs, 12 projects/worktrees, and ~240 MiB of state. Each version had one initial start and one actual restart of its own fixture. The patched build used66ffabc522acplus the final production change. All completed with clean shutdowns. The separate 50-agent proof covers multiple-store topology; this row-count fixture has one agent store.Restart measurements:
deliveryDiscoveryMsc5733c40baa266ffabc522ac66ffabc522ac+ final fixFirst-start discovery was 1,220.4 / 849.9 / 876.4 ms respectively. An additional unchanged-candidate start on the same fixture measured 754.1 ms discovery, 23.740 s HTTP readiness, and 30.699 s recovery completion. HTTP readiness precedes delivery recovery completion; these are distinct boundaries.
The shared 8-CPU rig had load ~13 and 1–3% sampled idle CPU during candidate runs. Candidate discovery spans 754–1,023 ms around the baseline's 812–850 ms, while reader admission, execution recovery, and registry activation also vary substantially. These measurements establish neither a discovery speedup nor end-to-end startup neutrality. The deterministic benefit is removal of the unnecessary registry queue dependency.
The reported production 0.6 ms → 50-second discontinuity was not reproduced or bisected to a specific commit. Source audit found no direct discovery-algorithm change between the cited revisions. This PR removes a proven unnecessary wait without claiming to explain the entire incident. Confirming incident resolution after deployment remains a follow-up.
CI inherited-failure exception
Landing under the authorized inherited-failure exception for head
adf22fb0a9df645cbad03ca96578e3f246825e39.The only failing product check is PostgreSQL conformance. PR job 117319295899 reports
src/infra/database-engine/matrix-roots.postgres.test.ts→ports every retained token/account root with the state family and restores fresh namespacestiming out at 300,000 ms; the job subsequently hit its 30-minute overall budget. Scheduled main job 117309835227, at737a0ac25447438a039295a6200ced99d6bc4a6d, reports the identical case and timeout. The test blob is identical in main and this PR (ed1c853fdd3486c10f6e8b2c0a360c9af3e4c243). No new failing test case appears in the PR log.All other selected code checks passed. The aggregate CI gate is red because PostgreSQL conformance was canceled by the job budget. Focused inventory/dedupe/target tests passed (32 tests), including both regressions; independent review is clean and the review thread is resolved. No CI rerun was requested. This exception does not claim the PostgreSQL check passed.