Repository navigation
feat(memory): PR-1 registry, index, recover, doctor foundation - #592
prodempsey wants to merge 7 commits into
Conversation
Corrective fixes on the PR-1 registry core against the exact-SHA QA findings. All changes stay within the inert memory/ package (code + tests); no workflow, migration, PGlite, vector, recall, or Fleet Bridge scope. Blockers fixed: - Cross-process lock: atomic mkdir mutex with an ownership token written via temp+rename; a freshly created lock with no visible owner is treated as initializing/busy for a bounded grace, never immediately stale; stale reclaim requires sufficient age plus proof the owner is absent, via an atomic rename-steal; release verifies the ownership token. Index projection now refreshes under the same mutation lock, with a monotonic compare-before-install guard so an older projection cannot overwrite a newer one. - State machine: explicit transition table for every legal edge; illegal transitions refused without altering canonical state; high-impact activation requires an independent activator or captain authority; quarantine recovery via a defined revalidate transition; supersession requires an existing active successor and updates both sides of the lineage atomically; terminal states are terminal. guard_linked and factual/procedural memory type added to the schema with event-specific structural validation. - Sparse, non-destructive mem update: only caller-supplied fields change. - Byte-faithful, crash-durable recovery: raw-byte corrupt-suffix preservation, exact valid-prefix repair, fsynced backup/sidecar/repaired/replacement, failpoints at every stage, mandatory green final audit. - mem audit verifies the full watermark, active ID set/count, per-record content and content hashes, and rejects any inactive/tampered/stale projection. - Canonical shim resolves code only from $HOME/fleet/firstmate-runtime; FM_HOME no longer redirects executable code. Hardened installer (lstat, temp+fsync+atomic rename, executable-mode validation, safe pre-existing symlink handling). - Fail-safe risk classification defaults upward on missing/uninspected/ambiguous inputs; captain override applies the downgrade, logs an opaque reference, and never leaks the raw token. - mem doctor uses real semver (minor floor) and one stable JSON schema in every condition, including missing dependencies. - Snapshots use safe hashed filenames (no path traversal), written atomically with fsync. Activity ledger gains cross-process locking, a segment manifest with row counts and content hashes, and corrupt-tail fold. Tests: added subprocess concurrency stress, lock init-race/token-release/stale reclaim, index non-regression, full transition matrix, high-impact activation, quarantine revalidation, non-dangling supersession, sparse-update preservation, binary sidecar fidelity, recovery failpoints, audit tamper matrix, stable doctor JSON, semver floor, risk fail-safe/override, snapshot traversal/atomicity, and activity concurrency/manifest. Fixed the A34 temp-dir self-copy fragility so the suite passes under any TMPDIR, including one under the package tree.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 746b46bbd7
ℹ️ 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".
| validTo: null, | ||
| recordedAt: event.ts, | ||
| verifiedAt: null, | ||
| confidence: 'unverified', |
There was a problem hiding this comment.
Do not apply passthrough fields to record internals
When an event carries an extra field such as fields.status, this assignment copies it straight onto the folded record because recordFieldsSchema is passthrough(). A valid retired event with fields.status: 'active' would pass schema validation, run the transition, and then leave the terminal record active, bypassing the state machine and active-index filtering; restrict application to the known mutable record fields or strip unknown keys before folding.
Useful? React with 👍 / 👎.
| const ok = Boolean( | ||
| compatible | ||
| && parts.requiredDependencies.ok | ||
| && parts.packageLock.present | ||
| && parts.packageLock.current | ||
| && registryOk | ||
| && snapshotsOk |
There was a problem hiding this comment.
Fail doctor when the active index is not current
When the registry is healthy but memory-index.json is missing or stale, auditRegistry() reports activeIndex.status !== 'current', but this health gate ignores parts.activeIndex entirely. That lets mem doctor exit 0 even though consumers would read an out-of-date or absent active-memory index, so the doctor result should include the active-index status in its ok calculation.
Useful? React with 👍 / 👎.
|
Speaking as Kun's firstmate: closing this as stale. It has been waiting on a contributor update for 14+ days with no author push or comment. Reopen if you want to pick it back up. |
Memory PR-1 — registry / index / recovery foundation
Exact reviewed SHA:
746b46bbd77d8f50fb23fc1fc338e416f6475e31Branch:
fm/memory-pr1-registry-r1Scope: PR-1 only (Milestone A foundation). This is not an operationally closed memory system.
Scope (PR-1 only)
Additive
memory/package:mem)Not in this PR (PR-2+ gated): PGlite/FTS, vectors/embeddings, migration/cutover, recall, session packs, brief injection, workflow hooks, Fleet Bridge memory UI, reconciliation, closeout enforcement, graph work.
The package is additive and not yet consumed by FirstMate workflow scripts.
Implementation report
Local path (fleet):
data/memory-pr1-registry-r1/report.md(also on the branch under that path if present).Independent QA (five rounds)
memory-pr1-qa-s1memory-pr1-qa-s24e684ad…memory-pr1-qa-s3a0f3f96…memory-pr1-qa-s4322beb5…memory-pr1-qa-s5746b46bbd77d8f50fb23fc1fc338e416f6475e31Final QA report (fleet):
data/memory-pr1-qa-s5/report.mdCaptain export:
D:\FirstMate-Reports\memory-pr1-qa-s5-report-2026-07-15.mdFinal fix report (f4):
data/memory-pr1-fix-f4/report.mdTest results (QA s5, isolated under
/tmp)snapshotHashrepro: repair-then-commit on event 501mem snapshotrepair, shared-validator parity: passmem audit --json/mem doctor --json: green$HOME/fleet/state/memory: absent before and after QA (no production records)Rollback
The package is additive; removing or not installing
memory/restores prior behavior for workflow paths that do not call it.Captain authorization
Captain accepted QA s5 and authorized land at exact SHA
746b46bbd77d8f50fb23fc1fc338e416f6475e31. PR-2 remains gated pending a separate Captain order.