Repository navigation
fix(memory): resume background reindex after foreground turns - #178979
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 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. |
|
Codex review: needs changes before merge. What this changesThis PR retains unfinished SQLite memory rebuilds across foreground turns and resumes them on the next sync. Example: A foreground turn interrupts a rebuild after 8 of 17 session sources finish.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 4 items remain Keep open: this PR addresses a current rebuild problem, but two recovery regressions and a diff-caused CI assertion need repair. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherMemory Core converts memory files and session transcripts into a private replacement index, then atomically publishes it while searches continue reading the existing index. flowchart TD
A[Memory files and transcripts] --> B[Memory sync owner]
C[Foreground activity] --> B
B --> D[Retained SQLite shadow]
D --> E[Publication worker]
E --> F[Published index]
F --> G[Memory search]
Technical reviewBest possible solution: Retain the existing shadow under the memory owner while restoring sessions-only retry cleanup and releasing terminal shadow state safely. Do we have a high-confidence way to reproduce the issue? Current main directly exposes the discard-on-interruption path, and the supplied baseline diagnosis records repeated shadows and discarded groups; no target code was executed during this review. Is this the best way to solve the issue? Keeping progress with the existing memory owner is a focused solution, and the extraction removes the superseded rebuild implementation, but recovery markers and terminal cleanup must preserve their previous contracts. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c622b70b2b4c. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +188, Tests +299, Docs +4. Total +491 across 15 files. Added test files: 1. View PR surface stats
Review metrics
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 20, 2026, 11:30 PM ET / October 21, 2026, 03:30 UTC. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 680bdd955c
ℹ️ 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".
| if (this.syncing || this.reindexProgress) { | ||
| return await this.syncAdmitted(params); |
There was a problem hiding this comment.
Preserve background mode when resuming search maintenance
When a suspended reindex exists and a search starts detached maintenance (for example, because a memory-file change left dirty set), this path resumes it through syncAdmitted without { background: true }. Consequently syncIsBackground becomes false, so shouldYieldSessionIndexing() ignores an active foreground agent turn and the resumed rebuild can process the entire remaining session corpus in 128-file groups instead of yielding. Pass the background option when this nominally background path reuses the serving manager.
Useful? React with 👍 / 👎.
…aw#178979) Keep the SQLite shadow and completed-source cursor in the memory owner when background indexing yields. Return from sync so the existing lock is released, resume on the next sync, and reconcile changed sources before atomic publication. Discard on close, shadow failure, provider/identity changes, and explicit full rebuild. Process restart still starts over. PostgreSQL retains discard-on-yield until its stage-backed spool supports suspension without pinning a pooled connection. Prove same-shadow resume, changed-source reconciliation, close cleanup, bootstrap without deadlock, unsupported-backend discard, and watcher admission. The large synthetic 60-second cadence lost zero groups versus 1,180 on base; warm memory work counts are unchanged.
#178979 moved watch notifications, session startup catch-up and session deltas from Memory Core's public sync() to its background sync owner so indexing can yield to foreground turns and resume. Memory Core's own tests were updated, but src/plugins/memory-background-reload.test.ts still waited for sync() calls that no longer happen, so three cases timed out after 120 s. Observe the background sync owner instead, keeping every outcome assertion. The reload-deadline case also passed only when an earlier case had already marked the main agent's index live in this process. A cold service start leaves untouched indexes closed, so open the index before waiting for its first watcher.
…180826) openclaw#178979 moved watch notifications, session startup catch-up and session deltas from Memory Core's public sync() to its background sync owner so indexing can yield to foreground turns and resume. Memory Core's own tests were updated, but src/plugins/memory-background-reload.test.ts still waited for sync() calls that no longer happen, so three cases timed out after 120 s. Observe the background sync owner instead, keeping every outcome assertion. The reload-deadline case also passed only when an earlier case had already marked the main agent's index live in this process. A cold service start leaves untouched indexes closed, so open the index before waiting for its first watcher.
What Problem This Solves
Fixes background memory rebuilds repeatedly discarding completed indexing work when a foreground agent turn starts. A large rebuild could restart for each turn and fail to publish until activity stopped.
User Impact
SQLite memory rebuilds now keep their private shadow index across foreground turns and resume on the next sync, including a bootstrap search. Searches continue to use the published index until the replacement is complete. The existing foreground yield points are unchanged.
Owner close, shadow errors, provider or published-identity changes, and an explicit full rebuild discard the retained work. Process restart still starts over. PostgreSQL retains its existing discard-on-yield behavior; resumption there needs a stage-backed spool rather than holding a pooled connection between syncs.
Why This Change Was Made
The background sync returns when it yields, releasing the existing sync promise and reindex lock. The memory owner retains the shadow and completed-source cursor; it does not leave an awaited stack paused. This lets a foreground bootstrap resume the same work without a dependency cycle.
Completed session sources are skipped, and the shadow's existing memory-file hashes preserve completed memory work. Source-change notifications and targeted sync requests invalidate the affected completed entries before publication. The final publication and Forget/revision boundary remain unchanged. One backend capability preserves PostgreSQL's current lifetime contract.
Removed the discard-and-full-retry path for SQLite foreground yields and the duplicate shadow-close wrapper. The rebuild operation moves into its own owner layer so shadow lifetime is explicit. No schema, cursor table, new lock, freshness probe, or keyword-search change. Net change: production +200 lines, tests +315, docs +4; the growth is retained progress/lifecycle handling and regressions, with existing rebuild code extracted rather than duplicated.
Evidence
d121309e77400b1360d261b7aca02950244eab1a; its unchanged stage-discard and connection-lifetime behavior were verified. Final head41a4b0cee824498dcecfc5020e546e0e4f7d24c1changes two test files only; all measured/reviewed production blobs are identical. The coordinator approved the exact final head by test-only extension; all three PostgreSQL conformance shards also passed on the identical production head.check:changedreports three max-lines suppressions in untouched UI files; the same rule and files fail on exact basebeb97b5b7dc3(chat-message.test.tsx,config-page-state.ts,sessions-page-state.ts). No new static findings remain.The large synthetic comparison uses current main at start,
beb97b5b7dc368d8cafa507c781a32e9299a024d, against production headd121309e77400b1360d261b7aca02950244eab1a. One observation per arm/scenario: no additional turns, or real synthetic Gateway turns every 60 seconds until first publication (maximum ten minutes, then quiet recovery). These are not repeated-run medians; timing includes observer overhead and shared-host load. Host load was lower on the candidate: one-minute load before/after was 10.87/16.70 (base quiet), 15.17/14.10 (base cadence), 7.78/6.82 (head quiet), and 6.60/4.42 (head cadence), on 32 cores. Timings are observations, not isolated causal speedups; the removed-work counts are direct.The candidate recorded five foreground yield → owner return → same-shadow resume intervals, preserving prefixes of 336, 336, 336, 697, and 1,048 groups. No groups completed while suspended. It published during the cadence after five successful turns; the baseline needed ten turns and quiet recovery. Whole-run savings therefore also include the shorter run and fewer turns, not only avoided rebuilding. Candidate turn durations were 6.197–6.492 s (median 6.212 s).
Direct discarded-shadow cost fell from 851,050 SQL / 36,262 requests-with-SQL to zero; these exclude preparation on other stores and zero-SQL requests. Group replacements fell from 386,019 SQL / 2,431 requests to 198,740 / 1,251; session preparation fell from 19,465 requests to 10,004. Core quiet rebuild/cache counts match exactly, and background preparation width remains eight. Quiet whole-run +218 SQL / +21 requests includes transcript-index maintenance +209 / +19 and two extra initial vector-setup requests (+18 SQL), before any session group or suspension, through byte-identical vector setup. All increases are retained in the attribution.
Frozen-v3.1 standard pair: whole workload 3,004 SQL / 790 requests / 98 MAIN → 3,031 / 799 / 98. Ten warm causal turns have median [range] 46 [46–50] SQL → 46 [46–50], 11 [11–12] requests → 11 [11–13], and 0 MAIN → 0. Means are 46.7 / 11.2 / 0 → 46.7 / 11.3 / 0. All memory read, preparation, group-replacement and cache families are unchanged. The single additional warm request is the net of unchanged auth-profile reads (−4 SQL / −1 request), commit patch (+3 / +1) and plugin catalog (+1 / +1). Whole-run +27 SQL / +9 requests is entirely other maintenance/usage/deletion, model/plugin, commit, quarantine and metadata operations. Native errors are zero and duration coverage is complete in every accepted arm. Frozen harness hashes are unchanged.
Final test-only repair passed all 18 tests in the workspace-watcher and resume files (43.3 seconds command wall time), extension test types, type-aware lint, mock-export ratchet, formatting and diff checks. Watcher tests now await the existing owner-idle boundary and assert published rows before a search can repair them; bounded-drain and close assertions remain. Earlier CI repairs also retained pathname-custody protection and awaited cleanup while clearing successfully closed shadow state.
CI run
39544365556identified four inherited type errors:ui/src/components/overlay-registry.ts:32, TS2339,openClawModalLayersabsent fromDocument. They match current-main run39544978413at5be2b73ebf46, jobs119041151110,119041151122,119041151443, and119041151192; these UI files are untouched. The two in-scope failures (obsolete watcher synchronization and the mock annotation) are fixed in the final test-only commit. Final-head CI39547065636passed all 42 executed jobs (25 skipped), including all three PostgreSQL conformance shards. The requiredopenclaw/ci-gateis green (publisher39548862776). CI tested merge commitda733ab558545d520f319f9060a0413eb5a42794, whose main parentfbc99b8c03f5includes UI type fix20d2826d7c6. No branch integration was needed; the actual merge commit, rather than the stale API base field, was verified.Large-fixture validation caught an earlier candidate losing the background flag at watcher/automatic-recall admission; its measurements are excluded. The final watcher-boundary regression fails on that candidate (three groups instead of one after foreground activity starts), and passes with preserved background admission, no writes during suspension, and one final publication. The accepted candidate restores eight-source preparation and removes the rejected candidate’s +1,670 SQL / +391 cache-request anomaly.