Skip to content

fix(memory): preserve file changes during indexing - #157163

Merged
vincentkoc merged 3 commits into
mainfrom
perf/async-native-watch-20260924
Sep 24, 2026
Merged

vincentkoc merged 3 commits into
mainfrom
perf/async-native-watch-20260924

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Native watcher traversal blocks other Gateway work while probing large memory folders. Separately, an edit arriving after an active indexing pass planned its sources can join that old pass and remain unindexed.

User Impact

Directory probes use asynchronous I/O; newer edits receive a follow-on indexing pass; shutdown joins accepted watcher work. Linux correctness and static checks passed at the preceding head; the new head changes only one test's formatting. Responsiveness is now measured at the current head: maximum callback-free startup fell from 13.444 to 1.667 ms in one fixed instrumented pair. Total startup increased from 13.444 to 26.417 ms. This is a responsiveness and indexing-correctness change; no throughput, startup-speed or memory improvement is claimed.

Why This Change Was Made

The existing watcher resource owner owns startup, settling, bounded reconciliation, overflow rescans and joined close. The file watcher owns native coverage and generations. The manager waits for readiness outside database write admission; the remote worker joins shutdown when input closes.

Production: +578/-271 (net +307), justified by asynchronous traversal and joined resource ownership. Tests/helpers: +1013/-108 (net +905). Broad dirty callbacks and string notifications remain unchanged. Generations and queues are process-local: there is no schema, persisted data-model, configuration, public SDK or protocol change, and no migration is required.

Evidence

Current candidate e3a034e6fdd5d67ea7c2648705d8ec351b922d5f, tree 302a8802de31474f77a5346fd8ef43f8c98fee71; baseline 61214694cc150a11e551c0e97fbeaaa01a2b8141. The completed Linux proof below belongs to preceding head 813d922cb05cbc0a27e4be3bf66da66067ef219d, tree 4e93b7cf9608a4bffc0e8d2e8c26e95aa2b9adb1. All production bytes and 12 of 13 touched files are identical; only remote-worker test formatting differs.

  • Independent owner/caller/sibling reviews found no remaining P0–P2 code finding. Reviewed 13-file manifest: dd923846daacff892730d9ed61b355eafb15eb16162914c5356dce69fc3c4430.
  • Linux proof 35980900718, Node 24.19.0 / pnpm 12.4.0: 116/116 cases across six files, zero skips, in 85.06 seconds whole-phase wall. Coverage includes committed SQLite chunks after a post-planning edit, real Linux directory replacement/removal, settling and remote input-close shutdown.
  • Counterfactuals reached exactly two capacity-revocation failures, two parent-loss coverage failures and one baseline stale-chunk failure. The committed-row assertion precedes search, which otherwise could conceal the defect.
  • Canonical scoped static checks passed in 562.82 seconds. All eight child groups joined; source restored, 13 hashes verified, remote fixtures/capsule removed and lease stopped.
  • CI at the preceding head used oxfmt 0.68 while its frozen development inputs use 0.67. Oxlint passed; only remote/memory-files-worker.test.ts failed formatting. The current commit applies 0.68's six-line formatting delta, including a trailing comma. Pinned 0.68 formatting passes; both remote-worker cases also passed locally on Node 26.7. No production code changed. New-head CI/review remain required.
  • The earlier fixture-only failure omitted syscall: "watch" from a synthetic capacity error; the current head corrects it. No production bytes changed for that correction.

One fixed baseline → candidate screen used 500 directories and 5,000 files:

Observation Baseline Candidate
Startup wall 14.972 ms 35.842 ms
Startup CPU, including instrumentation 19.106 ms 47.660 ms
Change notification 11.230 ms 12.785 ms
Joined close 3.066 ms 4.089 ms
Synchronous stat/lstat/readdir calls 1,507 0
Live directory coverage 501 501
Native handles after close 0 0

This qualifies synchronous-I/O removal and coverage, not a speedup. Heap/RSS deltas include retaining Vitest spies, asynchronous Promise observers and GC timing; they do not establish production memory cost or peaks.

The original histogram result is withdrawn: Node 24.19's implementation clears its previous timestamp on reset, so the next tick only seeds an anchor. Its 0.786 → 2.640 ms maxima do not measure comparable startup stalls.

The corrected responsiveness run 35984525942 executed once at exact current head e3a034e, Linux x64 Node 24.19.0/pnpm 12.4.0, with the same 500-directory/5,000-file workload. A scalar 1 ms timer is armed immediately before startup; its first post-settlement callback captures terminal blocking too. Both measurement cases passed without retries or skips:

Observation Baseline Candidate
First timer callback 13.722 ms 1.281 ms
Callbacks while startup was pending 0 25
Maximum callback-free startup interval 13.444 ms 1.667 ms
Startup wall 13.444 ms 26.417 ms
Startup CPU, including instrumentation 18.137 ms 35.591 ms
Startup heap delta, including instrumentation 5,673,712 B 8,968,848 B
Startup RSS delta 0 B 1,179,648 B

Maintainer landing decision: accept this measured startup tradeoff for nonblocking traversal and lossless indexing. Other Gateway work can run during traversal, while traversal itself takes longer in this screen. This single pair establishes yielding under the tested workload, not a stable speedup multiplier or production memory footprint. Both variants covered all 501 directories, opened 502 native watches, delivered one real-change notification and closed every handle. Synchronous probes fell from 1,507 to zero. Driver/wrapper exited zero, child groups joined, source hashes restored, lease stopped and capsule removed. This supplements the original slower startup result above.

Exact-head CI 35983852335 passed. Its retained verbose logs expose rounded case durations, not full per-file wall times:

File Cases Summed case duration
file-watcher.lifecycle.test.ts 19 140 ms
watch-settle.test.ts 3 32 ms
manager-workspace-files.test.ts 12 14,617 ms
manager.watcher-config.test.ts 78 10,702 ms
manager.watcher-filesystem.test.ts (unchanged sibling) 2 19,445 ms
remote/memory-files-worker.test.ts 2 119 ms

These sums exclude import/transform/setup overhead. Standalone Linux proof retained the aggregate 85.06-second phase wall, not per-file wall; that optional profiling detail remains unavailable. No extra repeat of six already passing files was run merely to fill a timing column. The shared watcher-test-support.ts helper is covered through its consuming suites.

The exact-head ClawSweeper review at e3a034e has no actionable code/security findings. Its Linux lifecycle/committed-row proof, corrected responsiveness and explicit startup/CPU tradeoff requests are fulfilled above. Per-file cost evidence and its limitation are recorded explicitly. The automated data-model checkbox is addressed by the unchanged persistence contract above. The newer required security/status publication remains a separate landing gate.

Related contributor work remains separate: lost-watcher recovery and initially missing extra paths.

@vincentkoc vincentkoc self-assigned this Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

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

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 24, 2026, 6:01 AM ET / 10:01 UTC (Revision 4).

ClawSweeper review

What this changes

Memory Core now probes watched folders asynchronously, carries file edits into a follow-on indexing pass, and joins accepted watcher work during shutdown.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 5 items remain

Current main still has the watcher traversal and indexing race this PR addresses. The reviewed source shows no definite correctness defect, and the preceding-head Linux proof remains relevant because production blobs are unchanged. Merge readiness remains limited by an invalid startup-stall comparison and an observed startup wall-time increase.

Priority: P1
Reviewed head: e3a034e6fdd5d67ea7c2648705d8ec351b922d5f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has focused lifecycle and committed-row coverage, but its performance claim needs a valid comparison and its expanded tests need per-file cost figures.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored PR. Its body reports preceding-head Linux results through the Memory Core manager, real SQLite rows, native watcher paths, and remote stream shutdown; production blobs match the current head. The startup-stall measurement remains an independent merge gap. Watch queues and generations are process-local, so no stored-data migration is implicated.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored PR. Its body reports preceding-head Linux results through the Memory Core manager, real SQLite rows, native watcher paths, and remote stream shutdown; production blobs match the current head. The startup-stall measurement remains an independent merge gap. Watch queues and generations are process-local, so no stored-data migration is implicated.
Evidence reviewed 8 items Current-main race: Current main joins an existing sync promise for a watch-triggered call and uses synchronous filesystem probes in the file watcher; the central requested behavior remains absent.
Current-main synchronous traversal: The current-main watcher still calls synchronous lstat, stat, and readdir operations during native watcher traversal.
Introduced indexing repair: The branch tracks watcher generations and admits a new pass when a watch event leaves the index dirty after an active pass.
Findings None None.
Security None None.

How this fits together

The Memory Core plugin watches workspace and remote-host memory files, then updates a SQLite index used by memory search. Watch notifications and file reads enter the indexing manager; committed index rows feed later recall.

flowchart LR
  A[Memory files] --> B[File watchers]
  B --> C[Settle changes]
  C --> D{Index pass active?}
  D -->|Yes| E[Follow-on pass]
  D -->|No| F[Current pass]
  E --> G[SQLite memory index]
  F --> G
Loading

Decision needed

Question Recommendation
After the corrected startup responsiveness comparison, is the observed increase in startup wall time acceptable for this Memory Core watcher change? Require comparable responsiveness proof: Review the corrected baseline and candidate stall measurement alongside startup wall time before accepting the tradeoff.

Why: The current measurement establishes slower startup but does not establish whether Gateway event-loop stalls improve enough to justify it.

Before merge

  • Resolve merge risk (P1) - The only reported large-folder comparison shows startup wall time increasing from 14.972 ms to 35.842 ms; the event-loop histogram was reset in a way that makes its startup-stall maxima incomparable. A corrected paired responsiveness measurement is needed before accepting that tradeoff.
  • Resolve merge risk (P1) - The new or materially changed test files have an aggregate 85.06-second proof-phase time in the PR body, but no per-file wall times, leaving the repository's per-file CI cost budget unverified.
  • Complete next step (P2) - Record a corrected baseline/candidate startup responsiveness comparison and per-file test wall times, then obtain maintainer acceptance of the startup tradeoff before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +307, Tests +905. Total +1212 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 578 271 +307
Tests 6 1013 108 +905
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 1591 379 +1212

Review metrics

Metric Value Why it matters
Production versus test growth production net +307 lines; tests and helpers net +905 lines The PR explains production growth through asynchronous watcher ownership; the larger test addition makes per-file CI cost relevant.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/memory-core/src/memory/file-watcher.ts, unknown-data-model-change: extensions/memory-core/src/memory/manager-watch-ops.ts, unknown-data-model-change: extensions/memory-core/src/memory/manager-watch-resources.ts, unknown-data-model-change: extensions/memory-core/src/memory/manager.ts, unknown-data-model-change: extensions/memory-core/src/memory/watch-settle.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager-watch-ops.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Qualify startup responsiveness (recommended)
    Publish a corrected paired event-loop measurement, retain the slower wall-time result, and record per-file test costs before merge.
  2. Narrow the patch if the tradeoff fails
    Preserve the edit-generation fix while pausing the broader asynchronous watcher cutover if comparable proof does not support it.

Technical review

Best possible solution:

Keep lossless watcher generations and asynchronous traversal, then qualify the startup responsiveness tradeoff with a comparable paired measurement and record each changed test file's cost.

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

Yes, from source: current main joins an active sync promise for later watch events and performs synchronous watcher traversal. The branch includes a committed-row regression scenario, but this read-only review did not execute it.

Is this the best way to solve the issue?

Yes for the indexing race: the change stays with the Memory Core watcher and sync owners. The broader asynchronous traversal still needs a valid responsiveness comparison before its performance tradeoff is accepted.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 20590155d1bf.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A missed memory edit can leave later recall stale, while synchronous traversal can stall Gateway work on large folders.
  • merge-risk: 🚨 session-state: The patch changes when watched memory edits reach committed index rows.
  • merge-risk: 🚨 availability: Watcher startup now awaits asynchronous traversal, and the supplied large-folder comparison shows increased startup wall time.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored PR. Its body reports preceding-head Linux results through the Memory Core manager, real SQLite rows, native watcher paths, and remote stream shutdown; production blobs match the current head. The startup-stall measurement remains an independent merge gap. Watch queues and generations are process-local, so no stored-data migration is implicated.

Evidence

What I checked:

Likely related people:

  • Kimi Yu: Raw commit e8ccb39 adds extensions/memory-core/src/memory/file-watcher.ts:111 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e8ccb3944b8e; files: extensions/memory-core/src/memory/file-watcher.ts)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • EricCai: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the corrected paired startup event-loop responsiveness measurement while retaining the slower wall-time result.
  • Add measured wall time for each new or materially changed test file.

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 (3 earlier review cycles)
  • reviewed 2026-09-24T09:06:04.028Z sha e095390 :: blocked before merge. :: none
  • reviewed 2026-09-24T09:31:31.516Z sha 813d922 :: blocked before merge. :: none
  • reviewed 2026-09-24T09:40:51.243Z sha 813d922 :: blocked before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review September 24, 2026 09:32
@vincentkoc
vincentkoc merged commit 9b19fe8 into main Sep 24, 2026
116 checks passed
@vincentkoc
vincentkoc deleted the perf/async-native-watch-20260924 branch September 24, 2026 10:10
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
* fix(memory): preserve file changes during indexing

* test(memory): model native watch capacity errors

* test(memory): align worker fixture formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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.

1 participant