Skip to content

fix(mcp): start wait_for_event at the beginning of a half-written line - #31

Merged
jayhesselberth merged 1 commit into
mainfrom
worktree-mcp-wait-starts-on-a-line
Aug 29, 2026
Merged

jayhesselberth merged 1 commit into
mainfrom
worktree-mcp-wait-starts-on-a-line

Conversation

@jayhesselberth

Copy link
Copy Markdown
Member

Why

partial_lines_wait_for_their_newline failed once on CI for #30 and passed on re-run. Not a flaky assertion: wait_for_event took the event log's length as its starting point, and when the writer's first half-line landed before the reader measured the file, the offset sat mid-line — the second half arrived alone, failed to parse, and the wait timed out. The sampler appends lines in more than one write now and then, so an agent whose wait began at that moment lost a real event the same way.

What

  • The starting offset is now the first byte of any unterminated last line (start_of_unfinished_line, scanning the tail back to the nearest newline in 4 KiB chunks). A log that ends cleanly still starts at its end, so nothing already written is replayed.
  • Tests: a wait that begins mid-line gets that line once it completes and replays nothing afterwards; the offset helper on absent/empty/clean/partial logs and across chunk boundaries.

Tested

cargo test -p sint mcp:: (13 passed), cargo fmt --check, cargo clippy -p sint --all-targets -- -D warnings — in an acompile allocation.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MuezDnJq5Qh34SoGGAgzZU

wait_for_event took the event log's length as its starting point. The
sampler appends a line in more than one write now and then, so a call
that began between two of them had its offset in the middle of a line:
the second half arrived alone, failed to parse, and the event was lost.
That is the intermittent CI failure of partial_lines_wait_for_their_newline
(the writer thread's first write beat the reader's metadata() on a
loaded runner), and a real miss for an agent whose wait happened to start
at that moment.

The starting offset is now the first byte of any unterminated last line,
found by scanning the tail back to the nearest newline; a log that ends
cleanly still starts at its end, so nothing already written is replayed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MuezDnJq5Qh34SoGGAgzZU
@jayhesselberth
jayhesselberth merged commit d31f6fc into main Aug 29, 2026
3 checks passed
@jayhesselberth
jayhesselberth deleted the worktree-mcp-wait-starts-on-a-line branch August 29, 2026 18:08
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.

1 participant