Skip to content

Reject duplicate memories and preserve standing instructions when a user makes an exception #471

Not planned

Description

@WhollyMindless

Related to #390, which shipped support for retiring a memory when its value is corrected. Before a write changes the store, can we agree on how it should handle a repeated fact, a one-time exception, and a lasting correction?

Start each test with one saved instruction for the same project: “The default timeout is 30 seconds.”

New instruction Expected behavior
“The default timeout is 30 seconds.” Reject the duplicate write. Keep the original memory as-is.
“Thirty seconds is the default timeout.” Same result. Rephrasing the same fact adds no durable information.
“Use 90 seconds for this run.” Use 90 now. A fresh session still gets the 30-second default.
“Change the default timeout to 90 seconds.” Save the correction. A fresh session gets 90 as the default.

A difference of just a few words can carry the user’s intent. “For this run” limits the instruction. “Change the default” makes it durable. If the user only says “try 90 seconds,” the agent can act on that now while preserving the saved default.

Would you approve these as acceptance tests for memory writes? I’m proposing the expected behavior here. I haven’t verified which cases the current implementation already passes.

Activity

  1. added
    enhancement
    capture
    severity:medium
    tier:full
    on Nov 22, 2026
  2. ocsi-architect commented on Nov 27, 2026

    @ocsi-architect

    Pre-arch record for #471 — measured repro, design space, boundary map, PR overlap. No fix prescribed.

    Measured on a detached scratch worktree at 966bb7e (live checkout untouched). Repro script: /private/var/folders/52/f2djt5m14xl6vty9dxvf0xk40000gn/T/opencode/471-prearch/worktree/prearch471.ts, raw JSON: .../471-prearch/repro-out.json. The script drives the real write path (runWriteGate → appendMemory) and the real read path (selectRelevant) with the harness pattern of test/host/scenarios.test.ts; baseline bun test test/host/scenarios.test.ts test/gate/value-conflict.test.ts = 52 pass / 0 fail on this commit.

    1. Scope ruling (human, recorded here)

    The ticket's setup line, verbatim: each test starts with one saved instruction for the same project: "The default timeout is 30 seconds."

    row instruction restated / added ruling
    1 restate the identical instruction → reject the duplicate, keep the original regression pin (already-shipped behavior)
    2 "Thirty seconds is the default timeout." → same result; rephrasing adds no durable information fix
    3 "Use 90 seconds for this run." → use 90 now; a fresh session still gets the 30-second default fix
    4 "Change the default timeout to 90 seconds." → save the correction; a fresh session gets 90 regression pin (already-shipped behavior)

    2. Measured four-row table (966bb7e)

    Real constants in this checkout: OVERLAP_FLOOR = 0.9, CONFLICT_OVERLAP_FLOOR = 0.3 (src/gate/gate.ts). Measured jaccard vs the seed row: row 2 = 0.3333, row 3 = 0, row 4 = 0.4444. The 0.3333 (not the intuitive 5/7≈0.71) is because tokens() keeps stopwords and attaches the trailing sentence dot to the last token: ["the","default","timeout","is","30","seconds."] vs ["thirty","seconds","is","the","default","timeout."] — seconds ≠ seconds. and timeout ≠ timeout., so the intersection is only {the, is, default}.

    The ticket does not specify a memory type, and outcome flips by family (non-conflictProne vs decision/preference), so each row was run for both:

    row type action evidence events store rows (active) fresh-session recall delivers vs expectation
    1 context collapsed dedup_collapse (canonical_existing) 1 30 PASSES
    1 preference collapsed dedup_collapse 1 30 PASSES
    2 context promoted dedup_clean, write_promoted 2 both rows injected (30 + rewording) FAILS — duplicate stored
    2 preference blocked dedup_overlap, write_blocked:superseded_overlap (score=0.33) 1 30 partially passes — original kept, nothing stored; shape is a review-gated merge-advisory, not a row-1-style collapse
    3 context promoted dedup_clean, write_promoted 2 30 AND 90 FAILS — the ephemeral instruction is durable
    3 preference promoted dedup_clean, write_promoted 2 30 AND 90 FAILS
    4 context promoted dedup_clean, write_promoted; no superseded_by 2 30 AND 90 passes as shipped: correction saved and delivered — alongside the stale 30, not replacing it
    4 preference blocked superseded_overlap (score=0.44) 1 30 FAILS — the correction itself is review-gated

    Row-by-row notes:

    • Row 1 passes as measurement-justified pin. Mechanism is byte-exact GATE-3 collapse (gate.ts ~L723–732, dedup_collapse / canonical_existing, incoming_ignored:true), not the tombstone rejection lane (dedup_rejected / previously_rejected covers only human-rejected values).
    • Row 3's premise is confirmed and is in fact worse than narrated: today the fact persists durably and a fresh session receives both 30 and 90 (two active rows ride the block). No ephemeral / session-scoped / run-only lane exists anywhere in src/ (grep for ephemeral, session-scoped, run-only, this run returns comment prose only).
    • Row 4's pin is justified only for the context/learning family, and only in the coexistence sense. The Corrections must supersede in the data, not in the wording #390 correction-supersede does not fire on this pair: symbolValues (src/gate/value-conflict.ts) requires an ALL-CAPS or dotted-identifier anchor ([A-Z][A-Z0-9_]{2,} / foo.bar); neither sentence has one, so valueConflicts returns empty and the rows coexist. Under preference, the 0.44 overlap exceeds the 0.30 conflict floor and the correction is blocked. "A fresh session gets 90" (alone) is not what this commit does for unanchored prose.

    3. Design space (A) — row 2, rephrase equivalence

    Decisive measurement: the pair ordering is inverted. The rewording scores 0.3333; the correction (row 4) scores 0.4444. Therefore no single overlap-floor move can review-gate row 2 and store row 4 clean in the same type family — any context-family floor ≤ 0.3333 gates the 0.4444 correction first. Lowering OVERLAP_FLOOR additionally mutation-kills the anti-false-block pins in test/host/scenarios.test.ts: 0.8667 rewording stores clean (L754), 0.90 gate inclusive (L731), and for the conflict floor the 0.25/0.26/0.28 coexistence pins (L598/605/611) and the 0.30-inclusive pin (L617). src/core/tokenize.ts (header of "the two things token overlap cannot see") already records in-repo that overlap scoring "can never separate" a rewording from a correction — this ticket is a second measured instance of that documented limit.

    Where a machine-decidable rephrase notion could live, with the collision each must respect:

    1. Normalization before scoring (word-form numerals thirty→30; unit/spelling canonicalization; sentence-dot fold). Collisions to respect: (a) tokens() output must stay identical to the established split (documented fuzz-proven contract; numericTokens/figureExtent in tokenize.ts already extract figures canonically but read digits only); (b) the one-definition-of-a-token principle in the tokenize.ts header (rejection sketch and GATE-3 must score on the same notion, or refusals stop being reproducible) — so normalization must be a parallel pass, which knowingly creates two similarity definitions; (c) the pinned pairs in scenarios.test.ts contain no numeral tokens and no terminal dots, so a parallel pass could leave every pinned score byte-unchanged — the fixer must prove that with mutation runs, not assume it.
    2. A distinct predicate class (extend the value-conflict machinery): valueConflicts today refuses all unanchored prose (measured on row 4), so "same subject, equal canonical number" without an ALL-CAPS anchor is new machinery in value-conflict.ts, and it must inherit the same guard-floor philosophy (sameSentenceExceptValue, the editorial/ignore word sets, the environment guard). Note this is the dimension that separates rows 2 and 4 at all: row 2 has numeric agreement (thirty == 30 → duplicate), row 4 has numeric disagreement (90 ≠ 30 → correction). Token order cannot make that separation; value equality can.
    3. Nothing — drop row 2 as undecidable within the current single-predicate class. A legitimate architectural outcome given the inversion above; the preference family already review-gates it accidentally (measured score=0.33 ≥ 0.30), which could be pinned with an explicit type instead of new machinery.

    Answer to the standing question: within the existing overlap-floor class, row 2 is not satisfiable without reversing at least one named anti-false-block pin (the inversion is the proof). Outside that class, satisfiability is plausible but unproven: the normalization and value-agreement routes can leave every pinned pair's score untouched, because the pinned pairs carry no numerals and no terminal dots — subject to mutation verification. Also note "reject" vocabulary: durable storage has no "reject the near-duplicate as wrong" verdict today; the nearest shipped shape is the review-gated superseded_overlap block that stores nothing and keeps the original. A hard reject would be a new GATE-4 verdict class.

    4. Design space (B) — row 3, the ephemeral exception

    Precedent check, verified against code (not assumed): yes — the gate already declines to durably store things it deems non-durable, while still emitting the ordered evidence line: the collapse path returns collapsed with dedup_collapse/incoming_ignored:true and never calls appendMemory; every block path writes write_blocked evidence and stores nothing. Separately, isInjectable (src/store/model/predicates.ts) already withholds a durable row from every model-facing read by tag (init-stamp) and by quarantine, while viewer/forget/undo/export still see it. Both shapes — evidence-only writes, and durable-but-not-injected rows — are precedented.

    Lane options, each with its new state boundary and the fresh-session view:

    option placement NEW state boundary fresh session sees the fact?
    1 write-gate bypass that never reaches durable storage (new outcome action, in-memory buffer only) a per-session volatile buffer (state.ts SessionLru precedent: authoredRows); dies on restart/resetState no — never persisted
    2 session-scoped ledger consulted at injection buildMemorySection gains a volatile author-scoped input alongside authoredFor no — ledger is keyed to the authoring session
    3 recall-time suppression of a durable row for its authoring session only none new (inverse exists today as the riding-bytes ownRows subtraction — a cache affordance, not a semantic filter) yes — FAILS the row-3 test by construction: the row stays durable and injectable to every other session; suppression for the author does not hide 90 from the fresh session
    4 durable row carrying a scope marker that recall filters (new status value or tag) store schema + isInjectable/visibility predicate change (init-stamp-style) no, if the predicate withholds it — but then decide: visible to viewer/export like quarantine? visible to the author after restart?

    The "use 90 now" half needs no delivery machinery: the authoring session already holds the instruction in its own transcript. The lane's only obligation is non-delivery to later sessions.

    5. State-boundary map (tier:full)

    (i) where a write becomes a durable row
    tool entry (src/tools/remember.ts, src/tools/update.ts) → gateContext(sid) → runWriteGate (src/gate/gate.ts) → appendMemory (src/store/files/append.ts — the single write choke point; withStoreLock; repo-stamp via writeTarget(sessionID)) → <date>.logfmt.

    (ii) gate decision points, in order, with the predicate each applies

    1. GATE-1 graph/refs — embedded refs resolved; missingPaths, candidateStale.
    2. GATE-2 drift supersession + canonical neutralization — markManySupersededReport, reasons drift/canonical.
    3. GATE-3, computed here / enforced at GATE-4: probeRejection tombstones (exact hash → previously_rejected; near-sketch) → byte-exact exact collapse (~L723–732, with the update-metadata carve-out) → overlap rivalry scan (~L752–758: floor 0.3 for decision/preference else 0.9, best-over-floor rival wins, canonical hit suppresses the conflict scan, supersedesTs excluded).
    4. GATE-4 block ladder, in order: previously_rejected → drift_ref_stale_incoming → ref_path_missing → conflicts_with_canonical → superseded_overlap (review-gated; hint names the rival ts; advisory merge_proposal with the documented canonical=newest quirk) → ambiguous_memory.
    5. Post-append: Corrections must supersede in the data, not in the wording #390 valueConflicts numeric-conflict supersede (symbol-anchored only), then appendMemory, noteAuthored, write_promoted. Evidence chain order across all verdicts: gate_start → graph_* → ref_* → dedup_* → write_promoted/write_blocked.

    (iii) where a stored row becomes prompt bytes
    loadAll → isInjectable && isVisibleTo(readerFromSid) → buildMemorySection (src/inject/epochs.ts): systemDigest parts (standing digest + frontier + convergence, prompt-independent by construction) + the relevance block from selectRelevant (scoreMemories two-concept gate, guided lane, capToBudget) rendered by formatMemory; the joined parts are the epoch's byte key. On main the key is the whole section; PR #552 (open) makes the key the stable core only, with the relevance block as a per-turn tail. Adoption paths: silent adoption (prefix equal), riding-bytes counterfactual (authoredFor subtraction), else epoch_recompute with reason store_changed/prompt_reveal.

    (iv) new boundaries each fix introduces

    • Row-3 lane: one of — a new GateOutcome variant/action + volatile per-session buffer (option 1); a ledger read inside buildMemorySection (option 2, epoch-sensitive); a store-schema marker + isInjectable predicate change (option 4). Option 3 adds nothing and fails.
    • Row-2 predicate: a parallel scoring pass inside GATE-3 (normalization) or new anchor-less machinery in value-conflict.ts; either way a second similarity definition that must leave every pinned overlap score byte-unchanged and keep tokens() output frozen.
    • Both must preserve the evidence chain order and the write_blocked flag shape ([supersedes_check_<ts>,score=<s>,review_gated]) that scenarios.test.ts pins verbatim.

    Escape shapes a fix must not break: the coexistence bands 0.25/0.26/0.28 store-clean (L598/605/611) and the inclusive floors 0.30 (L617) / 0.90 (L731) with 0.8667 clean (L754); best-rival-not-first/not-newest selection plus the merge_proposal advisory quirk; the byte-exact collapse path with its update-metadata carve-out; the tombstone rejection lane; the #390 symbol-anchored numeric-conflict supersede; the evidence-record shape; the epoch's stable-core byte key — whose contract is in motion (PR #552).

    6. Overlap with open PRs (verified via gh pr view/diff, not assumed)

    #553 (for #550, OPEN, draft pending #552) — files: src/gate/gate.ts +16/−7, src/inject/epochs.ts +166/−23, src/store/files/append.ts +15/−9, src/tools/update.ts +7/−1, test/inject/epoch.test.ts. Its gate.ts hunks land at exactly three places: the GateOutcome union (~L147 — adds updateLine?: string to the promoted variant), the appendMemory call site (~L1007 — switches to a new receipt:true overload returning {ts, line}), and the final return (~L1087). appendMemory gains the receipt overload and the withStoreLock return shape changes.

    #552 (fix/388-stable-core, OPEN) — src/inject/epochs.ts only (+66/−29): byte key becomes the stable core only; silent adoption and the riding counterfactual compare core and tail; sectionChars semantics move; the body states the evidence-record shape is unchanged.

    7. Unresolved for the fixer (open questions, no ranked answer)

    1. Type binding. The ticket names no memory type and verdicts flip by family (rows 2 and 4 measured above). Every acceptance test must pin a type, or state that both families are asserted.
    2. Row 1 vocabulary. Is collapse the acceptance shape for "reject the duplicate," or does the ticket mean the tombstone rejection lane? (They are different mechanisms with different evidence events.)
    3. Row 2 route. Drop as undecidable / parallel normalization pass (must prove zero movement on the pinned pairs and accept two similarity definitions in-repo) / anchor-less value-agreement predicate in value-conflict.ts / pin the accidental preference-family review-gate with an explicit type. Plus: does "reject" mean today's review-gated block, or a new verdict class?
    4. Row 4 pin wording. Strict "a fresh session gets 90" fails today for unanchored prose (coexistence measured; supersede requires a symbol anchor). Re-word the pin to shipped coexistence, or anchor the setup line (e.g. a DEFAULT_TIMEOUT-style symbol so Corrections must supersede in the data, not in the wording #390 applies), or scope the pin to non-conflictProne types only.
    5. Row 3 placement. Choose among bypass / injection-ledger / durable+marker (option 3 excluded by the fresh-session test). Sub-decisions: does the lane emit evidence and under which event name; restart semantics (volatile buffer vs durable marker); marker-visible-to-viewer/export?
    6. Landing order. fix(inject): preserve the prefix for same-session memory corrections #553 and fix(inject): epoch accounting reports store moves beside byte moves #552 both sit in the epochs.ts region and fix(inject): preserve the prefix for same-session memory corrections #553 extends GateOutcome; a row-3 lane collides two- or three-way there. Decide rebase order before writing epoch-sensitive tests.
    7. Byte-key target shape. Epoch assertions for the row-3 lane must state whether they target main's whole-section key or fix(inject): epoch accounting reports store moves beside byte moves #552's core/tail split.
  3. ocsi-architect commented on Nov 27, 2026

    @ocsi-architect

    Maintainer rulings on this proposal

    Recorded after an offline re-measurement of the row-2/row-4 pair against the live write-path tokenizer and floors (OVERLAP_FLOOR 0.90, conflict floor 0.30), including a pricing pass on the one remaining row-2 route: a parallel normalization pass (word-form numerals, sentence-dot de-gluing) applied before overlap scoring. All scores below are jaccard over the production tokens() set.

    Row 1 — regression pin

    Byte-exact duplicate collapses already ship (dedup_collapse): the second write is rejected and the original memory is kept as-is. This row's expected behavior is current, verified behavior. Ruling: pin it in the test suite; do not re-implement.

    Row 2 — deferred, not accepted as written

    No floor change satisfies this row. The rewording scores 0.3333 and the row-4 correction scores 0.4444 against the same stored row, so the ordering is inverted: any floor that catches the rewording as a duplicate catches the real correction first. The normalization pricing pass measured four variants on both pairs:

    Normalization variant Row-2 rewording Row-4 correction Separable (reword ≥ floor > correction)?
    (a) as-is 0.3333 0.4444 no — inverted ordering
    (b) dot de-glue only 0.7143 0.4444 yes, band (0.4444, 0.7143]
    (c) numeral word-forms only (Thirty→30, Ninety→90) 0.5000 0.4444 yes, band (0.4444, 0.5000]
    (d) both 1.0000 0.4444 yes, band (0.4444, 1.0000]

    Two facts price these bands. First, none of the deliberate calibration pins move under any of the four variants — measured unchanged at 0.2500 / 0.2632 / 0.2800 / 0.3000 (conflict-band and 0.30-inclusive pins), 0.9000 and 0.8667 (overlap-floor inclusive and just-under pins), 0.8462 / 0.4375 / 0.0909 (rival-selection pins): the pinned pairs contain no trailing sentence dots and no numerals; the one word-form numeral (ninety) sits in a below-floor pair where the token swap moves neither intersection nor union. So normalization itself is pin-neutral. Second, exploiting the (b) and (c) bands is not: in the conflict family it means raising the floor off the deliberately pinned, inclusive 0.30 (killing the 0.30 pin); in the overlap family it means dropping the floor through the 0.8667 just-under pin. Only variant (d) works against the existing 0.90 overlap floor with no pin moved (1.0 gated, 0.4444 clean) — and only in the non-conflict family; under the 0.30 conflict floor the corrected row is still review-gated, so the type dependence survives unchanged.

    Ruling: deferred. The only predicate that separates a rewording from a correction in general — not just for this one sentence pair, at a razor-thin 0.0556 gap in variant (c) — is value agreement for the same key (thirty == 30 → duplicate; 90 ≠ 30 → correction). That is the same predicate row 4 requires, so row 2 follows from row 4's machinery rather than being built separately on overlap scoring.

    Row 4 — escalated: coexistence is the defect

    Measured on the current implementation: an unanchored "Change the default timeout to 90 seconds." never reaches the value-conflict supersede path, so both values are stored and both are injectable to a fresh session — the 30-second default and the 90-second correction ride the block together. That coexistence is the defect this ticket now covers, and the row's expected outcome is reworded to name it.

    The behavior is type-dependent and the acceptance test must state its row type rather than pretend to be type-independent: measured on the identical sentence pair, the preference family blocks the correction (0.4444 ≥ the 0.30 conflict floor, review-gated), while the other type family coexists (0.4444 < 0.90, stores clean beside the original).

    Row 3 — held, not rejected

    This is the one confirmed mechanism gap: a "for this run" fact persists durably today, and a fresh session receives both 30 and 90. No ephemeral / session-scoped lane exists anywhere in src/. It also conflicts with open PR #553 at the GateOutcome union, the appendMemory call site, and the final return of runWriteGate. Ruling: held; resumes after #553 lands.

    Revised scope

    This ticket now covers the row-1 regression pin plus the unanchored-coexistence defect (row 4). Rows 2 and 3 are sequenced behind it: row 2 as a consequence of row 4's value-agreement predicate, row 3 after #553.

  4. ocsi-architect commented on Nov 27, 2026

    @ocsi-architect

    Closing: fused proposal, substance redistributed

    This ticket fuses four rows into one proposal. Each row is a symptom of one missing capability, and every acceptance test it proposed needs a mechanism that does not exist in the gate today. The ticket is therefore closed and its substance moves to the problems and destinations below.

    Measured outcomes

    Seed row for every case: The default timeout is 30 seconds. All outcomes measured at 966bb7e.

    Row Follow-up write Measured outcome
    1 Identical restatement Collapsed (dedup_collapse), 1 row, fresh recall delivers 30. Already ships.
    2 Thirty seconds is the default timeout. Promoted clean, 2 rows, both injectable. Overlap score 0.3333 against OVERLAP_FLOOR 0.90. In the preference/decision row-type family the same write is instead blocked superseded_overlap at 0.33 with the original kept.
    3 Use 90 seconds for this run. Promoted durably, 2 rows, and a fresh session's recall delivers both 30 and 90. No ephemeral / session-scoped write lane exists anywhere in src/.
    4 Change the default timeout to 90 seconds. Promoted, no supersede: the retire path needs a symbol anchor, so the correction path stays inert and fresh recall delivers both 30 and 90. In the preference/decision family the correction itself is blocked at 0.44 against the 0.30 floor.

    Row 1 already ships; rows 3 and 4 were confirmed by measurement, not assumption.

    Root

    The gate compares surface token overlap, and the retire path requires a symbol anchor — symbolValues() demands a SCREAMING_CASE or dotted anchor (src/gate/value-conflict.ts:221), and valueConflicts() returns [] when either side lacks one (:253, :258–:259, :266; consumed pre-append at src/gate/gate.ts:969–:975). Nothing computes whether two rows answer the same question. That is why an exception, an unanchored correction, and a brand-new fact all arrive as "append another row."

    The three problems, with destinations

    P1 — the scoring input is artifact-sensitive. Sentence-final dots glue into tokens and numeral word-forms are disjoint from digits, so the score measures surface artifacts rather than stated content. Narrow, measured, and fixable without moving any calibration pin. Destination: the discriminator work in #449.

    P2 — no representation of what a row asserts. Not reachable at any floor. The published falsification stands on the record: the pair worth releasing scores 0.8235 and the changed-fact pair scores 0.8333, so any separating threshold is a window one hundredth wide fitted to two observations, and a token-overlap score cannot tell a replaced fact from an added one. Destination: #449. The unanchored-correction instance is the case left open by the closed corrections-supersede work, whose own record says the mechanism that works today is a prose sentence plus retrieval that happens to prefer it — not a guarantee.

    P3 — nothing can express "true for this run only." An absent mechanism, unowned by any open ticket: the measured row-3 exception persists durably with no lane to hold it. Destination: #557, opened for exactly this.

    For the record

    The row-3 and row-4 measurements stand on their own even though this ticket closes; nobody needs to re-derive them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    captureenhancementseverity:mediumtier:full

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions