# Session replay reuse
Prompt projection and agent execution share one bounded replay cache per `AgentSession`. The cache stores normalized replay output, diagnostics, a content fingerprint, the session path and file identity, and the in-process durable-write generation.
On Unix filesystems with stable high-resolution change metadata, an unchanged session reuses replay without rereading or reparsing JSONL. Durable appends and physical rotation advance the shared session generation. External append, truncation, replacement, partial-record completion, and same-size rewrites invalidate through file identity, change metadata, and content fingerprints. Coarse-timestamp and non-Unix filesystems conservatively fingerprint-read before reuse, avoiding stale replay and repeated JSON parsing or replay construction. A full replay read is accepted only when file identity and generation are stable before and after the read.
The cache is bounded to one replay per agent instance. Durable JSONL remains the source of truth. Replay diagnostics, event ordering, compaction cutoff behavior, bounded-history failures, and cancelled or failed partial assistant replay are unchanged.
## Benchmark
Command:
```bash
cargo test --release --quiet --lib replay_snapshot_benchmark_growing_sessions -- --ignored --nocapture
```
Environment: macOS 27.0, Apple M5 Pro, Rust 1.98.0, baseline commit `61171e0ce`. Fixture seed `sequential-0.70`; 1 warmup and 9 measured samples; 40 growing prompts per sample. The success threshold was chosen before implementation: optimized median wall time must be at least 25% lower than the forced-full-replay baseline.
| Measurement | Forced full replay | Shared replay |
|---|---:|---:|
| Median wall time | 39 ms | 18 ms |
| p95 wall time | 39 ms | 18 ms |
| Session scans | 80 | 40 |
| Bytes read | 8,046,060 | 4,023,030 |
| Lines/events parsed | 4,920 | 2,460 |
| Replay builds | 80 | 40 |
| Cache hits | 0 | 40 |
The baseline is a comparison harness, not a measured product regression.