Skip to content

Fix three flaky tests: CalDAV listing reads one calendar, away-plan and focus-sound tests wait on work, not time - #2208

Merged
pixari merged 4 commits into
mainfrom
fix/httpapi-flake
Nov 28, 2026
Merged

pixari merged 4 commits into
mainfrom
fix/httpapi-flake

Conversation

@pixari

@pixari pixari commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

What and why

We fix three tests that failed once and passed on rerun. Each had a real cause.

1. internal/httpapi TestCalDAVLargeAccountBudgets, the large CalDAV test. Its 1 s ceiling for a Depth 1 PROPFIND of a 500-task calendar was not generous: listing one calendar read the whole 10,000-task account (about 1.47 million allocations of fixed cost). That took 1.3 to 1.5 s on a 4-core sandbox, and on the commit that added the test as well (664d304), so the test failed every time here. On a CI runner it sat close enough to the ceiling to flake under load. We fixed the code, not the ceiling. A project calendar's listing (PROPFIND Depth 1, calendar-query, the first sync-collection) now reads only that calendar's tasks by project_id into the partial view, with what serving them needs (it reuses fetch's serve step: parents, blockers, labels, series), in list order (davroutes/narrow.go listing). The Inbox and a calendar of more than maxNarrow tasks still read the whole view. On 10,000 tasks:

Request Before After
PROPFIND Depth 1, 500 tasks 1.39 s, fixed cost 1,468,527 allocs 25–46 ms, fixed cost 5,925
calendar-query, 500 tasks 1.13–1.55 s 24–83 ms

To compare against, davroutes.Server.SetWholeView makes every request read the whole view, as before. TestCalDAVPartialViewServesWhatTheWholeViewServes and the new TestCalDAVPartialListingServesWhatTheWholeViewServes compare a calendar's three listings with it as ordered lists. The new test covers a member of a shared project, an event-mode app password, a task blocked by one of an archived project, and a calendar of 1,001 tasks. Both tests fail when the listing drops its last task or reverses its order. Task 2.2 and the design (D4) of caldav-verified record the change. The spec's budgets are the same. Changelog: changelog.d/Changed/caldav-verified.md.

2. internal/sync TestPlanAwayStopsAtTheLimit. It checked "refuses quickly" with a 1 s wall-clock limit. The call took up to 0.56 s on an idle machine and 1.097 s with three packages testing in parallel. The property is that planning stops as soon as the changes pass the limit, so the test now measures work: it counts the series planned (canEdit is asked once per series) and wants exactly those whose fields pass the limit (3 of 200). With the check moved after the loop, the test fails with "planned 200 series, want 3".

3. web useFocusTimer.test.tsx, "Turning the sound off stops a background Long and cancels a waiting tone" (expected 10 to be 2 on #2204). The test turned the sound off with mutate() and one flush(). The pref reaches the engine through the user prefs live query (IndexedDB), and under CPU load that takes longer than one macrotask, so the Long kept playing. The engine now renders its sound setting, and soundOff() waits for it, the same way the tests already wait for the phase. The test after it, "Sound turned off while the tone waits", had the same race and is fixed the same way.

No test is skipped, no limit is raised and nothing retries.

Runs

  • Before: go test ./internal/httpapi failed on its first run (PROPFIND time: 1.304s (ceiling 1s): over budget), and again twice with the test alone, also at 664d304.
  • After: internal/httpapi passed -count=20 -failfast with GOMAXPROCS=2 while a loop of internal/sync tests ran beside it, and passed -race -count=3 -failfast. The large test passed 11 more runs on its own.
  • go test ./internal/sync -run TestPlanAway -count=50 passed.
  • useFocusTimer.test.tsx failed 1 of 30 runs with 6 busy-loop processes on 4 cores (expected 10 to be 2). After the fix, the whole file passed 60 of 60 runs under the same load.
  • make staticcheck (deadcode included), go vet, make docs-check, node --test scripts/repo-checks.test.mjs, tsc and eslint are clean.

Checklist

  • Behaviour changes start as an OpenSpec change (openspec/changes/<name>/), or this PR has none (responses are unchanged; the caldav-verified design notes the listing)
  • One change per pull request; make check passes locally (three test fixes in one PR, as asked; we ran the parts listed above, not the full make check)
  • Commits credit every author, AI tools included, with a Co-Authored-By trailer
  • Data writes go through ops (no direct task/project row writes)
  • New API routes are registered with a policy in internal/httpapi/policy.go (none)
  • No telemetry, no new third-party requests, no new mandatory env vars
  • Docs updated and a changelog entry added as changelog.d/<Section>/<name>.md (not in CHANGELOG.md); size impact noted for new dependencies (none)
  • Templates only: n/a

https://claude.ai/code/session_0187cnkXBm72ZSggGvrvUMKW


Generated by Claude Code

TestPlanAwayStopsAtTheLimit checked that refusing a too-large away period
is quick with a 1 s wall-clock limit. On an idle machine the call took up
to 0.56 s, so with three packages testing in parallel it passed the limit
(1.097 s seen). The property is that planning stops as soon as the changes
pass the limit: the test now counts the series planned (canEdit is asked
once per series) and wants exactly those whose fields pass it, 3 of 200.
It fails with "planned 200 series, want 3" when the check moves after the
loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0187cnkXBm72ZSggGvrvUMKW
TestCalDAVLargeAccountBudgets failed its 1 s ceiling for a Depth 1
PROPFIND of a 500-task calendar (1.3 to 1.5 s here, also at the commit
that added it): listing a calendar, a calendar-query and the first
sync-collection loaded every task of the 10,000-task account, about 1.47
million allocations, so the ceiling sat at the real cost on a 4-core
machine or a loaded runner.

A project calendar's listing now reads its tasks by project_id
(sync.ListWhere) into the partial view, with what serving them needs (the
same serve step as fetch: refs, parents, labels, series), in list order.
The Inbox and a calendar over maxNarrow tasks still read the whole view.
On 10,000 tasks the PROPFIND fixed cost goes from 1,468,527 to 5,925
allocations and from 1.4 s to 46 ms; calendar-query from 1.5 s to 83 ms.

TestCalDAVPartialViewServesWhatTheWholeViewServes used calendar-query as
its whole-view reference; it now uses a multiget of more hrefs than
maxNarrow (which reads the whole view) and also compares the PROPFIND.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0187cnkXBm72ZSggGvrvUMKW
Two hidden-tab tests turned the sound off with mutate() and one flush()
and then expected the background Long cancelled. The pref reaches the
engine through the user prefs live query (IndexedDB), which under CPU load
takes more than one macrotask, so the Long kept playing ("expected 10 to
be 2", seen on CI and 1 in 30 runs here with the CPU busy). The engine now
renders its sound setting and soundOff() waits for it, as the tests
already wait for the phase. 60 of 60 runs of the file pass under the same
load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0187cnkXBm72ZSggGvrvUMKW
The partial-view test took its reference from listings that are now
narrow themselves, and compared maps, so a dropped or reordered resource
went unnoticed. davroutes.Server.SetWholeView makes every request read the
whole view, as before partial views; the tests compare the three listings
of a calendar (PROPFIND Depth 1, calendar-query, the first sync-collection)
with it as ordered lists. New cases: a member of a shared project, an
event-mode app password, a task blocked by one of an archived project
(whose calendar stays 404 either way) and a calendar of 1,001 tasks. Both
tests fail when the listing drops its last task or reverses its order.

Also: task 2.2 of caldav-verified records the change, the design note
says "up to 1.5 s on a loaded CI runner", the changelog fragment is named
after the change, and narrow.go says why a calendar over maxNarrow is read
twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0187cnkXBm72ZSggGvrvUMKW
@pixari
pixari marked this pull request as ready for review November 28, 2026 14:25
@pixari
pixari enabled auto-merge November 28, 2026 14:25
@pixari
pixari added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit f4789ad Nov 28, 2026
36 checks passed
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.

2 participants