You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: devdocs/superpowers/specs/2026-08-30-sdlbench-prompt-cache-design.md
+34-10Lines changed: 34 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,12 +71,13 @@ interface BenchmarkSession {
71
71
interfaceBenchmarkTurn {
72
72
turnIndex:number;
73
73
request:unknown;
74
+
canonicalModelInput:string;
74
75
toolCalls:unknown[];
75
76
toolResults:unknown[];
76
77
}
77
78
```
78
79
79
-
The persisted representation uses deterministic JSON serialization. Tool order, object key order, and result bytes are part of the measured cache surface. Operational timestamps, durations, request IDs, absolute paths, and other non-actionable noise remain outside the model-facing transcript.
80
+
The persisted transcript stores every canonical model-input string, not only a digest. It also records the assembly version, serialization version, UTF-8 encoding, and tokenizer identity needed to replay the cache calculation losslessly. Tool order, object key order, and result bytes are part of the measured cache surface. Operational timestamps, durations, request IDs, absolute paths, and other non-actionable noise remain outside the model-facing transcript. Benchmark transcripts contain controlled fixture data only, not user sessions.
80
81
81
82
The same task fixture defines the user request, turn limit, context budget, quality oracle, and completion criteria for every product. Product-specific instructions are allowed only when they arrive through that product's normal public installation or MCP loading path.
82
83
@@ -85,11 +86,22 @@ The same task fixture defines the user request, turn limit, context budget, qual
85
86
Each benchmark result contains deterministic simulated metrics and optional provider metrics:
Zero-input runs report zero percentages rather than `NaN`.
119
131
132
+
Each run starts a fresh product and model session. Turn `0` is the cold phase; turns `1..` are the warm phase. A one-turn run has an all-zero warm phase. Repeated executions use new run IDs and begin new cold phases. Whole-session values are the sum of the cold and warm phase values.
133
+
120
134
### Deterministic simulation
121
135
122
136
The simulator compares consecutive serialized model-input prefixes. A byte is reusable only while every preceding byte is unchanged. Content moved earlier, reordered keys, changing tool definitions, and injected runtime metadata invalidate the prefix from the first differing byte.
@@ -130,7 +144,16 @@ Token counts use SDLBench's existing tokenizer. The simulator records:
130
144
- invalidated-prefix tokens
131
145
- reusable-prefix percentage
132
146
133
-
For simulation, reusable-prefix tokens are cache reads and all remaining input tokens are uncached. Cache writes are reported separately but use a neutral weight of `1.0`, so the simulated gate measures deterministic reuse rather than provider pricing.
147
+
For each turn, the simulator partitions input tokens into two mutually exclusive categories. A token is a cache read only when all of its serialized UTF-8 bytes occur before the first differing byte from the prior turn. Every other token is a cache write. Simulated uncached input is zero, so `totalInputTokens = cacheReadTokens + cacheWriteTokens`.
148
+
149
+
The first turn has zero reads and writes its complete input. Later turns read the unchanged prefix and write the changed suffix. Simulation assigns read weight `0.0` and write weight `1.0`:
150
+
151
+
```text
152
+
simulatedEffectiveInputTokens = cacheWriteTokens
153
+
simulatedEffectiveSavingsTokens = cacheReadTokens
154
+
```
155
+
156
+
This is an ideal deterministic reuse measure, not a prediction of provider cache thresholds, expiration, or pricing.
134
157
135
158
### Provider normalization
136
159
@@ -151,7 +174,7 @@ effectiveInputTokens =
151
174
152
175
Weights are the provider's read and write prices divided by its normal input price for the recorded model. This expresses cache cost in full-price input-token equivalents. Cold writes can therefore produce negative savings when a provider charges a write premium. Dollar savings use the same profile but remain informational.
153
176
154
-
Provider comparisons are valid only when product results use the same provider, model, and pricing-profile version.
177
+
Provider comparisons are valid only when product results use the same provider, model, and pricing-profile version. Aggregation assigns `ranking.status`: compatible records are `ranked`; valid but incompatible records are retained as `unranked` with the mismatch reason.
155
178
156
179
## Provider Usage Import
157
180
@@ -168,7 +191,8 @@ Provider usage is imported after a benchmark session. SDLBench never stores cred
168
191
"turns": [
169
192
{
170
193
"turnIndex": 0,
171
-
"inputTokens": 12000,
194
+
"totalInputTokens": 12000,
195
+
"uncachedInputTokens": 3000,
172
196
"cacheReadTokens": 0,
173
197
"cacheWriteTokens": 9000,
174
198
"outputTokens": 800
@@ -177,7 +201,7 @@ Provider usage is imported after a benchmark session. SDLBench never stores cred
177
201
}
178
202
```
179
203
180
-
The importer joins records by `productId`, `taskId`, `runId`, and `turnIndex`. It rejects duplicate turns, negative or non-finite values, unknown runs, mismatched product identities, and incompatible provider/model/profile combinations.
204
+
The importer joins records by `productId`, `taskId`, `runId`, and `turnIndex`. It rejects duplicate turns, negative or non-finite values, unknown runs, mismatched product identities, and provider metadata that conflicts with the recorded run. A provider, model, or profile mismatch between otherwise valid product runs does not discard either run; aggregation retains both and marks that comparison unranked.
181
205
182
206
Imported files must not contain raw prompts, tool results, API keys, provider request IDs, or user data.
Saved results include the benchmark schema version, tokenizer identity, fixture revision, pricing-profile identity, and transcript digest. Comparisons reject incompatible schema, tokenizer, or fixture revisions instead of silently combining them.
248
+
Saved results include the losslessly replayable transcript artifact, transcript digest, benchmark schema version, assembly version, serialization version, tokenizer identity, fixture revision, and pricing-profile identity. The result summary references that artifact. Comparisons reject incompatible schema, assembly, serialization, tokenizer, or fixture revisions instead of silently combining them.
225
249
226
250
Synthetic traces are regenerated from the same session/result contract. Existing stale traces remain historical artifacts and must not be presented as current SDLBench evidence.
227
251
@@ -263,6 +287,6 @@ The rollout does not require provider credentials in CI. The first four steps ca
263
287
- SDL-MCP, the traditional baseline, and every tested competitor produce the same session/result shape.
264
288
- Every run saves simulated cache metrics; imported provider metrics are optional and explicitly ranked or unranked.
265
289
- Whole-session, cold, warm, and per-turn cache values are reproducible from saved inputs.
266
-
- Existing raw token, uncapped token, coverage, precision, and recall metrics remain available.
290
+
- Existing raw token, capped token, uncapped token, coverage, precision, and recall metrics remain available.
267
291
- Synthetic traces are regenerated and no stale-trace warning remains.
0 commit comments