Skip to content

perf: checkpoint acknowledged main rollout reads between Stop hooks - #129

Open
albin-zhu wants to merge 3 commits into
langfuse:mainfrom
albin-zhu:fix/incremental-rollout-read
Open

albin-zhu wants to merge 3 commits into
langfuse:mainfrom
albin-zhu:fix/incremental-rollout-read

Conversation

@albin-zhu

@albin-zhu albin-zhu commented Nov 10, 2026 •

Copy link
Copy Markdown

Summary

Repeated Stop hooks currently load and parse the entire main rollout, including already acknowledged turns. This change checkpoints acknowledged byte boundaries and parser context so ordinary main-thread hooks read only the newly appended suffix. It adds no daemon, SQLite dependency, model routing change, or exporter replacement.

  • Store a private, atomic <rollout>.langfuse.cursor checkpoint with parser context, bounded conversation suffix, original turn count and source guards.
  • Preserve generation input, developer/system instructions, discovered tool definitions, token usage, UTF-8 boundaries and seeded turn numbering across hook processes.
  • Defer incomplete trailing lines; retain pre-completion Stop-turn bytes until completion or a following turn.
  • Advance only after the export callback succeeds and the existing turn delivery receipt is present. Removed receipts, corrupt checkpoints, changed history limit, replaced/truncated sources rebuild.
  • Preserve the full-read ownership path for subagent/ancestor traversal and max_history_chars: 0; directory discovery remains unchanged. This is explicitly a main-rollout optimization, not a claim that all plugin I/O is incremental.

Why

#119 / #122 address generation-history allocation/flush pressure. Reading and parsing the acknowledged rollout prefix on each subsequent hook remains a separate cost. This PR reduces that repeated logical input; it does not assert physical disk bytes, an across-the-board machine-lag root cause, or lossless provider-wire history.

Verification

  • pnpm run lint: formatting and TypeScript passed.
  • pnpm test: 11 files / 136 tests passed.
  • New behavioral regressions cover warm/cold generation equality, omission counts, historical tool definitions, late subagent ownership, UTF-8 chunks/partial tails, final Stop before completion, failed acknowledgement, corrupted/replaced/truncated sources, removed receipts and seeded numbering.
  • Ran the actual bundled hook in separate Node processes against synthetic loopback OTLP data with fake credentials. No real model turns, production uploads or user configuration changes.
Synthetic acknowledged prefix Cold hook Warm hook Warm rollout suffix read Upload payload Cursor file
985,889 bytes 73 ms 61 ms 846 bytes 3,843 bytes 690 bytes
33,552,754 bytes 135 ms 58 ms 846 bytes 3,846 bytes 693 bytes

Both warm runs emitted one new root and preserved the previous turn's generation context. Reads also include fixed source guards, metadata discovery and checkpoint/receipt files; the measured suffix is not total physical disk I/O. Published 0.4.3 warm runs on equivalent fixtures took 83 ms and 92 ms; these single-run timings are descriptive, not a performance guarantee.

Review points

The checkpoint contains transcript content and is documented as private (POSIX 0600; Windows inherited directory ACLs). First use/cold rebuild still reads the history. Concurrent writers can roll the optimization back to an older acknowledged position (extra reads) rather than risking skipped delivery. Subagents deliberately remain on the existing fidelity path.

Also included: opt-in LANGFUSE_CODEX_DIAGNOSTICS hook progress records (no transcript content, credentials, raw errors or full paths), and bounded subagent discovery — the day pruning never matched on Windows because path.relative returns backslashes, so every hook walked the entire session history.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Nov 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@albin-zhu
albin-zhu force-pushed the fix/incremental-rollout-read branch from c2372aa to e5ab365 Compare November 11, 2026 04:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants