Skip to content

test(desktop): run what waits before the test loop draws again - #214

Merged
bketelsen merged 4 commits into
mainfrom
fix/settings-wait-race
Nov 12, 2026
Merged

bketelsen merged 4 commits into
mainfrom
fix/settings-wait-race

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

TestSettingsChangeAPreferenceAndAVaultSetting timed out now and then in the Race detector job (#203). The cause is the test loop, not notesd.

What takes the time. Timed under -race on a desktop: the vault setting's round trip through notesd is under 1 ms. The 4 s went to 19 frames of about 200 ms each. desktoptest.Loop.Until checks its condition after every posted function, and the window tests' condition draws a frame. One setting change posts about 19 functions: the call's answer, vault.configured, the scan's vault.scan events, and the catalog, panes and settings loads that they start. Some loads wait for an earlier answer, so they queue behind the frames. On a slower runner, with other race tests beside it, 19 frames go past the 10 s limit.

The fix.

  • Loop.Until now runs every function that waits in the queue before it checks the condition again. This is what the UI thread does: it runs what was posted, then it draws once. When frames are slow, more work waits, and 1 frame covers it all. So the wait no longer grows with frame cost × answers. It runs only what waits at that moment: a function that posts itself again runs at the next check, so the deadline still holds.

  • A vault setting loaded the vault's data twice: at the call's answer and at vault.configured. notesd emits that event after every change it writes (internal/vault/configure.go). The answer now loads the data only when the change failed, so the rows show what holds. That removes a second catalog, panes and settings load for each change.

  • A race this exposed. The first CI run of this branch failed TestJoiningALoopbackHub: it failed 6 times in 40 here, against 0 in 40 on main. The vault data's load asks sync.status. A sync.changed event can come while the call is in flight, because the two travel apart. The answer then replaced the event's newer status. The old loop checked between the two; the UI thread, like the new loop, runs both before it draws. After a join, the status bar could show "syncing" with no hub address until the loop changed state again. An event that crosses an answer can also be the older one: sent before a leave and delivered late, it would bring back the hub that the vault left, and no event follows a leave. An older ask's answer can also come after a newer one (asked before a leave, or before a switch to another vault and back). So each ask of sync.status now has a number, and only the last ask's answer shows. If a sync.changed of the vault came while that ask ran, the event's status stays and the window asks again, until an answer comes with no event during its call.

The 10 s limit is unchanged.

Closes #203.

Risk tier

Risk tier: 2 — test infrastructure, plus 2 behavior changes in the desktop app: the vault data load after a successful setting change now comes only from vault.configured, and a sync.status answer that a sync.changed crossed is asked again instead of shown. No path in .github/risk-paths.json matches.

Verification

  • make check green (host)
  • Review fix: 1 line in .memory/corrections.jsonl for the cross-review's blocking points on the sync status
  • 50 race runs of the flaky test at the head, all green: go test -race -count=50 -run '^TestSettingsChangeAPreferenceAndAVaultSetting$' -v ./internal/desktop/window/: 50 PASS, 0 FAIL; min 0.81 s, median 0.84 s, max 0.92 s. Before the fix, single runs took 4.8 to 7.6 s here.
  • go test -count=60 -run '^TestJoiningALoopbackHub$' ./internal/desktop/window/: 60 PASS (6 of 40 failed before the sync fix)
  • go test -count=1 ./internal/desktop/... 3 times, and go test -race -count=1 ./internal/desktop/..., green
  • Guards: TestUntilChecksOnceForWhatWaits and TestUntilRunsOnlyWhatWaitsBeforeItChecks (internal/desktop/desktoptest/loop_test.go); TestAnEventWhileTheStatusIsAskedOutlivesTheAnswer, TestAnEventWhileTheStatusIsAskedIsSettledByAStatusAskedAfterIt, TestAnOlderSyncStatusAnswerDoesNotShow and TestASyncStatusAnswerFromBeforeAVaultSwitchDoesNotShow (internal/desktop/window/syncstatus_test.go)
  • Revert test: from the PR head, revert internal/desktop/desktoptest/desktoptest.go and internal/desktop/window/settings.go to main. Keep the tests, then run go test -count=1 -run TestUntil ./internal/desktop/desktoptest/. TestUntilChecksOnceForWhatWaits fails: the condition ran 6 times for 1 batch, want 2. In takeSyncStatus (internal/desktop/window/app.go), let the answer always replace the status, as main does. Then TestAnEventWhileTheStatusIsAskedOutlivesTheAnswer fails: the answer replaced the event's status: <nil>. If the event is kept and no new ask is sent, TestAnEventWhileTheStatusIsAskedIsSettledByAStatusAskedAfterIt fails: timed out waiting for the vault's status with no hub. If the ask's number is not checked, TestAnOlderSyncStatusAnswerDoesNotShow and TestASyncStatusAnswerFromBeforeAVaultSwitchDoesNotShow fail: an older answer shows and an answer from before the switch shows.

TestSettingsChangeAPreferenceAndAVaultSetting timed out under the race
detector on CI. The vault setting's round trip through notesd takes under a
millisecond; the time went to frames. desktoptest.Loop.Until checked its
condition, which draws a frame, after each posted function, and one setting
change posts about 19 (the call's answer, vault.configured, the scan's
events and the vault data each starts). Under the race detector a frame of
the settings dialog costs about 200 ms here, so the wait grew to 4 s here
and past the 10 s limit on a slower runner.

Until now runs every function already waiting before it checks again, as
the UI thread runs what was posted and then draws once. A function that
posts itself again runs at the next check, so the deadline still holds.

A vault setting also loaded the vault's data twice: once at the call's
answer and once at vault.configured, which notesd sends after every
change. The answer now loads it only when the change failed.

Closes #203
@github-actions github-actions Bot added the level:L3 Skim label Nov 12, 2026
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Cross-review: Ready. Blocking: none. Findings: none.

  • Reviewer: openai/gpt-6.1-sol. Coder: anthropic/claude-opus-5-5.
  • Base b9c6c9006d666183f91313f79648f8323b8a61b0, head da40d1d1ff45dc426b412ec9f8ea6d49f8987b06. Scope: all 3 changed paths. Context: the desktop wait callers, window event handling, session reconnection, vault configuration and event delivery.
  • What it checked: runWaiting runs only what the queue holds at that moment, so a function that posts itself again cannot keep Until past its deadline. No wait condition needs a check between 2 queued functions. Vault.Configure emits vault.configured before every success, also for an unchanged value. If the emit fails, the call returns an error, so the app still reloads. Reconnection reloads all data. The guard asks for exactly 2 checks for 5 queued functions; without the fix there are 6.
  • Revert test: TestUntilChecksOnceForWhatWaits fails with the fix reverted (see the PR body).

The vault data's load asks sync.status, and a sync.changed event can come
while it is asked: the two travel apart. The answer then replaced the
event's newer status. After a join, the status bar could show syncing with
no hub address until the loop changed state again.

The window counts its vault's sync.changed events; a sync.status answer
asked before one of them leaves the event's status in place.

The test loop that runs what waits before it draws again found it:
TestJoiningALoopbackHub timed out 6 times in 40 when the answer and the
idle event ran in one batch.
A sync.changed that comes while sync.status is asked is not always newer
than the answer: an event sent before a leave can come late, and keeping it
would bring back the hub the vault left, with no event to follow.

The event's status now stays only until a status asked after it comes: the
window asks again, one ask at a time for each vault, until an answer comes
with no event while it was asked.
An older ask's answer can come after a newer one: asked before a leave, it
brought back the hub the vault left, and no event follows a leave. A vault
switch and back let one through too, since the vault matched again.

Each ask of sync.status now has a number; only the last ask's answer shows,
and a sync.changed that came while it ran has it asked again.
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Cross-review: Ready at 3e3a8cab8054e414ff0bf7bb90fc2fea260e1374. Blocking: none. Reviewer: openai/gpt-6.1-sol. Coder: anthropic/claude-opus-5-5. Base b9c6c9006d666183f91313f79648f8323b8a61b0.

The review took 1 pass and 3 re-reviews:

  • At da40d1d: Ready, no findings.
  • Re-review 1, at 08883d8, which added the sync status fix after CI failed TestJoiningALoopbackHub. X1 (blocking): a late sync.changed from before a leave was kept for good. Fixed: a crossed answer is asked again.
  • Re-review 2, at 6c5c745. X2 (blocking): an older ask's answer could show after a newer load, or after a switch from vault A to vault B and back. Fixed: asks are numbered, and only the last ask's answer shows. X3 (blocking): no corrections line. Fixed: 1 line in .memory/corrections.jsonl.
  • Re-review 3, at 3e3a8ca: X1, X2 and X3 are resolved; no new findings. The budget is used up.

Revert tests: see the PR body. CI is green at 3e3a8ca.

@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 12, 2026
@bketelsen
bketelsen merged commit a6e982c into main Nov 12, 2026
12 checks passed
@bketelsen
bketelsen deleted the fix/settings-wait-race branch November 12, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L3 Skim ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: the vault setting in TestSettingsChangeAPreferenceAndAVaultSetting times out under the race detector

2 participants