Skip to main content

extend_output_idx

Function extend_output_idx 

Source
pub(crate) fn extend_output_idx(fs: &FileStore, block_id: &str) -> Option<u64>
Expand description

Bring an existing output.idx up to output’s current size by scanning ONLY the appended bytes, instead of rescanning from byte zero.

Falls back to a full rebuild whenever the existing index can’t be trusted as a base: missing, header unreadable, no entries yet, built for another generation, or output shrank below what the index already covers (rotation/truncation).

Why this exists: the index is a pure cache with no incremental mutation, so a stale one used to mean a full O(file-size) rescan. On a live agent output grows continuously, so “stale” was the steady state — a 30-second line-count poll drove 37 full rebuilds in 19 minutes on a 759 MB transcript, mean 3168 ms, ~10% duty cycle (docs/reports/REPORT_AGENT_PANE_LOAD_RENDER_ARCHITECTURE_2026_08_27.md §5).

Returning the stale count instead was tried and is WRONG: line_count feeds useHistoryPagination’s tail window (offset = total - PAGE_SIZE), so an undercount silently drops the most recent history on reopen — codex P1 on PR #2838. The count has to stay exact; only the cost of keeping it exact is negotiable.