Repository navigation
fix(memory): break created_at ties by id when a store loads its traces - #831
Conversation
…ite and PostgreSQL
|
Warning Review limit reached
This review includes 3 billable files and costs up to $0.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 2 minutes for your next included review. View limit details
|
Reviewer's GuideImplementationAdd a dialect-aware hydration order that sorts newest traces first and breaks timestamp ties by id in character-code order for both engines, applying it to whole-brain and scope hydration.
DocumentationDocument deterministic tie ordering for both hydration paths and note the ordering change for upgrades from 0.17.3 or earlier.
TestsVerify whole-brain hydration, scope hydration, and equally scored recall preserve the expected id order on SQLite and optionally PostgreSQL, including case-sensitive id ordering.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…ter-code order on both engines
Codex Review Summary: ✅ CompletedThis 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. |
PR Summary by QodoMake memory hydration order deterministic across SQLite and PostgreSQL
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record |
|
Review after merge, of No change needed in the code. Checked:
One docs detail, left as it is. The Upgrading line says SQLite used to load tied traces in the order they were stored, and it names both reads. That holds for the whole-brain read: the first red run shows CodeRabbit and Sourcery did not review this head. |
QA: end to end through
|
What changed
The store's two hydration reads, the whole-brain load at a store's first read and
hydrateScope, sorted bycreated_at DESCalone, so traces filed in the same millisecond loaded in whatever order the engine returned them. SQLite returned them in the order they were filed; PostgreSQL in the order its plan and the rows' updates left, so two brains holding the same traces could load them, and return equally scored lines, in different orders.Both reads now sort by
created_at DESC, id ASC(hydrationOrder). On PostgreSQL the id compares underCOLLATE "C", since the database's default collation sorts by language (abeforeB) where SQLite's binary comparison putsBfirst; with it both engines give one order. The red run shows PostgreSQL ordering by the language collation (mt-A, mt-b, …).Which direction: neither keeps SQLite's current order. Trace ids are random UUIDs, so the order of filing, which SQLite returned for the whole-brain load, matches neither ascending nor descending ids. Ascending was picked to match the
created_at ASC, id ASCreads theMemoryfacade already makes. SQLite's order of same-millisecond rows changes from filing order to id order; the docs carry an Upgrading line for it.Issue
Part of #754
Spec, plan and design
None
Docs
docs/memory/COGNITIVE_MEMORY.md: the "Loading and moving one scope" paragraph that described the open order of same-millisecond traces now states the id order, and a new "Upgrading from 0.17.3 or earlier" section (0.17.3 is the latest on npm) records the change of order on SQLite.Tests
MemoryStore.hydration-order.test.tsruns on SQLite and, inTest & Lint, on PostgreSQL. Two brains hold the same eight traces (six in one millisecond, filed in neither id order, two of them with capitals), with a different set of rows updated in each; a fresh store on each must load them in one order through the whole-brain hydration and throughhydrateScope, and a recall must return the equally scored six in that order.