Skip to content

[PR] fix(diagnostics): preserve colliding incident dumps - #7400

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-20_preserve-colliding-error-dumps
Nov 20, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-20_preserve-colliding-error-dumps

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7399

Problem

Main-path and preflight-summary incident files use only Date.now(), the sanitized session ID and status as their name. An ordinary writeFileSync then overwrites the earlier incident when those values collide. This loses evidence even though err-* and summary-err-* files are explicitly protected from retention GC.

Changes

Both incident writers share exclusive file creation. The historical filename is retained when available; only EEXIST selects a fresh UUID-suffixed path, with the descriptive session portion bounded so the suffix fits. The fallback is also exclusive: an already-existing file is never replaced.

Other I/O failures keep the existing warning/null behavior. The plaintext warning, UTF-8 byte caps, payload formatting, GC prefixes and default-off option are unchanged. No config field, environment variable or dependency is added. This is a file-ownership fix, not a claim of fsync-backed or whole-file atomic persistence.

Validation

On unchanged production, the new suite has 7 failing behavior regressions and 1 passing error control. The fix passes 30/30 targeted tests:

node --import ./tests/preload-test-env.mjs \
  --import ./tests/preload-storage-baseline.mjs --import tsx \
  --test --test-concurrency=2 \
  tests/error-dump-collision.test.ts tests/error-dump.test.ts \
  tests/state-gc.test.ts
npm run typecheck
npm run build
npm run check:unused-exports
npm run check:test-import-graph
git diff --check

The regressions use actual files and public writers: repeated main bodies and summary exchanges, pre-existing incidents, sanitized session-name collisions, a 32-write same-timestamp burst, and a 200-character session ID. A controlled non-collision write error proves it returns without repeated attempts. Existing byte-cap/banner/GC tests remain unchanged.

Tested base: 1e357bf2d6632bfbd2a74ffb70ecee1af1ec7cc3; Node.js 24.22.3, Linux x86_64. Full regression remains the remote CI lanes on the pushed PR head.

Duplicate boundary

All-author/all-state searches and the latest 100 actual open PRs found no equivalent repair. #1994 distinguished main and summary prefixes, #4299 fixed the final byte cap, and #4483 added the plaintext warning. This change preserves those behaviors while preventing same-kind incidents from replacing one another.

Create incident files exclusively so repeated same-millisecond failures,
sanitized session-name collisions, and existing files cannot lose earlier
evidence. Keep the historical filename when available; on EEXIST use a
bounded session hint and a UUID suffix, again with exclusive creation.

Use the same writer for main and preflight-summary failures. Other I/O
errors retain the existing fail-soft warning/null behavior. The plaintext
banner, byte limits and protected GC prefixes are unchanged.

Seven regression failures on the unchanged base become passing, alongside
the write-error control and existing dump/GC coverage (30 tests total).
Typecheck, build, unused-export and import-graph gates pass.
@ranxianglei ranxianglei changed the title fix(diagnostics): preserve colliding incident dumps [PR] fix(diagnostics): preserve colliding incident dumps Nov 20, 2026
@ranxianglei
ranxianglei merged commit 560803a into ranxianglei:master Nov 20, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Repeated failures overwrite earlier incident dump files

2 participants