Skip to content

[PR] test: close persist-guard foreign-write race by settling on the landed-write stamp - #3657

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-18_persist-guard-flake-stamp-settle
Oct 18, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-18_persist-guard-flake-stamp-settle

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3652

What this is

#3652 reported tests/persist-guard-ownership.test.ts intermittently failing on win22 shard 2 ("DEBOUNCED saves stay stamped", expected 5, got 4). The primary symptom of that report was already fixed on master by 6748b235a ("test: wait for debounced saves to land instead of fixed sleeps", landed via #3626 after the same flake showed up there) — it replaced the three blind sleep(150) calls with poll-for-landed.

This PR closes the residual race that 6748b235a left open in the sibling test "a foreign write between DEBOUNCED saves no longer clobbers the envelope."

Root cause of the residual flake

The sibling test waits only for the envelope to be present on disk before performing its foreign write. But the ownership stamp (ownCommit[id].written) is applied asynchronously — in a .then() after the awaited writeNow resolves, i.e. after the file has already landed. A foreign write that slips into that gap is adopted as ours by the stamp (the documented #3406 residual gap at src/persist.ts → ownershipFastPath), so the second save's fast path passes and the guard below never trips → the test times out waiting for the full-read counter to move.

Unlike the DEBOUNCED-stamp loop (which has a 25ms debounce buffer that absorbs the gap more as load grows — structurally safer under starvation), the sibling test issues the foreign write immediately after detecting the landing, with no buffer, so it is exposed.

Evidence (CPU-load stress, simulating a starved CI runner)

flow master semantics with this fix
sibling first-save wait 58/80 pass (27% fail) 80/80 pass
DEBOUNCED-stamp loop 80/80 pass 80/80 pass

Real test file run under load: 10/10 green. Fast runs: 8/8 across multiple invocations. tsc --noEmit clean.

Fix

  • src/persist.ts: add a read-only test seam __ownWriteStampedForTests(id) (mirrors the existing __staleGuardFullReadsForTests). No production behavior change.
  • tests/persist-guard-ownership.test.ts: gate the sibling test's first-save settle on landedRequests >= 3 && __ownWriteStampedForTests(...) instead of file-presence alone. Builds directly on master's existing waitForLanded / landedRequests helpers (no duplication).

Behavior / scope notes

  • No production behavior change. The only src/ change is a test-only getter (__…ForTests); no code path reads it outside tests. No config surface, wire/message shape, persistence format/version, kernel/, update.ts, or security change.
  • Pure test-determinism fix; every assertion is unchanged.

…3652)

The sibling test 'foreign write between DEBOUNCED saves' still races under
loaded CI runners even after #3626's poll-for-landed fix (6748b23): it waits
only for the envelope to be present on disk, but the ownership stamp is applied
asynchronously in .then() AFTER the write resolves (after the file already
landed). A foreign write slipping into that gap is adopted as ours by the stamp
(#3406 residual gap) and the guard below never trips. Reproduced ~1-in-4 under
CPU load. Waiting for __ownWriteStampedForTests closes it deterministically.
@ranxianglei ranxianglei changed the title test: close persist-guard foreign-write race by settling on the landed-write stamp [PR] test: close persist-guard foreign-write race by settling on the landed-write stamp Oct 18, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

收到,这是 agent 已完成的 PR(ework-agent-pr 标记),不重做,进入审核:拉取分支核对代码、独立审 diff 与 CI。

查重: 不重复 — open+closed 检索 persist-guard-ownership / #3406 / foreign-write stamp / debounce flake,无同症状+同机制条目;本 PR 针对 #3652 的残留竞态(sibling test),与 master 上 6748b235a 已修的主症状(DEBOUNCED-stamp loop)是同一 issue 下的不同测试路径,归 #3652 一个 scope,合理。

正在审 diff 与 CI,结论按八问体例回复。

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-18_persist-guard-flake-stamp-settle (18e2bcf)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4313-pr.3657.6917ae9

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei merged commit 21a860f into master Oct 18, 2026
10 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.565-master.21a860f (rolling master tag).

npm install -g billion-context@0.0.565-master.21a860f  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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.

Windows CI flake: persist-guard-ownership "#3406 DEBOUNCED saves stay stamped" intermittently fails (win22 shard 2)

1 participant