Skip to content

Commit e10a41c

Browse files
korjwl1claude
andcommitted
Fix watch mode missing events for short-lived sessions
The file_sizes cache in process_file_with_ts's None branch was recording meta.len() at the time of the check, which could be larger than what was actually processed by process_lines_streaming. This caused subsequent watch events to skip the file via the current_size == cached_size fast path, permanently missing data for files that stopped growing. This primarily affected Codex sessions (short-lived, file stops growing quickly) but could also affect Claude Code for short conversations. Fix: do not cache file size when no complete lines were processed. The next watch event will re-attempt processing without a stale cache entry. Bump version to 1.1.2. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8ec83c6 commit e10a41c

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "toki"
3-
version = "1.1.1"
3+
version = "1.1.2"
44
edition = "2021"
55
description = "AI CLI tool token usage tracker module"
66
license = "FSL-1.1-Apache-2.0"

src/engine.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,13 @@ impl TrackerEngine {
463463

464464
match result {
465465
None => {
466-
if let Ok(meta) = std::fs::metadata(path) {
467-
self.file_sizes.insert(path_owned.clone(), meta.len());
468-
}
466+
// Do NOT cache file size here. process_lines_streaming found no
467+
// complete lines, but the file may have grown since it was opened
468+
// (concurrent writes). Caching meta.len() now would record a size
469+
// larger than what was actually processed, causing the next watch
470+
// event to skip the file via the current_size == cached_size check.
471+
// By leaving file_sizes un-cached, the next event will re-read and
472+
// re-attempt processing.
469473
let act = self.activity.entry(path_owned).or_insert(FileActivity {
470474
state, last_active: now, last_checked: now,
471475
});
@@ -564,9 +568,8 @@ impl TrackerEngine {
564568

565569
match result {
566570
None => {
567-
if let Ok(meta) = std::fs::metadata(path) {
568-
self.file_sizes.insert(path_owned.clone(), meta.len());
569-
}
571+
// Do NOT cache file size here — same race condition as the legacy
572+
// path above. See comment there for details.
570573
let act = self.activity.entry(path_owned).or_insert(FileActivity {
571574
state, last_active: now, last_checked: now,
572575
});

0 commit comments

Comments
 (0)