Skip to content

fix: guard the usage total and stop a PDF test flaking under load - #148

Merged
cheetahbyte merged 2 commits into
mainfrom
fix/usage-total-and-pdf-flake
Nov 17, 2026
Merged

cheetahbyte merged 2 commits into
mainfrom
fix/usage-total-and-pdf-flake

Conversation

@lauragarden

Copy link
Copy Markdown
Contributor

Summary

Two follow-ups to #146, which merged before the first could be pushed:

  • Usage total: ChatUsage (apps/web/features/bot-chat/chat-usage.tsx) renders the total with total !== null && instead of total &&. This addresses React Doctor's rendering-conditional-render warning on feat(web): show each bot chat's model and tool usage #146. total is a string or null, so no 0 could have shown; this makes the condition explicit.
  • PDF test flake: extractPdfText > worker text limit fails without a timeout now allows 30 s for each oversized PDF extraction instead of 5 s, and 60 s for the whole test instead of 15 s. workerErrorExit, which has its own guard timer, uses the same SLOW_WORKER_MS constant. The other tests' 5 s limits are unchanged; they extract small fixtures.

Replaces #147.

Why

The PDF test checks that the text limit stops a 180-page PDF before any timeout. Under a loaded parallel suite the extraction itself took longer than 5 s, so the test failed although the text limit worked:

  • runPdfExtraction returned "PDF extraction timed out" instead of "PDF extraction failed" (line 136).
  • With only that limit raised, workerErrorExit's 5 s guard fired instead (expect(timedOut).toBe(false), line 67).

Locally it failed in most pre-push runs and blocked pushing the usage fix. CI on main passed.

Evidence

  • bun run check passes on the branch: lint, format, typecheck, openapi:check, and 1323 tests, 0 failing. The pre-push suite passed on push.
  • React Doctor (bun run doctor in apps/web) reports nothing in chat-usage.tsx.
  • Load reproduction: 16 copies of the PDF test running at once (bun test apps/server/src/files/pdf-text.test.ts -t "worker text limit fails without a timeout"), on the same machine:
Limits Result
main (5 s / 5 s) 10 of 16 failed, all with "PDF extraction timed out"
Extraction limit 30 s, workerErrorExit 5 s 14 of 16 failed in workerErrorExit
This PR (30 s / 30 s, test 60 s) 32 of 32 passed over two rounds; slowest test took 22.5 s

Alone, the test still takes about 3.5 s.

Risk and rollback

Reversibility: Reversible.

Blast radius: The web bot details Usage section (no visible change) and one server test file; no production server code changes.

If extraction ever really hangs, the PDF test now takes up to 60 s to fail instead of 15 s.

The text-limit test and workerErrorExit allowed 5 s. Under a loaded
parallel suite the 180-page extraction ran past that and returned
"PDF extraction timed out", or tripped the helper's own timer, so the
test failed although the text limit worked. Both now allow 30 s, and the
test 60 s.
@lauragarden lauragarden self-assigned this Nov 17, 2026
@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 1407a6a.

@cheetahbyte
cheetahbyte merged commit af4d6a6 into main Nov 17, 2026
8 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