Skip to content

fix(test): drain session-event-log writes before rmSync cleanup in save-script transport tests - #1999

Merged
thymikee merged 1 commit into
mainfrom
fix/1998-save-script-transport-cleanup-race
Aug 24, 2026
Merged

fix(test): drain session-event-log writes before rmSync cleanup in save-script transport tests#1999
thymikee merged 1 commit into
mainfrom
fix/1998-save-script-transport-cleanup-race

Conversation

@thymikee

Copy link
Copy Markdown
Member

Summary

Fixes the pre-existing flake documented in #1996 ("Known pre-existing flake") and analyzed in #1998: request-save-script-transports.test.ts hit ENOTEMPTY in its own afterEach under coverage-shard load.

Every request the tests send queues a fire-and-forget session-event-log append (queueEventLogWrite: unawaited mkdir -p → rotate → appendFile into sessions/<session>/events.ndjson). The daemon response resolves before the write lands, so under load a pending append could re-create the session dir between rmSync's unlink sweep and its rmdir — cleanup then fails with ENOTEMPTY.

The fix awaits the existing quiesce hook, flushSessionEventLogWrites(), at the top of the afterEach before removing the temp roots. One line plus the import.

Closes #1998

Validation

  • pnpm vitest run src/daemon/__tests__/request-save-script-transports.test.ts — 8/8 green, six consecutive runs.
  • pnpm format:check, pnpm lint, pnpm typecheck clean.

The race itself is timing-dependent (one occurrence on a loaded shard), so the runs above show no regression rather than proving the flake gone; the flush removes the ordering hazard by construction. #1998 notes the wider sweep (other daemon tests that drive createRequestHandler then rmSync a temp root) as follow-up.

The save-script transport tests' afterEach removed the per-test temp
root while a fire-and-forget session-event-log append (queued by every
request the tests send) could still be in flight. Under coverage-shard
load the append re-created the session dir between rmSync's unlink sweep
and its rmdir, failing cleanup with ENOTEMPTY.

Await flushSessionEventLogWrites() before removing the roots.

Closes #1998
@github-actions

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 2.39 MB 2.39 MB 0 B
JS gzip 801.1 kB 801.1 kB 0 B
npm tarball 925.0 kB 925.0 kB 0 B
npm unpacked 3.21 MB 3.21 MB 0 B

npm unpacked components

Component Base Current Diff
JS / dist source 2.54 MB 2.54 MB 0 B
Apple runner source/project 570.6 kB 570.6 kB 0 B
macOS helper source 54.5 kB 54.5 kB 0 B
Android helper artifacts 0 B 0 B 0 B
Other package files 44.5 kB 44.5 kB 0 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 28.7 ms 29.1 ms +0.4 ms
CLI --help 79.9 ms 80.8 ms +0.9 ms

Top changed chunks: no changes in the largest emitted chunks.

Top changed packed files

No changed packed files.

@thymikee

Copy link
Copy Markdown
Member Author

Reviewed exact head dcc887362. Clean. The test cleanup now awaits the existing session-event-log quiesce hook before removing its temp roots, which removes the ENOTEMPTY ordering hazard at the owning async boundary without changing production behavior. The focused regression and all 27 exact-head checks pass.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Aug 24, 2026
@thymikee
thymikee merged commit 6c4b740 into main Aug 24, 2026
27 checks passed
@thymikee
thymikee deleted the fix/1998-save-script-transport-cleanup-race branch August 24, 2026 14:06
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-08-24 14:07 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test flake: request-save-script-transports afterEach rmSync races the fire-and-forget session-event-log write (ENOTEMPTY)

1 participant