feat(memory): enforce the Step 4 divergent-write guarantees (#137) #145

Merged
clawdie merged 3 commits from feat/step4-divergent-write-guarantees into main 2026-10-08 17:22:16 +02:00
Owner

Closes #137.

The Step 4 scaffold encoded the memory contract but permitted exactly the
duplicate-writer and authority-drift conditions the architecture forbids. This
makes the issue's three guarantees real, behind the same Store interface.

1. Divergent writes are preserved, not clobbered

Remember now treats a second write to an existing (tenant, id) with a
different content hash as a conflict, not an overwrite:

  • both candidates are preserved in a ConflictRecord (existing + candidate, each
    with its own provenance);
  • Remember returns ErrConflictPending and the incumbent stays canonical;
  • a new Conflicts method lists unresolved conflicts and
    ResolveConflict applies an explicit operator disposition
    (accept_candidate or keep_existing), requiring a resolver identity.

Accepting a candidate supersedes the incumbent and appends it to the record's
revision trail. Identical content stays idempotent.

2. Improve cannot rewrite authority

The silent DerivationMethod = DerivationAgentSummary downgrade is gone:

  • a content change requires replacement provenance (ErrProvenanceRequired),
    and the replacement must target the same record and tenant;
  • an operator-asserted record additionally requires an approval on the
    replacement (ErrOperatorApproval);
  • Improve no longer mutates derivation in place; the superseded version goes
    to an append-only revision trail (Revisions).

An operator_assertion envelope is now invalid without an operator approval
(NewOperatorProvenance is the supported constructor).

3. Freshness is real and fails closed

  • QueryNodeCapacity reads observedAt from the graph instead of stamping
    time.Now();
  • BuildBoundary1Envelope carries evidence_observed_at and returns
    MISSING_CAPACITY_EVIDENCE (ineligible) when the observation is missing,
    unparseable, or older than the max age (default 5 min, overridable with
    WithMaxEvidenceAge).

Also

  • FormatSPARQLTurtle now emits sourceRef / derivationMethod /
    contentHash when given the projection's provenance.
  • MemoryKind is documented as orthogonal to the storage planes and
    projections.

Tests

internal/memory — 15 tests, all passing under -race and the FreeBSD
cross-build: conflict preservation, both dispositions, resolver identity,
revision trail, ErrProvenanceRequired / ErrOperatorApproval,
operator-assertion approval, staleness fail-closed and the max-age override.

Drive-by fix

432d244 fixes a pre-existing red on main: four prose ISO dates in
docs/research/jev-second-brain-transcript.md (from #144) failed the
user-facing date gate. Same pattern as #136/#140 fixing the pre-existing
prettier break. Say the word if you'd rather have it as its own PR.

Gates

ci-checks.sh all green (Go build/vet/test/race, FreeBSD cross-build,
wiki-lint, date gate, okf, prettier, evidence, whitespace).

Closes #137. The Step 4 scaffold encoded the memory **contract** but permitted exactly the duplicate-writer and authority-drift conditions the architecture forbids. This makes the issue's three guarantees real, behind the same `Store` interface. ## 1. Divergent writes are preserved, not clobbered `Remember` now treats a second write to an existing `(tenant, id)` with a different content hash as a **conflict**, not an overwrite: - both candidates are preserved in a `ConflictRecord` (existing + candidate, each with its own provenance); - `Remember` returns `ErrConflictPending` and the incumbent stays canonical; - a new `Conflicts` method lists unresolved conflicts and `ResolveConflict` applies an explicit operator disposition (`accept_candidate` or `keep_existing`), requiring a resolver identity. Accepting a candidate supersedes the incumbent and appends it to the record's revision trail. Identical content stays idempotent. ## 2. `Improve` cannot rewrite authority The silent `DerivationMethod = DerivationAgentSummary` downgrade is gone: - a **content change requires replacement provenance** (`ErrProvenanceRequired`), and the replacement must target the same record and tenant; - an **operator-asserted** record additionally requires an approval on the replacement (`ErrOperatorApproval`); - `Improve` no longer mutates derivation in place; the superseded version goes to an append-only revision trail (`Revisions`). An `operator_assertion` envelope is now invalid without an operator approval (`NewOperatorProvenance` is the supported constructor). ## 3. Freshness is real and fails closed - `QueryNodeCapacity` reads `observedAt` from the graph instead of stamping `time.Now()`; - `BuildBoundary1Envelope` carries `evidence_observed_at` and returns `MISSING_CAPACITY_EVIDENCE` (ineligible) when the observation is missing, unparseable, or older than the max age (default 5 min, overridable with `WithMaxEvidenceAge`). ## Also - `FormatSPARQLTurtle` now emits `sourceRef` / `derivationMethod` / `contentHash` when given the projection's provenance. - `MemoryKind` is documented as orthogonal to the storage planes and projections. ## Tests `internal/memory` — 15 tests, all passing under `-race` and the FreeBSD cross-build: conflict preservation, both dispositions, resolver identity, revision trail, `ErrProvenanceRequired` / `ErrOperatorApproval`, operator-assertion approval, staleness fail-closed and the max-age override. ## Drive-by fix `432d244` fixes a pre-existing red on `main`: four prose ISO dates in `docs/research/jev-second-brain-transcript.md` (from #144) failed the user-facing date gate. Same pattern as #136/#140 fixing the pre-existing prettier break. Say the word if you'd rather have it as its own PR. ## Gates `ci-checks.sh` all green (Go build/vet/test/race, FreeBSD cross-build, wiki-lint, date gate, okf, prettier, evidence, whitespace).
Restore the user-facing date gate, red on main since #144: four metadata
lines wrote ISO dates in prose. Use DD.mmm.YYYY per AGENTS.md.
feat(memory): enforce the Step 4 divergent-write guarantees
Some checks failed
CI / markdown (pull_request) Successful in 10s
CI / port (pull_request) Successful in 1s
CI / agent-jail-pkgs (pull_request) Successful in 1s
CI / python-tests (pull_request) Successful in 15s
CI / go (pull_request) Successful in 12s
format-check / prettier (pull_request) Successful in 5s
leak-guard / guard (pull_request) Successful in 10s
ci-gate / gate (pull_request) Has been cancelled
51d9ef2b3a
Closes #137. The Step 4 scaffold encoded the memory contract but permitted
exactly the duplicate-writer and authority-drift conditions the architecture
forbids. This makes the three guarantees real:

- Remember preserves a divergent write as a ConflictRecord instead of
  overwriting the incumbent, and needs an explicit operator disposition.
- Improve cannot change content (and so authority) without replacement
  provenance; operator-asserted records additionally require an approval.
  Superseded versions are kept in an append-only revision trail.
- Boundary 1 carries the projection's real observation time and fails closed
  with MISSING_CAPACITY_EVIDENCE when that evidence is absent or stale.

Also: an operator assertion is invalid without an operator approval, projected
Turtle triples carry provenance, and MemoryKind is documented as orthogonal to
the storage planes.
test(memory): expand test coverage for unparseable timestamps, multi-conflicts, tenant isolation, and revision order
Some checks failed
CI / markdown (pull_request) Successful in 9s
CI / port (pull_request) Successful in 1s
CI / agent-jail-pkgs (pull_request) Successful in 1s
CI / python-tests (pull_request) Successful in 15s
CI / go (pull_request) Successful in 12s
format-check / prettier (pull_request) Successful in 5s
leak-guard / guard (pull_request) Successful in 11s
ci-gate / gate (pull_request) Has been cancelled
4f05bc7206
clawdie deleted branch feat/step4-divergent-write-guarantees 2026-10-08 17:22:16 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
clawdie/colibri!145
No description provided.