Skip to content

⚔️ Conflict Auto-Resolution #217

Closed

Description

@hurttlocker

Summary

When cortex conflicts detects contradictory facts, an LLM evaluates recency, source authority, and context to auto-resolve them — superseding losers and reinforcing winners.

Priority: HIGH IMPACT — cleans up existing fact corpus, improves search quality downstream.

Spec

New File: internal/extract/resolve.go

type ConflictResolution struct {
    WinnerID    int64
    LoserID     int64
    Reason      string
    Confidence  float64
    Action      string // "supersede", "merge", "flag-human"
}

func ResolveConflicts(ctx context.Context, llm llm.Provider, conflicts []ConflictPair) ([]ConflictResolution, error)

Resolution logic:

  1. Gather both facts + their metadata (source, timestamp, reinforcement count)
  2. Send to LLM with evaluation prompt:
    • Which is newer? (newer usually wins)
    • Which source is more authoritative? (MEMORY.md > daily note > import)
    • Is this a genuine update or error?
    • Can they be merged into one better fact?
  3. LLM returns structured JSON: {winner, loser, reason, confidence, action}
  4. If confidence < 0.7 → flag for human review instead of auto-resolving

CLI Integration

cortex conflicts --resolve                    # detect + auto-resolve
cortex conflicts --resolve --llm openai/gpt-5.1-codex-mini
cortex conflicts --resolve --dry-run          # show what would be resolved, dont act
cortex conflicts                              # unchanged (just lists conflicts)

Actions

  • supersede: Mark loser fact as superseded, boost winner confidence
  • merge: Create a new fact combining both, supersede both originals
  • flag-human: Print to stdout for manual review (low confidence)

Files to Create/Modify

  • internal/extract/resolve.go — resolution logic
  • internal/extract/resolve_test.go — tests (mock LLM)
  • internal/search/prompts/resolve_conflict.txt — prompt template
  • cmd/cortex/main.go — add --resolve and --dry-run flags to conflicts command
  • internal/store/fact_store.go — add SupersedeFact() method

Benchmark Test Spec

Test Corpus

Generate 20 synthetic conflict pairs covering:

  • Temporal updates (old value → new value)
  • Source authority (MEMORY.md vs daily note)
  • Genuine contradictions (needs judgment)
  • Near-duplicates (merge candidates)
  • Ambiguous cases (should flag for human)

Metrics (per conflict pair, per model)

Metric Target
Latency (per pair) <2s
Tokens in <300
Tokens out <100
Cost per resolution <$0.005
Accuracy (vs human judgment) ≥85%
Appropriate flag rate Flags ≥80% of ambiguous cases

Accuracy Rubric

  • Correct: Same decision a human would make
  • Acceptable: Reasonable but not optimal (e.g., superseded when merge was better)
  • Wrong: Kept the wrong fact or auto-resolved what should be flagged
  • Dangerous: Deleted correct information

Benchmark Script

Create scripts/benchmark_resolve.go:

  • Runs all 20 pairs against both models
  • Records latency, tokens, cost, decision
  • Compares to pre-labeled human judgments
  • Outputs accuracy matrix + cost comparison

Acceptance Criteria

  • --resolve flag on cortex conflicts works
  • --dry-run shows resolutions without applying
  • Confidence threshold (0.7) gates auto-resolution
  • SupersedeFact() properly marks losers
  • Merge creates new fact with provenance from both originals
  • Benchmark results documented in PR
  • All existing tests pass

Dependencies

Estimated Cost

~$0.005/conflict × 50 conflicts/week = **$0.10/month** (weekly batch job)

Activity

  1. added
    v0.9.0
    llm
    benchmark
    on Feb 24, 2026
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

    benchmarkllmv0.9.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions