Implementation:2akouwu Reverify validate handoff
| Knowledge Sources | |
|---|---|
| Domains | Context_Engineering, Validation |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for validating a rollover hand-off file and generating the opening prompt for the fresh session, provided by the Reverify library.
Description
The validate_handoff function checks that a hand-off file is usable: exists, non-empty, not too large, has ≥3 ## sections, and was rewritten after the block epoch. Returns None if valid, or a reason string. The companion write_receipt writes a receipt JSON with transcript anchors (first/last user messages, SHA-256) and context tokens. The opening_prompt function generates the fresh session's opening message: quotes the user's original request verbatim, points to the hand-off file, and instructs the agent to continue from "Next step" without mentioning context or cleanup.
Usage
Use these functions when you need to:
- Validate a hand-off file before triggering a rollover.
- Write a receipt with transcript anchors.
- Generate the opening prompt for a fresh session.
Code Reference
Source Location
- Repository: Reverify
- File: reverify/rollover_harness.py
- Lines:
validate_handoffat L560-578;write_receiptat L651-673;opening_promptat L716-732
Signature
def validate_handoff(path: Path, not_before: float) -> Optional[str]:
"""None when the hand-off is usable; otherwise the reason it is not."""
def write_receipt(session_id: str, transcript: Any, handoff: Path,
tokens: Optional[int], reason: str, launch_id: Optional[str],
anchors: Optional[Dict[str, Any]] = None,
harness: str = "claude") -> Path:
"""Write receipt JSON with transcript anchors; return path."""
def opening_prompt(receipt: Dict[str, Any]) -> str:
"""Generate the fresh session's opening prompt."""
Import
from reverify.rollover_harness import validate_handoff, write_receipt, opening_prompt
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| path | Path | Yes | Hand-off file path |
| not_before | float | Yes | Epoch time the file must be newer than |
| receipt | Dict | Yes | Receipt dict with anchors/handoff path (for opening_prompt) |
Outputs
| Name | Type | Description |
|---|---|---|
| validate_handoff return | Optional[str] | None if valid; reason string if not |
| write_receipt return | Path | Path to receipt JSON file |
| opening_prompt return | str | Opening prompt for the fresh session |
Usage Examples
from reverify.rollover_harness import validate_handoff, write_receipt, opening_prompt
from pathlib import Path
# Validate the hand-off
problem = validate_handoff(Path("/project/.reverify/rollover-handoff.md"), not_before=epoch_time)
if problem:
print(f"Hand-off invalid: {problem}")
# Continue session instead of rolling over
else:
# Write receipt and start fresh session
receipt_path = write_receipt("s1", transcript, handoff, tokens=210000,
reason="threshold", launch_id="abc", anchors=anchors)
receipt = json.loads(receipt_path.read_text())
prompt = opening_prompt(receipt)
# prompt quotes the user's original request verbatim