Repository navigation
feat(memory): memory_traces.scope_id at schema version 3, filled on upgrade and set by its writers, and importers that deduplicate inside one scope id - #451
Conversation
|
Warning Review limit reached
This review includes 18 billable files and costs up to $4.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 4 minutes for your next included review. View limit details
Comment |
Reviewer's GuideThis PR adds an opt-in durable learning layer with per-learner hash-chained audit records and host controls, then threads tenant/session scope IDs through Brain, memory writers, retrieval, imports, summaries, and gmi() durable memory. It also migrates existing Brain databases to schema version 3, persists access state, adds deletion/freeze safeguards, and validates enabled, disabled, migration, and multi-tenant paths with unit and integration tests. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…y a schema-3 migration and set by the store
…ne scope and scope id A record's scope id is its metadata scopeId, else the scope_id an export of a schema-3 brain carries, else ''; every importer's INSERT names scope_id. The dedup check matches only a trace of the same scope and scope id, so a record whose text another tenant's trace holds is imported, and the SQLite importer's tag and time merge stays inside one scope id. Markdown, Obsidian and ChatGPT records carry no scope id and file under ''.
…traces.scope_id at schema version 3
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. |
PR Summary by Qodofeat(memory): persist trace scope IDs and scope import deduplication
AI Description
Diagram
High-Level Assessment
Files changed (18)
|
Code Review by Qodo
1. The schema migration lacks TSDoc
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d54c426d7b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…Lite import, Obsidian links and the Postgres full-text rebuild stay within the brain
- recall: the candidates of both halves of the hybrid recall pass the
recall's filters (brain, deleted, type, scope, scope id, strength, after,
before) before reciprocal rank fusion, and each half's ranks count the
candidates that passed; with none left the full-text path answers.
- export({ format: 'sqlite' }): Brain.exportToSqlite writes this brain's
rows of every portable table to a new SQLite file from either backend.
It replaces the adapter's exportToFile, which copied the whole SQLite
file (VACUUM INTO) or ran pg_dump of the whole Postgres database.
- SQLite import: reads the one brain a source file holds; a file whose rows
carry several brain ids imports nothing and errors names them; a file
older than the brain_id column is read whole.
- Obsidian export: the link prefetch reads this brain's edges and joins
nodes on (brain_id, id).
- Brain.fullTextRebuild(): the rebuild statement, bound to the brain's rows
on Postgres; the facade's import rebuild, memory_update, memory_merge and
the consolidation re-index use it.
- Docs: MEMORY_OPERATIONS (SQLite export and import, Obsidian links, the CSV
metadata rule from #451, the rebuilds, the file table) and
MEMORY_SYSTEM_OVERVIEW (the adapter's exporters copy the whole database).
Summary
memory_tracesgains ascope_idcolumn: each trace's scope id as a column of its own, with the indexidx_memory_traces_brain_scope_idon(brain_id, scope, scope_id, created_at). Before it, the scope id lived only in the metadata JSON, so a read of one scope scanned every row of a brain.''. Each brain's own migration then fills its rows that still hold'', which catches rows an older release wrote after another brain's migration added the column. On Postgres the migration runs in one transaction, so the table is locked for every brain until that fill commits.Brainalso adds the column, on any open, to a table another path created without it.MemoryStore.store(),Memory.remember(), the ingest,memory_add, the five importers, andBrain.importFromSqlite(), which copies the column from a source it opens at version 3. A release without the column writes its default,''.scopeId, else thescope_idan export of a version-3 brain carries, else'') and deduplicate, merge tags and remap trace ids inside one scope and scope id: a record whose text another tenant's trace holds is imported, where before it was dropped. Markdown, Obsidian and ChatGPT records file under''.docs/memory/MEMORY_STORAGE.mdgives the column and schema version 3;docs/MEMORY_OPERATIONS.mdgives the import rule.Not in this pull request
The branch was opened for the whole learning increment: the learning store, the hash-chained ledger, the operator host calls on
AgentOS.getLearningLayer()andagent.learning, namespaced scope ids for the GMI's memory, the memory tools, the standalone retriever and the rolling-summary sink,forgetUserand its tombstones,persistAccessState, the withdrawal ofmemory_reflect, andmemory.storeongmi(). None of that is in this diff. The description the branch was opened with is kept below for the pull request that carries it.The learning increment as first described (not in this diff)
Learning gets a durable record. With the learning flag on, a learning store keeps each learner's trait row, the run-time freezes and suspensions, a sessions index and the tombstones of forgotten users; an append-only ledger, one hash chain per learner whose heads advance by compare-and-swap, records every memory write the memory tools and the rolling-summary sink make and every operator call, so an edit made outside the layer shows at the next load. Operators freeze, suspend, set, revert, export, import and forget through host calls on
AgentOS.getLearningLayer()andagent.learning. Memory a learner owns is filed and read under scope ids that keep tenants, users and sessions apart (the GMI's memory, the memory tools, the standalone retriever and the rolling-summary sink), and every write of a user's memory honoursforgetUser's tombstone, writes in flight included.gmi()gets durable memory (memory.store). For every host:memory_traces.scope_id, per-scope import deduplication, and the stability fix behindpersistAccessState.For every host, flag on or off:
memory_tracesgains ascope_idcolumn (Brain schema version 3), backfilled from each row's metadata and set by every INSERT: the store's,Memory.remember()'s, the ingest's,memory_add's, the five importers' andBrain.importFromSqlite()'s. Nothing reads it with the learning flag off. An older release's writes leave it''. The first open of a Brain after the upgrade adds the column and fills it for every brain in the table, about one read and one write statement per 300 rows; on Postgres the table is locked for every brain until that fill commits.persistAccessState, defaulttrue;falsekeeps the previous behaviour for one release).memory_reflect, refuse withfrozenunderAGENTOS_LEARNING_FREEZE=1, with a learning layer or without one.IKnowledgeGraph.deleteMemories,ICognitiveMemoryManager.deleteScopeanddeleteTraces, the learning interfaces,IAgentOS.getLearningLayer), which no implementer has to add.gmi()'smemory.storeneeds the learning option andlearning.agentKey, and fails at construction naming them without either.With the learning flag on:
learning.ledgerKeykeys the hashes.freeze,unfreeze,suspend,unsuspend,operatorSet,revert,exportLearnedState,importLearnedState,forgetUser(onAgentOS.getLearningLayer(), and onagent.learningwith the agent's key and namespace filled in).MemoryStore.refileScope, and runs it before it relies onforgetUserfor them (until thenforgetUserwith a namespace leaves their plain-form traces and logs a WARNING).userorpersonascope that holds a/, a%or a:is filed percent-encoded, and a Brain's earlier traces under such ids are re-filed when a layer first opens it.threadids are filed and read in that form, so a conversation's thread traces from before the layer are not read.userrecall list; the bridge no longer adds the owner id to theorganizationlist, where a turn's own organization ids stay; an owner id that begins with/or holds//leaves thethreadlist.organizationwrite; their writes and the sink's are recorded, with no user on a turn with no learner; only a freeze stops them, and in modeoffor under a suspension they write with no row.memory_reflectis withdrawn; hosts consolidate withMemory.consolidate().memory.storeongmi()gives durable memory, with the learning store on the same adapter.Memory.consolidate()merges and derives across scope ids, andforgetUserdoes not reach the memory archive (its report names it), so products turn the flag on with the release that keeps consolidation inside each scope id and reaches the archive, or a later one.Linked issues
None.
Type of change
How this was verified
CI on this pull request (
ci.yml): Build, the exports check, Lint, the documentation word check, Type check and Test with coverage.Brain.scope-id.test.tsruns on real SQLite files through@framers/sql-storage-adapter: the migration of a version-2 file holding two brains (every metadata shape, a malformed row, and 650 rows a brain across pages), a fresh brain, a row an older writer adds after another brain migrated,MemoryStore.store(),remember(), the ingest andmemory_add, and the JSON, SQLite, CSV and Markdown importers with two tenants holding one equal text.Brain.test.tsandBrain.postgres.test.tsread schema version 3.Migration notes
No caller changes. A host's first open at version 3 adds and fills the column (see the Summary); on Postgres that fill holds the table's lock for every brain until it commits. An import that skipped a record because a trace of another scope id held its text imports it now.
Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).Summary by Sourcery
Introduce schema version 3 scope IDs for memory traces and apply scope-aware persistence and import deduplication.
New Features:
scope_idcolumn and supporting index to memory traces in schema version 3.Bug Fixes:
Enhancements:
Documentation:
scope_idcolumn and scope-aware import deduplication behavior.Tests: