Skip to content

fix(memory): prevent dirty-index maintenance from delaying searches - #139230

Merged
steipete merged 12 commits into
openclaw:mainfrom
Barry-886:fix/memory-search-lifecycle-reconcile
Nov 5, 2026
Merged

steipete merged 12 commits into
openclaw:mainfrom
Barry-886:fix/memory-search-lifecycle-reconcile

Conversation

@Barry-886

@Barry-886 Barry-886 commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #137366

What Problem This Solves

A dirty resident memory index made interactive searches start source-wide reconciliation, competing with retrieval even when a usable published index already existed.

User Impact

Resident searches use the published index without launching ordinary or full-retry reconciliation. Pending updates remain visible through the existing stale-result fields. Watcher updates continue normally, and the existing idle-indexing timer now provides five-minute recovery for missed events, including during a running turn. Standalone CLI searches refresh sources before reading.

There are no new configuration options, schema changes, or index-format changes. Existing indexes remain usable after updating; no manual migration is required. Empty-index bootstrap and required identity repair retain their existing behavior. Provider failures and full-rebuild cooldowns can delay successful publication: the five-minute deadline bounds admission of recovery, not completion under an unavailable provider.

Why This Change Was Made

Recovery reuses the session indexing owner's existing SESSION_MAX_DEFERRAL_MS and timer, plus the existing detached maintenance operation. Activity cannot move its recovery deadline. Ordinary session work still prefers idle periods. CLI freshness uses the automatic cli-search sync path, preserving format-repair notices and embedding fallback custody; its redundant pre-search diagnostic scan is removed. Legacy Gateway RPC searches borrow the service-owned resident manager, while the explicit CLI owner RPC keeps its transient lifecycle. Recovery shares the existing retry settlement and cooldowns. Pending-update guidance uses the existing agent-scoped repair formatter and cost disclosure; timer failures retain nested diagnostic details. Teardown joins admitted recovery and closes the existing timer and watcher resources.

This incorporates @Barry-886's original separation of resident retrieval and reconciliation into the current maintenance owners. All three contributor commits are preserved; current main was merged into the branch without rebasing or force-pushing.

Production: +101/-102 lines (net -1). Tests/support: +282/-300 (net -18). Documentation: +15/-8.

Evidence

  • Both dirty-search regression variants fail on current main because search acquires a maintenance manager. The missed-event regressions also fail on main. They pass with this change, including continuous activity, exhausted watching, source publication, and owned timer/watcher teardown.
  • Native macOS, Node 26.12.1, isolated Gateway on port 20460, SQLite, and shared Ollama nomic-embed-text: five dirty searches started one source-wide pass on main and zero on the candidate. On the final head, the legacy memory.search RPC returned in 2.485 s including a new CLI connection. Five tool reads then took 210 ms followed by 29–36 ms, all reporting pending updates and starting zero source-wide syncs. These are a small synthetic functional workload, not a benchmark of the reporter's large Linux corpus.
  • Native events were suppressed for a new synthetic note while a real Gateway agent turn stayed open at a local relay. The existing five-minute recovery made the note searchable after 296.588 seconds, before that turn ended. Pending staleness cleared after publication. Releasing the relay produced a real qwen2.5:7b answer, RECOVERY-PROOF-OK. Gateway process teardown took 430 ms and the listener closed.
  • CLI add/edit/delete regressions pass before manager close. The final-head native one-shot CLI read found a new note after Gateway shutdown in 3.564 s including CLI startup; the earlier edit proof took 4.637 s. No task-owned listener or child process remained after teardown.
  • Final admission repair: CLI preflight now propagates database capability and worker overload errors using the same rule as bootstrap/repair. A new capability regression fails on the preceding code and passes with the fix; all 37 search/bootstrap/active-retrieval cases pass in 65.33 s. The active-retrieval fixtures now use resident ownership, preserving their synthetic rows and cleanup gates (nine cases also passed in 31.85 s).
  • Final cooldown suite: all 21 cases pass in 25.97 s, exercising publication through watch/recovery while preserving the original cooldown and request-count assertions.
  • CI follow-up: nine scheduler/retrieval tests pass in 31.53 s and all 19 affected memory tool tests pass in 50.37 s. Scheduler construction now uses the fake clock from the start; retrieval fixtures use resident ownership; pending-state and retry tests follow the timer-owned contract. Production source is unchanged from the live-tested head.
  • Final review follow-up adds 18 passing targeted checks (53.94 s) for scoped guidance, nested recovery errors, Gateway response text, and resident/CLI preservation of newer chunking/provenance versions. Scoped guidance, nested errors, and both CLI rollback cases were demonstrated red with their original defective code.
  • Final follow-up validation: all 62 tests passed across the Gateway RPC, search orchestration, watcher configuration, session scheduling, and startup/close suites (179.16 s wrapper wall time; Gateway shard 25.64 s, memory shard 130.53 s). Prior unchanged sibling proof covers 11 staleness cases and 48 startup/close/tool cases (77.74 s). The database-worker suites preserve real publication/lifecycle boundaries; no real sleeps or timers were added to committed tests.
  • Final pnpm build passed in 2m 29.4s; UI budget warnings match the main baseline. Scoped memory typecheck, scoped lint/format, and all baseline ratchets pass, including line cap and a shrinking test-line budget. A broader local extension typecheck hits an unrelated missing @openclaw/crabbox-provider/cli-runtime-api.js declaration. Prompt snapshots regenerate unchanged (token delta 0).
  • Codex autoreview of base af7ea2ba51a906fe2e6e2dd6b7ad0ba101ba1a83 to head fb9eb894586c1eab9fff184682392c4836915394, with source/sync/recovery/registry context: scoped-clean, no actionable P0–P2 findings.

Recorded trace of the final scheduling implementation (native Gateway, SQLite, shared Ollama; synthetic notes):

rpc-search ms 3202
search-0: 266 ms, memory/seed.md, stale=true
search-1..4: 32–35 ms, memory/seed.md, stale=true
resident search source-wide syncs 0
after-deadline-1: 34 ms, memory/missed.md + memory/seed.md
catchupMs=296588, agentStillRunning=true
model reply: RECOVERY-PROOF-OK
gateway teardown ms 430
cli-fresh ms 7128
recorded task processes remaining: []; listeners: []

The later error-handling and fixture repairs reuse this scheduling evidence because they do not change timer scheduling, source publication, or cleanup. With the final production bytes, real CLI searches preserved both newer chunking and provenance metadata, chunk counts, and index revisions (3.217 s and 3.231 s). An older provenance index then repaired successfully and retained the automatic-repair/provider-cost notice (3.873 s).

Platform limitation: this repair has native macOS proof; the reporter's full-size Linux workload and native Windows were not rerun. CI and advisory review are tracked against the pushed head.

The five-minute timing proof reuses the unchanged scheduling implementation; the final Gateway/CLI compatibility proof was repeated on fb9eb894586c1eab9fff184682392c4836915394 after the admission-error repair.

Final exact-head CI run 42010254552 passed: 48 successful jobs, 28 intentionally skipped, including all three PostgreSQL conformance shards and openclaw/ci-gate. ClawSweeper reviewed this head with no actionable findings or before-merge items; local Codex review is also scoped-clean at P0–P2.

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Moves resident memory reconciliation to the existing recovery timer and refreshes standalone CLI searches before retrieval.

Example: Search memory/seed.md repeatedly while memory/missed.md awaits indexing.

  • Before: Five dirty searches started a source-wide maintenance pass alongside retrieval.
  • After: Resident searches started no source-wide passes, and timer recovery made the missed note searchable during an active turn.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused repair with production-entry-point evidence, meaningful compatibility regressions, and no open findings; the supplied workload is synthetic rather than the reporter's full corpus.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied native macOS Gateway, agent, SQLite, and Ollama traces exercise resident dirty reads without reconciliation, missed-event recovery during an active turn, standalone CLI freshness, and shutdown; final production-byte CLI runs preserve newer chunking/provenance metadata and disclose older-index repair costs. The full-size Linux workload remains unmeasured, and unavailable videos belong to a related PR rather than this proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Interactive memory searches compete with dirty-index reconciliation and can time out despite a usable published index.
Reason: The repair removes unnecessary foreground-triggered work, retains eventual freshness, and has been explicitly adopted by the scheduler's feature owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses dirty-search reconciliation still present on current main, preserves CLI freshness, and has no actionable findings in the reviewed head.

Priority: P1
Reviewed head: fb9eb894586c1eab9fff184682392c4836915394

Before merge

None.

Findings

None.

Agent review details

How this fits together

Memory Core receives tool, Gateway, and CLI queries, reads a published index, and uses watcher and timer maintenance to publish updated memory and transcript sources.

flowchart LR
  A[Tool and Gateway searches] --> B[Resident memory manager]
  C[Standalone CLI search] --> D[Refresh sources]
  D --> E[Published index]
  B --> E
  F[Watchers and recovery timer] --> G[Existing maintenance owner]
  G --> E
  E --> H[Results and freshness guidance]
Loading

Technical review

Best possible solution:

Retain this focused repair using the existing maintenance and timer owners, with published resident reads and fresh one-shot CLI reads.

Do we have a high-confidence way to reproduce the issue?

Current main visibly schedules maintenance from dirty searches, matching the linked report and supplied baseline trace; this read-only review ran no target code.

Is this the best way to solve the issue?

The change fixes the scheduling boundary using existing owners, removes the replaced search path, and preserves bootstrap, identity repair, retry custody, and CLI freshness.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5382559b66da.

Provenance checked

  • Published-index retrieval and detached maintenance keeps the original intent (a7766f1: Keep a stable published generation readable while a separate maintenance manager builds updates.)
  • Search-triggered reconciliation and watcher fallback changes intended behavior with a stated reason (563b155: Search refresh recovered changes after native watcher exhaustion; this PR replaces that trigger with periodic recovery to avoid retrieval contention.)
  • Session quiet-period scheduling changes intended behavior with a stated reason (8e02d1a: Batch transcript indexing during idle periods and prioritize foreground turns; the current owner explicitly adds deadline recovery during active turns while preserving ordinary idle scheduling.)
  • Routine dirty-state diagnostics changes intended behavior with a stated reason (162df44: Avoid presenting routine pending work as failed indexing; this PR deliberately reports pending published-index freshness with retry-first guidance because reconciliation no longer starts on search.)
  • CLI refresh lifecycle keeps the original intent (16d1b9e: Finish CLI-started refreshes before releasing their database connection; refreshing before retrieval preserves that publication guarantee.)
  • Newer-index preservation and rebuild disclosure keeps the original intent (e9c1cb7: Automatic searches must preserve newer indexes and disclose automatic rebuild costs; cli-search retains those existing guards.)
  • Nested maintenance failure diagnostics keeps the original intent (13b6f39: Expose nested failure causes through the existing formatter; the replacement recovery warning retains that behavior.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 8e02d1a adds extensions/memory-core/src/memory/manager-session-sync-ops.ts:363 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8e02d1ae9694; files: extensions/memory-core/src/memory/manager-session-sync-ops.ts)

PR surface

Source -1, Tests -18, Docs +7. Total -12 across 24 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 10 101 102 -1
Tests 13 282 300 -18
Docs 1 15 8 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 398 410 -12

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test changes Production +101/-102; tests/support +282/-300 The repair removes search-triggered machinery and adapts existing recovery, compatibility, and lifecycle regressions without net code growth.

Root-cause cluster

Relationship: same_root_cause
Canonical: #137366
Summary: This PR addresses the canonical issue's search-triggered reconciliation; merged contention and CLI-settlement repairs cover adjacent problems.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Dirty memory searches can contend with reconciliation and time out in real agent workflows.
  • merge-risk: 🚨 compatibility: Resident freshness timing, successful-response stale fields, and CLI refresh timing change deliberately; the feature owner's integration records this direction and the supplied proof exercises those contracts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (8 earlier review cycles)
  • reviewed 2026-09-05T17:15:09.951Z sha a6ceeb2 :: blocked before merge. :: [P1] [P1] Keep sweep observations out of diagnostic status activation | [P1] [P1] Preserve CLI refresh or explicitly report skipped freshness
  • reviewed 2026-09-05T18:53:47.058Z sha 8015b98 :: blocked before merge. :: [P3] Update the documented search-triggered freshness behavior
  • reviewed 2026-09-05T19:10:38.821Z sha 8bd39c0 :: blocked before merge. :: none
  • reviewed 2026-10-04T08:22:42.645Z sha 8bd39c0 :: blocked before merge. :: none
  • reviewed 2026-11-01T19:53:58.941Z sha 8bd39c0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-05T09:10:37.079Z sha 6089aed :: needs real behavior proof before merge. :: [P1] Preserve newer-index protection during CLI search refresh | [P2] Retain automatic-repair notices for CLI searches | [P2] Keep pending-update recovery scoped to the affected agent | [P2] Migrate affected scheduling and lifecycle test consumers | [P3] Preserve nested failure details at the recovery warning sink
  • reviewed 2026-11-05T09:35:51.040Z sha a65d6ff :: needs real behavior proof before merge. :: [P2] Keep pending-update recovery scoped to the affected agent | [P2] Update the real-manager tool test for pending-update fields | [P3] Preserve nested failure details at the recovery warning sink
  • reviewed 2026-11-05T10:03:28.267Z sha bdf7f43 :: needs maintainer review before merge. :: none

Reviewed November 5, 2026, 5:28 AM ET / 10:28 UTC (Revision 9).

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 5, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 1, 2026
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@steipete
steipete merged commit 5a22b8c into openclaw:main Nov 5, 2026
147 of 150 checks passed
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
…penclaw#139230)

* fix(memory): prevent dirty-index maintenance from delaying searches

Signed-off-by: Barry-886 <[email protected]>

* fix(memory): preserve CLI freshness and cheap sweep status

Signed-off-by: Barry-886 <[email protected]>

* docs(memory): explain resident and CLI freshness

Signed-off-by: Barry-886 <[email protected]>

* test(memory): exercise deadline recovery and owned timer teardown

* test(memory): name the scoped bootstrap spy binding

* test(memory): restore the bootstrap spy explicitly

* fix(memory): preserve recovery retries and resident RPC ownership

* fix(memory): preserve scoped recovery guidance and error details

* test(memory): align recovery fixtures with resident ownership

* test(memory): exercise cooldowns through recovery owners

* fix(memory): preserve CLI search admission failures

---------

Signed-off-by: Barry-886 <[email protected]>
Co-authored-by: Barry-886 <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: memory_search triggers full source reconciliation while dirty, causing CPU starvation and timeouts

2 participants