Repository navigation
Fix the Backend CI test failures after the branch-restore and Omni routing merges - #13173
Conversation
… and Omni routing merges test_new_chat_context_recount: #13109 made the history restore estimate the selected branch (estimateContextUsage(branch)) instead of every stored row. The product change is right; the harness that replays the sliced restore did not bind the loader's new `branch` local, so every history-hydration case threw "branch is not defined", and the binding guard's self-check still pinned `msgs`. Bind `branch` with the real orderBySelectedBranch and resolveSavedBranchHead from message-order.ts, the way the loader computes it without a saved head, and make the guard's self-check require only the destructured remoteId plus one plain local, not a specific input of the block. test_omni_text_only_load: #13087's _route tests call FastModel.from_pretrained, which repoints transformers' LOSS_MAPPING at Unsloth's Triton loss for the whole process before the route is captured, and never undo it. Any Omni forward with labels later in that xdist worker then ran Triton on the CPU runner ("0 active drivers"), so 0 to 4 of these tests failed depending on scheduling. Stub patch_loss_functions in _route, which routing does not need, and have the Omni tests use transformers' own causal-LM loss on a CPU host so another leaker cannot break them; on a GPU host they keep Unsloth's loss.
|
@codex review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2fbdccdb4e
ℹ️ 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".
| for key, fn in list(loss_utils.LOSS_MAPPING.items()): | ||
| if getattr(fn, "__name__", "") != "ForCausalLMLoss" and "Unsloth" in repr(fn): | ||
| monkeypatch.setitem(loss_utils.LOSS_MAPPING, key, loss_utils.ForCausalLMLoss) |
There was a problem hiding this comment.
Restore loss mappings after loader tests
On a worker that starts with the stock mapping, this setup loop records no monkeypatch changes, but _capture_fast_base_kwargs subsequently calls FastModel.from_pretrained, whose loader.py:2457 invocation mutates LOSS_MAPPING; teardown therefore leaves the Triton loss installed. If the worker starts contaminated, teardown instead restores the contaminated values captured here. Consequently, another CPU forward test scheduled later in the same --dist loadgroup worker can still fail with 0 active drivers; snapshot the mapping, install the stock loss for the test body, and restore the complete snapshot after yielding.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 10f72cd: the fixture now snapshots LOSS_MAPPING, installs the stock loss for the test body on CPU, and restores the full snapshot afterwards.
| // it follows the newest stored row to its leaf, as the loader does without one. | ||
| const branch: any[] = orderBySelectedBranch( | ||
| msgs, | ||
| resolveSavedBranchHead(msgs, props.savedHeadId ?? msgs.at(-1)?.id), |
There was a problem hiding this comment.
Derive the fallback head after sorting messages
When props.messages is not already ordered by timestamp, msgs.at(-1) is not necessarily the newest stored row. The real loader sorts msgs in runtime-provider.tsx:2642-2648 before using the last row as the fallback at line 2672, so this harness can select and price a different branch from production. A branch-restoration test using unsorted storage records can therefore pass or fail against behavior users never receive; sort with compareStoredMessages or otherwise select the newest row before resolving the fallback head.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 10f72cd: the harness now sorts msgs by createdAt, role and id before taking msgs.at(-1), as runtime-provider.tsx does.
…ness messages like the loader The Omni fixture now snapshots LOSS_MAPPING, installs transformers' own loss for the test body on CPU, and puts the full snapshot back afterwards, so a load inside the test (_capture_fast_base_kwargs) cannot leave the Triton loss behind for the next test in the worker. The recount harness sorts the stored messages by createdAt, role and id before taking msgs.at(-1) as the fallback head, as runtime-provider.tsx does, so an unsorted fixture cannot price a branch the loader would not select.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
Backend CI on main fails two shards for test-only reasons. The product code is right in both cases, and only test files change.
1.
tests/studio/test_new_chat_context_recount.py(Repo tests, studio shard): 8 failures#13109 ("reopen a chat on the branch it was left on") made the history restore estimate the selected branch,
estimateContextUsage(branch), instead of every message inmsgs. That is correct. The test lifts that restore block out ofruntime-provider.tsxand runs it in a harness, which caused two failures:branch, so it fails withReferenceError: branch is not defined.msgs.Fix:
branchwith the realorderBySelectedBranchandresolveSavedBranchHeadfrommessage-order.ts, the same way the loader does when no head is saved.remoteIdplus at least one other loader local, instead of pinningmsgs.test_new_chat_context_recount.pyNegative control: with the
branchbinding removed, the same 8 tests fail and the guard names the cause ("reads the loader locals ['branch'], which hydrateThreadUsage does not declare").2.
tests/test_omni_text_only_load.py(Repo tests, rest shard): 0 to 4 failures per run,RuntimeError: 0 active drivers#13087's new
_routetests intests/test_omni_auto_class_resolution.pycallFastModel.from_pretrained. Before the route is captured, that reachespatch_loss_functions(torch_compile = False), which points transformers'LOSS_MAPPINGat Unsloth's Triton loss for the whole process.Any later Omni forward with labels in the same xdist worker then runs Triton on the CPU runner. How many tests fail depends on which worker they land on, which matches main's history of 4, 1, 0 and 1 failures.
The process-wide loss patch is intended Unsloth behaviour, and fast CE has never had a CPU path, so this is not a user-facing CPU regression.
Fix:
_routestubsloader.patch_loss_functions, since routing needs none of it.ForCausalLMLoss. On a GPU host they keep Unsloth's loss as before.Verification (Python 3.13, CPU torch, same installs as Backend CI)
With
test_import_fixes_drift.pyadded, under-n 4: 160 passed, 14 skipped.