Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): preserve files outside log rotation naming #27503

Mergedmacodev00(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/27503/headmerged by maria-rcks View on GitHub

Problem

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 .4 and .50 are removed, .1 and .3 remain, 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.ts pass.
  • From packages/shared: node node_modules/vite-plus/bin/vp test run src/logging.test.ts and ../../node_modules/.bin/tsc --noEmit pass.
  • Targeted format/lint and git diff --check pass.
  • 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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      Run configuration
      Commits

      Reviewing 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_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • Trigger review

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 32ecd71726fee16f335484c1f95cbce126d461f6 and 03d7368a2de4678c554dd4698797e1707a06d002.

      Files selected for processing: 2
      • packages/shared/src/logging.test.ts
      • packages/shared/src/logging.ts

      Included 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

      Layer / File(s)Summary
      Canonical suffix pruning and tests
      packages/shared/src/logging.ts, packages/shared/src/logging.test.ts
      Both sinks check that a backup suffix round-trips through integer conversion and stringification before pruning it. Tests verify that canonical suffixes are removed and noncanonical suffixes remain.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Possibly related PRs

      • pingdotgg/t3code#24485: Creates relay-client.ndjson with a rotating file sink, which uses the updated startup-pruning behavior.

      Suggested reviewers: t3dotgg

      Merge Risk: Minimal · previous review 03d73

      The pruning change has no identified merge-blocking issue; complete the usual downstream checks before merging.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main fix: preventing log rotation from deleting files outside its naming scheme. It uses a valid conventional commit format.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe 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) 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) that Number() 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 title fix(shared): preserve files outside log rotation naming, which matches the template's conventional-commit guidance.

      Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
    3. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      Verified unchanged head 645a5bf9dd1d5d25221f7d28dde64b6df57bcc1a on this Linux Boat VM. Reproduced the bug first on github/main at 8f1e61cc7f, in a separate installed worktree. Ran one background dev server at a time with isolated state.

      Used repository Playwright with /usr/bin/google-chrome to pair the web client, add a project pointing at a real git repository, and create a thread. Real Codex gpt-6.1-sol turns read README.md through 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 .1 and .10, and removed canonical overflow .11 and .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=32768 and T3CODE_TRACE_MAX_FILES=3, normal app activity rotated real traces through .1/.2/.3, kept .4 absent, and left the noncanonical neighbors unchanged.
      • Blacksmith: all 5 logging tests passed. vp run check:changed 54c5f25249961a1aa0b61932329092eadbd9d6fc passed formatting, lint, both knip passes, 33 package typechecks, and 6 tests.

      Runtime transcript with before/after filesystem observations

      Real Codex follow-up after restarting the PR dev server

      Completed resumed turn with the README tool call visible

      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.

    4. maria-rcks merged this7c511b3

    5. maria-rcks closed this

Sign in to join this conversation.