Repository navigation
Conversation
relay.log grows unbounded on long-lived relays: the detached launch redirects > relay.log 2>&1, which truncates only at relaunch, so per-stream stderr lines and reconnect flaps accumulate forever and can fill small remote hosts. Add an in-process RotatingLogWriter (the relay owns its own stderr; a shell redirect can't cap size). installRelayLogRotation wraps process.stdout/stderr so all logging (42 call sites) flows through a writer that appends to relay.log, tracks size, and at 10MB renames relay.log -> relay.log.1 (one archived generation) and reopens a fresh relay.log. Wired only for the detached daemon; deploy passes --log-file on the POSIX and Windows launch paths. Constraints: portable node:fs sync calls (works with pipe/redirect on Linux/macOS/Windows); the current log is always relay.log so the tail-diagnostics workflow keeps working; writes and rotation are guarded so a filesystem error degrades to uncapped logging rather than crashing, and rename (not delete) means no window without a log file. Tests cover rotation at the cap, tail-ability, boot-output preservation, ~2x cap footprint bound, and stderr wrapping/restore. Co-authored-by: Orca <[email protected]>
Self-review found a HIGH cross-platform bug: on Windows the launch shell holds
its own `1>relay.log` handle without FILE_SHARE_DELETE, so renameSync of the
live file fails (EPERM/EBUSY). The previous rotate() swallowed that, reopened the
un-renamed file, and re-read its full over-cap size — so the cap never held on
Windows AND every subsequent log line churned a failing close/rename/open.
On rename failure, fall back to truncating relay.log in place ('w') so the size
cap still holds and there is no per-line churn. The shell's fd keeps appending at
its own offset but truncation bounds total growth; trade-off is no archived
generation on that path. New test models the rename-blocked case (archive path is
a directory) and asserts the cap still holds (fails pre-fix: 20100 > 4096).
Also fixed a test nit: spy on process.stderr so the post-restore assertion write
does not leak to the real test-runner stderr.
Co-authored-by: Orca <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a size-capped rotating writer for relay diagnostics, including append-on-start behavior, single-generation rotation, stream interception, restoration, and failure handling. Adds the optional 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/relay/rotating-log-writer.test.ts (2)
69-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider tightening the archive size assertion.
The archive file is a rotated copy of the previous current log, which was itself capped at
maxBytes. AssertingarchiveSize <= capwould be a tighter and more meaningful bound thancap * 2, while still validating the single-generation retention guarantee.♻️ Suggested tighter assertion
- expect(archiveSize).toBeLessThanOrEqual(cap * 2) + expect(archiveSize).toBeLessThanOrEqual(cap)
88-101: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a stdout routing assertion and a failure-fallback test.
The
installRelayLogRotationimplementation wraps bothprocess.stdoutandprocess.stderr, but this test only verifies stderr routing. A brief assertion thatprocess.stdout.writealso lands in the log file would guard against a future regression that accidentally drops the stdout wrapper. Additionally, no test exercises the failure/fallback path (e.g., unwritable log directory) wherewriter.activeisfalseand output falls back to the original stream.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f07fdca5-54a0-4bb0-ab73-69fc3939aa4c
📒 Files selected for processing (4)
src/main/ssh/ssh-relay-deploy.tssrc/relay/relay.tssrc/relay/rotating-log-writer.test.tssrc/relay/rotating-log-writer.ts
|
Follow-up (commit eb0f0db) fixes a HIGH cross-platform bug caught in self-review: Windows: rotation never succeeded and churned on every line. On Windows the launch shell holds its own Fix: on rename failure, fall back to truncating New test models the rename-blocked case (archive path is a directory so Verified-correct in review (no change): stdout-as-transport is safe (detached mode sets stdoutAlive=false, no protocol on stdout; sentinel/CLI/connect modes return before rotation installs), no bypass writes (console.warn/error route through the patched process.stderr.write), rotation math (single oversized line lands wholly in the fresh file), and fd/crash safety. |
Summary
relay.loggrows unbounded on long-lived relays. The daemon is launched detached with> relay.log 2>&1(src/main/ssh/ssh-relay-deploy.ts), which truncates the file only at relaunch. A relay that stays up for days accumulates per-stream stderr lines (fs-handler-file-read.tsstream start/end/error, reconnect flaps, etc.) with no bound, eventually filling small remote hosts' disks.Fix & design rationale
Rotation is implemented in the relay process (it owns its own stderr; a shell redirect cannot cap size). New
src/relay/rotating-log-writer.ts:installRelayLogRotation(logPath)wrapsprocess.stdout.write/process.stderr.writewith aRotatingLogWriter. Wrapping the two stream functions captures all relay logging (42process.stderr.writecall sites) without touching each one, and without missing native/early output.O_APPENDfd torelay.log, tracks bytes, and at the cap closes,rename(relay.log → relay.log.1)(replacing any prior archive), and reopens a freshrelay.log. One archived generation is kept; total footprint ≤ ~2× cap.relay.tsonly for the detached daemon (--connectbridges and--orca-cliare short-lived and return earlier). Deploy passes--log-file <relay.log>on both the POSIX and Windows launch paths.Cap = 10 MB, one archive. Enough history to diagnose reconnect/sleep-wake sequences while bounding disk on small hosts (e.g. a Raspberry Pi). Justified in a code comment.
Constraints honored
node:fssync calls (openSync/writeSync/renameSync) — no POSIX-only tricks. The shell redirect stays in place so pre-JS boot/crash output is still captured; once JS starts, the in-process rotator owns all subsequent logging.tail -100 ~/.orca-remote/relay-*/relay.logkeeps working: the current log is alwaysrelay.log; rotation renames the old file torelay.log.1and reopensrelay.log, so the tail target never moves.Repro / evidence
src/relay/rotating-log-writer.test.ts(4 tests):relay.log.1created,relay.logreset under the cap, norelay.log.2; the newest line lands in the currentrelay.log(tail-ability).relay.logis preserved (append, not truncate).maxBytes(current + one archive).installRelayLogRotationroutesprocess.stderrthrough the rotator and cleanly restores it.Before:
relay.logsize = total lifetime output (unbounded). After: ≤ ~2× cap (20 MB with defaults), current log always atrelay.log.Screenshots
No visual change.
Testing
pnpm typecheckoxlinton changed files cleanrotating-log-writer.test.ts(4),ssh-relay-deploy*.test.ts,ssh-relay-cross-version-isolation.test.tspass (43 total)AI Review Report
Reviewed cross-platform launch: the POSIX launch adds
--log-filealongside the existing> relay.log 2>&1; the Windows launch (windowsRelayLaunchCommand, WMI/Invoke-CimMethod) adds--log-filealongside its1>relay.log 2>relay.err.logsplit redirects — the rotator points atrelay.log(the tail target) on both. Verified detached-mode stdout is not used for protocol (dispatcher setsstdoutAlive=false; theRELAY_SENTINELstdout write is--connect-only), so wrappingprocess.stdout.writeis safe. No path assumptions beyond the caller-supplied absolute log path.node:fssync calls are portable to Linux/macOS/Windows remote hosts.Security Audit
No new input handling, command execution, auth, secrets, or IPC surface. The log path comes from the relay's own launch args (
--log-file), not remote input. Rotation only renames/reopens a file the relay already owns; guards ensure a filesystem error degrades logging rather than crashing or corrupting.Notes
The pre-existing shell redirect is intentionally retained to capture pre-JS boot/crash output; in steady state all logging flows through the in-process rotator, so there is effectively a single active writer to
relay.log.Made with Orca 🐋