Skip to content

Audit prompt_reveal cache cost on multi-topic sessions #346

Closed

Description

@abogartz

Part of #335. retrieval, bench, severity:medium.

Problem

Prompt-reveal rescore (#334) re-scores at every user turn. Cache invalidation now happens whenever the SELECTED rows change at a turn boundary. On a local seat (~1.7k t/s prefill at 128k context) a full bust costs minutes. The freeze existed because of #162 ("every memory write busts the prompt cache") and #165 (92% of lifetime busts were self-writes). We changed that policy on correctness grounds; the cost side is unmeasured.

Change

Multi-topic session audit on the live host:

  1. Drive one session through 5–8 unrelated topic turns (build question → auth question → docs question …), warm store.
  2. Count from evidence + status: epoch_recompute reason=prompt_reveal events, invalidations, measured prompt-cache read share per turn (the badge's measured receipts).
  3. Compare against the same script on the pre-fix build (frozen epochs): tokens saved by better retrieval vs tokens spent on busts.

Acceptance

A table in this issue: busts per session, cache-read share, net token delta. Then a keep/tune decision (tune knobs: re-score only when the abstain/overlap state flips; guided cap; budget).

Footguns

  • Keep the seat quiet during measurement (leftover harness traffic skews both timing and cache receipts — measured before).
  • The comparison build differs in TWO ways (rescore + hint channel); to isolate rescore, run the audit with guided rows absent (store with no user-guided tags).

Activity

  1. added
    retrieval
    bench
    severity:medium
    on Nov 7, 2026
  2. abogartz commented on Nov 7, 2026

    @abogartz
    OwnerAuthor

    Measured: per-turn rescore is cheap on the provider cache (#346, 2026-11-07 night)

    Harness: chain-cache.ts in the bench repo — one session, 6 topic turns (test-suite / tax / deploy / rate-limit / haiku / repeat-of-1) over a 10-row seeded store (2 guided), autoCapture: false so only rescore moves the block. Real opencode serve + recording proxy + local seat. Transports: V2 API (POST /api/session, /prompt, /experimental/.../wait).

    Fixed build (chain-audit-on, branch @ ee769ef) — prompt_reveal fires every turn (invalidations 5/6):

    turn topic wall s input cache.read block chars
    1 test suite 6 79 9732 675
    2 tax 5 82 9984 520
    3 deploy 32 427 11066 680
    4 rate limit 18 68 12768 689
    5 haiku 5 3257 10060 520
    6 test suite (repeat) 21 86 13975 675

    Total input 3999, cache.read 67,585 — 94.4% cache share.

    Frozen baseline (chain-audit-pin @ 29268ef) — block computed once, never moves:

    Total input 1934, cache.read 74,219 — 97.5% cache share. Block frozen at 236 chars: the SAME single row (test-suite) rode all six turns; the tax, deploy and rate-limit turns got zero relevant rows.

    Why the bust is small

    The wire shows the block rides at the END of the system message — the divergence point sits after ~9.7k stable prefix tokens, so a selected-row change re-prefills only the tail: 68–427 input tokens/turn. Turn 5 (guided-only, biggest content move) is the one real spike at 3257.

    Verdict: KEEP prompt_reveal

    Footguns found building this:

    1. POST /api/experimental/session/{id}/wait returns instantly when the session is not marked busy YET — the prompt is queued async. Poll for a NEW assistant receipt, not just wait.
    2. OPENCODE_MEMORY_DIR resolves against the serve process cwd (the repo copy), not the driver's — pass an absolute path or the plugin silently writes a second store.
    3. POST /api/session rejects a model field (400); the profile's default model is the source of truth.
  3. abogartz commented on Nov 8, 2026

    @abogartz
    OwnerAuthor

    Table (bench@b53a102, run dirs results-cache-audit-on / results-cache-audit-pin, per-turn rows in audit.json): with rescore ON, cache-read share 94.4% vs 97.5% frozen; net rescore cost ~344 tok/turn; invalidations land on prompt_reveal boundaries only, matching the #340 contract (bytes move when SELECTED rows change).

    Decision: KEEP rescore. 3.1 pp cache share and ~344 tok/turn buy back the later-topic rows the freeze hid (#340 was a correctness bug; correctness outranks the cache delta). Tune knobs (re-score only on abstain/overlap flip, guided cap, budget) not needed at this cost; revisit if the per-turn delta grows with store size.

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

    benchretrievalseverity:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions