Heuristic:23blocks OS Ai maestro Tail Only Read
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Status_Presence |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Read only the tail of a growing transcript file (last 64KB) to extract live status, and grow the read only for the first line's session metadata — bounding I/O on large rollout files.
Description
Codex transcript rollouts are JSONL files under `~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl`. They can grow to tens of MB over a long session. Two read patterns extract what's needed without reading the whole file:
For live status, the last task event is near the end of the file. `codexLiveStatusFromFile` reads only the last 64KB — enough to contain the most recent events — and scans backwards for status strings. Re-reading the entire file on every status poll (every few seconds) would be wasteful.
For session metadata (the `cwd` recorded in line 1's `session_meta` envelope), the first line is always `session_meta`, but it embeds `base_instructions` (the system prompt) and routinely exceeds tens of KB. A fixed small read truncates the JSON mid-string. So `rolloutCwd` reads in 64KB chunks, growing until a newline is found, capped at 2MB — a session_meta larger than that is pathological and not worth parsing.
Usage
Use this heuristic when:
- Polling a growing file for the latest state (status, last event) where the relevant content is at the tail
- Reading a large JSONL first line that may be tens of KB (embedded system prompts)
- Bounded I/O on large transcript files during frequent polling
The Insight (Rule of Thumb)
- Action: For tail reads, seek to `fileSize - 64KB` and read to EOF. For first-line reads, grow the read in 64KB chunks until a newline is found.
- Value: Tail read: 64KB. First-line cap: 2MB. Scan cap for directory walks: 400 files.
- Trade-off: A tail read may miss an event if the last 64KB spans more than ~1000 lines of large events. This is acceptable for status polling — the next poll catches it.
- Compatibility: Works with append-only JSONL. The first-line growth read handles JSON strings with embedded newlines (escaped as `\n`, not literal newlines, so `indexOf('\n')` is safe).
Reasoning
Status polling runs every few seconds. A full file read of a 10MB rollout on every poll would saturate disk I/O across many agents. The status event is always the most recent — appended at the end — so the tail contains it. 64KB is large enough for the last several events (each event is a few hundred bytes) while being a single fast read.
The session metadata case is the opposite: the needed content is at the start of the file, but the first JSON line can be huge because Codex embeds the full system prompt (`base_instructions`) in the `session_meta` envelope. A naive 4KB read truncates the JSON mid-string and fails to parse. Growing the read in chunks until a newline is found handles any size, and the 2MB cap bounds the worst case.