Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 2, 2026, 9:51 PM ET / September 3, 2026, 01:51 UTC. ClawSweeper reviewWhat this changesThe PR keeps agent SQLite handles warm after session-startup maintenance so Gateway transcript reconciliation can reuse them instead of reopening and integrity-checking the same database. Merge readiness⛔ Blocked before merge - 4 items remain Keep open: the duplicate-open path remains on current main and in stable v2026.8.2, but this branch globally removes a close from a shared routine and regresses Local TUI handle lifecycle. Priority: P2 Review scores
Verification
How this fits togetherGateway startup performs session-store maintenance before reconciling transcript indexes, both of which use the process-owned agent SQLite cache. The Local TUI also calls the maintenance routine but does not enter reconciliation. flowchart TD
A[Gateway startup] --> B[Session-store maintenance]
B --> C[Agent database cache]
C --> D[Transcript reconciliation]
D --> E[Gateway serves history]
F[Local TUI startup] --> B
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource -8, Tests +34. Total +26 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase or replace this branch with a Gateway-owned migration-to-reconciliation handoff that retains only the needed handles, while preserving the shared routine's default close for Local TUI and other non-handoff callers. Do we have a high-confidence way to reproduce the issue? Yes — the supplied cold-Gateway trace shows the two-open baseline, and current main still has the source sequence that opens, closes, then reconciles through the same database owner. Is this the best way to solve the issue? No — retaining every handle in the shared routine fixes Gateway's path but changes Local TUI behavior; the cache handoff belongs at the Gateway boundary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 63974421ae54. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review Real behavior proof added to the PR body: cold-start gateway runs against a real 1.5 GiB agent database, before/after. Baseline (main without the fix) reproduces the two |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
b79d904 to
c71c7b3
Compare
|
Rebased onto current The defect is still reachable on current
|
|
🦞🧹 I asked ClawSweeper to review this item again. |
Startup migration opened each existing agent database to refresh its canonical session main key, then closed it again whenever it had not already been open. Transcript reconciliation reopens the very same file moments later, so every gateway start paid a second open plus a second SQLite integrity check of a file it had just finished checking. On a multi-gigabyte agent store that is the dominant cost of an otherwise idle startup. Startup now leaves the handle it opened in place and lets reconciliation reuse it, which is what the rest of startup already assumes. The `alreadyOpen` bookkeeping and the conditional close go away rather than being made smarter, so there is one open per database per start. Main's openclaw#128513 reduced how often the migration loop rescans stores, but the open/close churn was independent of that and is still reachable for cold databases that need registration or canonical-key work. Regression coverage asserts the handle is still open while reconciliation runs. Note the suite's `sessionSqliteDatabaseExists` stub answers `params.path === undefined`, so a test that supplies a real resolved path skips the migration branch entirely and would pass without ever opening anything; the new test forces that stub true so it exercises the real open path. It fails on unfixed code with `expected false to be true`. Refs openclaw#121985
c71c7b3 to
d3a7cdb
Compare
|
CI note on the previous head ( The failing verifier was That is a 0.7 MB overshoot — 0.17% — decided by a median of three samples whose spread is 74 MB. This branch cannot plausibly move that number:
The reading I would offer instead is that I do not have rerun rights on this repository, so I refreshed the head to re-fire CI. If the re-run reproduces the same overshoot, that is stronger evidence for the drift reading than for a regression here, and I am happy to open a separate issue for the startup-memory budget. |
|
CI is green on That settles the earlier For whoever owns that budget, the failing sample set was: A 1 MB tolerance over samples spanning 328.8-402.5 MB will keep flipping for unrelated PRs. Happy to open a separate issue for it if that is useful — it is out of scope for this change, so I have left it alone here. |
Borrow verified per-agent connections across manager work and release them without closing the shared owner. Pin exact handles against cache eviction, retain explicit disposal, and keep shadow publication synchronous. Hand startup maintenance directly to Gateway reconciliation while preserving temporary maintenance cleanup. Use the same connection for vector deletion and guard native extension loading against post-import revocation. Fixes #137750 Fixes #121985 Supersedes #122005 Co-authored-by: Grynn <[email protected]>
Memory managers reopened and synchronously rechecked per-agent databases that Gateway startup had already verified. Borrow the exact canonical connection and retain its complete owner lifecycle across native and transformed SDK modules, including query caches, registry invalidation, and commit observers. Manager cleanup releases only its borrow; explicit owner disposal remains authoritative. Preserve read-only diagnostics, isolated shadow rebuilds, synchronous publication, native vector-loading boundaries, and temporary startup-maintenance cleanup. Remove duplicate initialization and transaction bookkeeping. Production delta: -23 lines. Regression proof covers physical-open/integrity counts, corruption before exposure, settings replacement, maintenance isolation, shutdown, cross-module rollback and discovery, and failed lease-release recovery. Real Crabbox CLI/Gateway searches, packaged sqlite-vec loading, and candidate/baseline/candidate database compatibility pass. Repair fixture-owned database cleanup exposed by the process-shared lifecycle without changing production incognito lifetime. Closes #137750 Closes #121985 Supersedes #122005 Thanks to Hampert for reporting the cold-search stall and @Grynn for identifying the startup duplicate checks. Co-authored-by: Grynn <[email protected]>
|
Thanks, @Grynn. Your duplicate-startup-check intent is now absorbed in #138166, merged as 10afd71a79e6, with The landed repair reuses the already-verified canonical connection throughout Gateway startup and memory-manager acquisition, removing the redundant writable open and initialization. It also preserves temporary TUI maintenance cleanup, isolated rebuild writers, validation before exposure, and borrowed-handle shutdown. Native/transformed SDK identity and transaction semantics are covered. Exact-head CI and Crabbox CLI/Gateway/vector/older-reader compatibility proof passed. Closing this PR as superseded by that complete owner-lifecycle repair; no remaining implementation from this PR is needed separately. |
…w#138166) Memory managers reopened and synchronously rechecked per-agent databases that Gateway startup had already verified. Borrow the exact canonical connection and retain its complete owner lifecycle across native and transformed SDK modules, including query caches, registry invalidation, and commit observers. Manager cleanup releases only its borrow; explicit owner disposal remains authoritative. Preserve read-only diagnostics, isolated shadow rebuilds, synchronous publication, native vector-loading boundaries, and temporary startup-maintenance cleanup. Remove duplicate initialization and transaction bookkeeping. Production delta: -23 lines. Regression proof covers physical-open/integrity counts, corruption before exposure, settings replacement, maintenance isolation, shutdown, cross-module rollback and discovery, and failed lease-release recovery. Real Crabbox CLI/Gateway searches, packaged sqlite-vec loading, and candidate/baseline/candidate database compatibility pass. Repair fixture-owned database cleanup exposed by the process-shared lifecycle without changing production incognito lifetime. Closes openclaw#137750 Closes openclaw#121985 Supersedes openclaw#122005 Thanks to Hampert for reporting the cold-search stall and @Grynn for identifying the startup duplicate checks. Co-authored-by: Grynn <[email protected]>
Closes #121985
What Problem This Solves
Fixes an issue where operators starting the Gateway with an existing SQLite agent database would pay for a full physical database open and integrity check twice during startup. The duplicate work is especially visible on large agent databases.
Why This Change Was Made
The session startup migration now leaves its agent database handle in the existing bounded cache so transcript reconciliation can reuse it. The per-physical-open integrity policy is unchanged, and a lifecycle regression test verifies that the handle remains warm across the migration-to-reconciliation boundary.
User Impact
Gateway startup avoids one redundant database open and integrity check per affected agent within the existing cache capacity. Database validation and repair behavior are otherwise unchanged.
Evidence
node scripts/run-vitest.mjs src/gateway/server-startup-session-migration.test-support.ts— 28 tests passed.node scripts/check-changed.mjs --dry-run -- src/config/sessions/startup-migration.ts src/gateway/server-startup-session-migration.test-support.ts— classified as focused core production + core test changes.node_modules/oxfmt/bin/oxfmt --check src/config/sessions/startup-migration.ts src/gateway/server-startup-session-migration.test-support.ts— both files formatted.git diff --check origin/main...fix/gateway-agent-db-double-open— clean.AI-assisted: yes. I reviewed and understand the lifecycle change and its test coverage.
Real behavior proof (added 2026-08-17)
After-fix gateway startup runtime trace demonstrating removal of the second physical open, on a real dataset: a 1.5 GiB
agents/main/agent/openclaw-agent.sqliteplus its realagents/main/sessionsstore (operator state copies), isolatedOPENCLAW_STATE_DIR, dist-backednode dist/index.js gateway, cold process, run to[gateway] ready. Physical opens were observed two independent ways: the product's own[state/agent-db] slow OpenClaw agent database openwarning (fires per physical open slower than 1s; this database's integrity check takes ~2s) andstrace -f -e trace=openatfiltered to the exact database path.Before — current
mainwithout this fix (baselinec98ae0f99cb, the fix's rebase parent):After — exact PR head
b79d9047e68:The three read-only probe/verification opens are identical across both runs; the delta is exactly the redundant close→reopen pair between canonical-key migration and transcript reconciliation described in #121985 (which also predicted the two slow-open warnings — reproduced verbatim in the baseline run).