v3.4.0 — Contradiction Detection (Layer 5)
v3.4.0 — Contradiction Detection (Layer 5)
Summary
- Memory Compiler 후속 단계로
contradiction_detector자동 fire (session_memory_end.py:make_contradiction_aware_writer) - Hybrid recall (FTS5 + Arctic-ko-MLX RRF) top-5 → Gemma 4 E4B 4-way 분류 (metric_update / decision_reversal / fact_correction / no_conflict)
- Review CLI (
python -m src.contradiction_review_cli) 로 dismiss / supersede / update 결정 - Layer 4 recall hook 이
deprecated_by메모리의 raw_cosine + score 둘 다 × 0.3 감쇠 (primary sort key 가 raw_cosine 이므로 양쪽 감쇠 필요)
Inspiration
외부 CDSS MindVault fork 의 LLM-detected contradictions (fact-layer 4-type 중 detection 부분만 차용). 4-type 메모리 분류는 이번 범위 밖 (현재 detection 만 구현).
What's new
src/contradiction_detector.py— detection engine + jsonl queuesrc/contradiction_review_cli.py— list / show / resolve applyhooks/memory-recall.py+src/memory_search.py— Layer 4 deprecated_by decaysrc/session_memory_end.py—make_contradiction_aware_writerhook integrationscripts/contradiction_backfill.py— one-shot pair-wise sweep for existing memories
Test count
470 (v3.3.0) → 533 (+63)
Migration
bash install.sh재실행 (스키마 변경 없음)- 신규 메모리는 SessionEnd hook 자동 처리
- 기존 메모리는
python scripts/contradiction_backfill.py --dry-run으로 먼저 모집단 확인 후 본 sweep 권장
Limitations
- Gemma cold 응답이 timeout 초과하면 silent skip (graceful fail). debug.log 에 telemetry
- confidence < 0.7 false negative 허용 (silent abstention 정책). 보수적 retrieve 가 필요한 도메인 (e.g. CDSS 임상결정지원 fork) 은 threshold 낮춰야 함
_patch_frontmatter_list는 block-style YAML list 검출 시 mutation refuse (debug.log 기록). 수동 변환 또는 flow-style 로 통일 후 재시도- review CLI 는 single-writer 가정:
resolve --apply의 jsonl rewrite (_mark_resolved) 와 frontmatter list mutation (_patch_frontmatter_list) 은 대상 파일에 lock 을 잡지 않는다. 동시에 두 resolve 를 실행하거나, resolve 도중 다른 세션의 SessionEnd 가 queue 에 append 하면 last-write-wins race 로 한쪽 변경이 소실될 수 있다 (드뭄 — 인터랙티브 단일 사용자 환경에서는 발생하지 않음). append 가 소실돼도 다음 세션에서 같은 메모리가 재staged 되면 재검출되므로 영구 손실은 아니다. - supersede audit-trace 가 staged stem 을 기록:
supersederesolve 는 신규(staged) 파일의 stem (YYYYMMDD-HHMMSS_type_slug) 을deprecated_by/supersedes에 쓴다. promote 후 파일 stem 이 clean slug 로 바뀌므로 이 audit 링크는 더 이상 존재하지 않는 stem 을 가리킨다. decay 는deprecated_by키의 존재만 검사하므로 회수 down-weight 기능 자체는 정상 작동한다 — audit trace 만 부정확하다. - backfill
--memory-dir <custom>는 prod index DB 에 인덱싱된 디렉토리만 의미:recall_memory가 production index DB 를 읽으므로, 인덱싱되지 않은 custom dir 을 주면 0건 검출된다 (스크립트가 stderr 경고 출력). default (prod memory dir) 사용 시 정상.
Memory ops
- 새 jsonl path:
~/.claude/mindvault-v3/contradictions.jsonl(append-only) - Atomic rewrite: tmp + os.replace + fcntl.flock (single-user 가정)
- Frontmatter mutation: tmp + os.replace per file