Skip to content

Fix the Backend CI test failures after the branch-restore and Omni routing merges - #13173

Merged
danielhanchen merged 2 commits into
mainfrom
fix-main-ci-backend-1009
Oct 10, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix-main-ci-backend-1009

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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 in msgs. That is correct. The test lifts that restore block out of runtime-provider.tsx and runs it in a harness, which caused two failures:

  • The harness never defined branch, so it fails with ReferenceError: branch is not defined.
  • The harness's own guard still required the block to read msgs.

Fix:

  • The harness now builds branch with the real orderBySelectedBranch and resolveSavedBranchHead from message-order.ts, the same way the loader does when no head is saved.
  • The guard's self-check now requires the destructured remoteId plus at least one other loader local, instead of pinning msgs.
main this branch
test_new_chat_context_recount.py 8 failed, 56 passed 64 passed

Negative control: with the branch binding 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 _route tests in tests/test_omni_auto_class_resolution.py call FastModel.from_pretrained. Before the route is captured, that reaches patch_loss_functions(torch_compile = False), which points transformers' LOSS_MAPPING at 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:

  • _route stubs loader.patch_loss_functions, since routing needs none of it.
  • The Omni text-only tests get an autouse fixture that, on a CPU host only, puts back transformers' own ForCausalLMLoss. On a GPU host they keep Unsloth's loss as before.
Route + Omni files together result
main 4 failed, 39 passed
route fix only 43 passed
Omni fix only 43 passed
both 43 passed

Verification (Python 3.13, CPU torch, same installs as Backend CI)

All three files in one process result
main 12 failed, 95 passed, 8 skipped
this branch 107 passed, 8 skipped

With test_import_fixes_drift.py added, under -n 4: 160 passed, 14 skipped.

… 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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T01:19:44.461350Z 10f72cd Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-10T00:25:07.671947Z 2fbdccd PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 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".

Comment thread tests/test_omni_text_only_load.py Outdated
Comment on lines +35 to +37
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

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.

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),

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 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 👍 / 👎.

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.

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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 10f72cdf79

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

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