Skip to content

Timing-aware recording and replay with --replay-speed multiplier#223

Merged
jpr5 merged 5 commits into
mainfrom
blitz/timing-replay/integration
May 19, 2026
Merged

Timing-aware recording and replay with --replay-speed multiplier#223
jpr5 merged 5 commits into
mainfrom
blitz/timing-replay/integration

Conversation

@jpr5
Copy link
Copy Markdown
Contributor

@jpr5 jpr5 commented May 18, 2026

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

  • 3097 tests pass (9 new across 2 test files)
  • TypeScript clean
  • Lint + format + build clean
  • CR Round 1: 1 finding fixed (Bedrock/Ollama defaults fallback)
  • CR Round 2: 7/7 confirmed 0 findings
  • CR Round 3 adversarial: 6 findings — fixed eventIndex reset, NaN validation, Bedrock capture, docs language
  • Positive control tests for precedence and replaySpeed
  • Backward compat verified

🤖 Generated with Claude Code

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 18, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@223

commit: 3c0a6f3

@jpr5 jpr5 force-pushed the blitz/timing-replay/integration branch from 53a304f to fe9aa07 Compare May 18, 2026 20:56
@jpr5 jpr5 force-pushed the blitz/timing-replay/integration branch from 8171c3c to f2c5df8 Compare May 18, 2026 21:48
@jpr5 jpr5 merged commit 75dbb72 into main May 19, 2026
23 checks passed
@jpr5 jpr5 deleted the blitz/timing-replay/integration branch May 19, 2026 05:23
jpr5 added a commit that referenced this pull request May 19, 2026
## Summary

- Adds `X-AIMock-Context` header support for scoping fixtures per
integration — fixtures with `match.context` only match requests carrying
that exact context value; fixtures without `context` remain shared
- Injects context extraction in all 21 handler files (28 call sites) —
HTTP handlers via `getContext(req)`, WebSocket handlers via
`upgradeHeaders` extraction
- Enriches recorder to auto-capture context in `buildFixtureMatch()` and
route recorded fixtures into context subdirectories in
`persistFixture()`
- Adds context validation in fixture-loader (type check, dedup key,
discriminator)
- 15 new tests across 5 test files covering matching, helper extraction,
fixture loading, recording, and strict-mode interaction
- Bumps version to 1.26.0 (includes timing-replay from #223)

## Test plan

- [x] 3151 tests pass (90 files)
- [x] TypeScript clean (`tsc --noEmit` — 0 errors)
- [x] Prettier clean
- [x] ESLint clean
- [x] Pre-commit hooks pass on all commits
- [x] CR loop: 7-agent Round 1 + confirmation round — 0 bucket (a)
findings on context routing code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant