# Context guide
Reconstructs provider conversations from session history and estimates request budgets.
## Where to look
| Context types/event visibility | `../context.rs` |
| Ordered turns and compaction cutoff | `replay.rs`, `replay/builder.rs` |
| Incomplete-stream recovery | `replay/recovery.rs` |
| In-memory replay reuse | `replay_cache.rs` |
| Local token projection | `tokens.rs` |
| Profiling-only disk material/workloads | `cache.rs`, `profiling/` |
## Local contracts
- Replay filtering is separate from tolerant JSONL parsing in `../sessions/read.rs`. Local events/reasoning summaries are not ordinary provider messages.
- Reconstruct ordered turns and matched calls/results, not flat payload lists. Preserve failed/cancelled assistant text from terminal records.
- Apply shared prompt-injection projection before output compaction. Match later `ToolResultAssessment` by unique result ID/session/call/enforcement, allowing background events between records. Require complete coverage and matching redacted stored bytes/hash; withhold pending or unmatched enforced output. Assessment warnings stay local.
- Replay `reasoning_selection` immediately before its user message, including partial turns. Compaction cutoff resets baseline with retained prefix.
- Checkpoint `execution_effects` follows model summary as separate bounded evidence. Do not reconstruct checkpoint prefix from later results or infer no writes from clean final diff.
- `ConversationReplayCache` validates session identity, generation, file stamps and content digest; file size alone cannot establish reuse.
- `cache.rs` is profiling-only. Normal runs neither read nor write disk conversation snapshots; leave existing snapshots untouched.
- Token estimates are not observed usage; keep projection changes aligned with agent request construction.