Skip to content

test(cache): wait on the observed-store flush's completion, not a 2s file poll (#955) - #981

Merged
bpalermo merged 2 commits into
mainfrom
fix/observed-upstreams-store-flake
Sep 27, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/observed-upstreams-store-flake

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Closes #955

Root cause

The issue suspected the 1s production debounce, but newStoreTestCache already sets observedFlushDebounce = 10ms. The real cost sits behind the debounce: writeObservedUpstreams → file.WriteFileAtomic fsyncs the temp file and then the parent directory. On a loaded workstation disk (the output base is on /mnt/md0) those two fsyncs alone can take longer than the tests' 2s Eventually budget. So the tests went red 6/6 locally and green in CI.

Fix (test-only)

waitObservedFlush(t, c) waits on the store's own completion order instead of polling the file against a deadline:

  • flushObservedUpstreams holds observedWriteMu across both takeObservedSnapshot and the write. takeObservedSnapshot is what disarms the timer and clears observedDirty.
  • Once observedFlushTimer == nil && !observedDirty (read under depMu), the pending change has been taken by a flush that holds, or already released, observedWriteMu. Acquiring observedWriteMu then returns only after that write has landed.
  • The only bounded wait (flushFireWait = 30s) covers scheduling a 10ms timer, not I/O. After it, the tests read the file with strict assertions.

No production change and no new seam: the helper reads existing unexported fields from the in-package test. The tests still go through the real debounce timer; they don't call FlushObservedUpstreams() to short-circuit it. eventuallyWait is removed.

Evidence

run old tests (origin/main) new tests
--runs_per_test=20, idle workstation 0/20 failed 0/20 failed
--runs_per_test=200 / race ×100, idle 0/200, 0/100 —
--config=race --runs_per_test=20 — 0/20 failed
temporary, uncommitted time.Sleep(3s) before WriteFileAtomic (a slow fsync), ×5 5/5 failed, at :150, :202, :227 (the issue's lines) plus :100, :189 0/5 failed

On an idle machine the flake does not reproduce, so the slow-write experiment is the proof. It reproduces the issue's exact failure lines on the old tests, and the new tests pass against it. Full //agent/internal/xds/cache:all passes. Lint (--config=lint --@aspect_rules_lint//lint:fail_on_violation) and //:format are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 27, 2026 08:29
…file poll (#955)

The observed-upstreams store tests polled the persisted file for up to 2s
after a change. The debounce under test is only 10ms; the real cost is the
write behind it, file.WriteFileAtomic, which fsyncs the temp file and then
the directory. On a loaded workstation disk those two fsyncs alone can
exceed 2s, so the tests went red 6/6 locally while passing in CI.

waitObservedFlush now waits on the store's own completion order:
flushObservedUpstreams holds observedWriteMu across takeObservedSnapshot
(which disarms the timer and clears the dirty bit) and the write. Once the
timer is disarmed and nothing is dirty, acquiring observedWriteMu returns
only after that write landed. The only bounded wait (30s) covers
scheduling a 10ms timer, not I/O. The tests then read the file strictly.

Test-only; no production change and no new seam. The tests still exercise
the real debounce timer path.

Closes #955

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit ca11d06 into main Sep 27, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/observed-upstreams-store-flake branch September 27, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant