feat(remediation): change-remediation policy for diff-impacted memories - #444
Merged
Conversation
Detection (memory_staleness_pass, #443) marks an impacted memory stale — it points at the bug. This adds the *remediation* half: given the memories a commit impacted (change_impact's matcher ∩ the diff), decide how to make each correct again, safely. The safety split (auto-rewriting prose from a diff would fabricate): - code-derived memories (agent_context='codebase') -> collect their changed files and re-ingest once; codebase_analyze (incremental, content-hash) then supersedes the stale AST fact with the current one. - hand-authored memories (decisions, lessons) -> mark_memory_stale and leave the re-authoring to a human/LLM; never silently rewritten. - core/change_remediation.py: pure classifier (is_code_derived / Remediation REINGEST|FLAG_STALE). Reuses agent_context=='codebase', the same marker the codebase-analyze and change_impact paths already use — no new signal. - handlers/consolidation/change_remediation_pass.py: DI orchestrator (remediate_impacted) — pure policy + injected re-ingest callback + injected store. Batches/dedups re-ingest paths; flags hand-authored stale. Foundation only: the real wiring (codebase_analyze as reingest_fn, the commit diff via change_impact/post_commit as the impact source) is the composition step and is validated against AP + a real codebase. Addresses cdeust/fleet-watch#110 (remediation, not just detection). Tests (DB-free, fakes): classifier both classes + missing fields; orchestrator split, path dedup, no-op. ruff + craftsmanship clean; all 7 run locally. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017fnomaXS71hgxMw2zr7HGR
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Detection (#443) marks a stale memory ⚠stale — it points at the bug. This adds the remediation half: when a commit's diff invalidates memories, decide how to make each one correct again, safely. It closes the loop from "this memory is stale" to "this memory is now right."
The impact-mapping already exists —
change_impact.py(ADR-0046 Phase 4) maps a commit's changed files/symbols to the memories that reference them, but it's read-only (heat-bump/tag only). This PR supplies the missing remediation policy + action, with one safety split because auto-rewriting prose from a diff would fabricate:agent_context='codebase') → collect their changed files and re-ingest once;codebase_analyze(incremental, content-hash) supersedes the stale AST fact with the current one.mark_memory_staleand leave re-authoring to a human/LLM. Never silently rewritten.Addresses cdeust/fleet-watch#110 (remediation, not just detection).
Scope — foundation only
This PR ships the pure policy + a DI orchestrator, both fully unit-tested. It deliberately does not yet wire itself into the commit path: the real
reingest_fniscodebase_analyze, and the impact source ischange_impact/post_commit_reindex's diff — that composition step needs AP enabled + a real codebase to validate, so it's a follow-up. Nothing runs automatically from this PR.Type of change
Test plan
Authoring env lacks the DB/AP, so the full suite runs in CI. Verified locally (executed the test functions directly — all 7 pass):
tests_py/core/test_change_remediation.py: code-derived byagent_context, by tag, by hash-tag; hand-authored → FLAG_STALE; missing fields default to FLAG_STALE.tests_py/handlers/consolidation/test_change_remediation_pass.py: code-derived→reingest / hand-authored→flag split; re-ingest path dedup across memories; empty-input no-op.ruff check+ruff format --check+ craftsmanship gate: clean (no numeric constants introduced — the# source:lesson from feat(staleness): auto-fire is_stale via a bounded file-existence revalidation pass #443 applied).All existing tests pass — deferred to CI.
New tests for new behavior.
Mutation check: swapping the reingest/flag branches, not deduping paths, or auto-marking code-derived stale (which would fight
codebase_analyze's supersession) are all caught.Coding-standards compliance
core/(stdlib+enum only); I/O orchestration is a composition root taking injected store + callback.Breaking changes
None. New modules only; no existing behavior changed; not yet invoked anywhere.
Reviewer checklist
Generated by Claude Code