fix(mcp): start wait_for_event at the beginning of a half-written line - #31
Merged
Merged
Conversation
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
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
partial_lines_wait_for_their_newlinefailed once on CI for #30 and passed on re-run. Not a flaky assertion:wait_for_eventtook 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
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.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