Skip to content

Studio: fix two intermittently failing tests - #9200

Merged
danielhanchen merged 1 commit into
mainfrom
studio-ci-test-robustness
Aug 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-ci-test-robustness

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Two tests were failing intermittently in CI. Both turned out to be faults in the tests themselves, not in the code they cover, so the implementations are unchanged here.

Orphan cleanup test keyed on an invented pid

test_orphan_cleanup_kills_under_real_root never spawns a process. It invents a pid as os.getpid() + 888, but _kill_orphaned_servers gates every candidate on _pid_parent_is_alive, which asks the real OS. When something already occupies that pid with a live parent, the candidate is skipped and the test fails with assert 0 == 1. PIDs are handed out sequentially, so the allocator passes that number shortly after pytest starts, which is what makes this reachable rather than theoretical.

Reproduced by forking pytest, squatting pytest_pid + 888 with a live process, then releasing pytest: the unmodified test fails with exactly the CI message.

The gate was added in #8498 without updating this test, so the flake has been latent since then.

The [procfs] parametrization was also passing for the wrong reason: its os.kill stub raised ProcessLookupError for every pid except the fake one, and psutil.pid_exists is os.kill(pid, 0) on POSIX, so every parent read as dead. That is why only [psutil] ever failed.

The tests now stub _pid_parent_is_alive for the invented pid only and delegate every other pid to the real implementation, and the procfs stub delegates too. A new test covers the ownership gate with a process the test genuinely owns, so nothing is lost by stubbing it elsewhere.

Project source test raced its own announce

saveMarkdownAsProjectSource fires watchIngestion without awaiting it, and that watcher polls for up to 300 seconds. Watchers from earlier tests therefore outlive them and keep calling the shared fetch stub, which by then belongs to whichever test is running now. Since the stub answered any /jobs/ URL and the uploads shared a filename, a stale watcher emitted a toast byte-identical to the one the test was waiting on, under a different project id.

The test waited on the toast and then read the announce count without polling, so a tick landing between a foreign toast and its own announce saw 1 instead of 2. The 2014 ms duration in the CI log is a stale 2 s watcher.

Each job handler now answers only its own job id and 404s anything else, so a stale watcher dies quietly instead of borrowing the running test's answers. The save under test gets its own filename, and the test polls on the announce, which the watcher does last, then asserts the toast synchronously.

Verified with a gap sweep: with a 150 ms delay inserted the old test fails 10 of 10 and the new one passes 10 of 10.

Import resolution

image-input-support.ts imported ./mmproj-fallback without an extension. CI runs Node 22 and is unaffected, but under Node 24 the package is ESM and the specifier does not resolve, which hides four tests from anyone running the suite locally. Test-reachable modules elsewhere already use the explicit .ts form.

Checks

Both fixes were mutation tested to confirm they still prove what they did before: removing the parent gate from the implementation fails the new orphan test, and removing announceProjectSourcesUpdated fails the new source test.

  • tests/test_local_llama_cpp_link.py: 10 passed, plus 50 sequential runs idle and 40 under CPU load with no failures
  • neighbouring process-management suites: 329 passed, 4 skipped
  • frontend: 3760 passed, 0 failed; npm run typecheck clean

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

Consolidating the PRs that overlap on the current main breakage, so you know where this one stands: this PR stays open and I am not touching it.

Three files here, and only image-input-support.ts overlaps with #9220 (which is carrying the full main-red fix). The other two are unrelated flake fixes that nothing else on the board has, and closing this as a duplicate would have silently dropped them. I nearly made that mistake.

I can independently corroborate the test_local_llama_cpp_link.py one. Running the backend suite locally, before seeing this PR, I hit exactly:

FAILED tests/test_local_llama_cpp_link.py::test_orphan_cleanup_kills_under_real_root[psutil]

Your diagnosis matches what I saw. _FakeProc's pid is invented, the sweep asks the real OS whether that pid's parent is alive, and so whatever unrelated process happens to be sitting on that pid decides the assertion. That is a genuine bug in the test, it is not deterministic, and the assert 0 == 1 it produces tells you nothing about the code under test. Pinning the invented pid to orphan while leaving every other pid to the real implementation is the right shape, and keeping the opposite direction covered by test_orphan_cleanup_spares_a_live_server_with_a_running_parent with a process the test genuinely owns is the part that stops this from being a blanket stub.

On the overlapping hunk: your ./mmproj-fallback.ts change is byte-identical to the one on #9220, so I have deliberately not stripped it from your branch. Once #9220 lands, git resolves an identical change with no conflict, and rewriting someone else's branch to remove a no-op is more churn and more risk than leaving it. If it does somehow conflict, drop the hunk at that point.

No action needed from you. This is queued behind #9220 only because everything is, while main is red.

Reduced to the one fix of the original three that is still needed. The other two
landed by other routes while this sat: the orphan-scan flake was fixed by #9280,
and the extensionless `./mmproj-fallback` import is already `.ts` on main. Both
are verified identical to main here rather than assumed.

On #9280 taking a different approach: it pins `_pid_parent_is_alive` to a
constant for the whole test, where this PR stubbed it only for the invented PID
and delegated every other PID to the real implementation. That is a real
difference in coverage, so I checked whether main lost anything before dropping
mine. It did not: `test_reap_recorded_pid_spares_live_server` in
test_llama_cpp_wait_for_vram_settle.py exercises the ownership gate for real,
against a process the test genuinely owns. So the gate is still covered and
#9280's version stands.

What is left, and why it is still needed
------------------------------------------------------------------------
`saveMarkdownAsProjectSource` fires `watchIngestion` without awaiting it, and
that watcher polls for up to 300 seconds. Watchers from earlier tests therefore
outlive them and keep calling the shared fetch stub, which by then belongs to
whichever test is running now. The stub answered any `/jobs/` URL and the uploads
shared a filename, so a stale watcher emitted a toast byte-identical to the one
the running test was waiting on, under a different project id.

The test then waited on the toast and read the announce count without polling.
The watcher toasts and announces with nothing awaited between them
(save-markdown-source.ts, `toast.error(...)` then
`announceProjectSourcesUpdated(...)`), so a tick landing in that window saw 1
instead of 2.

Each job handler now answers only its own job id and 404s anything else, so a
stale watcher dies quietly instead of borrowing the running test's answers. The
save under test gets its own filename, and the test polls on the announce, which
the watcher does last, then asserts the toast synchronously.

Verified
------------------------------------------------------------------------
Gap sweep, inserting a 150 ms delay into the source between the toast and the
announce to widen the window the race needs: main's version of the test fails 6
of 6 runs, this version passes 6 of 6. Both pass 6 of 6 on an idle box with no
delay, which is why this reads as an intermittent CI failure rather than a
reproducible one.

Mutation-tested: deleting `announceProjectSourcesUpdated` from the watcher fails
this test (9 passed, 1 failed), so it still proves what it did before rather than
having been loosened into passing.

Full frontend suite: 4087 passed, 0 failed.
@danielhanchen
danielhanchen force-pushed the studio-ci-test-robustness branch from 01cec7f to 5b9740a Compare August 20, 2026 10:19
@danielhanchen
danielhanchen merged commit 7266f1b into main Aug 20, 2026
36 checks passed
@danielhanchen
danielhanchen deleted the studio-ci-test-robustness branch August 20, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant