Repository navigation
fix(memory-wiki): stop long searches on deadline or turn cancellation - #166329
Conversation
|
🦞👀 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. |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Codex review: blocked before merge. Reviewed October 6, 2026, 7:29 PM ET / 23:29 UTC (Revision 3). ClawSweeper reviewWhat this changesMemory Wiki searches gain a 30-second deadline and honor turn cancellation while reading pages, scoring results, and searching shared memory. Merge readiness⛔ Blocked before merge - 1 item remains This remains a useful fix with convincing runtime evidence and no blocking findings. The prior migration concern does not apply because the patch changes no persisted-data contract. Priority: P1 Review scores
Verification
How this fits togetherMemory Wiki searches compiled knowledge and Markdown vault pages for agent tools. Its search tool combines caller cancellation with plugin lifecycle cancellation, then returns ranked results or an explicit tool error. flowchart TD
A[Agent search request] --> C[Search deadline and cancellation]
B[Turn and plugin signals] --> C
C --> D[Source synchronization]
D --> E[Vault reading and scoring]
D --> F[Shared memory search]
E --> G[Ranked results or tool error]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource +77, Tests +94, Docs +4. Total +175 across 9 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep search cancellation at the tool boundary, preserve existing ranking and vault formats, and report deadline failures explicitly. Do we have a high-confidence way to reproduce the issue? Yes: current-main source drops the per-call signal and lacks a deadline, and an underfilled large-vault query reaches the exhaustive scan. Contributor baseline/fixed Gateway observations support the mechanism; this review did not execute it. Is this the best way to solve the issue? Yes: the patch uses the existing SDK abort helper and threads cancellation through the existing search owner while preserving ranking, safe-file checks, and stored formats. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 45228e1aeed6. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…openclaw#166329) Give wiki_search a deadline and thread the abort signal through page reading, scoring and shared-memory search, so a large vault returns a deadline error instead of hanging the turn, and chat.abort stops the CPU-bound scoring. No stored data or persisted format changes. Fixes openclaw#166303. Co-authored-by: Ayaan Zaidi <[email protected]>
…#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]>
…#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)
…#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]>
…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]>
Fixes #166303
What Problem This Solves
Fixes agent turns getting stuck when
wiki_searchscans a large vault without honoring turn cancellation or a search deadline.User Impact
Wiki searches now have a 30-second deadline, matching
memory_search, and stop scanning when the turn is cancelled. Deadline and cancellation failures are tool errors, not misleading empty results. Search ranking, prefiltering, and the other wiki tools are unchanged.Why This Change Was Made
The search tool combines its per-call and plugin-lifecycle signals with a local deadline, using the existing SDK abort-race helper. The page reader checks cancellation before reads and parsing; scoring yields between batches so cancellation can run during CPU-heavy searches too. Shared-memory searches receive the same cancellation signal. No SDK contract or cross-plugin private import was added.
There is no persisted-data change: no schema, embedding/vector metadata, vault format, cache format, migration, or upgrade behavior changes. Cancellation is call-local. The existing vault is read without conversion; the five tool controls below preserve their baseline output. The page-reader extraction also preserves the mutation tool's existing reader behavior.
Thanks @etzelm for the report.
Evidence
wiki_search timed out after 30sin 30.252 seconds.chat.abortacknowledged cancellation during CPU-bound scoring in 505 ms. The session had no active run afterward; page-open counts stayed unchanged and Gateway CPU usage dropped to 0.21 CPU-seconds over the next 4.13 seconds. The earlier reader-abort run also stopped page opens within 7 ms of cancellation; the scan-abort regression verifies that boundary after extraction.wiki_search,wiki_get,wiki_status,wiki_apply, andwiki_lintreturned identical text on base and fix.tool.deadline.test.tsand 10.57 s forquery.abort.test.ts(wall time includes test startup). The canonical mock-export scanner passed both new test files.tsgocheck covering memory-wiki source and tests passed. The package-boundary configuration initially lacked SDK declarations; the source-mapped extension project was used for the successful check.READY166303).Data-model compatibility
No stored data or persisted format changes. The touched files are read and query paths only.
query-pages.tsmoves the existing page reader so it can check the abort signal between pages.apply.tsandmarkdown.tsonly change imports and export an existing type.query-shared-memory.tspasses anAbortSignalinto the existingsearchoptions. Nothing writes vault pages, frontmatter, embeddings or index metadata differently. Existing vaults read identically: all five wiki tool controls matched baseline output on the same vault, so no migration or upgrade step is needed.