Repository navigation
fix(ai-memory): bound claude-mem sync runs and drop per-row table scans - #290
Merged
Merged
Conversation
The import looked up each incoming row's natural key with a query on the unindexed created_at column, and the attribution repair did the same with up to five UPDATEs per row. On a 220k-row store, a 50k-row overlap window meant hundreds of thousands of full table scans under the write lock: the scheduled run spun for hours, blocked the peer's imports with SQLITE_BUSY and kept dot admit deferring heavy work. - Load the receiver's natural keys once per import and repair by rowid. The same 50.8k-row bundle on a copy of the real store now imports in 1.4 s (the previous code did not finish in 60 s). - Thread the context through every DB call and add --timeout (default 10m), so a deadline or SIGTERM interrupts the statement and the open import rolls back. - Log each phase's start and end with row counts; errors name the phase. - The LaunchAgent wrapper sends SIGTERM after 15 min and SIGKILL 30 s later as a backstop. Fixes #289 Claude-Session: https://claude.ai/code/session_01Tc37VsosXPm6MTjU6ej3c9
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Oct 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #289.
Root cause
SyncDB.Importchecked each incoming row's natural key withWHERE created_at = ? AND COALESCE(title,'') = ?.created_athas no index, so every lookup scanned all ofobservations, and the attribution repair ran up to five more full-scan UPDATEs per dedupe hit. With 219k observations and a 50.8k-row 7-day overlap, that is hundreds of thousands of full scans inside an IMMEDIATE transaction: the run spun at ~100% CPU for hours, held the write lock (the peer's and the worker's writes got SQLITE_BUSY), and ignored SIGTERM because no DB call took the context.Changes
(created_at, key)→ rowids once per table (from the bundle's oldestcreated_at), dedupes in memory, repairs by rowid, and records rows it inserts so duplicates inside one bundle still dedupe.SyncDBcall;dot ai memory sync --timeout(default 10m) bounds client and--serveruns. Deadline or SIGTERM interrupts the statement; the deferred rollback leaves no partial import. The error says "sync aborted after the 10m0s deadline" or "sync canceled".RunMemorySynclogs each phase's start and end with row counts; errors are prefixed with the phase (pull: local import: ...). Import logs each table.docs/commands/dot_ai_memory_sync.md(generated),docs/COMMANDS-GUIDE.md.Verification
.backup), 8-day export (50,827 obs, 2,274 sums, 324 sessions) re-imported: new code 1.4 s; v2.70.46 killed unfinished after 60 s.--timeout 300msaborted with no row change andintegrity_checkok.pull: local import+ SQLITE_BUSY within the busy timeout; stalled phase ends at the deadline namingpull: peer export; cancel mid-import rolls back; in-bundle duplicates dedupe.go test ./... -race(2 workers): all pass exceptTestJSONGoldens, which fails only because the Orca session exportsCLAUDE_CONFIG_DIR; it passes with that unset (environment leak, unrelated).golangci-lint --new-from-rev main: 0 issues (two errcheck hits in untouchedclaudemem.gopredate this branch).After release
The push-direction import runs on the peer, so both Macs need the new
dot. The plist is rewritten only bydot ai memory install --peer <target>.🤖 Generated with Claude Code
https://claude.ai/code/session_01Tc37VsosXPm6MTjU6ej3c9