Commit 75dbb72
authored
Timing-aware recording and replay with --replay-speed multiplier (#223)
## Summary
Records per-frame arrival timestamps during proxy recording and replays
them at configurable speed. Requested by Atai.
- **Recording:** SSE frame parser captures per-frame timestamps. NDJSON
uses `\n` delimiter. Bedrock binary EventStream uses 4-byte
length-prefix frame detection. Stores `recordedTimings { ttftMs,
interChunkDelaysMs, totalDurationMs }` on fixtures.
- **Replay:** `calculateDelay` extended with `recordedTimings` +
`replaySpeed` params. Precedence: streamingProfile > recordedTimings >
global latency. Speed multiplier divides all delays.
- **CLI:** `--replay-speed 2.0` (2x faster). Per-fixture `replaySpeed`
override.
- **Coverage:** All 11 streaming paths — 8 SSE/NDJSON/EventStream
writers + 3 WebSocket handlers. All providers including Bedrock.
- **Validation:** Per-fixture `replaySpeed <= 0` stripped with warning.
NaN/negative values in `recordedTimings` sanitized.
Approximate timing reproduction based on recorded TTFT and inter-frame
cadence. Replay chunk count may differ from recording — TTFT and average
pace are preserved, not per-token fidelity.
**Spec:** https://www.notion.so/3643aa38185281328fe6ddf27407c6ed
## Test plan
- [x] 3097 tests pass (9 new across 2 test files)
- [x] TypeScript clean
- [x] Lint + format + build clean
- [x] CR Round 1: 1 finding fixed (Bedrock/Ollama defaults fallback)
- [x] CR Round 2: 7/7 confirmed 0 findings
- [x] CR Round 3 adversarial: 6 findings — fixed eventIndex reset, NaN
validation, Bedrock capture, docs language
- [x] Positive control tests for precedence and replaySpeed
- [x] Backward compat verified
🤖 Generated with [Claude Code](https://claude.com/claude-code)28 files changed
Lines changed: 1130 additions & 44 deletions
File tree
- .claude-plugin
- charts/aimock
- src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
7 | 16 | | |
8 | 17 | | |
9 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
104 | 108 | | |
105 | 109 | | |
106 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
0 commit comments