Skip to content

Wait for the model load before reading the unsloth run banner - #11679

Merged
danielhanchen merged 2 commits into
mainfrom
fix/serve-banner-waits-on-load
Sep 23, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/serve-banner-waits-on-load

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

connection (opencode, stable) failed on #11603 with:

[serve] /api/health healthy
::error::Unsloth server/API regression: could not parse an API key from the banner (banner-parse fragility -- check the 'API Key:' line in unsloth_cli/commands/studio.py)

The banner had not changed. The server log shows it had not been printed yet:

13:11:04.593  GET /api/health 200
13:11:05      Loading model: .../gemma-4-E4B-it-UD-Q4_K_XL.gguf...
13:11:20.186  Model load exceeded 15s; padding the response so a proxy cannot time it out
(step fails about 30s after health, no banner yet)

Cause

unsloth run answers /api/health before it loads the model. It prints the banner, including API Key:, only when the load finishes. After health, serve-unsloth-run.sh gave the banner 30 one-second polls. That is usually enough: on the same base, #11666's opencode leg read the key 10s after health. Here the 4.8 GB GGUF took longer on a busy CPU runner, and the script reported a banner regression while the model was still loading.

It is rare. I checked the last 40 failed runs of this workflow and found this one occurrence. Every leg on every PR goes through this script, though, and the error sends whoever reads it to studio.py for a bug that is not there.

The product is right and the script was wrong: a fixed 30s window was standing in for "until the load finishes".

Change

.github/scripts/serve-unsloth-run.sh now waits for the banner as long as the load is actually going:

  • Waits for the key: it polls until an sk-unsloth- key appears, up to --banner-timeout. The default is 300, the same as --health-timeout.
  • Stops early on an exited server: if the server exits first, it fails at once with "process exited before printing its banner", instead of polling a dead process.
  • Separate messages for a slow load and a changed banner:
    • A timeout with no banner says the model is still loading.
    • An API Key: line without an sk-unsloth- token still goes to the existing fallback. If that finds nothing, it gives the original banner-parse message.

The script is shellcheck clean.

Test

tests/studio/test_serve_unsloth_run_waits_for_the_load.py runs the real script against stand-in unsloth and sleep commands on PATH:

  • The unsloth stand-in is a small HTTP server that is healthy at once and holds its banner back for a set number of polls.
  • The sleep stand-in counts its calls, so one call is one of the script's one-second polls. That makes the test deterministic and under 2 seconds.

It has two cases:

  • Slow load: the banner comes 40 polls after health, past the old window. The script reads the key and resolves /v1/models.
  • Dead server: the server exits during the load. The script fails with the new message within a few polls.

Sabotage: against main's script, both cases fail. The first fails with the same could not parse an API key from the banner that CI showed.

unsloth run answers /api/health before it loads the model and prints its
banner, API key included, only once the load finishes. serve-unsloth-run.sh
gave the banner 30 one-second polls after health, which a 4.8 GB GGUF on a
busy CPU runner outlasted, and the connection leg reported a banner-parse
regression while the model was still loading.

Poll until the key appears, the server exits, or --banner-timeout (300,
like --health-timeout) runs out, and say which of the three it was.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 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-09-23T14:10:06.828060Z e851200 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 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: 107cc0eb18

ℹ️ 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 on lines +86 to +87
# Counts a call and returns: the script's `sleep 1` becomes one poll.
STANDIN_SLEEP = '#!/bin/sh\nprintf x >> "$SLEEP_COUNTER"\nexec /bin/sleep 0.01\n'

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 Start counting banner polls only after health succeeds

When the Python stand-in takes at least ten mocked sleeps to bind on a busy runner, this shared counter has already advanced before /api/health succeeds, so banner_after = 40 leaves no more than the old 30 banner polls and the pre-change script can pass this regression test. The same coupling can make the -5 case exit before health and produce the wrong diagnostic. Reset or separately track the counter once health is observed so these tests measure the banner-wait phase they intend to exercise.

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 e851200: the stand-in records the poll count when it first answers /api/health and delays the banner (or its exit) from there, and the reported polls exclude startup. The slow-load case now also holds health back for 15 polls, which is the scenario described: main's script still fails it, and the branch passes.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: e851200eab

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

@danielhanchen
danielhanchen merged commit aede992 into main Sep 23, 2026
3 of 36 checks passed
@danielhanchen
danielhanchen deleted the fix/serve-banner-waits-on-load branch September 23, 2026 14:51
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…hai#11679)

* Wait for the model load before reading the unsloth run banner

unsloth run answers /api/health before it loads the model and prints its
banner, API key included, only once the load finishes. serve-unsloth-run.sh
gave the banner 30 one-second polls after health, which a 4.8 GB GGUF on a
busy CPU runner outlasted, and the connection leg reported a banner-parse
regression while the model was still loading.

Poll until the key appears, the server exits, or --banner-timeout (300,
like --health-timeout) runs out, and say which of the three it was.

* Count the stand-in's banner polls from its first health answer
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