Repository navigation
fix(test): release self-held handles before temp-tree teardown — Windows EBUSY/EPERM (#2799) - #2808
ranxianglei wants to merge 2 commits into
Conversation
…ows EBUSY/EPERM (#2799) Two distinct self-held-handle mechanisms made Windows CI teardown reds non-deterministic (R1: unlink index.db EBUSY in storage-engine-proofs; R2: rmrf golden-chat-* EPERM). Backoff cannot absorb a lock held by the deleting process itself, so release such handles up front: - src/logger.ts: _releaseLogFileForTest() seam — synchronously close the tee-log fd and clear its path (closeLogger() keeps the path → next log() reopens into the deleted tree; configureLogger("off") leaks the fd). - tests/tmp-rm.ts: rmrf() releases the handle when the current log path lies under the deletion target — systemic guard for every importer. - tests/golden-storage-drive.ts: the producer fix — driveWire pointed XDG_STATE_HOME at its disposable tmp BEFORE startServer, landing the default log file INSIDE the tree finally deletes; set logFile:"off" and close the drive store explicitly in finally instead of relying on flushAllSessions()'s shadow-close side effect. - tests/mode-upgrade-proof.test.ts: switch its local bare-rmSync rmrf to the shared retried helper. - tests/tmp-rm.test.ts: deterministic regression pin for the guard (release + path-clear + no resurrection of the deleted tree).
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3108-pr.2808.ac64325This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2808.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 已拉取分支核对代码并确认 CI 状态。这是本 agent 自己开的 PR(#2808,Closes #2799),按 [PR] 流程只核对、不重做。 分支: CI(截至本条):全部 guard 绿(version-guard / unused-exports / kernel-guard / docs-sync / config-surface-guard / pi-subagents-guard / lane-guard / lock-sync / docs-coverage / build-artifact);4 个 test 矩阵(windows-latest 22/24、ubuntu-latest 22/24)仍在跑。测试落地后再补一条最终确认。 代码核对(逐文件,diff 与描述一致):
结构化八问:
判定:代码审查干净,与描述一致,修法打在根因上;等 4 个 test 矩阵转绿即可合并,无需改动。测试落地我再补最终确认。 |
… warn still fires (#2808) The shared rmrf() guard added in #2808 releases the self-held tee-log handle AND clears the log path before deleting (#2799). The reopen-failure rotation test removes its own live-log tree mid-test (via rmrf) to force an ENOTDIR reopen; after the guard clears logPath, the post-clobber log() hit the !logPath early-return instead of attempting the reopen, so the degradation [warn] never fired (0 !== 1) and the test went red on every platform. Re-point the logger at the now-invalid path after the clobber so the reopen attempt still happens and degrades with exactly one [warn]. No production code or behavior changes; the rmrf guard and its no-resurrection pin are unchanged.
PR #2808 的 CI 红了,我定位到一个真实回归并已修复,往 PR 分支补了一个 additive commit。 先分清两条红腿——性质完全不同: ① 真实回归(本 PR 引入)— 已修
② 环境抖动(与本 PR 无关) 回归审查(逐条既有行为):本次改动只落在 八问结论:
收工判定:真实回归已修并推到 PR 分支(commit |
Closes #2799
Root cause
The two red legs were facets of one failure domain — test teardown deleting a tree its own process still holds handles into — plus one instance that was already fixed upstream:
R2 (
golden-chat-*EPERM) — new root cause found while working this issue.driveWire(tests/golden-storage-drive.ts) pointsXDG_STATE_HOMEat its disposable tmp beforestartServer;startServerunconditionally callsconfigureLogger(opts.logFile ?? defaultLogFile()), anddefaultLogFile()resolvesXDG_STATE_HOMEat call time (src/paths.ts), so the tee logger's process-lifetime WriteStream lands at<tmp>/billion-context/bili.log— inside the very treefinally'srmrf(tmp)deletes. On Windows a process cannot unlink a file it holds open, so the delete fails EPERM regardless of the retry budget (backoff only helps against external transient locks such as AV/indexer — that is what the existing ~3.2s ladder in tests/tmp-rm.ts defends against). Empirically confirmed on Linux: after any driveWire run,/proc/self/fdshows our own fd pointing into<deleted tmp>/billion-context/bili.log.R1 (
bili-engproof-corrupt-*index.db EBUSY) — already fixed upstream before this PR. Every sqlite handle in that suite is now closed before cleanup: 54f21d3 (PR #2781, open-phase + read-only stores) and 9365fb2 (PR #2788, failed-open handle close). The CI red predates both merges; the suite passes locally 10/10 on current master, and the Windows rename guard (tests/storage-engine-proofs.test.ts:380-382) pins "no live handle inside the dir". Recorded as the third checklist item in #2799; no code change needed here.Changes (all test-hygiene; no product behavior)
src/logger.ts: new_releaseLogFileForTest()seam — synchronously closes the held log fd and clears its path. Neither existing exit works for this:closeLogger()keeps the path set (the nextlog()reopens into the deleted tree) andconfigureLogger('off')drops the stream without ever closing it (fd lingers until GC). The close is synchronous because an async end()/destroy() cannot complete while a teardown retry sleeps via Atomics.wait (blocked main thread ⇒ libuv never services the close within the retry window).tests/tmp-rm.ts:rmrf()releases the self-held log handle when the current log path lies under the deletion target — a systemic guard for every importer. A family scan found ~20 suites that point XDG_STATE_HOME at their scratch tree around in-process servers; all of them using the shared helper are covered automatically.tests/golden-storage-drive.ts: producer fix —logFile: 'off'so the harness never points the persistent logger into a disposable tree; plus explicitstore.cancelAll()/closeQuietly()infinallyinstead of relying onflushAllSessions()' shadow-close side effect (an early exit mid-drive previously left index.db open, pinning the tree on Windows AND masking the real failure with a cleanup error).tests/mode-upgrade-proof.test.ts: switched its local bare-rmSync rmrf to the shared retried helper.tests/tmp-rm.test.ts: deterministic regression pin (guard fires, path cleared, deleted tree not resurrected by later logging).Behavior changes (test-observable only)
startServerreconfigures (stderr continues). Old behavior: the logger kept holding the deleted tree's path (on Windows the deletion then failed). No product code path changes — the seam is test-only and only invoked fromrmrf().bili.loginside their tmp trees (it was deleted along with the tree anyway; nothing consumed it).Config surface
None — no new env vars, config fields, or CLI flags.
Verification
npm run typecheckclean.Issue checklist status (#2799)
Watch item (not blocking): a few suites set XDG_STATE_HOME + start in-process servers but their exact call ordering wasn't verified line-by-line (dump-mask, issue2421-dump-body-buffer, acp-cache-diff, auto-restart, loop-strict-echo* — the latter likely safe since startServer precedes the env set there). If any goes red on Windows with the same signature, triage it against this PR's guard; if one uses a non-shared local rmrf, switching it over is the mechanical follow-up.