Skip to content

feat(memory): establish canonical promotion pipeline - #10772

Merged
Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
Git-on-my-level:feat/canonical-memory-promotion-pipeline
Jul 28, 2026
Merged

Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
Git-on-my-level:feat/canonical-memory-promotion-pipeline

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

What changed and why

Replace the remaining split memory lifecycle with one canonical pipeline: broad, bounded intake always lands in Short-term; canonical consolidation is the sole route into Long-term and atomically records its promotion receipt and graph assertion. Retrieval now collapses canonical lineage, while vector, keyword, compatibility, and graph projections converge from a durable outbox instead of acting as memory authority.

High-level change map

  • Broad Short-term intake: conversation extraction, explicit writes, observations, imports, APIs, plugins, and integrations now enter the same Short-term lifecycle. Capture is subject-aware, accepts useful short utterances, preserves source state when grounding is invalid, and retracts only genuinely empty extraction results.
  • One Long-term admission authority: canonical consolidation gives every pending item exactly one route—promote, archive, review, or reject. Promotion is the only route into Long-term and atomically commits the promotion receipt, canonical item, ledger state, structured graph assertion, and derived-view outbox work. The old generic L2 promotion workers and helper paths are removed.
  • Cleaner, higher-context retrieval: default access can use eligible Short-term and Long-term memory, but collapses aliases and superseded items by canonical lineage so one logical fact appears once. Vector hydration is fenced to the authoritative item revision/commit, restricted content stays provider-ineligible, and chat/developer/MCP compatibility adapters preserve the canonical policy.
  • Reliable derived projections: vector, keyword, V3 compatibility, and graph cleanup are durable, retryable outbox effects rather than competing memory owners. Workers reload authoritative state, use leases and idempotent writes, reconcile after provider calls, and acknowledge only successful convergence.
  • Correct replacement and privacy closure: conversation reprocessing replaces its complete source set atomically, restores independently supported facts when a merged source disappears, and keeps source-addressable lineage. Memory deletion, conversation cascades, exact 100-item batches, and account deletion now close over canonical lineage under durable deletion and processing fences.
  • Bounded cost and failure handling: consolidation and required-processing work use stable cursors, bounded Firestore queries, capped batch sizes and LLM calls, retry leases/backoff, and terminal review/quarantine after repeated failure. Sparse legacy scans rotate durably so old rows cannot starve newer work.
  • Operational and contract updates: the PR adds the canonical maintenance schedule/runtime contract, Firestore indexes and rules, malformed-document read-boundary coverage, deployment setting classification, architecture/runbook updates, the proposed INV-MEM-4 lifecycle invariant, and a backend prevention artifact for FC-split-mutation-authority.

Why these are improvements

  • Simpler ownership: capture, admission, mutation, and projection responsibilities now have one named authority each. Removing parallel promotion paths makes contradictory tier/graph state structurally harder to create.
  • Better recall without simply returning more noise: broad intake retains potentially useful observations in Short-term, while evidence/subject validation and the exact-one-route consolidation boundary decide what deserves durable Long-term status.
  • Better precision: promotion requires structured grounding and a graph plan; retrieval rehydrates authoritative records and collapses lineage before returning results, rather than trusting stale provider rows or showing both an alias and its survivor.
  • Higher reliability and privacy: canonical state and every derived effect are journaled together, external work is retried from authoritative state, stale generations are fenced, malformed Firestore documents use the shared sanitized boundary, and deletion wins over delayed projection work.
  • Controlled cost: all new maintenance scans and LLM paths have explicit query, batch, attempt, and per-pass bounds. Failed or poisoned work is quarantined instead of being retried forever or starving the queue.
  • Evidence, not only structure: behavioral tests execute production seams for capture, consolidation, atomic apply, replacement, deletion, retrieval, projection delivery, scheduling, and malformed data. Fault cases assert rollback, retry, redaction, and no-side-effect behavior.

The requested recall, precision, reliability, and cost percentages remain design targets. This PR establishes the mechanisms expected to improve those metrics but does not claim production benchmark results.

Product invariants affected

  • INV-MEM-1
  • INV-MEM-2
  • INV-MEM-4 (proposed)

How it was verified

  • BACKEND_PYTEST_WORKERS=1 bash test.sh swept all 776 backend test files. It initially exposed nine integration-fixture regressions; after repairing those seams, BACKEND_UNIT_TEST_FILE_LIST=.unit-failures.txt BACKEND_PYTEST_WORKERS=1 bash test.sh passed every formerly failing file.
  • Focused canonical capture, consolidation, apply/outbox, lineage/privacy, adapter, runtime-contract, and source-replacement suites passed, including the hermetic canonical pipeline path.
  • make preflight passed the complete diff-scoped local manifest.
  • The bounded pre-push gate passed all 60 selected backend test files with serial workers; the one prior parallel-only duration failure passed its required guarded rerun (22 passed in 0.80s).
  • Pyright (0 errors), Black, Ruff, Python compilation, changed-workflow actionlint, Firestore index generation/coverage, runtime validators, and the app-client OpenAPI drift check passed.
  • npx tsc --noEmit --incremental false passed for the admin web workspace.

No production deployment or live personal account data was used. A live-service/user-facing production exercise therefore remains intentionally unperformed.

Tests

Core-path and error-path coverage was added or updated for broad Short-term capture, sole-route consolidation, atomic graph-backed promotion, required-processing retries, source replacement/reactivation, lineage collapse, projection retries/read fences, privacy deletion, account purge, bounded review queries, scheduler wiring, and compatibility adapters.

Failure class (fixes)

Failure-Class: FC-split-mutation-authority

New guards (only when adding a check or ratchet)

Merged PRs #9365 and #9597 are the recorded instances this would have caught. backend/tests/unit/test_canonical_maintenance_ordering.py is intentionally a backend behavioral contract, not a new shared checker, because it must execute the production memory-maintenance owner and prove that no second promotion route can run when consolidation is blocked; the shared cross-component primitive remains the FC-split-mutation-authority registry contract.

Review in cubic

Failure-Class: FC-split-mutation-authority

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 165c041a93

ℹ️ 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".

…tch guard

- Remove module-level pydantic import from run-canonical-maintenance.py;
  duck-type BaseModel via model_dump so the bare-Python dev-harness test
  lane (repo-checks Hygiene + PR Metadata Preflight) can load the script
  without backend deps. The serialization test now skips when pydantic
  is unavailable instead of erroring.
- Add batch-level duplicate-supersede-target detection in
  _validate_agent_batch so two decisions that supersede the same active
  Long-term candidate are rejected pre-apply rather than producing a
  partial-apply maintenance run after the first promotion commits.
- Add regression test for the duplicate-supersede scenario.

Addresses Codex P2 review comment r3665114173.
The duplicate-supersede batch guard adds 11 lines to the canonical
admission authority file, squarely within its existing split-mutation
justification.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Resolved Codex P2 thread r3665114173 — duplicate-supersede-target guard.

The batch-level guard added in 28db796a5c rejects two decisions that supersede the same Long-term candidate before any apply phase runs, so the second decision can no longer reach _validate_authoritative_targets with an already-superseded (inactive) target after the first promotion commits. Verified locally: test_batch_rejects_duplicate_supersede_across_decisions and all 56 canonical_consolidation unit tests pass.

@Git-on-my-level
Git-on-my-level marked this pull request as draft July 28, 2026 16:32
@Git-on-my-level
Git-on-my-level marked this pull request as ready for review July 28, 2026 22:25
@Git-on-my-level
Git-on-my-level merged commit 9d4e353 into BasedHardware:main Jul 28, 2026
34 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

for decision in agent_batch.decisions:
for target_id in decision.supersedes:
if target_id in seen_supersede_targets:
return f"output_invalid:duplicate_supersede_target:{decision.source_memory_id}"
seen_supersede_targets[target_id] = decision.source_memory_id

P2 Badge Reject targets superseded elsewhere in the batch

When one promotion supersedes Long-term item X and another non-promote decision uses X as its target_memory_id (for example, an archive decision with reconciliation="duplicate"), this guard accepts the batch because it records only decision.supersedes. Promotions are applied first, so the first decision marks X superseded; the later decision then fails _validate_authoritative_targets, which also requires target_memory_id to remain active, after the promotion has already committed. Fresh evidence in the current guard is this mismatch between the references it records and the references the apply boundary validates; reject an intersection between any decision's target and another decision's supersedes before applying the batch.

AGENTS.md reference: AGENTS.md:L45-L49

ℹ️ 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".

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