Skip to content

fix(kv): canonical stable-tier order + the cache probe that proves it (#266) — and the ActivityAdapter seam - #2348

Merged
joelteply merged 3 commits into
canaryfrom
feat/activity-adapter-seam
Aug 21, 2026
Merged

joelteply merged 3 commits into
canaryfrom
feat/activity-adapter-seam

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Three commits. The first is the KV fix Joel has been waiting on; the second is the
instrument that makes it self-proving; the third is the seam the judge wiring needs.

1. 40075d7ea — canonical order inside the STABLE tier (the other half of #266)

The tier-split shipped for #266 (stable framing first, volatile grounding last) did not
deliver reuse, and the comment at the sort said why without noticing:

"A stable sort preserves the salience order WITHIN each tier, so attention ranking is untouched."

That was treated as harmless. It is the remaining half of the defect. Salience is
recomputed every turn
, so preserving it as EMIT ORDER re-shuffles the very tier whose
only purpose is to be byte-identical across turns.

Measured live inside Atlas's pallets__flask-4045 run, from her own prompt captures:

turns common prefix diverges into
0→1 8,216 / 9,906 chars [now …]
1→2 7,879 [active-work]
2→3 8,133 [workspace-map]

~82% shared prefix, and the divergence points are stable-tier blocks trading places.
Because the system prompt is FIRST, a swap at token ~2,000 invalidates KV for everything
after it — including a 34,000-token conversation tail. --cache-reuse 256 was passed the
whole time and every turn reported cachedTokens: 0. The cache was correct; we were
destroying the prefix ourselves.

Cost at the measured 111 tok/s prefill: ~306 seconds of re-prefill per act, growing as
her conversation grows (9,847 → 36,242 tokens). One observed turn was 20 minutes of
apparent silence that was a single 36k re-prefill — with the run reporting active the
whole time, because the pulse is a timer.

The fix: within the stable tier, order canonically by faculty name. Attention ranking
is genuinely untouched — salience still decides WHICH contributions survive the budget. It
simply stops deciding WHERE the survivors sit, which it never needed to. The volatile tier
deliberately keeps salience order: it re-prefills by construction, so canonical ordering
would buy nothing and would cost the "most salient nearest the write point" placement #205
put there on purpose.

2. faf8c07c9 — delib.generate.cache

Joel: "hopefully it will prove itself via probes." It could not have. delib carried
turn.demand and context.render — how big the prompt WAS — and nothing about what the
lane did with it
. A prompt whose prefix we destroyed every turn looked identical in the
probe stream to one served entirely from cache. That absence is why this survived from
#266 until today, and why the only way to see it was hand-diffing raw captures.

One row in metrics_from, the funnel every generation already passes through, so it covers
every turn of every citizen with no caller change. hit_rate is the existing
TurnMetrics::cache_hit_rate(), which had no way out of the process. Emitted only when
the lane actually reported timings — a fabricated 0.0 for a provider that never measured
one is a lying receipt of the #151/#357 class.

3. e404dcecd — ActivityAdapter: material in, verdict out

Slice 1 of the judge wiring, per
docs/architecture/BENCHMARKS-ARE-ADAPTERS-NOT-A-RUNNER.md. Generic over benchmarks /
gameplay / whatever comes next, per Joel's ask — not a benchmark-shaped special case.
Growable Outcome with Channel/ChannelValue; resolve_all fails loud naming the bad
key and the known set; an empty declaration is legal. 5 tests.

Not yet consumed — the hardcoded swe_bench::grade branch is still the live path.
Deleting it is a subtraction across four call sites and is the next commit, deliberately
not smuggled in here.

Verification

Owed, and not claimed as done

  • Live proof. The running core still holds the flask run, so deploy is correctly
    blocked. The proof is a delib.generate.cache query showing hit_rate climbing off the
    floor from act 2 — which is now a probe query rather than a capture diff, which was the
    point.
  • A regression test pinning "same set, different salience → identical bytes". Without
    it this regresses the same way Rust Module Consolidation Phase 2: Optimization & Compute Migration #266's half did.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 3 commits August 21, 2026 08:54
…of the judge wiring)

An activity adapts the outside world's form into ours and renders a verdict on what the
citizen produced. Benchmarks, a game level, a life-drawing critique, a robot that either
picked up the block or didn't — one interface, N implementations, declaring none is normal.

WHY NOT `BenchmarkAdapter`, WHICH ALREADY EXISTS: it was the right SHAPE and the wrong
SCOPE. It already carried both directions — `dataset()`/`tasks()` in, `grade()` out — so
this is a generalization, not a rewrite. But the NAME is load-bearing: an interface called
`BenchmarkAdapter` cannot plausibly host a game level, so the second activity gets its own
trait, registry and runner, and the substrate ends up with two of everything. Same failure
as naming a room for a subsystem and making it immortal. Named for the JOB, gameplay is a
sibling implementation instead of a fork.

THE GROWABLE OUTCOME, and why the fixed struct was the real blocker: `TaskOutcome` had
`patch` and `workspace` as bare fields, which means SWE-bench OWNS the outcome type. A game
trajectory or a robot's joint log could only arrive by widening a struct every other
activity compiles against — so in practice it would never arrive there; it would grow its
own parallel outcome and its own parallel judge. `Outcome` now keeps the UNIVERSAL facts as
named fields (she spoke; she worked somewhere; the harness had its own opinion) and puts
modality-specific ones in a typed `channels` carrier, the same growable shape this codebase
already uses for adapter capabilities. Gameplay adds a channel without SWE-bench
recompiling; a judge asks for the channel it grades and gets a typed None when the activity
produced none. Growing the enum stays deliberate — a new variant needs a REAL activity — but
the cost of a wrong guess drops from "a second subsystem" to "one unused variant".

WHAT THIS IS FOR (measured today, 450 runs): 253 of them — 56% — ended with NO GRADE AND NO
ERROR. Not a failure, not a verdict: nothing. In classroom terms the exams were sat and
nobody was assigned to mark them. `benchmark.json` declares `suite/instances/team/budget`
and NO judge; `BenchmarkAdapter` has zero production consumers; grading is hardcoded to
`swe_bench::grade` behind four private call sites. When a run doesn't come through one of
those doors, nothing marks it and nothing says so.

`resolve_all` is the seam that makes that unrepresentable: a declared judge that cannot be
resolved is an error AT STAGING, naming the bad key and the known set — never a run that
ends quietly. An EMPTY declaration resolves to empty and is explicitly NOT an error, because
most activities judge nothing and that is normal, not a missing judge.

Five tests, each pinning a contract that failed in the wild: registry round-trip + named
miss; empty declaration is legal; unknown declaration fails loud and names it; the default
judge defers to the harness (so a task whose EvalTask already encodes done-ness needs no
judge code); an absent channel reads ABSENT, not as empty success.

NOT YET WIRED — deliberately, this is slice 1. Next: the recipe declares its judges in
`params`, dispatch resolves them through this registry, and the hardcoded `swe_bench::grade`
branch is DELETED rather than supplemented (a subtraction, per the design doc's build order).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
#266 prefix defect

The tier-split shipped for #266 (stable framing first, volatile grounding last) did not
deliver reuse, and the comment at this sort said why without noticing: a stable sort
"preserves the salience order WITHIN each tier, so attention ranking is untouched". That
was treated as harmless. It is the remaining half of the defect. Salience is recomputed
EVERY turn, so preserving it as EMIT ORDER re-shuffles the very tier whose only purpose
is to be byte-identical across turns.

MEASURED LIVE 2026-08-21, inside Atlas's `pallets__flask-4045` run, from her own prompt
captures — not inferred:

  turn0→1  common prefix 8,216 / 9,906 chars   diverges into [now …]
  turn1→2  common prefix 7,879                 diverges into [active-work]
  turn2→3  common prefix 8,133                 diverges into [workspace-map]

~82% shared prefix, and the divergence points are stable-tier blocks TRADING PLACES.
Because the system prompt is FIRST, a swap at token ~2,000 invalidates the KV for
everything after it — including a 34,000-token conversation tail. `--cache-reuse 256`
was passed the entire time and every turn reported `cachedTokens: 0`. The cache was
correct; we were destroying the prefix ourselves.

Cost at the measured 111 tok/s prefill: ~306 SECONDS OF RE-PREFILL PER ACT, growing as
her conversation grows (9,847 → 36,242 tokens and climbing as tool results accumulate).
One observed turn was 20 minutes of apparent silence that was a single 36k re-prefill —
the run reporting `active`/`not stalled` the whole time, because the pulse is a timer.

THE FIX: within the stable tier, order CANONICALLY (by faculty name). Attention ranking
is genuinely untouched — salience still decides WHICH contributions are selected, which
happened above against the budget. It simply stops deciding WHERE the survivors sit,
which it never needed to. Same set in, same bytes out, every turn.

The volatile tier deliberately KEEPS salience order: it is re-prefilled by construction,
so canonical ordering would buy no reuse and would cost the "most salient nearest the
write point" placement #205 put there on purpose.

VERIFIED: 181 prompt tests pass, including
`framing_flip_never_perturbs_the_cacheable_prefix` — the #266 invariant is intact, this
extends it to the case it did not cover (a FIXED framing with re-ranked context).

NOT YET LIVE-PROVEN: the running core still holds the flask run, so deploy is correctly
blocked. The proof owed is her next captures — common prefix ~82% → ~100%, and
`cachedTokens` 0 → nonzero from turn 2. A regression test pinning "same set, different
salience → identical bytes" follows immediately.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ead of me diffing captures by hand

Joel: "hopefully it will prove itself via probes." It could not have. `delib` carried
`turn.demand` and `context.render` — how big the prompt WAS — and nothing about what the
lane DID with it. A prompt whose prefix we were destroying every single turn looked
identical in the probe stream to one served entirely from cache. That absence is why the
prefix defect (fixed in 40075d7) survived from #266 to today, and why the only way to
see it on 2026-08-21 was hand-diffing a citizen's raw prompt captures — exactly the manual
step a probe exists to delete.

The row lands in `metrics_from`, the single funnel every generation already passes
through, so one probe covers every turn of every citizen with no caller change:

  delib.generate.cache  cached_tokens prefill_tokens hit_rate prefill_ms decode_ms
                        input_tokens output_tokens latency_ms

`hit_rate` is `TurnMetrics::cache_hit_rate()` — the ratio that already existed and had no
way out of the process. 1.0 = fully warm prefix. Near 0 with a large `prefill_tokens` =
the prefix is being invalidated upstream, which is the measured pre-fix state: ~306s of
wasted re-prefill per act while `--cache-reuse 256` was set and working correctly.

Emitted ONLY when the lane actually reported timings. Cloud and older endpoints omit
them, and a fabricated 0.0 hit-rate for a provider that never measured one is a lying
receipt of the #151/#357 class — those stay silent rather than report a floor they did
not observe.

So the verification of the ordering fix is now a probe query rather than a capture diff:
hit_rate should climb off the floor from the second act of a task onward.

cargo check green (metal,accelerate). Signature and return value unchanged — purely
additive. The --lib gate in CI is the test proof; live proof still waits on the flask run
clearing the core.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply enabled auto-merge (squash) August 21, 2026 14:35
@joelteply
joelteply merged commit 58a691a into canary Aug 21, 2026
5 checks passed
@joelteply
joelteply deleted the feat/activity-adapter-seam branch August 21, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant