fix(shared): preserve files outside log rotation naming #27503
main fromrefs/pull/27503/head·merged by maria-rcks View on GitHubProblem#
Starting either rotating log sink can delete neighboring files that are not its rotated backups. Startup converts the filename suffix with Number(), so names such as debug.log.04, debug.log.4.0, debug.log.4e0, debug.log.0x4, and debug.log.+4 are all treated as backup 4 and removed when maxFiles is 3. Rotation itself never produces those spellings.
Change#
Require the parsed index to round-trip to the exact suffix before pruning it. Apply the same check to the synchronous and asynchronous sinks. Normal overflow backups are still removed; rotation limits and writes are unchanged.
Scope and approval#
This is a very small, focused fix for an obvious file-ownership bug under CONTRIBUTING.md's exception: cleanup must not delete files outside the naming scheme it creates. Both paths share the same underlying defect. There is no known user incident; the failure was established with real temporary filesystem fixtures. No product defaults, contracts, or UI behavior are changed.
Verification#
Verified on Linux with Node 26.12.1:
- Two regression cases initialize the actual synchronous and asynchronous sinks with real temporary files. They assert that normal overflow backups
.4and.50are removed,.1and.3remain, and noncanonical names retain their contents. A normal append still succeeds. - With the final regression tests and base production code: 2 failed, 3 existing tests passed. With the fix: all 5 tests in
logging.test.tspass. - From
packages/shared:node node_modules/vite-plus/bin/vp test run src/logging.test.tsand../../node_modules/.bin/tsc --noEmitpass. - Targeted format/lint and
git diff --checkpass. vp run check:changed upstream/main: formatting, lint, both Knip passes, and both changed-test files pass (6 tests total). The affected-package typecheck could not start its desktop process:failed to initialize seccomp_unotify supervisor: Operation not permitted. The package-local typecheck above succeeds. The aggregate command therefore exits 1; full downstream typechecking remains unverified locally.
No live log directory or installed application was touched. macOS and Windows were not run. No UI code changed.
Standalone runtime transcript#
On Linux / Node v26.12.1, imported both actual production sink implementations from base 32ecd71726fee16f335484c1f95cbce126d461f6 and published head 03d7368a2de4678c554dd4698797e1707a06d002; the latter's production blob matches 69888b53c2a1ad04b23a879ed79bfe09bfb22b38. Each isolated temporary directory started with debug.log containing existing\n and suffixes 1, 3, 4, 50, 04, 4.0, 4e0, 0x4, +4, notes, each containing its own marker. Started the sink with maxFiles: 3, maxBytes: 1000, then appended appended\n. The async path used the actual Node filesystem services, not mocks.
Literal stdout for the four post-startup observations:
{"stage":"before","mode":"sync","phase":"after-startup-and-append","names":["debug.log","debug.log.1","debug.log.3","debug.log.notes"],"backupContentsUnchanged":true,"log":"existing\nappended\n"}
{"stage":"before","mode":"async","phase":"after-startup-and-append","names":["debug.log","debug.log.1","debug.log.3","debug.log.notes"],"backupContentsUnchanged":true,"log":"existing\nappended\n"}
{"stage":"after","mode":"sync","phase":"after-startup-and-append","names":["debug.log","debug.log.+4","debug.log.04","debug.log.0x4","debug.log.1","debug.log.3","debug.log.4.0","debug.log.4e0","debug.log.notes"],"backupContentsUnchanged":true,"log":"existing\nappended\n"}
{"stage":"after","mode":"async","phase":"after-startup-and-append","names":["debug.log","debug.log.+4","debug.log.04","debug.log.0x4","debug.log.1","debug.log.3","debug.log.4.0","debug.log.4e0","debug.log.notes"],"backupContentsUnchanged":true,"log":"existing\nappended\n"}
Thus both fixed sinks remove only canonical overflow .4/.50, retain all neighboring noncanonical files unchanged, and append to the existing log. Only generated temporary directories were used and removed afterward; no live logs, installed app, or UI session was involved. Screenshots would add no evidence for this filesystem-only behavior.
AI assistance: OpenAI model (exact model identifier/version is not exposed by this runtime). Harness: dot / OpenAI Codex.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
Verified unchanged head
645a5bf9dd1d5d25221f7d28dde64b6df57bcc1aon this Linux Boat VM. Reproduced the bug first ongithub/mainat8f1e61cc7f, in a separate installed worktree. Ran one background dev server at a time with isolated state.Used repository Playwright with
/usr/bin/google-chrometo pair the web client, add a project pointing at a real git repository, and create a thread. Real Codexgpt-6.1-solturns readREADME.mdthrough a tool, both initially and after restarting the server, on main and the PR. No mocks, replay provider, or seeded application data.- Both actual server startup sinks: main deleted
.04,.4.0,.4e0,.0x4, and.+4. The PR preserved every file and its contents. Canonical overflow backups were still removed. This exercised the asynchronous trace sink and synchronous event-loop sink through normal server initialization. - Actual thread provider log after restart and a real follow-up turn: main deleted
.011,.11.0,.11e0,.0xb, and.+11. The PR preserved them byte-for-byte, preserved in-range.1and.10, and removed canonical overflow.11and.50. - Nearby behavior: the resumed turn completed, the provider log grew from 29 to 60 records while retaining its exact original prefix, and every timestamped event payload parsed as JSON. With
T3CODE_TRACE_MAX_BYTES=32768andT3CODE_TRACE_MAX_FILES=3, normal app activity rotated real traces through.1/.2/.3, kept.4absent, and left the noncanonical neighbors unchanged. - Blacksmith: all 5 logging tests passed.
vp run check:changed 54c5f25249961a1aa0b61932329092eadbd9d6fcpassed formatting, lint, both knip passes, 33 package typechecks, and 6 tests.
Runtime transcript with before/after filesystem observations


Inspected the captures. The uploaded video plays through and seeks successfully in the T3 browser.
Not verified#
macOS and Windows filesystem behavior, Electron and native iOS/Android shells, and other providers were not exercised on this Linux VM. Startup pruning was exercised for the synchronous stall sink; a stall-triggered write in the running server was not established. Its ordinary append and rotation behavior is covered by the passing existing logging tests.
- Both actual server startup sinks: main deleted
maria-rcks merged this7c511b3
maria-rcks closed this
Sign in to join this conversation.
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
29eb28bc-2a1b-4cfe-bba9-82cb5e392f6aReviewing files that changed from the base of the PR and between 03d7368a2de4678c554dd4698797e1707a06d002 and 645a5bf9dd1d5d25221f7d28dde64b6df57bcc1a.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review.
d7215576-3d64-493c-bf80-127b4a1c5e69Reviewing files that changed from the base of the PR and between 32ecd71726fee16f335484c1f95cbce126d461f6 and 03d7368a2de4678c554dd4698797e1707a06d002.
packages/shared/src/logging.test.tspackages/shared/src/logging.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Walkthrough
Both synchronous and asynchronous rotating-file sinks now prune backups only when the suffix is a canonical integer string above
maxFiles. Tests cover pruning behavior in both modes.Changes: Backup pruning
packages/shared/src/logging.ts,packages/shared/src/logging.test.tsEstimated code review effort: 2 (Simple) | ~10 minutes
Possibly related PRs
relay-client.ndjsonwith a rotating file sink, which uses the updated startup-pruning behavior.Suggested reviewers:
t3dotggMerge Risk:
Minimal · previous review
03d73The pruning change has no identified merge-blocking issue; complete the usual downstream checks before merging.
Pre-merge checks:
4
debug.log.04,debug.log.4.0,debug.log.4e0,debug.log.0x4,debug.log.+4) that `Number()…Full details: Description check
Explanation
The description follows the repository template closely. It states the problem with concrete examples (
debug.log.04,debug.log.4.0,debug.log.4e0,debug.log.0x4,debug.log.+4) thatNumber()parses as backup 4, and it explains that rotation never produces those spellings. The Change section explains the round-trip check and applies it to both sinks, and notes that normal overflow backups and rotation limits are unchanged. The Scope and approval section invokes the very-small-fix exception, explains why it qualifies, and states that no defaults, contracts, or UI behavior change. The Verification section gives specific commands, test counts before and after the fix, the platform tested, and what was not verified (the affected-package typecheck, macOS, and Windows). It also includes a standalone runtime transcript and AI-assistance attribution, as the template requests. The description is thorough. It has no visible screenshot section, but the change has no UI, so that omission is acceptable. The title is not in the description block, so the template's conventional-commit title check is not applicable here. The objectives also reference the commit titlefix(shared): preserve files outside log rotation naming, which matches the template's conventional-commit guidance.Finishing Touches
🧪 Generate unit tests (beta)