diff --git a/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-13-1000-draft.md b/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-13-1000-draft.md new file mode 100644 index 0000000..9c300dd --- /dev/null +++ b/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-13-1000-draft.md @@ -0,0 +1,18 @@ +# Origin alignment check — memkernel-0-10-decision-revalidation, the draft spec + +Origin: gosha70/memkernel#123 (origin/2026-11-13-issue-123.md). + +Origin claim: as in plan.md. + +Working claim: +> FR-001–FR-006: a source_hash recorded at retain for decisions with a readable source under the project root; +> revalidate flags decisions missing/changed (missing only without a hash); recall returns flagged decisions and +> keeps hiding flagged code; additive needs_review and review_reason on every recall result; the startup list per +> D1; docs. + +Mismatches: + - none. D2 puts the new fields on every result, not only decisions: #123 asks for an additive field on recall + results, and the same field for code keeps one result shape. + +Verdict: aligned +Confidence: high diff --git a/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-13-1030-review.md b/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-13-1030-review.md new file mode 100644 index 0000000..6363fc5 --- /dev/null +++ b/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-13-1030-review.md @@ -0,0 +1,18 @@ +# Origin alignment check — memkernel-0-10-decision-revalidation, the draft after DeepSeek round 1 + +Origin: gosha70/memkernel#123 (origin/2026-11-13-issue-123.md). + +Origin claim: as in plan.md. + +Working claim: +> FR-001–FR-006: a source_hash recorded at retain for decisions with a readable source under the project root; +> revalidate flags decisions missing/changed (missing only without a hash); recall returns flagged decisions and +> keeps hiding flagged code; additive needs_review and review_reason on every recall result; the startup list per +> D1; docs. + +Mismatches: + - none. D2 puts the new fields on every result, not only decisions: #123 asks for an additive field on recall + results, and the same field for code keeps one result shape. + +Verdict: aligned +Confidence: high diff --git a/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-14-0900-clarified.md b/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-14-0900-clarified.md new file mode 100644 index 0000000..34826ca --- /dev/null +++ b/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-14-0900-clarified.md @@ -0,0 +1,18 @@ +# Origin alignment check — memkernel-0-10-decision-revalidation, the draft with the dedup and hint clarifications + +Origin: gosha70/memkernel#123 (origin/2026-11-13-issue-123.md). + +Origin claim: as in plan.md. + +Working claim: +> FR-001–FR-006: a source_hash recorded at retain for decisions with a readable source under the project root; +> revalidate flags decisions missing/changed (missing only without a hash); recall returns flagged decisions and +> keeps hiding flagged code; additive needs_review and review_reason on every recall result; the startup list per +> D1; docs. + +Mismatches: + - none. D2 puts the new fields on every result, not only decisions: #123 asks for an additive field on recall + results, and the same field for code keeps one result shape. + +Verdict: aligned +Confidence: high diff --git a/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-14-0930-approved.md b/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-14-0930-approved.md new file mode 100644 index 0000000..13cbd1b --- /dev/null +++ b/specs/memkernel-0-10-decision-revalidation/origin-alignment-2026-11-14-0930-approved.md @@ -0,0 +1,16 @@ +# Origin alignment check — memkernel-0-10-decision-revalidation, approved + +Origin: gosha70/memkernel#123 (origin/2026-11-13-issue-123.md). + +Origin claim: as in plan.md. + +Working claim: +> The owner accepted D1–D4 on 2026-11-14 with two clarifications: the startup hint is type-aware (D1, FR-005), and +> a hash is computed only for the source of a newly created record, a dedup hit keeping the existing record's +> source and source_hash (D3, FR-001), with tests for cross-source, same-source and legacy dedup hits (SC-3). + +Mismatches: + - none. The clarifications keep a decision's hash bound to the file the record actually cites. + +Verdict: aligned +Confidence: high diff --git a/specs/memkernel-0-10-decision-revalidation/origin/2026-11-13-issue-123.md b/specs/memkernel-0-10-decision-revalidation/origin/2026-11-13-issue-123.md new file mode 100644 index 0000000..c17271c --- /dev/null +++ b/specs/memkernel-0-10-decision-revalidation/origin/2026-11-13-issue-123.md @@ -0,0 +1,30 @@ +# Origin: Revalidate decisions that cite files: flag them, don't hide them + +Source: https://github.com/gosha70/memkernel/issues/123 (copied 2026-11-13, verbatim) + +## Issue body + +## Why +#57's replay ([#121](https://github.com/gosha70/memkernel/pull/121); results in [`eval/decisions-57/results-k5.json`](https://github.com/gosha70/memkernel/blob/main/eval/decisions-57/results-k5.json) and [`results-k3.json`](https://github.com/gosha70/memkernel/blob/main/eval/decisions-57/results-k3.json), discussion in the [research note](https://github.com/gosha70/memkernel/blob/main/docs/research/implementation-decisions-57.md), sections 4–5) found two things: +- **Decisions are never revalidated.** `revalidate` checks `code` memories only. A probe retained a `decision` and a `code` memory citing the same file, then rewrote and deleted the file: the `code` memory was flagged both times, the `decision` neither time (`file_probe` in the results). +- **A file-hash check would catch real stale decisions, and also valid ones.** In code-copilot-team's history at `00d49c0`, the first cited file of both stale decisions changed after the decision date. So did the cited file of 3 of the 10 decisions still in force, two of them safety rules (`cited_file_history` in the results). `recall` hides flagged memories by default, so hiding flagged decisions would lose those rules. + +## Proposed (needs a spec first) +- **Record a hash at retain.** A `decision` whose `source` names a file under the project root stores that file's hash, as `code` memories do. Only `source` is tracked for now, not the other paths in `evidence`. +- **Flag on change or loss.** `revalidate` flags such a decision when the file is missing or its hash changed, and clears the flag when the hash matches again or the decision is superseded. +- **Flagged code stays hidden; flagged decisions are returned.** `recall` keeps hiding flagged `code` memories, as today, but returns flagged decisions, so the agent re-checks the evidence instead of losing the decision. +- **The mark is an additive field.** Each `recall` result gains `needs_review` and `review_reason` (false and empty when not flagged). The preview is unchanged, and existing fields keep their meaning. +- **Older decisions** (no stored hash) are flagged only when the cited file is missing. +- No new record type or MCP tool; reuse the `code` revalidation path. + +## Acceptance (sketch) +- The #57 file probe: the decision is flagged on rewrite and on delete, and `recall` still returns it with `needs_review: true` and a `review_reason`. +- The replay: every seed record is still found; decisions whose cited files changed come back flagged, not hidden. +- `recall` still hides flagged `code` memories. +- Stores from 0.1.x to 0.9.x load unchanged (the new key loads with a default). + +## To decide in the spec +- Whether flagged decisions also appear in the session-start "Needs review" list (`lifecycle.py`, today fed by revalidation's flagged items, at most 10 lines). + +Related: #57, #121 (replay), #118 (decision records in the template). + diff --git a/specs/memkernel-0-10-decision-revalidation/plan.md b/specs/memkernel-0-10-decision-revalidation/plan.md new file mode 100644 index 0000000..96df394 --- /dev/null +++ b/specs/memkernel-0-10-decision-revalidation/plan.md @@ -0,0 +1,40 @@ +--- +feature_id: memkernel-0-10-decision-revalidation +spec_mode: full +status: approved +date: 2026-11-13 +collaboration_mode: single +origin: + issue: gosha70/memkernel#123 + urls: + - https://github.com/gosha70/memkernel/issues/123 + - https://github.com/gosha70/memkernel/pull/121 + transcripts: + - specs/memkernel-0-10-decision-revalidation/origin/2026-11-13-issue-123.md + origin_claim: | + "Revalidate decisions that cite files: flag them, don't hide them." Record a hash of a decision's source file at + retain; flag it when the file changes or disappears; recall keeps hiding flagged code but returns flagged + decisions, marked by additive needs_review and review_reason fields; track source only; decide in the spec + whether flagged decisions appear in the startup "Needs review" list; needs a spec first. +--- + +# Plan: revalidate decisions that cite files (#123) + +## Approach + +1. **Retain** (`core/services.py`): for a `decision` with a readable `source` under the project root, store + `source_hash` in the record's metadata (`core/models.py` key, loaded with an empty default in + `storage/chroma.py`). +2. **Revalidate**: extend `revalidate()` to live `decision` memories with a `source` (FR-002); `flagged` items gain + the memory's type, so the startup list can name them (D1). +3. **Recall**: `_filter_live` lets flagged decisions through (FR-003); `build_artifact_refs` fills `needs_review` + and `review_reason` (FR-004). +4. **Lifecycle**: the "Needs review" list per D1. +5. **Tests**: the #57 probe as a unit test (SC-1), the legacy and clearing cases (SC-2), the replay re-run (SC-3), + a 0.9.x store fixture (SC-4). +6. **Docs**: README and CHANGELOG. + +## Risks + +- A decision flagged for an unrelated edit to its file (3 of 10 in #57's corpus) is shown flagged, not hidden: the + cost is a re-check, by design. diff --git a/specs/memkernel-0-10-decision-revalidation/spec.md b/specs/memkernel-0-10-decision-revalidation/spec.md new file mode 100644 index 0000000..b3c370a --- /dev/null +++ b/specs/memkernel-0-10-decision-revalidation/spec.md @@ -0,0 +1,96 @@ +# Spec: revalidate decisions that cite files; flag them, don't hide them (#123) + +Status: approved by the owner, 2026-11-14 (D1–D4 with the dedup and hint clarifications). + +## Checked facts (`main` at `e53a113`) + +- **`revalidate()` checks `code` memories only** (`core/services.py`, `revalidate`): for each live canonical + `code` memory with a `source`, it hashes the file and compares the hash with the memory's own `content_hash`, + flagging `missing` or `changed` (`REVIEW_REASON_*`), clearing the flag when the file matches again, and leaving + paths outside the project root or unreadable files untouched (`unknown`). +- **That comparison works for `code` only because its content is the file.** A `decision`'s content is its record + text, so it has no stored hash of the file it cites; one has to be recorded at retain. +- **`recall` hides every flagged memory, whatever its type,** unless `include_needs_review=True` + (`_filter_live`, the owner check for document parts too). +- **`recall` results do not carry the flag:** `ArtifactRef` has `ref_id`, `preview`, `score`, `token_count`, `type`, + `timestamp`, `tier`, `importance` (`core/models.py`; built in `retrieval/search.py`, `build_artifact_refs`). + `get` returns the full `Memory`, which has `needs_review` and `review_reason`. +- **The session-start "Needs review" list** is built from `revalidate()`'s `flagged` items, at most 10 lines + (`lifecycle.py`, `_needs_review_block`), each the source path, the reason and the `ref_id`. Its hint speaks of + code only: "These code memories no longer match their source; retain the file again as code to refresh them." +- **Retain deduplicates by content hash, globally by default** (`_retain_single`: no `source` scope unless + `dedup_source=True`): retaining the same decision text again, from any `source`, returns the existing record, + which keeps its own `source`. +- **#57's replay** (`eval/decisions-57/`): the `file_probe` shows a `decision` never flagged when its cited file is + rewritten or deleted; `cited_file_history` shows file-hash checks would flag both real stale decisions and 3 of + 10 decisions still in force, two of them safety rules. + +## User Scenarios + +1. An agent retains a decision with `source="src/redact.py"`. Later the file is rewritten. At the next session + start (or `consolidate(revalidate=true)`), the decision is flagged `changed`. +2. The agent recalls before building. The decision still comes back, with `needs_review: true` and + `review_reason: "changed"`, so it re-checks the evidence instead of losing the decision. +3. A flagged `code` memory stays hidden from `recall`, as today. + +## Requirements + +- **FR-001 Hash at retain.** A `decision` whose `source` resolves to a readable file under the project root + stores that file's content hash as `source_hash`: a new `Memory` field (`str`, default empty) and metadata key, + loaded empty from older records. No hash is stored otherwise, and none is ever added later. The hash is computed + only for the `source` of a newly created record: a dedup hit returns the existing record unchanged, keeping its + own `source` and `source_hash` (or none, for a record retained before this change). +- **FR-002 Revalidate decisions.** `revalidate()` branches on type: `code` is unchanged; live `decision` memories + with a `source` are checked against `source_hash`: missing file → `missing`; a different hash → `changed`; a match + clears the flag. A decision without a `source_hash` (retained before this change, or whose file was unreadable + then) is flagged only when the file is missing, and a present file clears a `missing` flag. Paths outside the + project root or unreadable files count as `unknown`, as for `code`. A superseded or withdrawn decision is not + checked: `recall` already hides it. Each `flagged` item gains a `type` key (an additive change to the report). +- **FR-003 Flagged decisions are returned.** `recall` returns flagged `decision` memories, with the flag in the + result (FR-004); it keeps hiding other flagged memories unless `include_needs_review=True`. +- **FR-004 The mark is additive.** `ArtifactRef` gains `needs_review: bool = False` and `review_reason: str = ""`, + filled for every result; the preview and existing fields do not change. +- **FR-005 Startup list (D1).** Flagged decisions appear in the session-start "Needs review" list, each line naming + its type; the hint becomes type-aware: re-check a flagged decision's evidence and retain a corrected one with + `supersedes`, or retain a flagged code file again to refresh it. +- **FR-006 Docs.** README (revalidation section, `recall` description), the `recall` tool's docstring (the new + fields, and `include_needs_review` no longer needed for decisions), CHANGELOG under `[Unreleased]`. + +## Constraints / What NOT to Build + +- No new record type, MCP tool, setting or dependency. +- Only `source` is tracked, not the other paths in `evidence`. +- Stores from 0.1.x to 0.9.x load unchanged: `source_hash` is optional and loads empty. +- `code` revalidation and its hiding behaviour do not change. + +## Key Entities + +- **`source_hash`:** the content hash of a decision's `source` file at retain (new metadata key). + +## Success Criteria + +- **SC-1** #57's file probe: a decision citing a file is flagged `changed` on rewrite and `missing` on delete, and + `recall` returns it with `needs_review: true` and the reason; a flagged `code` memory for the same file is not + returned. +- **SC-2** A decision retained without a `source_hash` is flagged only when its file is missing; restoring the file + content clears a `changed` flag; a `source` outside the project root, or unreadable, is `unknown` and not + flagged. +- **SC-3** Dedup: the same decision text retained again from another `source` (global dedup) returns the existing + record with its original `source` and `source_hash`; retained again from the same `source`, the record is + unchanged; a dedup hit on a record retained before this change leaves it without a `source_hash`. +- **SC-3b** #57's replay still finds every seed record. +- **SC-4** A store written by 0.9.x, holding a decision with a `source` and no `source_hash`, opens, and that + decision revalidates per FR-002 (flagged only when its file is missing). Fast suite, ruff, mypy strict, + coverage ≥ 80%; MCP tool set unchanged. + +## Decisions (the owner's, 2026-11-14) + +- **D1 Startup list.** Flagged decisions appear in the session-start "Needs review" list, each line naming it a + decision, with a type-aware hint (FR-005). The list keeps its 10-line cap. +- **D2 The new result fields.** `needs_review` and `review_reason` on every `recall` result, for all + types (a flagged `code` memory shows them when `include_needs_review=True`). +- **D3 Which files get a hash.** Only a `source` under the project root that can be read, as `code` + revalidation already requires, and only on a newly created record (a dedup hit keeps the existing record's + `source` and `source_hash`); otherwise no hash, and the decision is checked for a missing file only. +- **D4 Only decisions.** Only `decision` memories, as #123 asks; conventions or facts citing files are + out of scope. diff --git a/specs/memkernel-0-10-decision-revalidation/tasks.md b/specs/memkernel-0-10-decision-revalidation/tasks.md new file mode 100644 index 0000000..0887f53 --- /dev/null +++ b/specs/memkernel-0-10-decision-revalidation/tasks.md @@ -0,0 +1,16 @@ +# Tasks: memkernel-0-10-decision-revalidation + +## US1: hash and revalidate +- [ ] `source_hash` key, recorded at retain for decisions (FR-001, D3); loads empty for old records +- [ ] `revalidate()` checks decisions (FR-002); flagged items carry the type +- [ ] Unit tests for SC-1 (probe), SC-2 (legacy, clearing, unknown) and SC-3 (cross-source dedup, same-source dedup, + a legacy hashless dedup hit) + +## US2: recall and startup +- [ ] `_filter_live` returns flagged decisions (FR-003); `ArtifactRef` fields (FR-004, D2) +- [ ] Startup "Needs review" list per D1, with a type-aware hint (FR-005) +- [ ] Tests: recall marks, code still hidden, the startup list; a 0.9.x store fixture (SC-4) + +## US3: docs and checks +- [ ] README, CHANGELOG (FR-006) +- [ ] #57 replay re-run (SC-3); fast suite, ruff, mypy strict, coverage