fix(util): bound opencode.log by trimming its head in place - #47676
Conversation
|
Addressed in 2573ba9. 1. Cross-process trims — valid, and not theoretical: the same 2. Appender vs. truncate — accepted as a known trade-off and documented in a comment on |
|
1. Interruption-safe acquisition — done. The mkdir now runs inside 2. Stale-lock removal race — declining. Preconditions: a process dies inside a sub-second trim (leaving a stale lock), then ≥3 processes tick within the same few milliseconds ≥5 minutes later, with the file over 50 MB at that instant. The consequence is the same bounded tail loss already documented on |
opencode.logis appended forever with no rotation since #31310. Long-lived installs end up with a 500 MB–1 GB file, which also defeats the desktop debug export (#47672).Per discussion with @thdxr: keep one file, no rotation, just trim it.
LOG_MAX_BYTES(50 MB) the head is dropped soLOG_KEEP_BYTES(25 MB) remain.\n, found by scanning raw bytes in 64 KiB chunks from the cut offset (no decoding), so the kept tail always starts on a complete line.fileLoggeras a scoped fiber: immediately on boot, then everyLOG_TRIM_INTERVAL(1 hour). Astatper hour is the steady-state cost.packages/util/src/observability/logging.ts.Compaction is in place on an
r+handle rather than temp-file + rename. Every opencode process on the machine (TUI, CLI, desktop's server) appends to the same file withO_APPEND; they keep writing to the compacted file, whereas a rename would strand them on the unlinked inode and lose their output.Against a real 60 MB tail of a 1 GB
opencode.log: 62,914,560 → 26,214,178 bytes in 99 ms, first kept byte istimestamp=, tail byte-identical.