Skip to content

fix(store): non-blocking validateStoragePath async background init (Issue #795)#796

Closed
jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
jlin53882:james/issue795-validate-storage-path-async
Closed

fix(store): non-blocking validateStoragePath async background init (Issue #795)#796
jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
jlin53882:james/issue795-validate-storage-path-async

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Issue: #795 — plugin init 時 validateStoragePath 的 5 個 sync I/O 會 block event loop

Fix: 新增 validateStoragePathAsync + pathExistsAsync async 版本,並在 register() 內以 fire-and-forget 方式在 setImmediate() 中執行,不 block plugin 註冊的 critical path。

Changes

src/store.ts

  • 新增 import: { access, lstat, mkdir, realpath } from node:fs/promises
  • 新增 pathExistsAsync(p: string): Promise
  • 新增 validateStoragePathAsync(dbPath: string): Promise — 完全非同步版本
  • 原有 validateStoragePath sync 版本完全保留,不修改

index.ts

  • 新增 import: validateStoragePathAsync
  • 新增 _singletonAsyncValidationDone: boolean flag
  • 新增 _startAsyncValidation(resolvedDbPath, api) — fire-and-forget wrapper
  • register() 在 claim API slot 後、_initPluginState 前呼叫 _startAsyncValidation()

設計說明:兩全其美方案

同時滿足兩目標:

  1. 不 block event loop — setImmediate() 將 5 個 sync I/O 移出 register() critical path
  2. 維持 sync register() API — register(api): void 不變,OpenClaw error semantics 完全保留

不採用完整 async 方案的原因:register() 是固定 API signature,改為 async 會破壞 OpenClaw core error detection 能力,且需要重構所有 60+ hook registrations。

關聯 Issue

…#693)

- Adds countBefore/countAfter validation in smart-extractor.ts after bulkStore
- Adds ExtractionValidation type and callback interface in memory-categories.ts
- Adds extraction-validation.test.mjs (6 scenarios, all pass)
- Adds dedup-false-alarm.test.mjs (P0 regression: bulkStore does NOT dedup)
- Registers new tests in CI manifest
- Adds store.count() mock to existing tests (preference-slots, batch-embed, bulk-store)
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29653644a0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +65 to +67
// Issue #693 extraction write validation tests
{ group: "core-regression", runner: "node", file: "test/extraction-validation.test.mjs", args: ["--test"] },
{ group: "core-regression", runner: "node", file: "test/dedup-false-alarm.test.mjs", args: ["--test"] },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the unrelated regression tests in the CI manifest

This manifest is what the GitHub CI jobs run via npm run test:core-regression / test:storage-and-schema (.github/workflows/ci.yml -> scripts/run-ci-tests.mjs), so replacing the existing block with only the new Issue #693 tests silently stops CI from running the Issue #690, #606, provider inference, recall-governance, and tier1 counter regressions. Unless those tests are intentionally retired elsewhere, keep the existing entries and append the new validation tests so these regressions remain covered.

Useful? React with 👍 / 👎.

@jlin53882 jlin53882 closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant