Skip to content

feat(orchestration): wire plan_with_cache into handle_plan_goal (#1856 follow-up) #2070

@bug-ops

Description

@bug-ops

Problem

PR #2068 added plan template caching infrastructure (PlanCache, plan_with_cache, SQLite migration 040, PlanCacheConfig) but the integration into the actual planning code path was not completed.

In crates/zeph-core/src/agent/mod.rs (line ~521), handle_plan_goal() calls:

let (graph, planner_usage) = LlmPlanner::new(
    self.provider.clone(),
    &self.orchestration.orchestration_config,
)
.plan(goal, &available_agents)
.await

This bypasses plan_with_cache() entirely. As a result, setting [orchestration.plan_cache] enabled = true in config has no effect — the cache is never consulted, and completed plans are never stored.

Expected Behavior

When orchestration.plan_cache.enabled = true:

  1. On /plan <goal>: call plan_with_cache() instead of planner.plan() directly
  2. PlanCache::new() must be instantiated in the Orchestration state struct (or in Agent)
  3. After a plan completes successfully, cache_plan() must be called to store the template
  4. Subsequent similar goals should trigger cache hit path: "plan cache hit, adapting template" logged

Required Changes

  1. Instantiate PlanCache in the agent's orchestration state (requires SqlitePool access and embedding model name)
  2. Replace the direct planner.plan() call in handle_plan_goal() with plan_with_cache()
  3. After plan execution completes in finalize_plan_execution() or equivalent, call cache.cache_plan()
  4. Thread goal embedding through the planning flow (embed the goal text before calling plan_with_cache)

Evidence

grep -rn "plan_with_cache\|PlanCache::new" crates/ --include="*.rs" | grep -v plan_cache.rs
# Returns only: lib.rs re-export line (pub use plan_cache::{...})
# No production call sites found.

Severity

MEDIUM — config option has no effect, feature silently unused. No crash, no data loss. Graceful degradation is unintentional (there is no cache path, only the full planner path).

Reproduction

  1. Add [orchestration.plan_cache] enabled = true to config
  2. Run /plan research and summarize recent Rust async patterns
  3. Run /plan summarize recent developments in Rust async (similar goal)
  4. Observe logs — "plan cache hit, adapting template" is NEVER logged
  5. Verify SELECT COUNT(*) FROM plan_cache on test DB → always returns 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingorchestrationTask orchestration / DAG scheduling

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions