fix: improve log file position tracking accuracy#164
Merged
Conversation
Fix two issues in log file tailing: 1. Race condition on initialization: Previously used separate metadata() call to get file length, which could miss content written between the metadata check and file open. Now uses seek(End) + stream_position() atomically on the opened file. 2. Position drift after reading: Previously calculated new position by summing line lengths, but this missed newline characters that are stripped by lines(). Now uses stream_position() after reading to get the accurate file position. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a TODO item by improving log file position tracking to eliminate race conditions and position drift. The changes ensure accurate file position tracking when tailing logs from multiple daemon processes.
Changes:
- Replaced separate metadata call with atomic seek-to-end and position retrieval to prevent race conditions during initialization
- Switched from manual line-length calculation to
stream_position()after reading to account for stripped newline characters
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merged
jdx
added a commit
that referenced
this pull request
Jan 19, 2026
## 🤖 New release * `pitchfork-cli`: 1.0.2 -> 1.1.0 <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [1.1.0](v1.0.2...v1.1.0) - 2026-01-19 ### Added - add file watching to auto-restart daemons ([#165](#165)) - support boolean values for retry configuration ([#170](#170)) - disable web UI by default ([#172](#172)) - auto-generate JSON schema from Rust types ([#167](#167)) ### Fixed - improve cron watcher granularity for sub-minute schedules ([#163](#163)) - improve log file position tracking accuracy ([#164](#164)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Releases `pitchfork-cli` v1.1.0 and syncs version across `Cargo.toml`, `Cargo.lock`, `docs/cli/*`, and `pitchfork.usage.kdl`. > > - **Added**: file watching to auto-restart daemons; boolean support for retry config; web UI disabled by default; JSON schema generation from Rust types > - **Fixed**: improved cron watcher granularity (sub-minute); more accurate log file position tracking > - Updated `CHANGELOG.md` with 1.1.0 notes > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2e6d4c6. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.
Summary
Fixes the TODO at
src/cli/logs.rs:207about building log file length when reading to avoid gaps.Issues fixed:
Race condition on initialization: Previously used a separate
metadata()call to get file length after opening. Content written between the metadata check and starting to watch would be missed. Now usesseek(End)+stream_position()atomically on the already-opened file.Position drift after reading: Previously calculated new position by summing line lengths:
This missed newline characters that are stripped by
lines(), causing the position to drift behind the actual file position. Now usesstream_position()after reading to get the accurate position.Test plan
pitchfork logs --tailworks correctly with multiple daemons🤖 Generated with Claude Code
Note
Improves log tail accuracy and eliminates an init race in
src/cli/logs.rs.get_log_file_infos, open the log file,seek(End), then usestream_position()to setcur, replacingmetadata().len()to avoid missing writes between metadata and opentail_logs, replace manual byte counting of read lines withstream_position()to correctly advancecur(including newline bytes)Written by Cursor Bugbot for commit 48be4e4. This will update automatically on new commits. Configure here.