Skip to content

Fix the five ways main is red - #9220

Closed
danielhanchen wants to merge 6 commits into
mainfrom
fix-main-red-mmproj-extension
Closed

danielhanchen wants to merge 6 commits into
mainfrom
fix-main-red-mmproj-extension

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

main is red in five distinct ways and every open PR is blocked behind it. This PR started as the one-line import fix and now carries all five, because fixing the first one is what made the rest visible.

The same four checks fail identically on #9051, #9058, #9062, #9068, #8935 and this branch. Failing on six independent branches is what says main-side rather than PR-side.

The five failures

1. Frontend build + bundle sanity and Frontend unit tests (Windows), at Unit tests

npm test is node --experimental-strip-types --test, so modules are resolved by node, not vite. Node's ESM resolver does not guess extensions. src/features/chat/utils/image-input-support.ts imported ./mmproj-fallback without one, and tests/queued-model-capabilities.test.ts reaches it:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module
  '.../src/features/chat/utils/mmproj-fallback' imported from
  '.../src/features/chat/utils/image-input-support.ts'

Reproduced on a clean origin/main worktree: pass 0, fail 1. After: pass 3781, fail 0.

Nothing caught it at authoring time, and that is worth stating: the import is valid TypeScript, vite resolves it, typecheck and lint both pass.

A judgement call worth recording. src/ has 2319 extensionless relative imports against 55 with .ts, and the test suite already has a sanctioned mechanism for this exact case, registerBundlerResolver(), used by 61 of its 392 test files. So extensionless is the convention here and the .ts extension is the minority style. #9189 fixes this by registering the resolver in the test instead, which is arguably the more idiomatic answer. I kept the one-line version because it is the smaller blast radius while main is red. That was a call about risk, not a verdict that the other approach is wrong, and a proper fix for the class is still worth doing. I would rather this be on the record than have someone later find 2319 extensionless imports and conclude we did not look.

2. (Python 3.13): test_tensor_split_abort_raises_early_to_layer_fallback

assert raise_idx < src.find("_strip_mmproj_args(_last_spawn_cmd)")
E   AssertionError: assert 249423 < -1

The test was stale, not the product. #9173 renamed the strip's argument from _last_spawn_cmd to _vision_gpu_cmd. I checked the product side directly before touching the test: _vision_gpu_cmd = list(_last_spawn_cmd) is a snapshot taken before the CPU-projector retry can mutate it, so the strip still reads the argv it always did. Nothing was dropped, and the call is still there.

The anchor now matches the call rather than its argument, and each landmark must be found before it is ordered, so the next rename fails saying a landmark moved instead of assert 249423 < -1. Wording adopted from #9189, which reached this independently, as did #9192. Three-way agreement, nobody found a dropped call.

Before: 1 failed. After: 42 passed.

3. Repo tests (CPU), three separate symptoms

A. test_chat_autoload_failure_gate.py names its own fix: the sliced region gained a mmprojFallbackMessage import with no stub behind it, so add one to PREAMBLE.

B. assert "description: cpuFallbackReason" in success_toast pinned the head of a conditional chain, and the mmproj fallback added a branch above the CPU one. That changes which degraded loads get a description, not the contract the test exists to hold. It now asserts the contract: description conditional on a degraded-load reason, CPU still among them, undefined for a load with nothing wrong. Product correct, test pinned too tightly.

C. ImportError: cannot import name 'Page' from 'playwright.sync_api' (unknown location). This one is pre-existing and unrelated to the mmproj merge - it reproduces at 077593612^. _load_harness() in test_heavy_thread_measurement_integrity.py builds a fake playwright.sync_api and left it in sys.modules, which is process-wide. importorskip("playwright") then found a module, declined to skip, and the real harness import died on Page. (unknown location) is the tell: a hand-built ModuleType has no __file__.

The two red tests are the smaller half. Six false greens were the larger one: harnesses importing only sync_playwright imported clean against the fake and passed while testing nothing. They now skip correctly. The stub is torn down after the one import it exists for, restoring whatever was there before rather than popping the keys, and a new test fails if a __file__-less stub is ever left behind again.

4. Browser smoke for heavy-thread interaction cost - masked behind failure 1

[heavy-thread] HARNESS-BROKEN chromium at 25000 chars let 2 /api/ requests reach
the network during the measured actions; the timings include a round trip per request

This was masked on main. The job aborts at Unit tests, which is failure 1, so it never reached this step. Fixing the import is what revealed it.

I identified the leaker by URL before changing anything: /api/chat/threads/__LOCALID_G0w1QWF/forks. The stub allowlist named the old per-message endpoint /threads/{id}/messages/{mid}/forks. Fork counts were since batched into one whole-thread GET, so the pattern matched nothing - the stub looked present and correct while the real request went to the network, inside the measured actions.

The request legitimately fires, so this is a stale allowlist entry rather than app fan-out, and the fix belongs in the harness, not the product. The guard that should have caught it pinned only the response body, which is why it rotted silently; it now builds the URL the app builds and requires the pattern to match, so the next rename fails in a browserless test that costs a second.

The HARNESS-BROKEN guard itself is untouched. It was right, and it exists to stop timings being reported that include network round trips.

Verified at the full CI configuration (SMOKE_HEAVY_CHARS='25000,100000'): before, exit 1 with HARNESS-BROKEN; after, exit 0, zero strays.

5. Frontend unit tests (Windows)

Failure 1 on another OS. That job's only test step is npm test. No separate cause.

Verification

check result
npm test 3781 passed, 0 failed
npm run typecheck clean
npm run build built
test_tp_vision_regression.py 42 passed
heavy-thread smoke, 25000,100000 exit 0, no HARNESS-BROKEN
Repo tests (CPU) 0 failures under tests/studio/

Two notes on honest gaps. Repo tests (CPU) shows 84 failures locally outside tests/studio/, and the full backend suite shows more; both reproduce identically on a clean origin/main and are local environment (bitsandbytes CUDA detection, missing av, fastmcp, ddgs, sqlite_vec). They are not related to these changes and I have not tried to fix them. npx vitest run reporting "No test suite found" for node:test files is a false red, not a failure.

Relationship to the other open PRs

#9181 was byte-identical on the import and is closed as subsumed, with the reasoning recorded there.

#9200 stays open. Only its import hunk overlaps; it carries two unrelated flake fixes nothing else has, including a real bug where test_orphan_cleanup_kills_under_real_root[psutil] asked the real OS about an invented pid, so an unrelated process decided the assertion. I hit that failure independently. Its hunk is byte-identical to this one and git will resolve it.

#9189 overlaps on failures 1, 2 and 3 and is the better answer on failure 2, which I have taken. Its failure-3C fix does not work - importorskip("playwright.sync_api") finds the leaked stub and declines to skip, so the same two tests still fail on its branch (2 failed, 104 passed there against 98 passed, 9 skipped, 0 failed here, same command, same environment). Detail and evidence are in a comment on that PR. It also improves failure 4's diagnostic by naming the offending endpoints, which is how I confirmed the leaker; that is worth landing whichever way the rest goes.

`npm test` is `node --experimental-strip-types --test`, so the suite is resolved
by node, and node's ESM resolver does not guess extensions: `./mmproj-fallback`
must be a file of exactly that name, and a sibling `mmproj-fallback.ts` does not
satisfy it. Vite does guess, which is why this import was fine for the app and
fine for typecheck and lint, and only broke once a test reached it.

`tests/queued-model-capabilities.test.ts` reaches it through
`image-input-support.ts`, and has been failing on main since it landed:

    not ok 239 - tests/queued-model-capabilities.test.ts
    # pass 3777
    # fail 1

    Error [ERR_MODULE_NOT_FOUND]: Cannot find module
      '.../src/features/chat/utils/mmproj-fallback' imported from
      '.../src/features/chat/utils/image-input-support.ts'

Reproduced at origin/main before the change (0 pass, 1 fail) and green after
(4 pass, 0 fail), with `tests/mmproj-fallback.test.ts` also 4 pass alongside it.

Scoped deliberately to this one import. Roughly 600 other extensionless relative
imports under `src/` are correct as they stand, because nothing in the suite
loads them and vite resolves them; rewriting those would be churn with no defect
behind it.
…argument

#9173 renamed the strip's argument from _last_spawn_cmd to _vision_gpu_cmd, and
this test anchored on the argument, so its find() silently became -1 and the
ordering assert failed as "assert 249423 < -1" -- a message about ordering for
what was really a moved landmark.

The rename has no behavioural content: _vision_gpu_cmd is a snapshot of
_last_spawn_cmd taken before the CPU-projector retry can mutate it, so the strip
still reads the argv it always did. Nothing was dropped; the test was stale.

Anchor on the call rather than on what is passed to it, and require each
landmark to exist before ordering it, so the next rename fails with a message
that says a landmark moved.

Wording adopted from #9189, which reached the same conclusion independently.
Both are source-slicing tests over chat-adapter.ts and the auto-load toast, and
both broke on the text-only mmproj fallback for the same reason: they pinned one
spelling of code that legitimately changed.

test_chat_autoload_failure_gate.py executes a sliced region against a stub
PREAMBLE, and the region gained a mmprojFallbackMessage import with no stub
behind it. The test said so itself -- "add a stub to PREAMBLE" -- so add it.

test_model_picker_contracts.py asserted `description: cpuFallbackReason`, the
head of a conditional chain, and the mmproj fallback added a branch above the CPU
one. That is a change to which degraded loads get a description, not to the
contract the test holds. Assert the contract instead: the description is
conditional on a degraded-load reason, the CPU one is still among them, and the
arm for a load with nothing wrong is undefined. Another reason can be added
tomorrow without touching it.

Product code is correct in both cases; the tests were pinned too tightly.
…e worker

_load_harness() builds a fake playwright.sync_api so the arithmetic in this file
stays runnable on the CPU job, then left it in sys.modules. sys.modules is
process-wide, so from that point on every test in the worker had a playwright
that existed and was empty -- the worst of both answers.

That is what "cannot import name 'Page' from 'playwright.sync_api' (unknown
location)" was: importorskip("playwright") found the stub, declined to skip, and
the real harness import then died on Page. "unknown location" is the tell -- a
hand-built ModuleType has no __file__.

Worse than the two red tests are the six false greens: harnesses that import only
sync_playwright imported clean against the fake and passed while testing nothing.
Those now skip correctly.

Restore whatever was there before rather than popping the keys, so a partially
imported real playwright is not damaged, and add a test that fails if a stub
without a __file__ is ever left behind again.

This failure is pre-existing: it reproduces at 0775936^, so it predates the
mmproj work rather than being fallout from it.
…quests

The smoke's stub allowlist named the per-message endpoint
/threads/{id}/messages/{mid}/forks. Fork counts were since batched into one
whole-thread GET, so that pattern matched nothing: the stub still looked present
and correct while the real request went to the network, three times inside the
measured actions -- once while seeding, once after the delete's
notifyChatHistoryUpdated, once when the reopened thread resubscribes.

The request legitimately fires, so this is an allowlist entry that went stale
rather than app fan-out, and the fix belongs in the harness. Match the per-thread
URL and answer with {"counts":{}}, the shape getThreadForkCounts parses, so every
badge reads 0 and the fixture does not grow DOM in proportion to thread size --
the axis being measured.

The guard that was supposed to catch this pinned only the response body, which is
why it rotted silently. Build the URL the app builds and require the allowlist
pattern to match it, so the next rename fails in a browserless test that costs a
second instead of as two stray requests in a browser smoke.

The HARNESS-BROKEN guard itself is untouched. It was right.

This was masked behind the mmproj import failure: the job aborts at Unit tests, so
it never reached this step until that was fixed.
@danielhanchen danielhanchen changed the title Give the mmproj-fallback import its extension, so main goes green Fix the five ways main is red Aug 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed the extensionless import in studio/frontend/src/features/chat/utils/image-input-support.ts is still there on main and that the playwright stub leak in tests/studio/test_heavy_thread_measurement_integrity.py is pre-existing, so the direction is right. Could you split this so the import fix lands on its own and the harness and test repairs follow separately, since the branch is conflicting and overlaps #9189 and #9200?

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: ca9a5067c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

Closing as superseded. Every fix here reached main by another route while this sat unreviewed.

Checked file by file against main rather than by title:

  • studio/frontend/src/features/chat/utils/image-input-support.ts: the mmproj-fallback import already carries the .ts extension on main.
  • studio/backend/tests/test_tp_vision_regression.py: the landmark-existence loop that replaces the bare raise_idx < src.find(x) is on main, arriving with Say both load fallbacks when both fire, and repair the two suites that guard it #9189, and the surviving text of that assertion is the reasoning written here.

The remaining five files are test and smoke files whose fixes landed the same way. The branch is 142 commits behind main and reopening it would mean re-resolving all of that to add nothing.

Worth keeping the reasoning, since it recurred twice more today. A bare raise_idx < src.find(x) reads as an ordering assertion but is really two claims, and when the landmark moves it fails as assert 249423 < -1, which points at the ordering rather than at the rename. That is what happened when #9173 renamed _last_spawn_cmd to _vision_gpu_cmd with no behavioural change. The same rename went on to break the Python job on #9058 and needed handling again in #9515.

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