Skip to content

fix(memory-wiki): finish snapshot recovery after search timeout - #187429

Merged
obviyus merged 3 commits into
openclaw:mainfrom
Baumus:fix/wiki-search-snapshot-recovery
Oct 29, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
Baumus:fix/wiki-search-snapshot-recovery

Conversation

@Baumus

@Baumus Baumus commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large-vault wiki_search can commit imports and then repeatedly cancel missing-snapshot recovery at its 30-second response deadline. Later searches restart the same repair without obtaining a usable snapshot.

User Impact

Shared import and snapshot publication can finish after an individual search times out or is cancelled. Subsequent searches use the recovered snapshot. Search/query cancellation remains prompt, and stopping the plugin still cancels and joins maintenance. No config or data migration is required.

Why This Change Was Made

Use the existing plugin-service signal for shared synchronization, while retaining the composed caller/deadline/service signal for the response race and query. Outside an active service, synchronization stays caller-bound. This repairs the maintenance lifetime edge of #166329 without adding a scheduler, retry mechanism or performance change. Contributor implementation and commits are retained.

Evidence

Built Gateway before/after captures and lifecycle controls.

  • Built pinned main and candidate independently in secretless Node 24.22.1 Linux Docker. Invoked bundled wiki_search through the shipped Gateway after plugin services were ready, using fresh valid 12,400-page synthetic vaults, real local compilation/storage/query and no paid keys, clock changes or compiler delays.
  • Main twice: searches timed out at 30.082s/30.083s; real compilation never published a snapshot.
  • Candidate twice: searches still timed out at 30.079s/30.078s, but real compilation published at 48.867s/46.899s; subsequent searches returned source snippets in 2.295s/2.200s.
  • Healthy-snapshot control returned results without another compile. Concurrent callers shared one repair; disconnect released the caller promptly. Service stop cancelled/joined compilation without publication; restart recovered successfully.
  • Consolidated maintenance and query cancellation regressions, including caller/service/deadline and outside-service fallback. Identical regression fails on main and passes on candidate; 4 focused files / 22 tests pass. Targeted formatting and oxlint pass.
  • Simplification retains one signal-selection change and no new production machinery. Against main: production +7/-1 (net +6); tests +40/-45 (net -5), no new test file. Real coordinator sharing remains covered by its existing suite and the Gateway proof.

Merge Danger

Two-way door: reverting restores the prior lifetime selection; no schema, config, protocol or published-contract changes. Blast radius is limited to Memory Wiki searches that synchronize or recover snapshots, especially large vaults. Existing service shutdown remains authoritative. Performance work is separate.

@clawsweeper

clawsweeper Bot commented Oct 29, 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets shared wiki synchronization finish after an individual search times out while preserving query cancellation and service shutdown.

Example: Search a 12,400-page vault without a compiled snapshot.

  • Before: The search times out after 30 seconds and cancels snapshot recovery.
  • After: The search still times out, but recovery publishes its snapshot and the next search returns results.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused fix with shipped-entry-point before/after proof, lifecycle controls, and no actionable findings; remaining CI is still running.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Exact-head built Gateway terminal evidence exercises /tools/invoke with real compilation, storage, and queries in secretless Linux Docker: recovery publishes after search timeout, later searches use the snapshot, concurrent callers share recovery, and shutdown cancels maintenance before publication.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Large-vault searches repeatedly time out without obtaining the snapshot needed for subsequent searches.
Reason: The change restores recoverable progress using the existing service owner and preserves the documented query deadline and cancellation behavior.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a current-main snapshot-recovery defect, and no actionable code findings remain.

Priority: P2
Reviewed head: 013a9a10a40d37a6bebc8a21f4c0af001625ee8c

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Memory Wiki search tool synchronizes configured vault sources before querying them; synchronization imports pages and publishes a compiled snapshot under the plugin service lifecycle.

flowchart TD
A[Gateway wiki search] --> B[Response deadline and caller cancellation]
A --> C[Shared source synchronization]
D[Plugin service lifetime] --> C
C --> E[Compiled snapshot publication]
E --> F[Caller bound query]
B --> F
F --> G[Search results]
Loading

Technical review

Best possible solution:

Use the existing service signal for shared synchronization while keeping search responses and queries caller-bound.

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

Current-main source directly couples recovery to the search deadline, and the supplied built-Gateway before/after traces reproduce the failure; this review did not execute target code.

Is this the best way to solve the issue?

The patch is the smallest complete fix: it corrects maintenance lifetime at the existing search integration without adding scheduling, retries, state, or a competing synchronization owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Search-triggered synchronization cancellation changes intended behavior with a stated reason (d462cac: Bound large searches to a deadline and stop query work when the turn is cancelled.)
  • Cancellation regression suite keeps the original intent (d462cac: Protect deadline, caller, and lifecycle cancellation; the revised suite retains query coverage and distinguishes shared maintenance.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 27e1bc9 adds extensions/memory-wiki/src/tool.ts:161 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 27e1bc92c282; files: extensions/memory-wiki/src/tool.ts)
  • Vincent Koc: Raw commit 5716d83 adds extensions/memory-wiki/src/tool.ts:89 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 5716d83336fd; files: extensions/memory-wiki/src/tool.ts)

PR surface

Source +6, Tests -5. Total +1 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 7 1 +6
Tests 1 40 45 -5
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 47 46 +1

Review metrics

Metric Value Why it matters
Production versus test LOC Production +7/-1; tests +40/-45 The production growth documents one signal-selection change; consolidated tests reduce net test code while covering the distinct cancellation lifetimes.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The defect prevents large-vault snapshot recovery from completing, with impact limited to Memory Wiki searches requiring synchronization.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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 (1 earlier review cycle)
  • reviewed 2026-10-29T07:29:55.895Z sha 4837157 :: needs real behavior proof before merge. :: none

Reviewed October 29, 2026, 5:01 AM ET / 09:01 UTC (Revision 2).

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Built Gateway recovery proof

Head: 013a9a10a40d37a6bebc8a21f4c0af001625ee8c (contributor production change unchanged; final commit consolidates tests). Baseline main: 933304ebaa40c3bcc6503567cbce7a480df808db.

Both refs were installed and built independently in secretless Linux/arm64 Docker, Node24.22.1. Each run used explicit isolated profile/config/state/database paths, disabled external integrations, and the bundled memory-wiki plugin with local search. Requests used the shipped Gateway /tools/invoke → wiki_search entry point after Gateway ready and plugin-service startup, not direct compiler/helper calls. No model, account or paid key was used.

Input: a fresh valid vault containing12,400 synthetic Markdown source pages (60 archive paragraphs and wikilinks per page), with no compiled publication. Real importer/synchronizer, Markdown scanner, backlink writer, compiler, SQLite snapshot store and local query reader ran unchanged. No mocked I/O, clock adjustment, compiler delay or30-second budget change.

main repetition1: search HTTP500 at30,082ms; Gateway log: wiki_search timed out after30s.
  real compile reservation31c2d69d-fb76-4cee-8d6e-7dc407696a9a
  no publication at deadline or10s after; snapshot remains missing.
main repetition2: search HTTP500 at30,083ms; same timeout.
  real compile reservation5fa691ff-1be1-4f1c-810f-115bc9e04a92
  no publication at deadline or10s after.

candidate repetition1: search HTTP500 at30,079ms; no publication yet.
  SAME reservationeee9da62-c04e-458b-b90a-c315af6ee7db publishes at48.867s.
  accepted publicationf1409901-e131-4ddd-966a-2e34f2813481;12,400 sources.
  next search HTTP200 in2,295ms, returns Source0/1/10 with archive snippets.
  healthy-snapshot control HTTP200 in2,043ms; no additional compile reservation.

candidate repetition2 (after service restart): search HTTP500 at30,078ms.
  reservation5eacc823-77cc-4de3-b924-1d09eb034c83 publishes at46.899s.
  accepted publication3d7e58e6-1a69-41eb-987e-384ebea3aa91;12,400 sources.
  next search HTTP200 in2,200ms, returns Source0/1 with archive snippets.

lifecycle control before repetition2:
  two concurrent HTTP searches share ONE reservation45c8a069-befd-4abf-9a56-a0c598d87751.
  caller disconnect returns promptly (665ms from request start).
  service SIGTERM exits in1,424ms, clean shutdown; compile never publishes.
  journal remains unchanged after exit; restart then recovers as above.

Focused regression: the identical consolidated cancellation suite fails on main because the search deadline aborts maintenance, while the query-cancellation control passes. Candidate:4 files/22 tests pass (tool deadline, tool, source-sync, plugin lifecycle). The suite also retains caller cancellation, service cancellation and caller-bound fallback outside an active service. Targeted oxlint:0 warnings/errors. Test-line delta against main -5; production +6. The contributor's commits remain intact.

Proof limitation/setup note: an initial harness used /health before plugin services finished starting; that intentionally caller-bound fallback cannot prove active-service behavior and is excluded from the matrix above. The corrected harness waits for Gateway ready. A retry on that partially updated vault compiled within30s, so it is only a healthy/recovery control, not counted as changed-behavior proof. The two main failures and two candidate timeout/publication runs above use the proper service boundary.

This addresses the actual lifetime defect: a search deadline/caller abort must not cancel shared recovery. It does not claim main lets recovery escape service shutdown; shutdown already owns cancellation/joining and remains effective.

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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 Oct 29, 2026
@obviyus
obviyus merged commit 12ee7bb into openclaw:main Oct 29, 2026
119 of 120 checks passed
@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Landed in 12ee7bb. Thanks @Baumus. A timed-out wiki search no longer cancels snapshot recovery.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
…claw#187429)

fix(memory-wiki): let snapshot recovery finish when a search times out

When a wiki search hit its 30 s deadline, or its caller went away, it also cancelled the shared snapshot compile that was recovering the vault, so the snapshot was never published and later searches kept failing. Recovery now runs under the existing service lifetime: one search can time out without cancelling it, and service shutdown still cancels and joins it.

Evidence: built Gateway with real 12,400-page vaults. On main the search failed at 30 s and no snapshot was published (twice); with this change the search still timed out, but the snapshot was published at about 47 to 49 s and later searches succeeded (twice). Healthy-snapshot, concurrent-search, caller-disconnect, service-cancellation and restart-recovery controls behave correctly. Details: openclaw#187429 (comment).

Thanks @Baumus.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 27, 2026
…#188256)

Root cause: `extensions/memory-wiki/src/tool.ts:174` awaits `syncMemoryWikiImportedSources` (import, then a full compile) inside the 30 s `wiki_search` deadline, and `extensions/memory-wiki/src/gateway.ts:277` awaits the same sync before `wiki.search` with no deadline, so a large pending import fails or stalls searches for pages that are already on disk.

Related: #187429, #132296, #166329

## What Problem This Solves

Fixes: `wiki_search` fails with "wiki_search timed out after 30s", and the `wiki.search` Gateway method hangs, when a large vault has source changes waiting to import and compile. The pages being searched for are already on disk.

## User Impact

Searches answer from the current wiki at once while the Gateway imports and compiles in the background. Content that changed in the sources since the last refresh shows up on the next search, not this one. That one-search delay is the only staleness: pages written with `wiki_apply` are read live, and a vault with no compiled snapshot yet still answers through the existing full scan.

Unchanged: `wiki_get`, `openclaw wiki search`, imports, compile, lint, apply and status still wait for the sync. `ingest.autoCompile: false` still never compiles. A caller with no running wiki service (one-shot hosts) still waits as before.

## Why This Change Was Made

When the wiki service is running, `wiki_search` and `wiki.search` run the query first and then start the service-owned source sync that the Overview and Import Insights dashboards already use (#132296). That helper moves from `gateway.ts` to `source-sync.ts` as `refreshMemoryWikiImportedSources`. It still single-flights equal requests, queues on the vault mutation lock, is cancelled by the service signal and is joined at shutdown. The refresh starts after the query because a cold read owner activates through the same vault queue, so a refresh started first would block the search.

The helper runs the sync with `runInDetachedAsyncContext`. Without it the built Gateway aborted every refresh after the `/tools/invoke` response with `Failed to open the plugin state database. | This operation was aborted`, so nothing was ever published. The dashboard path on main has the same defect and this fixes it too.

This takes over Baumus's PR. Thanks @Baumus for finding this, carrying the fix in your own deployment since 2026.10.10 and for the real-Gateway proof (#188256 (comment)), which also found the async-scope abort. Your commits stay in the branch. The commits on top replace the refresh coordinator (60 s freshness window, 5–60 s retry backoff, retry handles), the move to the plugin service scheduler, the query hook, the README section and the test-line allocation with the existing dashboard helper. No new freshness or retry policy is needed: the next search or dashboard poll is the retry, as for dashboards today.

## Evidence

The built Gateway (dist) runs in an isolated profile with a task-owned state, config and port. Requests go through `/tools/invoke` → `wiki_search` and through `openclaw gateway call wiki.search`. The importer and compiler are the real unsafe-local ones, with no mocks or delays. Fixture: a compiled vault with one `entities/cobalt.md`, then 6,000 new synthetic source files. Source `0` contains "Zirconium publication evidence." Harness and raw captures: #188256 (comment).

| Run | Base 6052fff | This PR |
| --- | --- | --- |
| `wiki_search cobalt`, run 1 | HTTP 500 at 30.5 s, `wiki_search timed out after 30s` | HTTP 200 at 4.9 s, `entities/cobalt.md`, 0 pages imported, no new publication |
| `wiki_search cobalt`, run 2 | HTTP 500 at 30.4 s, `wiki_search timed out after 30s` | HTTP 200 at 4.3 s, `entities/cobalt.md` |
| `wiki_search zirconium` after publication | n/a | HTTP 200 at 8.4 s, the newly imported source page |
| `wiki.search` RPC (`openclaw gateway call`), twice | no answer within 600 s; all 6,000 imported, still no publication | `entities/cobalt.md` in 8.8 s and 7.7 s; after publication `zirconium` returns the new page |

Controls on this PR:
- Cold vault with no compiled snapshot: answers `cobalt` in 4.3 s through the scan fallback.
- Two concurrent searches plus one `wiki.overview` poll: all answer, and exactly one compile is published.
- SIGTERM during the refresh: exit 0 in 2.2 s, no publication, journal unchanged after exit.
- `ingest.autoCompile: false`: the search answers, all 6,000 sources import, and nothing compiles.
- One-shot `openclaw wiki search zirconium`: still waits for import and compile (508 s on a loaded host) and returns the new page.
- Without `runInDetachedAsyncContext`, both runs logged `background source sync failed: Failed to open the plugin state database. | This operation was aborted` and never published.

Unit: `tool.deadline.test.ts` "answers from the current index while the service refreshes" fails on base with `wiki_search timed out after 30s` and passes here. Focused memory-wiki suites pass: 8 files, 95 tests. Local review on the head reports no findings.

## Merge Danger

Two-way door. No config, schema, protocol or stored-data change; a revert restores the awaited sync. Blast radius: memory-wiki search through the agent tool and the `wiki.search` Gateway method while the plugin service runs.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…#188256)

Root cause: `extensions/memory-wiki/src/tool.ts:174` awaits `syncMemoryWikiImportedSources` (import, then a full compile) inside the 30 s `wiki_search` deadline, and `extensions/memory-wiki/src/gateway.ts:277` awaits the same sync before `wiki.search` with no deadline, so a large pending import fails or stalls searches for pages that are already on disk.

Related: #187429, #132296, #166329

## What Problem This Solves

Fixes: `wiki_search` fails with "wiki_search timed out after 30s", and the `wiki.search` Gateway method hangs, when a large vault has source changes waiting to import and compile. The pages being searched for are already on disk.

## User Impact

Searches answer from the current wiki at once while the Gateway imports and compiles in the background. Content that changed in the sources since the last refresh shows up on the next search, not this one. That one-search delay is the only staleness: pages written with `wiki_apply` are read live, and a vault with no compiled snapshot yet still answers through the existing full scan.

Unchanged: `wiki_get`, `openclaw wiki search`, imports, compile, lint, apply and status still wait for the sync. `ingest.autoCompile: false` still never compiles. A caller with no running wiki service (one-shot hosts) still waits as before.

## Why This Change Was Made

When the wiki service is running, `wiki_search` and `wiki.search` run the query first and then start the service-owned source sync that the Overview and Import Insights dashboards already use (#132296). That helper moves from `gateway.ts` to `source-sync.ts` as `refreshMemoryWikiImportedSources`. It still single-flights equal requests, queues on the vault mutation lock, is cancelled by the service signal and is joined at shutdown. The refresh starts after the query because a cold read owner activates through the same vault queue, so a refresh started first would block the search.

The helper runs the sync with `runInDetachedAsyncContext`. Without it the built Gateway aborted every refresh after the `/tools/invoke` response with `Failed to open the plugin state database. | This operation was aborted`, so nothing was ever published. The dashboard path on main has the same defect and this fixes it too.

This takes over Baumus's PR. Thanks @Baumus for finding this, carrying the fix in your own deployment since 2026.10.10 and for the real-Gateway proof (#188256 (comment)), which also found the async-scope abort. Your commits stay in the branch. The commits on top replace the refresh coordinator (60 s freshness window, 5–60 s retry backoff, retry handles), the move to the plugin service scheduler, the query hook, the README section and the test-line allocation with the existing dashboard helper. No new freshness or retry policy is needed: the next search or dashboard poll is the retry, as for dashboards today.

## Evidence

The built Gateway (dist) runs in an isolated profile with a task-owned state, config and port. Requests go through `/tools/invoke` → `wiki_search` and through `openclaw gateway call wiki.search`. The importer and compiler are the real unsafe-local ones, with no mocks or delays. Fixture: a compiled vault with one `entities/cobalt.md`, then 6,000 new synthetic source files. Source `0` contains "Zirconium publication evidence." Harness and raw captures: #188256 (comment).

| Run | Base 6052fff | This PR |
| --- | --- | --- |
| `wiki_search cobalt`, run 1 | HTTP 500 at 30.5 s, `wiki_search timed out after 30s` | HTTP 200 at 4.9 s, `entities/cobalt.md`, 0 pages imported, no new publication |
| `wiki_search cobalt`, run 2 | HTTP 500 at 30.4 s, `wiki_search timed out after 30s` | HTTP 200 at 4.3 s, `entities/cobalt.md` |
| `wiki_search zirconium` after publication | n/a | HTTP 200 at 8.4 s, the newly imported source page |
| `wiki.search` RPC (`openclaw gateway call`), twice | no answer within 600 s; all 6,000 imported, still no publication | `entities/cobalt.md` in 8.8 s and 7.7 s; after publication `zirconium` returns the new page |

Controls on this PR:
- Cold vault with no compiled snapshot: answers `cobalt` in 4.3 s through the scan fallback.
- Two concurrent searches plus one `wiki.overview` poll: all answer, and exactly one compile is published.
- SIGTERM during the refresh: exit 0 in 2.2 s, no publication, journal unchanged after exit.
- `ingest.autoCompile: false`: the search answers, all 6,000 sources import, and nothing compiles.
- One-shot `openclaw wiki search zirconium`: still waits for import and compile (508 s on a loaded host) and returns the new page.
- Without `runInDetachedAsyncContext`, both runs logged `background source sync failed: Failed to open the plugin state database. | This operation was aborted` and never published.

Unit: `tool.deadline.test.ts` "answers from the current index while the service refreshes" fails on base with `wiki_search timed out after 30s` and passes here. Focused memory-wiki suites pass: 8 files, 95 tests. Local review on the head reports no findings.

## Merge Danger

Two-way door. No config, schema, protocol or stored-data change; a revert restores the awaited sync. Blast radius: memory-wiki search through the agent tool and the `wiki.search` Gateway method while the plugin service runs.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit f9f7bf7)
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…#188256)

Root cause: `extensions/memory-wiki/src/tool.ts:174` awaits `syncMemoryWikiImportedSources` (import, then a full compile) inside the 30 s `wiki_search` deadline, and `extensions/memory-wiki/src/gateway.ts:277` awaits the same sync before `wiki.search` with no deadline, so a large pending import fails or stalls searches for pages that are already on disk.

Related: #187429, #132296, #166329

## What Problem This Solves

Fixes: `wiki_search` fails with "wiki_search timed out after 30s", and the `wiki.search` Gateway method hangs, when a large vault has source changes waiting to import and compile. The pages being searched for are already on disk.

## User Impact

Searches answer from the current wiki at once while the Gateway imports and compiles in the background. Content that changed in the sources since the last refresh shows up on the next search, not this one. That one-search delay is the only staleness: pages written with `wiki_apply` are read live, and a vault with no compiled snapshot yet still answers through the existing full scan.

Unchanged: `wiki_get`, `openclaw wiki search`, imports, compile, lint, apply and status still wait for the sync. `ingest.autoCompile: false` still never compiles. A caller with no running wiki service (one-shot hosts) still waits as before.

## Why This Change Was Made

When the wiki service is running, `wiki_search` and `wiki.search` run the query first and then start the service-owned source sync that the Overview and Import Insights dashboards already use (#132296). That helper moves from `gateway.ts` to `source-sync.ts` as `refreshMemoryWikiImportedSources`. It still single-flights equal requests, queues on the vault mutation lock, is cancelled by the service signal and is joined at shutdown. The refresh starts after the query because a cold read owner activates through the same vault queue, so a refresh started first would block the search.

The helper runs the sync with `runInDetachedAsyncContext`. Without it the built Gateway aborted every refresh after the `/tools/invoke` response with `Failed to open the plugin state database. | This operation was aborted`, so nothing was ever published. The dashboard path on main has the same defect and this fixes it too.

This takes over Baumus's PR. Thanks @Baumus for finding this, carrying the fix in your own deployment since 2026.10.10 and for the real-Gateway proof (#188256 (comment)), which also found the async-scope abort. Your commits stay in the branch. The commits on top replace the refresh coordinator (60 s freshness window, 5–60 s retry backoff, retry handles), the move to the plugin service scheduler, the query hook, the README section and the test-line allocation with the existing dashboard helper. No new freshness or retry policy is needed: the next search or dashboard poll is the retry, as for dashboards today.

## Evidence

The built Gateway (dist) runs in an isolated profile with a task-owned state, config and port. Requests go through `/tools/invoke` → `wiki_search` and through `openclaw gateway call wiki.search`. The importer and compiler are the real unsafe-local ones, with no mocks or delays. Fixture: a compiled vault with one `entities/cobalt.md`, then 6,000 new synthetic source files. Source `0` contains "Zirconium publication evidence." Harness and raw captures: #188256 (comment).

| Run | Base 6052fff | This PR |
| --- | --- | --- |
| `wiki_search cobalt`, run 1 | HTTP 500 at 30.5 s, `wiki_search timed out after 30s` | HTTP 200 at 4.9 s, `entities/cobalt.md`, 0 pages imported, no new publication |
| `wiki_search cobalt`, run 2 | HTTP 500 at 30.4 s, `wiki_search timed out after 30s` | HTTP 200 at 4.3 s, `entities/cobalt.md` |
| `wiki_search zirconium` after publication | n/a | HTTP 200 at 8.4 s, the newly imported source page |
| `wiki.search` RPC (`openclaw gateway call`), twice | no answer within 600 s; all 6,000 imported, still no publication | `entities/cobalt.md` in 8.8 s and 7.7 s; after publication `zirconium` returns the new page |

Controls on this PR:
- Cold vault with no compiled snapshot: answers `cobalt` in 4.3 s through the scan fallback.
- Two concurrent searches plus one `wiki.overview` poll: all answer, and exactly one compile is published.
- SIGTERM during the refresh: exit 0 in 2.2 s, no publication, journal unchanged after exit.
- `ingest.autoCompile: false`: the search answers, all 6,000 sources import, and nothing compiles.
- One-shot `openclaw wiki search zirconium`: still waits for import and compile (508 s on a loaded host) and returns the new page.
- Without `runInDetachedAsyncContext`, both runs logged `background source sync failed: Failed to open the plugin state database. | This operation was aborted` and never published.

Unit: `tool.deadline.test.ts` "answers from the current index while the service refreshes" fails on base with `wiki_search timed out after 30s` and passes here. Focused memory-wiki suites pass: 8 files, 95 tests. Local review on the head reports no findings.

## Merge Danger

Two-way door. No config, schema, protocol or stored-data change; a revert restores the awaited sync. Blast radius: memory-wiki search through the agent tool and the `wiki.search` Gateway method while the plugin service runs.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit f9f7bf7)
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…openclaw#188256)

Root cause: `extensions/memory-wiki/src/tool.ts:174` awaits `syncMemoryWikiImportedSources` (import, then a full compile) inside the 30 s `wiki_search` deadline, and `extensions/memory-wiki/src/gateway.ts:277` awaits the same sync before `wiki.search` with no deadline, so a large pending import fails or stalls searches for pages that are already on disk.

Related: openclaw#187429, openclaw#132296, openclaw#166329

## What Problem This Solves

Fixes: `wiki_search` fails with "wiki_search timed out after 30s", and the `wiki.search` Gateway method hangs, when a large vault has source changes waiting to import and compile. The pages being searched for are already on disk.

## User Impact

Searches answer from the current wiki at once while the Gateway imports and compiles in the background. Content that changed in the sources since the last refresh shows up on the next search, not this one. That one-search delay is the only staleness: pages written with `wiki_apply` are read live, and a vault with no compiled snapshot yet still answers through the existing full scan.

Unchanged: `wiki_get`, `openclaw wiki search`, imports, compile, lint, apply and status still wait for the sync. `ingest.autoCompile: false` still never compiles. A caller with no running wiki service (one-shot hosts) still waits as before.

## Why This Change Was Made

When the wiki service is running, `wiki_search` and `wiki.search` run the query first and then start the service-owned source sync that the Overview and Import Insights dashboards already use (openclaw#132296). That helper moves from `gateway.ts` to `source-sync.ts` as `refreshMemoryWikiImportedSources`. It still single-flights equal requests, queues on the vault mutation lock, is cancelled by the service signal and is joined at shutdown. The refresh starts after the query because a cold read owner activates through the same vault queue, so a refresh started first would block the search.

The helper runs the sync with `runInDetachedAsyncContext`. Without it the built Gateway aborted every refresh after the `/tools/invoke` response with `Failed to open the plugin state database. | This operation was aborted`, so nothing was ever published. The dashboard path on main has the same defect and this fixes it too.

This takes over Baumus's PR. Thanks @Baumus for finding this, carrying the fix in your own deployment since 2026.10.10 and for the real-Gateway proof (openclaw#188256 (comment)), which also found the async-scope abort. Your commits stay in the branch. The commits on top replace the refresh coordinator (60 s freshness window, 5–60 s retry backoff, retry handles), the move to the plugin service scheduler, the query hook, the README section and the test-line allocation with the existing dashboard helper. No new freshness or retry policy is needed: the next search or dashboard poll is the retry, as for dashboards today.

## Evidence

The built Gateway (dist) runs in an isolated profile with a task-owned state, config and port. Requests go through `/tools/invoke` → `wiki_search` and through `openclaw gateway call wiki.search`. The importer and compiler are the real unsafe-local ones, with no mocks or delays. Fixture: a compiled vault with one `entities/cobalt.md`, then 6,000 new synthetic source files. Source `0` contains "Zirconium publication evidence." Harness and raw captures: openclaw#188256 (comment).

| Run | Base fa7a528 | This PR |
| --- | --- | --- |
| `wiki_search cobalt`, run 1 | HTTP 500 at 30.5 s, `wiki_search timed out after 30s` | HTTP 200 at 4.9 s, `entities/cobalt.md`, 0 pages imported, no new publication |
| `wiki_search cobalt`, run 2 | HTTP 500 at 30.4 s, `wiki_search timed out after 30s` | HTTP 200 at 4.3 s, `entities/cobalt.md` |
| `wiki_search zirconium` after publication | n/a | HTTP 200 at 8.4 s, the newly imported source page |
| `wiki.search` RPC (`openclaw gateway call`), twice | no answer within 600 s; all 6,000 imported, still no publication | `entities/cobalt.md` in 8.8 s and 7.7 s; after publication `zirconium` returns the new page |

Controls on this PR:
- Cold vault with no compiled snapshot: answers `cobalt` in 4.3 s through the scan fallback.
- Two concurrent searches plus one `wiki.overview` poll: all answer, and exactly one compile is published.
- SIGTERM during the refresh: exit 0 in 2.2 s, no publication, journal unchanged after exit.
- `ingest.autoCompile: false`: the search answers, all 6,000 sources import, and nothing compiles.
- One-shot `openclaw wiki search zirconium`: still waits for import and compile (508 s on a loaded host) and returns the new page.
- Without `runInDetachedAsyncContext`, both runs logged `background source sync failed: Failed to open the plugin state database. | This operation was aborted` and never published.

Unit: `tool.deadline.test.ts` "answers from the current index while the service refreshes" fails on base with `wiki_search timed out after 30s` and passes here. Focused memory-wiki suites pass: 8 files, 95 tests. Local review on the head reports no findings.

## Merge Danger

Two-way door. No config, schema, protocol or stored-data change; a revert restores the awaited sync. Blast radius: memory-wiki search through the agent tool and the `wiki.search` Gateway method while the plugin service runs.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-wiki P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

2 participants