Skip to content

fix(memory-wiki): stop long searches on deadline or turn cancellation - #166329

Merged
obviyus merged 2 commits into
mainfrom
fix/memory-wiki-search-deadline-166303
Oct 6, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/memory-wiki-search-deadline-166303

Conversation

@obviyus

@obviyus obviyus commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #166303

What Problem This Solves

Fixes agent turns getting stuck when wiki_search scans 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

  • Built baseline and fixed Gateways in isolated Linux/Node 24.16 containers with a generated 12,002-page bridge vault (about 518 MB), warming each with a filled search first.
  • The reported nine-term query completed in 7.1 seconds on this synthetic vault. Adding 512 absent terms made the same underfilled multi-term path expensive without changing product code or increasing the page count: baseline remained pending at the 60-second observation cap; the final fixed head returned wiki_search timed out after 30s in 30.252 seconds.
  • On the final head, chat.abort acknowledged 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.
  • Small-vault wiki_search, wiki_get, wiki_status, wiki_apply, and wiki_lint returned identical text on base and fix.
  • Fake-timer deadline/caller-abort regressions and the real-page scan-abort regression fail on base and pass with the fix. 78 focused tests passed after the final repair. Separate single-worker commands took 13.12 s for tool.deadline.test.ts and 10.57 s for query.abort.test.ts (wall time includes test startup). The canonical mock-export scanner passed both new test files.
  • Candidate Gateway build and a scoped native tsgo check 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.
  • One real gpt-5-mini request through the fixed Gateway passed, with low reasoning and a 4096-token output budget (READY166303).

Data-model compatibility

No stored data or persisted format changes. The touched files are read and query paths only. query-pages.ts moves the existing page reader so it can check the abort signal between pages. apply.ts and markdown.ts only change imports and export an existing type. query-shared-memory.ts passes an AbortSignal into the existing search options. 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.

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@obviyus

obviyus commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-wiki size: M labels Oct 6, 2026
@obviyus
obviyus marked this pull request as ready for review October 6, 2026 22:54
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 6, 2026, 7:29 PM ET / 23:29 UTC (Revision 3).

ClawSweeper review

What this changes

Memory 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
Reviewed head: 521ccf2b10c8976a656824d85fe786a77352923d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with strong production-path observations and no blocking correctness or security findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured final-head Gateway evidence exercises wiki_search on a large synthetic vault: the deadline returns an error at 30.252 seconds, and chat.abort ends CPU-bound scoring with no further page opens and sharply reduced CPU use. Existing-tool controls match baseline. No stored-data contract changes, so migration proof is not applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured final-head Gateway evidence exercises wiki_search on a large synthetic vault: the deadline returns an error at 30.252 seconds, and chat.abort ends CPU-bound scoring with no further page opens and sharply reduced CPU use. Existing-tool controls match baseline. No stored-data contract changes, so migration proof is not applicable.
Evidence reviewed 10 items Pinned introduced change: Reviewed the merge-base-to-head delta, rather than endpoint drift. The checkout is the exact original PR head; the supplied test merge is stale and was not used to infer removal of main-branch behavior.
Cancellation owner: The tool accepts the caller signal, combines it with lifecycle cancellation and its deadline, uses the existing SDK abort-race helper, and clears the timer after settlement. Native memory calls retain their existing authority and current-invocation checks.
Underlying work cancellation: Page tasks check cancellation before opening and after reading; scoring yields between batches so timers and caller aborts can run. Existing safe-reader boundary checks and terminal security refusals are preserved. Already-started filesystem reads may finish.
Findings None None.
Security None None.

How this fits together

Memory 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
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +77, Tests +94, Docs +4. Total +175 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 6 171 94 +77
Tests 2 94 0 +94
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 269 94 +175

Review metrics

Metric Value Why it matters
Search budget 30-second deadline; 0 new settings Bounds previously unbounded agent searches using the established memory-search budget.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/memory-wiki/src/query-pages.ts, unknown-data-model-change: extensions/memory-wiki/src/query.ts, unknown-data-model-change: extensions/memory-wiki/src/tool.ts, vector/embedding metadata: extensions/memory-wiki/src/query-pages.ts, vector/embedding metadata: extensions/memory-wiki/src/query-shared-memory.ts, vector/embedding metadata: extensions/memory-wiki/src/tool.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The linked report establishes a stalled agent search and degraded Gateway responsiveness on a released version.
  • 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. Sufficient (live_output): The captured final-head Gateway evidence exercises wiki_search on a large synthetic vault: the deadline returns an error at 30.252 seconds, and chat.abort ends CPU-bound scoring with no further page opens and sharply reduced CPU use. Existing-tool controls match baseline. No stored-data contract changes, so migration proof is not applicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured final-head Gateway evidence exercises wiki_search on a large synthetic vault: the deadline returns an error at 30.252 seconds, and chat.abort ends CPU-bound scoring with no further page opens and sharply reduced CPU use. Existing-tool controls match baseline. No stored-data contract changes, so migration proof is not applicable.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta, rather than endpoint drift. The checkout is the exact original PR head; the supplied test merge is stale and was not used to infer removal of main-branch behavior. (521ccf2b10c8)
  • Cancellation owner: The tool accepts the caller signal, combines it with lifecycle cancellation and its deadline, uses the existing SDK abort-race helper, and clears the timer after settlement. Native memory calls retain their existing authority and current-invocation checks. (extensions/memory-wiki/src/tool.ts:152, 521ccf2b10c8)
  • Underlying work cancellation: Page tasks check cancellation before opening and after reading; scoring yields between batches so timers and caller aborts can run. Existing safe-reader boundary checks and terminal security refusals are preserved. Already-started filesystem reads may finish. (extensions/memory-wiki/src/query-pages.ts:49, 521ccf2b10c8)
  • After-fix production-path evidence: The captured PR body, sourceRevision 9cec967257709302796f190f5454ee501390069e8046b73c446325457c934fa0, describes isolated baseline and fixed Linux/Node Gateways using a 12,002-page vault. Baseline remained pending at 60 seconds; the final fixed head returned the timeout error in 30.252 seconds. During CPU-bound scoring, chat.abort acknowledged cancellation in 505 ms, the active run ended, page opens stopped increasing, and subsequent CPU consumption fell to 0.21 CPU-seconds over 4.13 seconds. These observations exercise the changed tool and scoring owners; the unrelated provider readiness smoke is supplemental. (521ccf2b10c8)
  • No persisted-model change: The introduced diff changes execution signals and reader ownership, without modifying vault serialization, cache schemas, publication identity, configuration, or mutation write algorithms. apply.ts uses the extracted reader without a signal, preserving its previous behavior. The captured body also reports identical baseline/fixed output for all five wiki tools on the same small vault. The previous review's migration next step is therefore resolved as not applicable. (extensions/memory-wiki/src/apply.ts:25, 521ccf2b10c8)
  • Current main still needs the repair: Fetched main still declares the search execute function without the caller-signal argument and has no tool-owned deadline. The latest release's tool implementation has the same missing boundary. No merged fixing PR establishes redundancy. (extensions/memory-wiki/src/tool.ts:149, 45228e1aeed6)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-06T22:59:52.572Z sha 74f9121 :: blocked before merge. :: [P3] Explain the source-sync mock's intentional isolation
  • reviewed 2026-10-06T23:15:13.179Z sha 521ccf2 :: blocked before merge. :: none

@obviyus

obviyus commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit d462cac into main Oct 6, 2026
104 of 108 checks passed
@obviyus
obviyus deleted the fix/memory-wiki-search-deadline-166303 branch October 6, 2026 23:44
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…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]>
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

docs Improvements or additions to documentation extensions: memory-wiki 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: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant