fix(logs): use userspace polling for -f follow mode#41
Conversation
fs.watchFile (libuv uv_fs_poll_t) does not reliably emit change events for cross-process file appends on Windows, so `bitsocial logs -f` would silently miss new log lines there. Replace it with a self-rescheduling setTimeout that calls fs.promises.stat() + reads new bytes — the same pattern production tail-f libraries use precisely because OS file watchers aren't cross-platform reliable for this scenario. Closes #40
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughReplace ChangesFollow Mode Polling Implementation
Dependency Update
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
bitsocial logs -fsilently misses lines appended to the current log file. Root cause:fs.watchFile(libuv'suv_fs_poll_t) is not reliable for cross-process appends on Windows. This is a long-standing platform gap (see nodejs/node#36888).fs.watchFilewith a self-reschedulingsetTimeoutpoll that callsfs.promises.stat()and reads new bytes when the size grows. This is the pattern production tail-f libraries (@logdna/tail-file, etc.) use precisely because OS file-watcher events are not cross-platform reliable.continues watching old file if no new file appears(test/cli/logs.test.ts:462) acts as the regression test. It was failing on Windows in CI (runs 26140177410, 25375977963).CPU/IO profile is unchanged — we were already polling, just inside libuv. Now the polling lives in JS, which behaves consistently across platforms.
Closes #40
Test plan
npm run build && npm run build:test— cleannpx vitest run test/cli/logs.test.tson Linux — all 29 logs tests pass, including the previously-Windows-flaky oneSummary by CodeRabbit
Chores
@pkcprotocol/pkc-jsdependency to the latest versionBug Fixes