Repository navigation
Give the auto-load harness the adapter's new import, and catch the next one - #7768
Conversation
…xt one main is red again: tests/studio/test_chat_autoload_failure_gate.py fails three scenarios on every PR since #7699, unrelated to what those PRs change. The harness slices autoLoadSmallestModel verbatim out of chat-adapter.ts and supplies stubs for everything it imports. #7699 replaced an inline setModels block in that region with a call to syncModelCapabilities, imported from ../hooks/use-chat-model-runtime, and the harness has no such stub. So the call is a bare ReferenceError, the retry loop around it catches that and scores it as a failed load, and a healthy model looks broken: assert _loaded_paths(out) == [GEMMA_REPO] AssertionError: assert ['unsloth/Qwen3.5-4B-MTP-GGUF', ...] == ['unsloth/gemma-...'] Nothing in the failure says what is actually missing, which is the worse half of this. So the harness now checks, before running anything, that every name chat-adapter.ts imports and the sliced region calls is defined here, and names the ones that are not. That check found two more of the same waiting: prepareHfTokenForUse and fetchGgufStagedMetadata. Both sit behind a GPU-selection branch no scenario currently takes, so they are unreached rather than broken, but they would have become this same bug on the first scenario that turned a GPU option on. Stubbed too. Bisected: 8b8eba6 passes, 2419ff1 (#7699) fails.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9a6a020c8
ℹ️ 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".
| missing = sorted( | ||
| name | ||
| for name in imported | ||
| if re.search(rf"\b{re.escape(name)}\s*\(", body) |
There was a problem hiding this comment.
Detect generic and constructor calls in the import guard
When a future imported helper is invoked with normal TypeScript syntax such as helper<Result>(), or an imported class is instantiated with new Helper(), this name\s*\( predicate does not recognize the call. The missing stub therefore passes this new guard, and the generated // @ts-nocheck harness still reaches the opaque caught ReferenceError that the guard is intended to prevent; include generic and constructor invocation forms in the check.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct about the predicate, and it is already gone at head -- this reviewed the first commit, and the second replaced \b{name}\s*\( with a bare-identifier match.
That covers both forms you name and more besides, because it does not care how the name is used: helper<Result>(), new Helper(), useChatRuntimeStore.getState(), a bare callback reference, a destructure. I went that way rather than enumerating invocation syntaxes because the failure is a ReferenceError on the identifier, so any mention of it is the thing worth catching, and an enumeration is only ever as complete as the next syntax someone uses.
Checked the two you raised against both versions:
helper<Result>() old: not flagged head: flagged
new Helper() old: flagged head: flagged
await doThing<T>() old: not flagged head: flagged
Comments are stripped from the region first so a name discussed in prose does not count as a use, and import { type Foo } specifiers are dropped since they are erased at runtime and can never be a ReferenceError.
… called
Three defects in the previous commit, found reviewing my own change.
The fetchGgufStagedMetadata stub returned is_diffusion. The call site reads
.isDiffusion, and chat-api.ts returns camelCase throughout, so the stub yielded
undefined and fed it into reconcilePersistedGpuIds and the load payload. That is
exactly the silent misbehaviour the comment above it claimed to be preventing,
which is a good argument for checking a stub against the call site rather than
against the name.
The guard only looked for a name followed by a paren, so it could not see an
import used any other way. useChatRuntimeStore, toast and GPU_LAYERS_AUTO are all
used in this region without one, and each is the same ReferenceError waiting to
happen; they pass today only because the preamble already defines them. It now
flags any mention, with comments stripped first so a name discussed in prose does
not count, and `import { type Foo }` specifiers dropped since they are erased at
runtime and can never be a ReferenceError.
The definition check rejected export-prefixed declarations, which is how half of
this preamble is already written, so the natural fix to a future failure would
itself have been refused. It accepts export and class now.
Checked that removing a bare-identifier stub is caught, which the previous
version missed entirely, and that an export-form definition is accepted.
|
Reviewing my own change before the automated pass turned up three defects in it, all now fixed. The The guard only matched a name followed by a paren, so it could not see an import used any other way. The definition check rejected Verified both directions after the change: removing a bare-identifier stub is now caught, which the previous version missed entirely, and an |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e24c37d0e
ℹ️ 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".
| # wrong-model assertion that says nothing about the real cause. That is what | ||
| # #7699 did by adding a syncModelCapabilities call here. | ||
| imported = set() | ||
| for match in re.finditer(r"^import\s+\{([^}]*)\}\s+from", "\n".join(lines), re.M): |
There was a problem hiding this comment.
Cover default and namespace imports in the harness guard
When the sliced region starts using a default or namespace import, such as import helper from "..." or import * as helpers from "...", this regex never adds the binding to imported. If the corresponding preamble stub is omitted, the new guard therefore passes and Node reaches the same caught ReferenceError that this check is intended to diagnose; parse these import forms as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right. The regex only read import { ... } from, so a default or namespace binding never entered the set and its missing stub would have passed the guard -- which is precisely the silent non-protection the guard exists to prevent. chat-adapter.ts has none today, so it was latent, but that is not a reason to leave it.
Adding them turned up a third gap I had not been asked about: the braced pattern anchored on ^import\s+\{, so the mixed form import def, { named } from had its braces skipped too.
Verified against all of them together -- default, namespace, mixed, plain braced and multi-line braced are captured, and import type { T } is still ignored, since type specifiers are erased at runtime and can never be a ReferenceError.
The guard only parsed `import { ... } from`, so a default or namespace binding
never entered the set and its missing stub would pass the check. chat-adapter.ts
has none today, which is why this was latent rather than broken, but a guard that
silently declines to look is the failure mode it exists to prevent.
Adding those turned up a third gap: the braced pattern anchored on `^import\s+\{`,
so the mixed form `import def, { named } from` had its braces skipped as well.
Verified against all of them at once: default, namespace, mixed, plain braced and
multi-line braced are captured; `import type { T }` is still ignored, since type
specifiers are erased at runtime and can never be a ReferenceError.
mainis red again.tests/studio/test_chat_autoload_failure_gate.pyfails three scenarios on every PR branched after #7699, for reasons unrelated to what those PRs change. That is how I found it.The harness slices
autoLoadSmallestModelverbatim out ofchat-adapter.tsand supplies stubs for everything it imports. #7699 replaced an inlinesetModelsblock in that region with a call tosyncModelCapabilities, imported from../hooks/use-chat-model-runtime, and the harness has no such stub. So the call is a bareReferenceError, the retry loop around it catches that and scores it as a failed load, and a healthy model looks broken:Bisected:
8b8eba615passes,2419ff199(#7699) fails.Nothing in that failure says what is actually missing, and that is the worse half. The harness now checks, before running anything, that every name
chat-adapter.tsimports and the sliced region calls is defined in the preamble, and names the ones that are not.That check immediately found two more of the same waiting:
prepareHfTokenForUseandfetchGgufStagedMetadata. Both sit behindcandidate.kind === "gguf" && (selectedGpuIds != null || tensorParallel), which no scenario currently sets, so they are unreached rather than broken today. They would have become this exact bug on the first scenario that turned a GPU option on, so they are stubbed too.The guard requires a real definition (
function/const/let/var) rather than a mention, because my first version substring-matched the preamble and a leftover comment satisfied it. Checked that removing any one stub now fails with the symbol named.