Skip to content

Repair the two studio test suites #9410 left behind - #9437

Merged
danielhanchen merged 3 commits into
mainfrom
fix-chat-adapter-harness-server-tuning
Aug 21, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix-chat-adapter-harness-server-tuning

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Repo tests (CPU) is red on main and has been failing every PR that runs it. On a clean checkout of main (e91f9720b):

71 failed

All 71 come from #9410 (5786a0ead, "Studio: add Mmap/Mlock, draft KV cache dtype, Checkpoints and Cache RAM to Run settings"). The product code from that PR is fine and is not touched here. What did not travel with it was the test-side consequences of two of its changes.

1. The sliced-harness stubs (70 failures)

tests/studio/test_chat_autoload_failure_gate.py does not import chat-adapter.ts. It slices a region out of it, prepends a PREAMBLE of stubs, writes harness.ts into a temp directory and runs it under node. The temp directory has no module resolution, so every name the sliced region uses has to exist in PREAMBLE.

#9410 added three imports to chat-adapter.ts:

clearedServerTuningState
committedServerTuningState
serverTuningLoadPayload

The file's own guard caught this and said exactly what to do:

the sliced region uses ['clearedServerTuningState', 'committedServerTuningState', 'serverTuningLoadPayload'], imported by chat-adapter.ts but absent from this harness. Add a stub to PREAMBLE, or these scenarios will fail as wrong-model assertions rather than saying what is actually missing.

So the guard worked. Nobody added the stubs.

They are added here mirroring server-tuning-fields.ts rather than as neutral no-ops. serverTuningLoadPayload spreads into the /load payload that these scenarios assert on, so a stub that always returned {} would keep passing if the real one started sending a field. The three functions are pure and import nothing, so copying them is cheap, and the name-level guard above is what catches drift.

2. A hardcoded count that the same PR outgrew (1 failure)

test_hydration_clears_the_batch_baselines_for_a_batchless_model asserted:

assert status.count("modelChanged: slotsModelChanged,") == 2

apply-inference-status-to-store.ts used to seed two values through resolveBatchSizeSeed, the batch pair. #9410 deliberately routed the four tuning knobs through the same seed, with the reasoning in the source:

The llama-server tuning group follows the same rule, and resolveBatchSizeSeed is generic in the value type for exactly this: each one is an echo of what the load REQUESTED, which is what makes the steady-poll and dirty-control cases identical to the batch pair's.

Six call sites, so the assertion failed 6 == 2. The code is right and the number was stale.

The assertion the test wanted, per its own comment, is that the seeds cannot drift apart ("The batch pair is told the same thing, from the same local, so the two cannot drift"). That is now what it checks:

seed_calls = len(re.findall(r"resolveBatchSizeSeed(?:<[^>]*>)?\(\{", status))
assert seed_calls >= 2, "the batch pair alone should be two seeds"
assert re.findall(r"modelChanged: (\w+)", status) == ["slotsModelChanged"] * seed_calls

This is strictly stronger than the count it replaces. The old form only counted occurrences; this pins that every seed call site is told modelChanged from the same local, so one of them being wired to a different value fails even though the totals still match. It also stops being wrong the next time the group grows.

Result

Same command, tests/studio, four workers:

result
main at e91f9720b 71 failed
this branch 4577 passed, 4 skipped, 0 failed

Only the two test files change. No product code is touched.

#9410 added the llama-server tuning group. Two test-side consequences were not carried
with it, and both are red on main.

chat-adapter.ts gained imports of serverTuningLoadPayload, committedServerTuningState
and clearedServerTuningState. test_chat_autoload_failure_gate.py slices a region of that
file and runs it against a PREAMBLE of stubs, so the three names were undefined and 70
scenarios failed. The stubs mirror server-tuning-fields.ts rather than returning
nothing, because serverTuningLoadPayload spreads into the /load payload these scenarios
assert on.

apply-inference-status-to-store.ts now seeds six values through resolveBatchSizeSeed
rather than two, so a hardcoded count of two in test_model_picker_contracts.py failed.
The count now tracks the number of call sites and additionally pins that every one of
them is told modelChanged from the same local, which is the anti-drift property the
assertion existed for and is stronger than the number it replaces.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acc03a2779

ℹ️ 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".

# which is the property actually under test.
seed_calls = len(re.findall(r"resolveBatchSizeSeed(?:<[^>]*>)?\(\{", status))
assert seed_calls >= 2, "the batch pair alone should be two seeds"
assert re.findall(r"modelChanged: (\w+)", status) == ["slotsModelChanged"] * seed_calls

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope modelChanged matches to seed calls

The right-hand regex scans the entire apply-inference-status-to-store.ts, while seed_calls counts only resolveBatchSizeSeed calls. If this file later adds an unrelated object containing modelChanged: someOtherValue, this contract fails even when every seed is still wired correctly; conversely, an unrelated modelChanged: slotsModelChanged can mask a seed that omitted the property. Extract and validate the argument block for each matching seed call instead of comparing it with all modelChanged properties in the file.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and the masking direction is the serious one: an unrelated modelChanged: slotsModelChanged could stand in for a seed that omitted the property, so the assertion could pass while the invariant it exists for was broken. Fixed in d32e4a1: each resolveBatchSizeSeed call's own argument block is extracted with parens balanced and checked individually. Verified by mutation, dropping modelChanged from one real seed call is now caught, and an unrelated modelChanged elsewhere no longer affects the result. One thing the per-call scan surfaced: this file discusses resolveBatchSizeSeed (modelChanged) in a comment, which a raw scan counts as a seventh call site, so comments are stripped first.

A whole-file scan for modelChanged had it both ways: an unrelated one elsewhere in the
file would fail the contract with every seed wired correctly, and an unrelated one could
equally stand in for a seed that omitted the property, so the assertion could pass while
the invariant was broken. Each resolveBatchSizeSeed call's own argument block is now
checked, with parens balanced so a nested call survives.

Comments are stripped first because this file discusses resolveBatchSizeSeed
(modelChanged) in prose, which a raw scan counts as a seventh call site.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d32e4a1a3d

ℹ️ 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".

# in prose, and a scan that counted that sentence as a call site would fail on a
# wording change.
seed_args = _call_arguments(_code_only(src), "resolveBatchSizeSeed")
assert len(seed_args) >= 2, "the batch pair alone should be two seeds"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require every status seed call

The lower bound only proves that two resolveBatchSizeSeed calls remain. If any of the four server-tuning seed calls and its corresponding state spreads are removed, the code still compiles and this contract still passes because the two batch calls satisfy len(seed_args) >= 2; model changes would then retain stale tuning controls or baselines. Assert the required incoming fields/call sites explicitly so the new per-call property check also detects a missing seed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not taking this one. The lower bound does not weaken anything: the assertion it replaced was count == 2, which also passed if the four tuning seeds were deleted, so a removal guard is coverage this test never had rather than something this PR gave up. This PR exists to unbreak main, and adding a required-call-site inventory here would mean every future knob has to edit this test to stay green, which is the maintenance cost without the drift protection the per-call check already provides. The gap you describe is real, but it belongs where the consequence is observable, a behavioural test on applyActiveModelStatusToStore asserting a model change reseeds the tuning controls, not an inventory in a test whose stated remit is that the wiring which exists is consistent. server-tuning-settings.test.ts already covers the payload, commit and clamp behaviour of the four.

@danielhanchen

Copy link
Copy Markdown
Member Author

These two are the whole of main's current CI breakage, and each one's remaining red check is the other's fix:

Merging both clears main. Neither depends on the other's code, so the order does not matter.

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.

1 participant