Skip to content

KV Cache Phase 1: make skills, prompts, extensions, and plugin tools deterministic #47

@shuyhere

Description

@shuyhere

Summary

Make prompt assembly inputs deterministic by sorting discovered skills, prompts, extension files, and plugin tools before rendering or request construction.

Why

Prompt/KV cache reuse depends on exact repeated prefixes, not semantic similarity. Today, filesystem discovery and plugin registration order can drift across runs, which can mutate:

  • the <available_skills> section,
  • prompt template listings,
  • extension load order,
  • plugin tool order,
  • final tool definitions sent to providers.

This is a direct cache-breaker.

Scope

Introduce deterministic ordering rules for all semi-static prompt resources.

Required ordering rules

  • extension files sorted by normalized path
  • skills sorted by (name, path)
  • prompts sorted by (name, path)
  • plugin tools sorted by (source path, tool name)
  • final tool definitions rendered in a stable order

Code touchpoints

  • crates/cli/src/extensions/discovery.rs
  • crates/cli/src/extensions.rs
  • crates/cli/src/session_bootstrap.rs
  • crates/cli/src/run.rs
  • plugin runtime assembly code

Acceptance criteria

  • repeated bootstrap in the same repo/settings yields identical skill/prompt rendering
  • plugin tool order is stable across runs
  • stable prefix hash does not change because of filesystem enumeration order
  • tests cover ordering stability

Reference

  • knowledge/internal/KV_CACHE_REFACTOR_MASTER_PLAN.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions