Repository navigation
studiobench: give the action bar selftest's two clocks one origin - #9578
Merged
Merged
Conversation
The mount deadline in HARNESS_JS started at script load, but the waitedMs it was compared against starts inside waitForActionButton, which runs after two readFileSync calls, the dom.js eval, two Function compiles and V8's lazy compile of the action body on first call. waitedMs was therefore LATE_MOUNT_MS minus that setup cost, and the setup cost is whatever else the machine is doing. The 0.8 in the assertion was absorbing that offset rather than allowing for timer jitter. Arm the deadline from the action's own first look at the DOM instead, off the same performance.now() dom.js reads. waitForActionButton stamps its clock, hovers, then reads a control, and that read is the first call into the shim, so the deadline starts level with the action's clock or a hair after it and never before. waitedMs can no longer undershoot LATE_MOUNT_MS, and a loaded machine can only push the sample that ends the wait later. The bound tightens from 0.8 * LATE_MOUNT_MS to LATE_MOUNT_MS - 1, the 1 ms being dom.js rounding waitedMs to a tenth. It stays a liveness assertion and keeps its upper bound of ACTION_BAR_WAIT_MS. Measured over 40 runs each, pinned to one core against 48 spinners so setup is inflated the way the runner inflated it: before, 24 of 40 fail with waitedMs from 210 to 300 while ran, items and the open and close timings are correct every time; after, 40 of 40 pass with waitedMs from 400.3 to 417.4. Idle, before and after both sit at 403 to 405.
This was referenced Aug 23, 2026
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Aug 23, 2026
…its text (unslothai#9591) * Read the settings route's contract off its parse tree, not its text `Repo tests (CPU)` has been red on main since unslothai#9492 (1f475d7) on test_the_backfill_fills_in_fields_rather_than_skipping_known_keys. The rule the test guards did not change. unslothai#9492 added a third name to the `model_dump(exclude = {...})` set in `update_openai_auto_switch_override`, the formatter then split the set one name per line, and assert '"remove", "fill_absent_fields"' in route no longer matched, because `route` is the raw source text of studio/backend/routes/settings.py and the two names now have a newline and sixteen spaces between them. Both names are still excluded. Nothing about the write-mode-is-not-a-saved-field rule moved. This is the third failure of this shape on main in as many days (unslothai#9578, unslothai#9579), so pinning a new literal only moves the next one into the future. A test that has to be re-edited whenever a set literal is reflowed is not testing the thing it names. The frontend greps in this file have no parser to hand. The backend does. Three helpers read the rule out of settings.py's AST instead: - `_model_dump_exclusions` returns the names the one `model_dump(exclude = ...)` in a given function leaves out. Exactly one such call, or the answer would be a union and a name dropped from the call that matters could hide behind another. - `_annotated_field` returns the annotation and literal default of a field on a pydantic model, so "declared as a bool defaulting to False" is asserted as that rather than as a substring. - `_forwarded_keywords` returns the keyword arguments passed as `name = payload.name`, which is the part the storage layer depends on. Each raises rather than returning empty when it cannot find what it was pointed at, so a renamed handler or field reddens here instead of passing vacuously. Verified by mutation against the repaired test, one at a time on settings.py: | Mutation | Result | |---------------------------------------------------|--------| | unmodified main | pass | | `"fill_absent_fields"` dropped from the exclude set| fail | | the exclude set reflowed onto one line, reordered | pass | | the payload field defaulted to True | fail | | `fill_absent_fields` no longer forwarded to the db | fail | | the route handler renamed | fail | | the payload field renamed | fail | The reflow is the case that caused this outage and is now the only one that stays green; every mutation that actually breaks the contract still reddens. Local: `tests/studio/test_model_picker_contracts.py` 187 passed, was 186 passed 1 failed. No production code changed. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Selftests, lint and the single-file buildis red on main at 83539fa (run 32637092740):The test is mine, from #9297.
What was wrong
The two numbers in that assertion were measured from different origins.
HARNESS_JSarmed the mount deadline at top level,const started = Date.now(), so the shimmed bar appeared 400 ms after the harness SCRIPT LOADED.waitedMscomes fromwaitForActionButtoninscene/dom.js, whose clock starts when the action is INVOKED. Between those two instants sit tworeadFileSynccalls, thedom.jseval, twonew Functioncompiles, and V8 lazily compiling the action body on its first call.So
waitedMswasLATE_MOUNT_MSminus that setup cost, and the setup cost is whatever else the machine happens to be doing. On an idle machine it is a few milliseconds and the assertion passes. On the runner it cost about 92 ms and it did not. The* 0.8was absorbing an offset that is not constant, not allowing for timer jitter, so it did not have a value that was correct for both machines.Note what the failure payload says:
ran: True,items: 2,openMsandcloseMsboth present. The action waited for the late bar and drove it correctly. Only the number describing the wait was measured against the wrong zero.The fix
Arm the mount deadline from the action's own first look at the DOM, read off the same
performance.now()dom.jsreads, rather than at script load.The ordering is what makes this safe rather than merely closer.
waitForActionButtonstampsstarted, callshoverLastAssistantMessage(which only queriesdocument), and then reads a control. That read is the first call into the shim'smounted(), so the deadline starts level with the action's clock or a hair after it, never before.waitedMstherefore cannot undershootLATE_MOUNT_MSby any elapsed time, and a slow machine can only push the sample that ends the wait LATER, never earlier.That lets the bound get tighter rather than looser:
>= LATE_MOUNT_MS - 1instead of>= 0.8 * LATE_MOUNT_MS. The 1 ms isdom.jsroundingwaitedMsto a tenth, and it does not scale withLATE_MOUNT_MS. The upper boundwaitedMs < ACTION_BAR_WAIT_MSis unchanged, and the assertion still says what it existed to say, that the bar was absent when the wait began rather than there all along. It remains a liveness test.No change to
scene/actions.pyorscene/dom.js. The shipped code was never at fault; the harness was measuring it wrong.Measurements
40 runs per condition. Loaded means pinned with
tasksetto a single core against 48 spinners, so setup time is inflated the way the runner inflated it.The loaded failures reproduce the CI signature exactly, including
ran: Trueanditems: 2on every one of them. Pushed further, to 96 spinners on one core, the fixed test still reports min 400.5 and 0 failures.test_the_wait_is_bounded_and_a_control_that_never_appears_still_reports_not_runis sound and is left alone. Both of its numbers are on the action's own clock: the loop runs while elapsed is under 300 ms, sowaitedMs >= 300structurally. Measured at min 300.3 across 40 runs under the same load, against its bound of 250.Full job test set on this branch:
python -m pytest tests/studio/studiobench -qgives 654 passed.One thing I did not change, recorded here because I saw it.
test_a_settled_reply_costs_the_action_nothingassertswaitedMs < 50and does genuinely measure elapsed wall time, so at 96 spinners on one core it goes over on 1 or 2 runs in 40 asdom.js's methods are JIT compiled inside the measured window. That is identical before and after this change, it needs a load far past the level that reproduces the actual CI failure, and it is a different defect, so it is out of scope here.Repo tests (CPU)is also red on main right now for an unrelatedstripSearchImageTokens is not defined, which another change is handling.