Principle:2akouwu Reverify Context Rollover
| Knowledge Sources | |
|---|---|
| Domains | Context_Engineering, State_Management, LLM_Agents |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Context-engineering pattern that replaces lossy context compaction with a verified file-based hand-off: when a conversation's context nears a token threshold, the model writes a structured hand-off to disk, the session is terminated, and a fresh session starts with the user's original request quoted verbatim and a pointer to the hand-off file.
Description
Context Rollover addresses the fundamental limitation of LLM context windows: as a conversation grows, the model's attention degrades ("lost in the middle"), and native compaction (automatic summarization) is lossy — it drops details and can hallucinate. Context Rollover replaces this with a verified hand-off:
- Guard hook: A hook (Stop/AfterAgent/SessionStart) fires after each agent turn. The guard checks the current context token count against a threshold. Below threshold: allow. At threshold: block (ask the model to write a hand-off).
- Hand-off: The model writes a structured hand-off file (
rollover-handoff.md) with sections for task/goal, decisions, done/not-done, identifiers/paths, verification status, waiting items, and next step. The file is the model's own notes — UNVERIFIED. - Receipt: The guard validates the hand-off (exists, non-empty, has ≥3 sections, not too large, rewritten after the block). If valid, it writes a receipt with transcript anchors (first/last user messages, SHA-256) and context tokens.
- Fresh session: The launcher terminates the old session and spawns a fresh one. The opening prompt quotes the user's original request verbatim and points to the hand-off file. The fresh session reads the hand-off and continues from "Next step."
The key insight: state lives in files, the conversation is a cache. The ledger (see Principle:2akouwu_Reverify_Durable_Ledger) carries verified facts; the hand-off carries the model's working notes. A fresh context starts clean but not blind.
The harness supports four AI coding CLIs (Claude Code, Codex CLI, Gemini CLI, OpenCode), each with its own adapter for hooks, config editing, and successor spawning.
Usage
Use this principle when:
- You run long AI coding sessions that exceed context windows.
- You want to avoid lossy compaction and keep verified state across context resets.
- You need the fresh session to have the user's original request, not a summary.
- You want a guard that fails closed (if the hand-off is missing or invalid, the session continues, not crashes).
Theoretical Basis
The rollover is a state machine with three states:
# Abstract algorithm (NOT real implementation)
state = load_state(session_id, threshold)
if state.pending:
# Hand-off was requested; check if it was written
problem = validate_handoff(handoff_path, blocked_epoch)
if problem is None:
write_receipt(anchors, tokens, reason)
spawn_fresh_session(opening_prompt(receipt))
return "receipt" # rollover complete
else:
return "allow" # invalid hand-off, continue session
elif tokens >= threshold:
state.pending = True
save_state(state)
return "block" # ask model to write hand-off
else:
return "allow" # below threshold
Key invariants:
- Atomic receipt consumption: A receipt is consumed exactly once (atomic rename to
.consumed.json) and never re-used after a restart. - User message cancels rollover: If a user message arrives after the hand-off was written, the rollover is cancelled — the user's intent takes precedence.
- Fail closed: An invalid hand-off (missing, empty, too large, too few sections, not rewritten after the block) returns "allow," not "rollover" — the session continues rather than losing state.
- Opening prompt quotes verbatim: The fresh session gets the user's first and last messages verbatim, plus a pointer to the hand-off. It does not get a summary.
- Threshold capped by window: The threshold is capped at 75% of the model's real context window so the guard fires before the window is full.
Practical Guide
To install and operate context rollover:
- Install hooks:
reverify rollover install --harness claude(wires the guard hook, turns off native compaction, creates config backups). - Verify with doctor:
reverify rollover doctor(checks all four harnesses: on PATH, hooks wired, compaction off, receipts consumed, no stuck successors). - Run through the launcher:
reverify rollover run -- claude [args](the launcher monitors for receipts and spawns fresh sessions). - Set the threshold:
REVERIFY_ROLLOVER_THRESHOLD=200000(token count; default 200k). - Inspect status:
reverify rollover status(shows guard state, pending hand-offs, rollover count, events log).
Related Pages
Implemented By
- Implementation:2akouwu_Reverify_Harness_install
- Implementation:2akouwu_Reverify_doctor_report
- Implementation:2akouwu_Reverify_Launcher
- Implementation:2akouwu_Reverify_run_guard
- Implementation:2akouwu_Reverify_validate_handoff
- Implementation:2akouwu_Reverify_run_status
Uses Heuristic
Related Principles
- Principle:2akouwu_Reverify_Durable_Ledger — verified facts survive context resets via the ledger.