Registered services write with a ranked authority, and a correction no rule can settle waits for an operator

MemoryOS (memengine)

A multi-tenant FastAPI memory service over PostgreSQL and Qdrant that ranks registered source services and withholds disputed records from retrieval.

LicenceMIT in LICENSE and in each SDK's LICENSE and manifest; the root pyproject.toml declares none; the hosted service's billing code is in the same tree
Size66,051 lines of Python in 272 files under api/, 57,022 in tests and 28,464 in benchmarks; the memory is conflict_resolver.py (3,207), extraction_service.py (3,145), retriever.py (2,001), extraction_tasks.py (1,942), memory_service.py (1,468), claim_ledger_service.py (702), service_correction_service.py (360) and db/models.py (3,431)
Activity541 commits from 20 March to 25 November 2026, 538 under two author names; no tags; Python SDK 0.1.2 and TypeScript SDK 0.1.3
Tests1,957 Python test functions, 1,591 unit and 356 integration; CI runs the unit suite and 16 integration files against PostgreSQL and Redis; four integration files carry an opt-in skip, the service-correction suite among them; none run for this reading

Carries 6 of 7 rubric mechanisms. Most systems here carry none or one (41%), and a dash means the mechanism was not found at this commit — not that the system needed it. Each mark is one LLM reviewer's reading of the code at this commit rather than a run of it — known limits.

  • Tombstone
  • Trust state
  • Bi-temporal
  • Scope enforced
  • Mutation audit
  • Human review
  • Negative evals

1. Executive Summary

MemoryOS is a multi-tenant memory API for agents that talk to customers: an application or a registered backend service sends a conversation or an event, a worker extracts facts with an LLM, and a later call retrieves the current records with their source. Notable: authority between sources is configured, not inferred. Each registered service carries a priority per category, a correction the rules cannot settle is held rather than guessed, and while it is held retrieval withholds the record it would replace and says so. Weak: the ledger that enforces all of this is bypassed by the plain edit route. PATCH and the agent-facing correct route rewrite a record's text in place, so the served text and the claim ledger disagree from then on.

The design treats retrieval as a reading of current state, not a similarity search. A vector hit only nominates an id; PostgreSQL decides whether the row is current, in scope, inside its validity interval, and the coherent winner of its claim (api/services/retriever.py:228-436). A record withheld for any of those reasons produces a memory_visibility notice in the response, and the agent is expected to read it before answering.

Six marks are present. tombstone is withheld (section 9).

Licence. MIT in LICENSE, sdk/python/LICENSE and sdk/typescript/LICENSE, and in both SDK manifests. The root pyproject.toml names no licence, and the copyright line reads memoryos at the root and MemoryO in the SDKs. The hosted product's billing, Razorpay webhooks and plan limits are in the same tree. SECURITY.md asks for vulnerabilities by private email, not public issues.

2. Mental Model

A memory becomes current through the resolver, and the resolver's first question is who said it. Conversation turns from an application carry a server-assigned evidence authority: 20 for a client assertion, 50 for a legacy conversation, 60 for an application-attested turn (api/services/evidence_policy.py:10-17). A backend event sent with a registered source.service carries that service's authority_rules, a default priority and optional per-category overrides between 0 and 100 (api/services/conflict_resolver.py:2386-2397). The extraction model must cite the user turn that supports each fact, and it labels each one asserted, correction or uncertain_change (api/services/extraction_service.py:2203-2343).

For each extracted fact the resolver finds candidates by vector search inside the owner and, for a registered source, the exact source scope (api/services/conflict_resolver.py:899-985). Then, in order:

  • Higher authority wins outright. If both sides have explicit rules and the incoming priority is higher, the result is UPDATE; if lower, REJECT, and a lower client assertion against trusted evidence becomes CLARIFY (api/services/conflict_resolver.py:2399-2526).
  • Same source, older event loses. An event observed before the stored one is rejected.
  • Equal authority, two writers, different text is CLARIFY for the tenant: the new value is stored archived, and a cross-user conflict row is opened (api/services/conflict_resolver.py:1066-1086, :1184-1238).
  • Otherwise a model classifies the pair, unless years in the two texts differ, which keeps both.
  • A correction from a registered writer with no safe target is not stored. It becomes a pending candidate with reason source_correction_unresolved (api/services/conflict_resolver.py:1351-1362).

UPDATE and MERGE archive the predecessor and link the successor through previous_version_id. REJECT writes an audit row holding the rejected text and nothing else. A claim ledger records each write: one memory_claims row per owner, category, scope and exact proposition, with revisions activated, asserted, superseded, disputed, rejected or archived, and a partial unique index allowing one activated revision per claim (api/db/models.py:866-1083).

A record stops being believed in four ways: a successor archives it, decay archives it after 90 days unread at importance below 1.5 (api/tasks/decay_tasks.py:37-66), its validity interval or expires_at passes, or a delete removes it. A pending correction suspends belief without changing the record: while it waits, retrieval withholds the incumbent.

Diagram — the resolver decides by writer authority and event time before any model; a correction it cannot bind is held, the incumbent is withheld from reads while it waits, and only an admin key applies or declines it; PATCH reaches the record without the ledger
Diagram source
%% caption: the resolver decides by writer authority and event time before any model; a correction it cannot bind is held, the incumbent is withheld from reads while it waits, and only an admin key applies or declines it; PATCH reaches the record without the ledger
flowchart TD
    I["Chat turn or<br/>registered service event"] --> X["LLM extraction:<br/>cited user span,<br/>claim_state"]
    X --> R["Resolver: candidates<br/>in owner and<br/>exact source scope"]
    R -- "authority or<br/>event time" --> U["Winner current,<br/>loser archived<br/>or rejected"]
    R -- "equal authority,<br/>two writers" --> C["Value stored archived,<br/>tenant conflict opened"]
    R -- "correction,<br/>no safe target" --> P["Pending candidate,<br/>not a memory"]
    P --> H["Reads withhold the<br/>incumbent: same category,<br/>same scope, notice"]
    H --> O["Operator, admin key:<br/>preview, then apply<br/>or decline by version"]
    O -- "apply" --> U
    O -- "decline" --> D["dismissed;<br/>incumbent returns"]
    U --> Q["Read: claim active,<br/>revision, memory and<br/>source coherent"]
    E["PATCH or MCP correct:<br/>text rewritten,<br/>ledger untouched"] --> Q

3. Architecture

A FastAPI service, a Celery worker, a Celery beat scheduler, PostgreSQL, Redis and Qdrant, with LocalStack standing in for the key service in the Docker beta (beta/compose.yml). Writes return a job id; the worker runs extraction and resolution and commits memories, claims, versions, audit rows and a vector outbox row in one transaction. A publisher drains the outbox to Qdrant every 5 seconds (api/tasks/vector_sync_tasks.py:24-29). Memory content is also written into a per-tenant encrypted envelope column during a rollout in which the plaintext column stays authoritative (api/db/models.py:756-758).

The default extraction model is gpt-4o-mini and the default embedding text-embedding-3-small (api/infra/llm_providers/openai_provider.py:11-12); Gemini, Anthropic, Cohere and a local provider are routable. Every embedding model gets its own Qdrant collection, and retrieval queries each model a user's memories were written with (api/services/retriever.py:1944-1991).

Three feature-flagged planes sit beside the main one: explicit preference claims (EXPLICIT_PREFERENCE_CLAIMS_ENABLED), EdTech and support domain schemas, and a cross-tenant "memory passport" whose routers mount only under MEMORY_PASSPORT_ENABLED (api/main.py:377-384, api/settings.py:81-83). This report reads the main plane and the preference gates where they touch it.

Deployment and ergonomics

Five services and an OpenAI key, which the beta guide says is needed to store anything (beta/README.md). beta/bootstrap.py creates one tenant, one admin key and two writer keys with priorities 20 and 95, and refuses any database but the Compose one. examples/demo/run.py simulates the Billing and CRM correction offline with mocked extraction. The store is relational and inspectable with psql; repairing it by hand means keeping memories, claims, revisions and the outbox consistent, which the code checks on every read.

4. Essential Implementation Paths

  • Write. POST /v1/memories/add → quality gate → ProxyUserService.resolve → MemoryService.queue_memory_add (api/routers/memories.py:235-420, api/services/memory_service.py:218). The writer is resolved from source.service or the key's binding, and a writer bound to a key refuses any other key (api/services/provenance_service.py:143-186).
  • Extraction. process_extraction_job → run_extraction_pipeline → ExtractionService, then evidence verification of cited spans (api/tasks/extraction_tasks.py:1408, :1907, api/services/extraction_service.py:2480-2560).
  • Resolution. ConflictResolver.check_and_store (api/services/conflict_resolver.py:854-1393), _authority_conflict_decision (:2399-2526), _store_new_memory (:2919-3036), _archive_memory (:3107-3140), and ClaimLedgerService.record_memory (api/services/claim_ledger_service.py:60-185).
  • Pending candidates. _buffer_source_candidate → _persist_pending_extraction_candidates (api/services/conflict_resolver.py:1660-1672, api/tasks/extraction_tasks.py:750-869).
  • Retrieve. RetrieverService.retrieve → _retrieve_candidates → _final_current_read → _project_source_claims → _withhold_pending_source_corrections (api/services/retriever.py:198-436, :475-822), then ContextBuilder (api/services/context_builder.py:15-110).
  • Operator correction. /v1/memories/service-corrections list, preview and decision → load_preview and decide (api/routers/service_corrections.py:33-62, api/services/service_correction_service.py:111-299).
  • Edit and delete. MemoryService.update_memory and delete_memory (api/services/memory_service.py:628-786); profile deletion ProxyUserService.delete_all_memories (api/services/proxy_user_service.py:159-197).
  • Background. Beat schedule in api/celery_app.py:58-75.

5. Memory Data Model

  • memories: content, category, importance, confidence, effective_from, effective_until, expires_at, previous_version_id, source_event_id, agent_id, is_archived, access counters, and metadata.provenance holding the writer snapshot and the extraction evidence (api/db/models.py:725-863).
  • memory_source_events: tenant, owner, writer, key, service, external event id, observed_at, received_at, payload hash, scope and evidence references, unique on tenant, service and event id (api/db/models.py:514-595).
  • service_writers: service key, bound API key, authority_rules, is_active (api/db/models.py:458-512).
  • memory_claims and memory_claim_revisions, described in section 2.
  • memory_versions: a full snapshot per change with change_type and changed_by in system, user or operator (api/db/models.py:1084-1127).
  • pending_extraction_candidates: content, reason, fingerprint, status pending, promoted, dismissed or expired, and the extraction evidence (api/db/models.py:3014-3136).
  • audit_logs: action, memory, old and new values, metadata (api/db/models.py:1130-1175).

The owner is a proxy user, one per tenant and external_user_id, hashed for lookup. Times are three: observed_at from the source, created_at on write, and the validity interval when a writer sends one in source.scope (api/services/temporal_validity.py:7-20). Nothing defaults the interval to the write time.

6. Retrieval Mechanics

Retrieval is tool-mediated: the application calls /v1/memories/retrieve with a query and gets ranked records, a prompt-ready system_prompt_addition capped at 500 tokens by default, and a visibility notice (api/routers/memories.py:571-760, api/services/context_builder.py:15).

The candidate path is tiered. A hot tier and a Redis cache nominate ids, and any cached ranking is re-hydrated from PostgreSQL and discarded whole if one row changed (api/services/retriever.py:550-570). Below five memories, or while the owner has outbox rows unpublished, retrieval lists rows from SQL instead of searching (:606-640). Otherwise each relevant embedding model is queried in Qdrant with tenant, owner, category, agent and archive filters, results below cosine 0.315 are dropped, and the rest are scored 0.60·semantic + 0.25·importance/10 + 0.15·recency (:76, :107-117, :779-785). A circuit breaker on Qdrant falls back to SQL listing.

Then one REPEATABLE READ snapshot decides what may be shown (api/services/retriever.py:228-335):

  • Runtime hold. An extraction job in flight on the runtime route, or one that failed, can withhold the whole profile, returning nothing with processing or unavailable.
  • Claim projection. A writer-sourced candidate is replaced by its claim's winner, and dropped unless claim, revision, memory, source event and owner all agree and the claim is active (:84-104, :388-436).
  • Pending corrections. Any pending source_correction_unresolved candidate withholds the owner's current writer-sourced records in the same category and exact scope (:341-386).

as_of skips all three. retrieve returns the candidate list before the snapshot whenever as_of is set (api/services/retriever.py:222), and the router skips source reviews for it. A historical read can therefore return a record that a current read would withhold.

Recall is narrow by design. The project's own LongMemEval and LoCoMo audits, committed with their numbers, conclude that the product stores durable state and not a searchable transcript, and close both tracks (benchmarks/public/README.md, benchmarks/public/longmemeval/longmemeval-root-cause-audit.md).

7. Write Mechanics

Every write is a queued job. The route returns a job id, an ETA and X-MemoryOS-Processing; the caller polls /v1/memories/jobs/{id}. Extraction is one model call per job plus one classifier call per conflicting pair, and the source-decision path counts its own calls and tokens (api/services/conflict_resolver.py:873-876).

The extractor admits a fact only with a cited user turn. A citation is checked against eligible user turns; a fact without one is dropped as unsupported_user_evidence, and the evidence records whether the span was verified, a registered proposal, or legacy token overlap (api/services/extraction_service.py:2522-2556). Questions alone do not produce facts.

Deduplication of pending candidates uses a fingerprint over category, normalised text and the source binding (writer, event, scope), plus a similarity and polarity check for reinforcement (api/tasks/extraction_tasks.py:560-652). A new event from the same service therefore opens a new candidate even with the same text.

An edit bypasses the ledger. update_memory assigns the new content, re-embeds, records a manual_edit version and commits; it reads no claim and writes no audit row (api/services/memory_service.py:628-722). The claim keeps the old proposition as active_value, the read gate compares revision and claim to each other and not to the memory's text, and so the edited text is served as the claim's winner. The operator path then refuses that record, because it requires revision.asserted_value == target.content (api/services/service_correction_service.py:151). The public MCP correct route calls the same function for the caller's own profile (api/routers/mcp.py:574-592).

A superseded value keeps an open interval. _archive_memory sets is_archived and records a version; it does not set effective_until (api/services/conflict_resolver.py:3107-3140). The as-of query admits an archived row only when it has a bound (api/services/retriever.py:1185), so a value replaced before anyone sent validity is invisible to every as-of read, including those dated while it was true.

Operational cost

The agent does not block on extraction; a memory is retrievable once the worker commits, and from SQL before the outbox publishes. Lag is the queue wait plus one or two model calls. No pass rewrites the whole store: decay and forgetting select by predicate nightly, validity transitions run every 5 minutes, and a lifecycle pass runs weekly (api/tasks/lifecycle_tasks.py:21-39). Per read, the injection is bounded by context_max_tokens, and the MCP session capsule uses a fixed query and six records (api/routers/mcp.py:216-220).

8. Agent Integration

The primary surface is the REST API through the SDKs, called by the application's server with a tenant key. /v1/memories/prepare-turn combines admission and retrieval for a chat turn. A LangGraph example reads with the visibility notice in the graph state.

/v1/mcp/tenant/* serves a public MCP client: remember, context, session-context, list, explain, correct, forget, clarifications and answer. These require a Clerk session and the header x-memoryos-mcp-client: public-v1, and the profile is derived from the tenant and the Clerk subject, so a caller cannot name another user (api/routers/mcp.py:291-306). Writes from it are client_assertion with authority 20. The MCP server that calls these routes is not in this tree.

9. Reliability, Safety, and Trust

What the read gates hold

The three gates in section 6 run on every current read with a tenant and an owner, in one snapshot, after any cache. The integration suite builds a cache entry for another profile's memory and requires the read to return only the caller's own (tests/integration/test_retrieval_cache_currentness_postgres.py:415-490). A withheld record is never silently missing: the response names the state and the scope, and the context builder renders a notice in its place.

Who settles a correction

The service-correction queue is the one place a person decides. List, preview and decision accept only an API key and check in SQL that it is an active tenant admin; a Clerk org admin is refused (api/routers/service_corrections.py:22-30, api/services/service_correction_service.py:82-94). The preview lists blockers (source disabled, credential revoked, lower authority, older observation, validity not current), and apply is offered only without them. The decision must carry the preview's review_version and target_version, and the final transaction re-reads everything under row locks (:225-299). A decision is replayable with the same request digest and refused with any other.

Two other queues exist. Self-scoped clarifications are answered by the end user's application or by the MCP client, which is the model (api/routers/mcp.py:670-753). Cross-writer conflicts are resolved on /v1/tenant/conflicts/{id}/resolve under tenant admin.

What a decline remembers

A decline sets the candidate to dismissed and keeps the incumbent. The candidate's fingerprint includes its source event, so the same correction sent in the next event from the same service opens a new pending candidate and withholds the incumbent again. REJECT keeps the rejected text only in an audit row that nothing reads back.

Deletion

A soft delete archives and queues a vector delete. A hard delete removes the memory; its versions and claim revisions cascade with it, and the claim is re-pointed to a remaining activated revision or archived (api/services/memory_service.py:724-855). The version recorded just before the delete is removed by the same cascade. Profile deletion deletes every memory and writes one audit row with the counts (api/services/proxy_user_service.py:159-197).

Marks

  • trust_state — present. A pending candidate is a state that withholds both itself and the record it would replace, and a writer-sourced memory is read only through an active claim.
  • bitemporal — present. Validity from the writer's scope, separate from record and observation time, enforced on current reads and queryable by as_of.
  • scope_enforced — present. Tenant and owner on every SQL and vector arm.
  • audit_log — present, for resolver, operator, decay and deletion paths. Direct edits and deletes write versions and no audit row.
  • human_review — present, for registered-writer corrections, decided by an admin key that writer keys and MCP sessions cannot use.
  • negative_eval — present, on scope and on a superseded value, in CI.
  • tombstone — withheld. A decline is keyed on the candidate and its source event, a REJECT is an audit row, and the comment calling an archived preference claim a "tombstone" describes a property reference with no value.

10. Tests, Evals, and Benchmarks

CI installs the package and runs migrations against PostgreSQL 15 and Redis 7, then pytest tests/unit/, 16 named integration files, and a "fast" benchmark tier that blocks the build (.github/workflows/ci.yml:51-132). The integration files exercise the real resolver and SQL with a fake embedder and scripted model decisions: source decisions, preference lifecycles, cache currentness and a two-process cache test.

The service-correction suite is thorough and opt-in. It covers apply, decline, replay, stale previews, revoked keys mid-embedding, foreign owners, injected outbox failure and a five-way concurrent retry, and requires after apply that the source projection returns only the successor (tests/integration/test_service_correction_resolution.py:51, :197-203). It runs only with MEMORYOS_SERVICE_CORRECTION_SQL=1, and CI does not set it.

Cases to want first: a PATCH on a writer-sourced record followed by a read and an operator preview; an as-of read during a pending correction; an as-of read dated before a supersession of an unbounded value; a declined correction re-sent as a new event.

benchmarks/internal holds datasets, baselines and runners for extraction, conflict, temporal, retrieval, deletion and fault injection, with a holdout the public runner refuses to load. benchmarks/public holds LongMemEval and LoCoMo adapters and the audits that closed both; the root-cause audit reports 54.70% mean answer-turn coverage on a 30-case sample and attributes the weak preview to an architecture with no episodic store. No paper describes the system; the one arXiv link is to MemoryAgentBench, reviewed and not adopted.

11. For Your Own Build

Steal

  • Rank sources by configuration, per category. A priority per writer and category decides most conflicts before any model is asked, and the decision records which rule fired.
  • Hold a correction you cannot bind, and withhold what it would replace. The agent gets a notice and no stale answer; nothing is guessed.
  • Let a vector hit nominate and SQL decide. Re-hydrate every cached or searched id through the same predicate as a fresh read, and drop a cached ranking whole when one row changed.
  • Make the operator decision a compare-and-swap on the preview. A digest of everything shown, re-checked under locks, refuses a decision on state the operator did not see.
  • Bind a writer to its key. A service name that arrives with another key is refused.

Avoid

  • Do not keep an edit route beside the ledger. Every text change should pass through the path that writes the claim, or the read gate checks the wrong thing.
  • Close the predecessor's interval on supersession, or historical reads lose the value they exist to answer.
  • Do not let a historical read skip the current read's holds without saying so in the response.
  • Do not key a decline on the event that carried it if the same claim will be sent again.

Fit

Fits a team building a customer-facing agent whose facts come from several backend systems that disagree, with an operator who can answer a correction queue, and an engineering budget for PostgreSQL, Redis, Qdrant, Celery and a model key. The machinery assumes the facts are about a customer and the writers are known in advance.

Walk away if memory must recall what was said in a conversation rather than what is true about a person, if one process and a file are the deployment, or if the only writer is the agent itself: then authority ranking has nothing to rank.

12. Open Questions

  • Whether PATCH and the MCP correct route are meant to leave the claim ledger untouched for a writer-sourced record.
  • Whether a declined correction is meant to return with the next event, or whether a value-keyed decline is planned.
  • Whether as_of is meant to bypass the holds and the claim gate.
  • How often a registered writer's correction falls through to pending in practice, since a higher-authority writer's correction resolves as UPDATE when the vector search finds the target.
  • Whether the hosted service runs the tree as committed.

Appendix: File Index

  • Schema: api/db/models.py, api/db/migrations/versions/
  • Write path: api/routers/memories.py, api/services/memory_service.py, api/services/provenance_service.py, api/tasks/extraction_tasks.py, api/services/extraction_service.py, api/services/evidence_policy.py
  • Resolution and ledger: api/services/conflict_resolver.py, api/services/claim_ledger_service.py, api/services/version_service.py
  • Retrieval and context: api/services/retriever.py, api/db/vector_store.py, api/services/context_builder.py, api/services/temporal_validity.py
  • Operator review: api/routers/service_corrections.py, api/services/service_correction_service.py, api/middleware/rate_limiter.py
  • Agent routes: api/routers/mcp.py
  • Background: api/celery_app.py, api/tasks/vector_sync_tasks.py, api/tasks/decay_tasks.py, api/tasks/lifecycle_tasks.py
  • Beta: beta/bootstrap.py, beta/compose.yml, beta/OPERATOR.md
  • Tests: tests/integration/test_retrieval_cache_currentness_postgres.py, tests/integration/test_source_decision_postgres.py, tests/integration/test_service_correction_resolution.py, tests/unit/test_source_retrieval_projection.py, tests/unit/test_service_correction_contract.py, tests/unit/test_as_of_retrieval.py
  • Benchmarks: benchmarks/internal/, benchmarks/public/

Recorded searches

Run from the repository root at the pinned commit with /usr/bin/git grep.

  • Nothing updates or deletes an audit row. git grep -n -E 'delete\(AuditLog|update\(AuditLog' -- api returns nothing; the control git grep -c 'AuditLog(' -- api/services/conflict_resolver.py counts 1.
  • Edit and delete write no audit row. git grep -n -E 'AuditLog' -- api/services/memory_service.py returns nothing; the control git grep -c 'record_version' -- api/services/memory_service.py counts 4.
  • The edit path reads no claim. git grep -n -E 'MemoryClaim|ClaimLedger' -- api/services/memory_service.py returns the imports and lines 797-825, all inside _hard_delete_memory_and_reconcile_claims.
  • Nothing reads a rejected value back. git grep -n -E 'AuditLog\.(action|old_value|new_value)' -- api returns nothing; git grep -n -w tombstone -- api returns only preference_claim_service.py:262.
  • Writer registration does not check key permissions. git grep -n -E '"admin"' -- api/routers/tenant.py api/services/provenance_service.py returns nothing; the control git grep -c '"admin"' -- api/services/service_correction_service.py counts 2.
  • No MCP server in the tree. git grep -n -E 'FastMCP|mcp\.tool|tools/list|@server\.' -- . ':!*.lock' returns nothing; the control git grep -c -E 'APIRouter' -- api/routers/mcp.py counts 2.
  • No paper. git grep -n -i -E 'arxiv|doi\.org|bibtex|@article|@misc' -- . ':!*.lock' ':!*package-lock.json' returns benchmarks/public/selection-v2.md:43 only; CITATION.cff is absent.
  • No submodules. .gitmodules is absent.

History

2026-12-02 — e3bcbd42…. First reading, read at the user's request from the 2026-12-02 triage shortlist, from a full clone at the head of main, read only. Screened: no auto-run surface; pyproject.toml inside the seven-day cooldown; three build-time execution surfaces (Makefile, the TypeScript SDK's prepublishOnly, tests/conftest.py); three unpinned surfaces (both Python manifests without lockfiles, two floating ranges in sdk/typescript/package.json beside its lockfile); AGENTS.md read as data. The EdTech, support and passport planes and the billing code were not read beyond where the main path reaches them. Nothing was installed, built or run, and no test was run. Six marks (section 9).