Repository navigation
Description
Two convex-test suites fail intermittently in CI and pass consistently in isolation. Both drain scheduled functions between cases, and both fail with a symptom that reads as missing data rather than as a timing problem.
Observed
convex/audit_logs/integrity_check.test.ts— documented in feat(platform): split chat rag_search into search and list actions #3029 as "a pre-existing load-dependent scheduler-drain flake, 0–5 failures varying per run, 3× standalone 17/17".convex/projects/rest_machine_door.test.ts—getProjectFileForUser … answers the blob ref + type for a bound filefailed once withConvexError: {"code":"PROJECT_NOT_FOUND"}. The case creates a project and immediately queries it. Passed 18/18 twice standalone, 32/32 combined with an unrelated suite, and 403/403 acrossconvex/projects+convex/file_metadata. A whole-run rerun of the same commit was green.
Shape
Both files create a fresh backend per case, so this is not cross-test contamination. Both then drain the scheduler in afterEach:
afterEach(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
await Promise.all([...testBackends].map((t) => t.finishInProgressScheduledFunctions()));
testBackends.clear();
});Under CI concurrency a case can proceed while work from the previous case's drain is still settling, and a create-then-read case then reads state that has not landed. The failure surfaces as a not-found error, which looks like a logic bug and is not one.
Why it costs more than a rerun
A change that merely adds tests redistributes files across vitest workers, which is enough to tip a timing-sensitive suite. So an unrelated PR gets a red Unit job, and the author has to prove a negative before merging. That happened here: the failing test was untouched by the diff and unreachable from it, but establishing that took a log read, four local runs, a check of which branches even contain the file, and a full-run rerun.
Worth considering
- Make the create-then-read cases await the state they depend on rather than relying on the drain.
- Or give the drain a deterministic barrier so a case cannot start while another's scheduled work is in flight.
- Or mark the known-fragile cases so a failure is attributable at a glance instead of looking like a regression in whatever PR happened to run.
Filed so the next person to hit a red Unit on an unrelated diff has something to compare against.
Activity
Israeltheminer commentedon Aug 22, 2026
Recurred, on a different PR and a different commit.
convex/projects/rest_machine_door.test.ts > getProjectFileForUser … answers the blob ref + type for a bound filefailed again withConvexError: {"code":"PROJECT_NOT_FOUND"}, thrown fromconvex/projects/internal_mutations.ts:90— the branch whose comment reads "Unreachable — the core just inserted it".Same discriminators as before:
convex/projects/, and nothing reachable from it.Transaction not startedandTransaction already committed or rolled backfrom unrelated scheduled functions, which is the drain-still-settling signature described above.Two data points now: it survived #3038 and #3041, so the toolchain change neither caused nor fixed it. The cost is unchanged — an author whose diff cannot reach the test still has to prove that before merging.
Israeltheminer commentedon Aug 22, 2026
Correcting myself, and adding the mechanism for the audit half.
The two files do not share a shape. The issue above says "both then drain the scheduler in
afterEach". Only the projects one does.convex/audit_logs/integrity_check.test.tsdrains inline, inside the test body —runCheck()calls a hand-rolleddrainScheduledFunctions()after every check run, and never callsfinishInProgressScheduledFunctions().The audit failures are not assertions. They are that helper's own guard:
Its budget is 200 attempts with a 5ms sleep between them — roughly one second plus a
t.runround-trip per iteration. When the fire-and-forget Slack dispatch chain does not quiesce inside that window, the guard throws. So the audit half is a bounded wait that runs out under load, not state read too early.Reproduced locally, which the CI-only version was not. On a branch whose diff adds two test files and touches nothing either suite imports, the full platform suite failed 2 runs out of 2, with 1 then 3 failures in this file — the varying count #3029 recorded. Clean
mainpassed the same suite in the same working copy. The branch's diff cannot reach either suite, so the channel is which worker the file lands on, not the change.Six files already use the harness API this one hand-rolls —
t.finishInProgressScheduledFunctions(), includingconvex/projects/rest_machine_door.test.ts,convex/tasks/rest_machine_door.test.ts, andconvex/documents/create_document_from_upload_rag_skip.test.ts. Replacing the poll with it would make the audit half deterministic rather than merely more patient.The projects half is still unexplained, and is a different failure. One fact that may help whoever takes it:
createProjectCore(convex/projects/mutations.ts) re-gets the row it just inserted and guards withif (project), tolerating a falsy result — while its caller atconvex/projects/internal_mutations.ts:90throwsPROJECT_NOT_FOUNDon exactly that condition. Two adjacent call sites defend against the same get-after-insert returning nothing.Israeltheminer commentedon Aug 22, 2026
Correction to the comment above: clean
mainfails this too.I reported "clean
mainpassed the same suite" on a single sample. A second sample of the same suite on the same commit failed —convex/audit_logs/integrity_check.test.ts, 2 failures, the same "did not drain" guard.Local samples of
bun run --filter @tale/platform test, same machine, run one at a time:main(f9bdbf7)So this is ambient on
main, not something a particular branch's worker distribution triggers. Drop the "which worker the file lands on" framing from my previous comment — the file fails on an unmodified tree, and the count varies run to run on both. Everything else in that comment stands: the failure is the inline poll's own guard, its budget is 200 attempts at 5ms, and six other suites uset.finishInProgressScheduledFunctions()instead of hand-rolling it.Practical consequence: the audit half is not a "prove your diff is innocent" problem, it is a red
mainproblem that happens to be invisible when CI's whole-suite timing lands the other way.