Skip to content

test: poll instead of fixed sleeps for debounced persist writes (Windows CI flake) - #559

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-05_ci-flake-poll-waits
Sep 5, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-05_ci-flake-poll-waits

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Fixes the recurring windows-22 CI flake seen on recent PRs (#540/#535/#539/#337…), where two tests intermittently fail:

  • tests/proxy-persist.test.ts:109 — scheduleSave debounces and eventually writes → Cannot read properties of null (reading 'stats')
  • tests/e2e-export-handoff.test.ts:174 — expected 1 persisted session, got 0

Both failures share the same upstream signature:

[persist] write failed for <id>: ENOENT: no such file or directory,
rename '...Temp\bili-persist-XXX\_unknown\.tmp-...' -> '...json';
SPILLOVER ALSO FAILED — data at risk

Root cause (two layers, this PR is layer 2)

  1. Data layer — acp-kernel PR release v0.1.46 #201 (separate repo, awaiting merge + release v0.0.53): GitHub Windows runners periodically sweep %TEMP%, deleting freshly-created files/dirs between writeFile(tmp) and rename. The kernel's old retry set (EPERM/EBUSY/EACCES) rethrew ENOENT immediately. release v0.1.46 #201 retries the whole write cycle (mkdir + fresh tmp + write + rename) on transient ENOENT/ENOTDIR and retries the spill too.
  2. Test layer — this PR: once the kernel retries, the debounced write can legitimately land well past its 5ms debounce (backoff ladder ~1.5s). A fixed settle(30ms) / setTimeout(100) assert would still flake even though the data is safe. Polling makes the tests observe the eventual write instead of racing it.

Changes

  • tests/proxy-persist.test.ts: new waitFor() poll helper; the debounce test now polls loadSync() with a 5s deadline (covers the kernel retry ladder with headroom).
  • tests/e2e-export-handoff.test.ts: poll listSessions() until the persisted session shows the compression block (blocks >= 1), deadline 10s. Note: polling on length alone raced the first pre-compression snapshot and failed blocks >= 1 — the poll condition must match the assertion.

No production code touched.

Pre-flight

  • npm run typecheck ✓
  • npm test 1046/1048 (2 known env-dependent fails in plugin-agent.test.ts, unrelated)
  • npm run build ✓

Follow-up

Once acp-kernel v0.0.53 is live on npm, a separate change will bump the acp-kernel pin here so the retry fix ships in the next bili release.

CI Windows runners intermittently sweep %TEMP% mid-test: the debounced
persist write hits a transient ENOENT on rename (tmp file or dir gone).
acp-kernel (PR 201) now retries the whole write cycle on transient
ENOENT/ENOTDIR, which can land the write well past the 5ms debounce —
so tests must poll with a deadline instead of asserting right after a
fixed settle()/sleep.

- proxy-persist.test.ts: waitFor() helper; debounce test polls loadSync
  (deadline 5s, covers the kernel retry ladder ~1.5s with headroom).
- e2e-export-handoff.test.ts: poll listSessions until the session shows
  the compression block (deadline 10s). Polling on length alone raced
  the first pre-compression snapshot and failed 'blocks >= 1'.

Fixes the recurring windows-22 flakes:
- proxy-persist.test.ts:109 'Cannot read properties of null'
- e2e-export-handoff.test.ts:174 'expected 1 persisted session, got 0'
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-05_ci-flake-poll-waits (bc4be04)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-559

Each push to this PR publishes a new version under the pr-559 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr559.tgz
npm install -g package

This comment is automatically updated on each push.

@ranxianglei
ranxianglei merged commit ae601a9 into master Sep 5, 2026
6 checks passed
ranxianglei added a commit that referenced this pull request Sep 5, 2026
- CONFIGURATION.md: keep both the EPERM alert knobs and master's
  BILI_TUNNEL_ALLOWED_HOSTS row.
- tests/proxy-persist.test.ts: keep master's #499 pfa migration test and
  the PR's wire test; the wire test now polls (waitFor, 5s) for the
  kernel failure line because acp-kernel 0.0.53 retries the whole write
  cycle on transient ENOTDIR (~1.5s) before logging it — a fixed
  settle(50) would fail.

Verified against pinned acp-kernel 0.0.53: recordFailure emits the same
'[persist] write failed for <id> (total <N>x): <err>' shape the detector
regex parses; EPERM/EBUSY/EACCES lock codes remain non-transient enough
to count toward the alert.

Pre-flight: typecheck ✓, tests 1058/1060 (2 known env fails in
plugin-agent.test.ts), build ✓.
ranxianglei added a commit that referenced this pull request Sep 5, 2026
- CONFIGURATION.md: keep both the EPERM alert knobs and master's
  BILI_TUNNEL_ALLOWED_HOSTS row.
- tests/proxy-persist.test.ts: keep master's #499 pfa migration test and
  the PR's wire test; the wire test now polls (waitFor, 5s) for the
  kernel failure line because acp-kernel 0.0.53 retries the whole write
  cycle on transient ENOTDIR (~1.5s) before logging it — a fixed
  settle(50) would fail.

Verified against pinned acp-kernel 0.0.53: recordFailure emits the same
'[persist] write failed for <id> (total <N>x): <err>' shape the detector
regex parses; EPERM/EBUSY/EACCES lock codes remain non-transient enough
to count toward the alert.

Pre-flight: typecheck ✓, tests 1058/1060 (2 known env fails in
plugin-agent.test.ts), build ✓.
antclt pushed a commit to antclt/billion-context that referenced this pull request Sep 5, 2026
Consumes acp-kernel v0.0.53 (PR ranxianglei#201): the whole write cycle (mkdir +
fresh tmp + write + rename) is retried on transient ENOENT/ENOTDIR —
Windows %TEMP% sweeps / AV no longer drop session persists — and the
spill write retries too. Test-side polling shipped in PR ranxianglei#559.
@ranxianglei
ranxianglei deleted the 2026-09-05_ci-flake-poll-waits branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant