Skip to content

fix: preserve consolidation provenance and version heads - #1545

Merged
rohitg00 merged 7 commits into
mainfrom
fix/consolidation-races
Nov 8, 2026
Merged

rohitg00 merged 7 commits into
mainfrom
fix/consolidation-races

Conversation

@rohitg00

@rohitg00 rohitg00 commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Concurrent consolidation runs could publish duplicate memories or evolve a stale version, while a failed successor write could leave the previous version hidden. Recheck current source evidence and memory heads under the existing ordered source/publication locks, then store the successor before demoting its predecessor.

  • Deduplicate identical observation and session provenance even when concurrent model responses use different titles.
  • Reject source edits, deletion, or session-scope changes during model generation; keep source locks through publication and model calls outside the locks.
  • Confirm writes after lost acknowledgements, roll back failed demotions, and repair unambiguous interrupted version chains on the next publication.
  • Count failed model attempts toward the ten-call budget and clear timeout handles on every exit.

This provides coordination within one worker and recovery from interrupted writes, not a distributed multi-row transaction. It complements #1506's pre-model optimization and overlap matching; those contributor changes are not included here.

Validation: required build, skill generation/check and documentation sync/check passed; full suite 3,288 passed, 4 skipped. Regression tests cover concurrent runs, source mutation, both source locks, project/session identity, lost acknowledgements, rollback failures, version repair and timeout cleanup. A clean installed npm archive with native iii 0.22.1 passed concurrent REST publication, evolution with new evidence, and durable deduplication after restart using a local deterministic model fixture. The installed CLI remained unchanged and test ports closed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved memory consolidation to reduce duplicate entries, update existing memories with new information, and verify source information is current before publishing.
    • Improved recovery from interrupted or unsuccessful consolidation attempts.
    • Memory deletion now waits for related memory updates to finish, helping prevent conflicting changes.
  • Documentation
    • Updated documented test counts to 4,600+ across the README and translated versions.

@vercel

vercel Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agentmemory Ready Ready Preview Nov 8, 2026 9:36am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

Consolidation now fingerprints evidence and validates source records under locks before publishing or evolving memories. Memory forgetting retrieves and deletes its target under the remember lock. The state file, project instructions, and translated READMEs update the reported test count to 4,600+.

Changes: Consolidation Publication

Layer / File(s) Summary
Evidence fingerprint and compression lifecycle
src/types.ts, src/functions/consolidate.ts, test/consolidate-publication.test.ts
Memory adds the optional consolidationKeys record. Consolidation fingerprints source evidence, counts provider attempts before compression, and clears timeouts. Tests cover attempt limits, timeout cleanup, and evidence changes.
Locked source validation and deduplication
src/functions/consolidate.ts, test/consolidate-project-scope.test.ts, test/consolidate-publication.test.ts
Publication checks source sessions and observations under locks, filters eligible memories by scope, and skips evidence already represented by a latest memory. Tests cover stale inputs, source locking, provenance, and repeated runs.
Versioned publication and recovery
src/functions/consolidate.ts, test/consolidate-publication.test.ts
Publication creates or evolves memories, updates predecessor lineage, and handles write and recovery cases. Tests cover concurrent runs, versioning, ambiguous lineages, and storage failures.

Memory Forget Locking

Layer / File(s) Summary
Serialize forget with remember operations
src/functions/remember.ts, test/remember-lock-scope.test.ts
mem::forget looks up and deletes a memory under the mem:remember keyed lock. The test checks that deletion waits for the lock to be released.

Test Count References

Layer / File(s) Summary
Update reported test counts
scripts/docs-sync.state.json, AGENTS.md, README.md, READMEs/*
The state file, project instructions, and translated READMEs update the reported test count from 4,500+ to 4,600+.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Consolidation
  participant LLM
  participant KeyedLocks
  participant MemoryStore
  Consolidation->>LLM: Request compression
  LLM-->>Consolidation: Return parsed result
  Consolidation->>KeyedLocks: Lock source records for publication
  Consolidation->>MemoryStore: Revalidate sources and read memory heads
  MemoryStore-->>Consolidation: Return current state
  Consolidation->>MemoryStore: Create or evolve a memory
  Consolidation->>MemoryStore: Update predecessor lineage when needed
Loading

Suggested reviewers: abhinav-m22, egantz

Merge Risk: Moderate · previous review fe41d

Consolidation improves overlapping publication and recovery, but publication can still block memory writes, miss mesh synchronization, or suppress an earlier insight. Legacy adoption also has audit reliability and display defects. Resolve or explicitly accept these remaining risks before merging.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: preserve consolidation provenance and version heads" names the main change. The changeset rewrites consolidate.ts to derive stable consolidation keys from source observations, validate…
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: preserve consolidation provenance and version heads" names the main change. The changeset rewrites consolidate.ts to derive stable consolidation keys from source observations, validate source sessions and observations under keyed locks, and evolve matching titles only when exactly one eligible head exists. It also adds rollback for failed predecessor demotion and a publication test suite. The PR objectives describe the same goal: preserving consolidation provenance and version heads when runs overlap or writes fail. The title is specific and accurate, and it is concise.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

devin-ai-integration[bot]

This comment was marked as resolved.

Read memories through collectAll and carry recurrence onto evolved
consolidation memories, as main does.

Deduplicate consolidation output by a key built from the concept and the
full contents of its selected observations instead of by source and
session ids. Two concepts that share observations now each publish their
insight, an observation recompressed in place produces a new version, and
an identical rerun or concurrent run is still published once.
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

Keep consolidation deduplication settled across reruns:

- Key each memory by concept, from the evidence the prompt uses, so
  compression bookkeeping no longer changes it, and carry the keys of
  every concept onto a same-title successor.
- Fall back to the source and session id comparison for memories
  published before keys existed.
- Skip a lineage with more than one same-title latest head.
- Leave agent-owned memories alone, and match the project exactly in a
  scoped run.
- Take the mem:remember lock when mem::forget deletes a memory, so it
  cannot race a consolidation publication.
coderabbitai[bot]

This comment was marked as resolved.

… heads

The pre-publication source check now compares the same evidence fields
the key hashes, so a compression retry that only updates bookkeeping
during generation no longer discards the result. A legacy head that
matches by source and session ids is stamped with the current key once
instead of blocking every later run, so a later evidence change
publishes a new version.
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@rohitg00
rohitg00 merged commit 7e53e1c into main Nov 8, 2026
17 of 24 checks passed
@rohitg00
rohitg00 deleted the fix/consolidation-races branch November 8, 2026 15:42

This branch was successfully deployed

1 active deployment
Preview — 76950f31 Deployed Nov 8, 2026 by vercel[bot]
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