Skip to content

feat(core): LLM consolidation executor reusing extraction setup (#1088) - #1094

Merged
ajianaz merged 5 commits into
developfrom
feat/consolidation-executor
Aug 25, 2026
Merged

ajianaz merged 5 commits into
developfrom
feat/consolidation-executor

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

What

Adds consolidation_exec — the execution layer completing the #1088 segment-consolidation pipeline:

  • Shared LLM setup: reuses ExtractionConfig (same model / API key / base URL as the import/extraction pipeline) — one setup serves both purposes, zero new configuration
  • execute_plan(): iterates the plan's batches; each batch → one LLM call with a consolidation prompt that merges same-topic memories into one dense record and explicitly preserves hedging markers (EN + ID)
  • Provenance gate: every generated record passes ProvenancePolicy::validate_output (Research: trust boundary & provenance for consolidated memories #1089) before write; rejected outputs are counted, never stored
  • Soft deprecation: source memories get deprecated=true with a reason pointing at the consolidated record — never deleted
  • Budget cap: max_llm_calls per run; skipped batches are reported
  • ConsolidationStore trait: store operations isolated for testability

Why

Final phase of #1088: the planner (PR #1092) showed 67–91% LLM call reduction on real rooms; this executor realizes it using the extraction endpoint already configured, and the #1089 policy guarantees consolidated records cannot launder untrusted content into human facts or manufacture confidence.

Testing

  • 4 unit tests: markdown-fenced & plain JSON parsing, empty/garbage rejection, endpoint join (empty and explicit path)
  • Full suite 511/511 passed, fmt + clippy clean, cora review in pre-commit passed
  • No network calls in tests; live LLM behavior exercised via the ConsolidationStore trait boundary

Adds consolidation_exec: executes a segment-based ConsolidationPlan via the
same OpenAI-compatible endpoint as the import/extraction pipeline (shared
ExtractionConfig - one setup, many uses). Each batch becomes one LLM call
with a consolidation prompt that preserves hedging. Outputs pass the #1089
provenance gate before write; sources are soft-deprecated, never deleted.
Budget-capped via max_llm_calls.
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

A failed LLM call no longer aborts execute_plan mid-run: the error is
recorded in ConsolidationExecution.batch_errors and remaining batches
still process. Failed batches leave their sources untouched.
…batch

- Compute embedding via ConsolidationStore::embed_content before insert so
  consolidated records are visible to vector recall (was embedding: vec![]).
- insert/deprecate failures abort only the affected batch and are recorded
  in batch_errors; the run continues (duplicate content from a partial
  write is recoverable by dedup, lost batches are not).
Failed calls still consume an API request against max_llm_calls, so the
guard now uses a dedicated llm_calls_made counter incremented before the
call regardless of outcome. Also rewords an error message that tripped a
false-positive SQL-injection pattern (no SQL involved).
/// validated against the provenance policy, embedded, written, and its
/// sources are soft-deprecated with a reason pointing at the new record.
pub fn execute_plan<U: ConsolidationStore>(
uteke: &U,
- reqwest blocking client gets a 120s timeout so a slow consolidation
  endpoint cannot hang the run (parity with update_check).
- LLM-provided fact_type is validated against the allowed set
  (fact/decision/preference/procedure/context); anything else falls back
  to "fact" so arbitrary model output can never set an unknown type.
@ajianaz
ajianaz merged commit f6bdb84 into develop Aug 25, 2026
13 checks passed
@ajianaz
ajianaz deleted the feat/consolidation-executor branch August 25, 2026 03:21
ajianaz added a commit that referenced this pull request Sep 6, 2026