Description
Problem
Every turn that needs repo context tends to re-run the same retrieval chain: search, read files, expand style slices, re-derive intermediate reasoning that already produced a useful diff or patch plan. Near-identical follow-up requests (same goal, same files, small prompt tweaks) pay again in latency, tool rounds, and tokens even though the expanded context barely changed.
Proposed approach
Backend-owned cache of expanded context
- The context engine caches expanded context — retrieved file spans, ranked style-profile slices, and other intermediate artifacts that fed a generation — keyed by a deterministic hash of inputs (goal, workspace identity, retrieval parameters, relevant path set, manifest/profile versions, etc.).
- On a cache hit, skip re-running retrieval tools and re-deriving the same expansion chain; serve the cached bundle into the model path (subject to freshness checks below).
- On a miss, run the full retrieval pipeline, populate the cache, then generate.
Architecture: client loop, backend context
- The client still owns the tool loop (director/session semantics unchanged at the product level).
- For context expansion, the client calls our backend instead of hitting the filesystem or git directly for the heavy path; the backend performs cache lookup, invalidation, and real retrieval only when needed.
- This is intentionally a provider-layer capability: value accrues when sessions use our hosted context/retrieval service, not when the harness talks to raw APIs and local tools only.
Cache invalidation (hard part)
Code context shifts quickly. A hit is only valid if reality still matches the key:
- Repo change: commits, dirty tree, branch switch, or file watcher events must bump workspace generation or content hashes so stale expansions are not reused.
- Profile/rules drift: style profile version, manifest hash, or pinned index revision should participate in the cache key or trigger invalidation.
- TTL vs event-driven: likely need both — short TTL for safety plus explicit invalidation on
gitstate and critical path changes.
Document failure mode: false hit is worse than a miss (wrong file contents in context); prefer conservative invalidation early.
Product positioning
Differentiator only when using our provider: “fast / smart context retrieval” — fewer redundant tool rounds, lower bill, snappier follow-ups on the same task cluster. Not something we can promise for BYO-key-only local mode unless we replicate the same backend contract.
Success criteria (draft)
- Repeatable benchmark: second request with equivalent inputs shows measurable drop in retrieval tool calls and input tokens vs cold path.
- Invalidation tests: edit file → next request misses or refreshes; clean tree at same commit → hit when appropriate.
- Observability: cache hit/miss, key version, invalidation reason in trace (no prompt bodies in strict mode).
Open questions
- Granularity: per-session vs per-workspace vs per-organization cache namespace?
- What exactly goes in the hash (full prompt vs normalized goal + retrieval fingerprint)?
- Encryption/at-rest and tenancy for cached file snippets on the provider.
- Interaction with semantic caching at the model layer (provider prompt cache) — compose or avoid double-counting?
Related
- Context engine / retrieval pipeline (
docs/harness-architecture/context-engine.md) - Observability and cost accounting (
docs/harness-architecture/observability.md) - Provider/router architecture (
docs/harness-architecture/model-router.md)
Activity