Skip to content

perf(memory): target session delta syncs with the dirty set instead of full directory scans#91841

Merged
amknight merged 1 commit into
ak/memory-sync-prune-guardfrom
ak/memory-targeted-session-delta-sync
Jun 11, 2026
Merged

perf(memory): target session delta syncs with the dirty set instead of full directory scans#91841
amknight merged 1 commit into
ak/memory-sync-prune-guardfrom
ak/memory-targeted-session-delta-sync

Conversation

@amknight

@amknight amknight commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

Every 5s-debounced session delta sync calls sync({ reason: "session-delta" }) with no targets, so syncSessionFiles performs a full sessions-directory enumeration — and then skips every listed file that is not in the dirty set anyway. The enumeration's only unique contribution to a delta sync is stale-row prune reconciliation; the indexing work is fully determined by sessionsDirtyFiles, which the engine populated from transcript events before triggering the sync.

On networked filesystems these scans are expensive: an NFSv4.1 profile of a real deployment measured full listings of agents/main/sessions at 3.4–3.8s each (~100 entries; the client requests a broad READDIR attribute set, which the backing server satisfies with per-entry metadata reads). Trace-level attribution later showed the specific scans that profile captured came from per-save archive-retention cleanup — fixed separately in #91957 — not from memory delta syncs (that deployment does not run memory session sync). The per-scan cost numbers still stand, and they are what every delta sync pays on such storage whenever memory session sync is enabled.

This PR makes delta syncs use the targeted path that already exists (runMemoryTargetedSessionSync):

  • processSessionDeltaBatch now passes the accumulated dirty set as explicit sessionFiles targets → the sessions-dir enumeration is skipped entirely. The targeted path clears only the synced files from the dirty set (files dirtied mid-sync survive) and retains targets as dirty on failure.
  • Bounded reconciliation: at most once per SESSION_PRUNE_RECONCILE_INTERVAL_MS (15 min), a delta sync falls back to the full enumeration so index rows for files deleted out-of-band (another process/node on shared storage) still get pruned. The timestamp only advances when an authoritative prune actually completed, so a failed scan retries on the next batch.
  • Boot catch-up, interval-with-dirty-files, CLI/forced, and full-reindex syncs keep their full enumerations unchanged — those are the intended reconciliation points.

Behavior notes

  • Indexing outcomes are unchanged. The full path already skipped non-dirty files during delta syncs; only the prune cadence shifts from per-batch (~5s) to the bounded window (≤15 min during activity). Idle agents are unchanged (no delta syncs → no scans, before and after).
  • Targeted syncs are sessions-only by existing contract, so a delta sync no longer incidentally flushes dirty memory-source files; those still sync via their own watch debounce and interval triggers.
  • Stacked on fix(memory): do not prune session index from a failed directory scan #91091 deliberately: the now-rarer full enumerations are exactly the scans fix(memory): do not prune session index from a failed directory scan #91091 makes authoritative ({ ok, files }), so a failed reconcile scan cannot prune and dirty state is retained for retry.

Identified while decomposing the NFS readdir-load report behind the #91081 discussion (its "avoid full scans when a targeted dirty-file set exists" recommendation). With this change, deployments running memory session sync stop paying a full directory scan per delta batch; the remaining enumeration cost (boot catch-up, periodic reconcile, qmd export, and the store-save retention sweeps addressed by #91957) is the much smaller surface the coalescing/TTL discussion in #91081 addresses separately.

Verification

  • node scripts/run-vitest.mjs extensions/memory-core/src/memory/manager-sync-ops.targeted-delta.test.ts extensions/memory-core/src/memory/manager-sync-ops.prune-guard.test.ts extensions/memory-core/src/memory/manager-targeted-sync.test.ts extensions/memory-core/src/memory/manager-session-sync-state.test.ts19/19 (5 new).
  • node scripts/run-vitest.mjs extensions/memory-core/src/memory/manager-sync-ops.archive-delta-bypass.test.ts4/4.
  • pnpm tsgo:extensions and pnpm tsgo:extensions:test — clean. node scripts/run-oxlint.mjs on touched files — clean.
  • New tests cover: targeted params within the reconcile window; accumulated dirty set (leftovers from earlier syncs) included in targets; full-enumeration fallback at window expiry (and at boot, timestamp 0); reconcile timestamp advancing only after an authoritative prune; failed scan leaving the timestamp unset so the next batch retries.
  • Not run here: live NFS before/after trace. The report's verification protocol applies directly — count scandir events on the sessions dir during steady-state activity; expected: one per 15-min reconcile window instead of one per 5s delta batch.

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: M maintainer Maintainer-authored PR labels Jun 10, 2026
@clawsweeper

clawsweeper Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 10, 2026, 10:53 AM ET / 14:53 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

PR surface: Source +21, Tests +183. Total +204 across 2 files.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Review metrics: none identified.

Merge readiness
Overall: 🌊 off-meta tidepool
Proof: 🌊 off-meta tidepool
Patch quality: 🌊 off-meta tidepool
Result: rating does not apply to this item.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • Review did not complete, so no work-lane recommendation was made.
Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

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

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: reasoning high; reviewed against ac21e89c13e4.

Label changes

Label changes:

  • add rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
  • remove P2: Current review triage priority is none.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🌊 off-meta tidepool, so this older rating label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.
  • remove status: 👀 ready for maintainer look: Current PR status no longer selects a status label.

Label justifications:

  • rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
Evidence reviewed

PR surface:

Source +21, Tests +183. Total +204 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 22 1 +21
Tests 1 183 0 +183
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 205 1 +204

What I checked:

  • failure reason: codex execution failed.
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stdout: Per-item Codex failure; continuing with the rest of the shard.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 10, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed 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 Jun 10, 2026
@amknight
amknight merged commit ed11c85 into ak/memory-sync-prune-guard Jun 11, 2026
226 of 238 checks passed
@amknight
amknight deleted the ak/memory-targeted-session-delta-sync branch June 11, 2026 05:15
amknight added a commit that referenced this pull request Jun 12, 2026
amknight added a commit that referenced this pull request Jun 16, 2026
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 maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant