Bug: notes.link-states is asked about every 30 ms, for ever, for links to files the notes list does not hold (task notes under Tasks/) #1178

Closed
opened 2026-11-15 23:12:45 +00:00 by kayg · 2 comments
Owner

Found by the stability lane while explaining why tasks-tick.spec.ts (and other tasks-* specs) fail much more often with --workers=2 --repeat-each=10 (see the #1136 lane's numbers) than alone.

What happens

With the Tasks screen open (the Notes shell stays mounted under it, with today's note), the page sends notes.link-states about 28 times a second, forever, with the same body and the same answer: {"paths": ["Tasks/Tick-….md", "Tasks/Undo-….md", …]} → every path here. Measured on dev 42c219afd, chromium-1440, one task made, page idle: 15 requests while loading, then 84 and 88 requests in the next 3 s with nothing changing. A trace of a failing tasks-tick repeat showed 571 of them in one test. The request carries every task note path of the vault (up to 200 per request), so the cost grows with the vault, i.e. with every repeat and worker. (Checked: it is not what makes tasks-tick fail under --workers=2; with the fix the same 6 / 80 still fail, see the PR.)

Cause

apps/web/src/lib/links/states.ts, word(path): for a link to a .md file the notes list does not hold (the files under Tasks/ are not in the notes list), the server's answer is here. The here branch asks again whenever the list is ready ("its note was here, and the list no longer has it"). The answer arrives, tell() redraws the editor's links, the redraw calls word() again, which asks again: one round trip every GATHER_MS (30 ms), for ever.

Fix (PR to follow)

Ask again about a here answer only after the notes list has changed since the answer was taken (notesState.paths, the counter checkPaths already uses), so the case the branch is for (a note that was here and left the list) is still asked at once, and a file the list never holds is asked once.

Found by the stability lane while explaining why `tasks-tick.spec.ts` (and other `tasks-*` specs) fail much more often with `--workers=2 --repeat-each=10` (see the #1136 lane's numbers) than alone. ## What happens With the Tasks screen open (the Notes shell stays mounted under it, with today's note), the page sends `notes.link-states` **about 28 times a second, forever**, with the same body and the same answer: `{"paths": ["Tasks/Tick-….md", "Tasks/Undo-….md", …]}` → every path `here`. Measured on dev `42c219afd`, chromium-1440, one task made, page idle: 15 requests while loading, then **84 and 88 requests in the next 3 s** with nothing changing. A trace of a failing `tasks-tick` repeat showed 571 of them in one test. The request carries every task note path of the vault (up to 200 per request), so the cost grows with the vault, i.e. with every repeat and worker. (Checked: it is **not** what makes `tasks-tick` fail under `--workers=2`; with the fix the same 6 / 80 still fail, see the PR.) ## Cause `apps/web/src/lib/links/states.ts`, `word(path)`: for a link to a `.md` file the notes list does not hold (the files under `Tasks/` are not in the notes list), the server's answer is `here`. The `here` branch asks again whenever the list is ready ("its note was here, and the list no longer has it"). The answer arrives, `tell()` redraws the editor's links, the redraw calls `word()` again, which asks again: one round trip every `GATHER_MS` (30 ms), for ever. ## Fix (PR to follow) Ask again about a `here` answer only after the notes list has changed since the answer was taken (`notesState.paths`, the counter `checkPaths` already uses), so the case the branch is for (a note that was here and left the list) is still asked at once, and a file the list never holds is asked once.
Author
Owner

Repro, fix and gates (stability lane, 15 Nov), PR #1180

Repro (dev 42c219afd, dev-02, chromium-1440, spec link-states-quiet.spec.ts, commit d200500bf, test only): one task made, Tasks screen open and idle, requests to notes.link-states counted over 3 s after 1.5 s of settling. Fails 3 / 3: 80, 82, 81 requests in 3 s (limit 12; the loop sends about 27 a second). The body is the same each time (every Tasks/*.md path of the vault, 17 in the trace I read) and so is the answer (all here).

Fix edec6a593, tidy 84f33ad57 (head of PR #1180). Same spec: 5 / 5 pass on chromium-1440, 5 / 5 on chromium-390 (dev-02).

Gates (dev-02, 84f33ad57): bun run check 0 errors (19 warnings, same as dev); bun run test 34 files, 319 tests pass; bun run lint ok; e2e/missing-links.spec.ts e2e/links.spec.ts e2e/link-states-quiet.spec.ts chromium-1440 --repeat-each=10: 250 / 250 pass (the link-state card paths of #448 included).

Effect on the tick flake: by itself it did not change tasks-tick under --workers=2 (6 / 80 before and after); that was the 503/409 handling, #1179. Both fixes together: 1 / 100 in the same run. The loop still removes ~27 requests a second per open page, each carrying every task note path, and grows with the vault (every repeat and worker).

Perf statement: removes a request loop; per link draw the only addition is one Map.get on a here answer. No effect on typing or list scroll.

## Repro, fix and gates (stability lane, 15 Nov), PR #1180 **Repro** (dev `42c219afd`, dev-02, chromium-1440, spec `link-states-quiet.spec.ts`, commit `d200500bf`, test only): one task made, Tasks screen open and idle, requests to `notes.link-states` counted over 3 s after 1.5 s of settling. **Fails 3 / 3: 80, 82, 81 requests in 3 s** (limit 12; the loop sends about 27 a second). The body is the same each time (every `Tasks/*.md` path of the vault, 17 in the trace I read) and so is the answer (all `here`). **Fix** `edec6a593`, tidy `84f33ad57` (head of PR #1180). Same spec: **5 / 5 pass on chromium-1440, 5 / 5 on chromium-390** (dev-02). **Gates** (dev-02, `84f33ad57`): `bun run check` 0 errors (19 warnings, same as dev); `bun run test` 34 files, 319 tests pass; `bun run lint` ok; `e2e/missing-links.spec.ts e2e/links.spec.ts e2e/link-states-quiet.spec.ts` chromium-1440 `--repeat-each=10`: **250 / 250 pass** (the link-state card paths of #448 included). **Effect on the tick flake:** by itself it did not change `tasks-tick` under `--workers=2` (6 / 80 before and after); that was the 503/409 handling, #1179. Both fixes together: 1 / 100 in the same run. The loop still removes ~27 requests a second per open page, each carrying every task note path, and grows with the vault (every repeat and worker). **Perf statement:** removes a request loop; per link draw the only addition is one `Map.get` on a `here` answer. No effect on typing or list scroll.
Author
Owner

Fixed by #1180, now on dev. Closing.

Fixed by #1180, now on dev. Closing.
kayg closed this issue 2026-11-16 00:53:17 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal#1178
No description provided.