Skip to content

Studio: say why a generation or a model load failed, and offer the log - #8804

Merged
danielhanchen merged 59 commits into
mainfrom
studio-surface-failure-reason
Sep 28, 2026
Merged

danielhanchen merged 59 commits into
mainfrom
studio-surface-failure-reason

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #8690. That PR gave people somewhere to look; this one points at it, and stops two surfaces throwing the reason away first.

From the same report:

I got a very nebulous "llamacpp failed to start" and that was it. Where is the log? no clue.

it fails again. It thinks a bit, and then says "video generation failed". Why? No clue.

Video threw the reason away

core/inference/video.py logged the exception and then replaced it with the constant "Video generation failed.". It now classifies, with fixed text only (never the engine's own message, which can carry local paths and argv):

failure what the user is told
OOM under native SDPA lower the resolution or the frame count (the score matrix is quadratic in tokens)
OOM otherwise the device ran out of memory, try a smaller resolution, fewer frames, or fewer steps
native crash (sd-cli exited, ggml_abort, signal, lost connection) the renderer stopped unexpectedly, see Settings > Logs
anything else the bare fallback, unchanged

The synchronous 500 in routes/video.py uses the same classifier.

Image generation had two branches that skipped its classifier

/images/generate and /v1/images/generations named the bare fallback for any non-RuntimeError, so the same OOM named its cause or not depending on which class torch raised. Both go through _generate_failure_detail now.

The GGUF load diagnostic was one run-on line

The backend already builds a real diagnostic (summary, llama-server tail, Full log: <path>), but it was the title of a toast with no white-space rule, so every newline collapsed. Summary is now the title, the rest the description, with pre-wrap on both.

View logs

  • A load failure whose diagnostic names a log offers View logs, which opens Settings > Logs on that exact file. The path is matched server-side (diagnostic_path on the sources route, canonicalised through the module's _identity), since the runner prints whatever spelling UNSLOTH_STUDIO_HOME had while the listing reports a realpath. By exact file rather than newest-in-family: a failed switch rolls back, and the rollback writes a newer log of a load that succeeded.
  • An image or video failure the server logged (the classified messages) offers View logs on the server family. Client-input refusals, which carry their own text and are never logged, offer nothing.
  • Only offered to an account that can open Settings > Logs (owner-only).

Not in this PR

sd.cpp drains its renderer output into an in-memory deque at logger.debug, so after a native image failure the server log holds the classified error and traceback but not the renderer's own output. That is a logging change, and the prerequisite for #8666 being diagnosable from the UI.

Verification

  • Backend: test_debug_log_sources.py, test_video_routes.py, test_openai_images_generations_route.py, test_diffusion_routes.py, test_video_backend.py: 711 passed. New cases: OOM and native crash classification (including sd-cli exited -6 / 3221225477 with an assertion-only tail), unclassified failure keeping the bare fallback, and exact-path matching across a raw, relative and unexpanded ~ spelling.
  • Frontend: npm test 9331 / 9332 (the one failure, tauri-backend-transport-failure, is a timing test this PR does not touch and passes 16/16 on its own), npm run typecheck clean, npm run i18n:check:strict parity across all 12 locales.

Before / after

Two isolated installs, the merge base (949b94a) and this branch (5b423b9), driven through the same scene: a 69-byte GGUF that parses and cannot run is planted in a scan folder and picked from the chat picker's On Device tab. Both sides reach the same real llama-server refusal, key not found in model: llama.context_length.

GGUF load failure toast, before and after

Read from the DOM of the same servers photographed:

before after
toast title 1740 chars, the whole diagnostic 113 chars, the summary line
title white-space normal (newlines collapsed) pre-wrap
description absent 1637 chars, one runner line per line
action none View logs
carries Full log: <path> yes yes

Three complaints from the same report, all of the shape 'it failed and I
have no idea why'. Settings > Logs gave people somewhere to look; nothing
pointed at it, and two of the three surfaces had thrown the reason away
before it got that far.

Video threw it away. core/inference/video.py logged the exception and then
overwrote str(exc) with a bare literal, so the transport carried a
constant. It now classifies, reusing the OOM and math-SDPA detection #8233
already does for the log: an OOM under native SDPA names the quadratic
score matrix and says to lower resolution or frames, a plain OOM says what
to reduce, a native crash points at the log. Fixed text only, never the
engine's own message, matching the image classifier's rule about paths and
argv. The synchronous 500 uses the same classifier, so which handler caught
a failure no longer changes what the user is told.

Image generation had two branches that skipped its classifier and answered
the bare fallback, so an OOM named its cause or not depending on which
class torch raised. Both route through it now, and the generate-progress
model gains the error field its load twin already had.

The GGUF load path was the opposite problem: the backend already sends a
summary, the llama-server tail and the log's path, and it arrived intact.
It was rendered as an 8 second toast title with no white-space rule, so
every newline collapsed and a structured diagnostic read as a wall of
prose. Summary as the title, the rest as the description, and pre-wrap so
the structure survives.

All three now offer View logs, which opens the pane on the family that
failed: llama-server for a load, server for a generation. By family rather
than source id, since an id is a digest of a path the frontend cannot
compute, and at the moment of failure the newest file in the family is the
attempt that just failed.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

video.py takes main's rewritten begin_generate and keeps the per-run
reset of the resolved shape inside the lock that reserves the job. The
worker's failure path records the classified reason and reports the same
one to the client, rather than the outcome keeping the bare fallback.

routes/video.py classifies at main's relocated handler inside the
auto-switch retry loop; the handler the branch had added ahead of it is
gone from that position on main. routes/inference.py keeps main's
_generate_failure_detail and extends it to both bare-Exception arms.

The settings store carries logFamilyRequested through requestsFor, the
sibling openers and closeDialog, so a pending View-logs request has the
same lifetime as the archive and connection ones. openLogs adopts
focusForOpen. The Logs tab keeps main's log-root read.

test_video_routes uses main's _shared_setup_4 helper. debug-log-export
gains a stub for the store the tab now imports.
The action and the logFamilyRequested request had no test on any of the
three surfaces that raise them. The only test loading the Logs tab is
stubbed to the no-request branch, so it could neither exercise nor
detect any of it.

Asserts the action's label comes from the shipped catalogue, that a load
failure asks for llama-server and a generation for server, and the
request's lifetime: consumed by the panel, kept across a navigation
landing back on Logs, dropped by any other tab, by closeDialog, and by
each sibling opener.

Removing the requestsFor entry fails the lifetime case 5 pass / 1 fail,
so that one is a real control rather than a restatement.
Two review items on the View logs action.

This hook loads GGUF diffusion models as well, and llama_cpp.py writes
their runner output under logs/diffusion-server, which
utils/debug_log_sources.py names as its own family. A fixed
llama-server therefore opened an unrelated LLM log for exactly the
loads whose diagnostic the action exists to surface. The family is now
chosen from the resolved target and diffusion-server joins
FailureLogFamily.

Family recency also picks the wrong file after a rolled-back switch.
performLoad reloads the previous model before rethrowing, and that
rollback writes a newer log in the same family, so the newest one is
the attempt that SUCCEEDED. llama_cpp.py already appends
"Full log: <path>" to the message it raises, so the action now carries
that path and the tab prefers the source whose realpath matches,
falling back to family recency when a diagnostic has no path in it.

The path rides with the family and is dropped with it, so a later visit
cannot land on a stale file.

npm test 8175 pass, typecheck clean, i18n:check:strict parity.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 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 ⚠️ Failed 2026-09-28T16:08:43.237465Z e8a7230 New commits
🔒 Security Review ✅ Completed 2026-09-21T11:52:17.462900Z 100a810 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.

@shimmyshimmer

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 100a810142

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ures to the server log

Two ways View logs still opened the wrong file.

Only a GGUF load goes through a runner that writes its own file per attempt.
A Transformers or MLX load reaches the same catch in performLoad, and its
reason is in the backend's current server log, but the family was picked from
isDiffusion alone so those answered llama-server: on a host with any older GGUF
attempt that opens an unrelated runner log, which reads as the reason and is
not. The decision moves into loadFailureLogFamily(isGguf, isDiffusion).

The exact-path match compared strings across a boundary where the two sides
spell paths differently. _swa_cache_path() builds Path(home) raw, so with a
relative or unexpanded UNSLOTH_STUDIO_HOME the runner reports a relative path
or one with a literal ~ component while list_sources() reports an
os.path.realpath. Equality missed and the viewer fell back to family recency,
which after a rolled-back load is the newer log of the attempt that succeeded,
the confusion carrying the path was meant to prevent.

So match it where both spellings are known. debug_log_sources gains
source_id_for_path, which canonicalises through the existing _identity (the
Windows extended-length-prefix and case quirks it already documents) and tries
both the raw and the expanded spelling, the way _scan_roots does. The sources
route takes an optional diagnostic_path and answers matched_source_id, always
an id already in its own allowlist, and the tab selects by that id. Additive
and optional: a caller sending no path, or an older client, is unaffected.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 21, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits September 21, 2026 12:34
Settings > Logs is owner-only and resolveSettingsTab sends a managed account
asking for it to General, while /debug/logs/sources is owner-guarded as well.
A non-owner can still run an image or video generation, or a model load, so the
unconditional action opened Settings on an unrelated tab and read as a broken
link rather than as a route to the reason.

viewLogsAction now returns undefined for a non-owner. Every call site already
passes the result straight through as sonner's action, where undefined renders
nothing, so no button beats a dead one. Ownership comes from a new non-hook
isAccountOwner(), since two of the call sites raise their toast from a callback
outside a component body; useIsAccountOwner now reads through it.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

performLoad's catch also sees PREFLIGHT failures: a rejected staged-metadata
read, a cancelled HF token prompt. Those reach it before the load request goes
out, so no runner was started and no file of its own exists, but the family was
chosen from the artifact type alone and answered llama-server or
diffusion-server. View logs then opened the newest unrelated prior attempt on
the host, which reads as the reason for this failure and is not.

loadFailureLogFamily takes runnerAttempted, set where the load request is
issued, and falls back to the server log without it. Same question as isGguf in
time rather than in kind: a GGUF load that dies in preflight has no runner log
either.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 21, 2026
loadModel prepares the HF token itself and only then sends the request, so a
flag set before the call was already true when that preparation prompted and
was cancelled. A local or native GGUF pick skips the outer preparation, which
is exactly where the inner one can prompt, and the failure then offered the
newest unrelated runner log for an attempt that never happened.

loadModel already has an onRequestStart callback, fired after the token and
after the abort check and immediately before the POST, for the same reason the
load notice uses it. Set the flag there.

tests/load-request-start-boundary.test.ts drives the real module and pins that
ordering as a contract: announced between the token and the request, and never
announced at all for a cancelled prompt or an abort landing during it.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 21, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

authFetch's account-transition gate refuses locally, with no request going
out, and loadModel announced the send before calling it, so a failed load
offered the server log for a request the backend never saw.

authFetch takes an onRequestStart option now and fires it immediately before
the transport, and loadModel hands its caller's callback through. Both callers
gain the stricter guarantee, chat's log decision and Audio's requestStarted
cancel, and the ordering they relied on is unchanged: after the token prompt,
before the POST.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The route retries a DiffusionModelReplacedError once, so the first raise is
not an outcome. The engine had already published the reason on both channels,
and an unscoped progress poll has no attempt id to be marked live by, so an
Images page opened during the queued retry read a terminal failure for a run
that was about to start again. Both records are dropped before the retry lap,
which records its own outcome; the second replacement keeps its 409.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

if not isinstance(raw, str) or not raw.strip():
return None
wanted = set()
for spelling in (Path(raw.strip()), Path(raw.strip()).expanduser()):
…eration as pending

A reloaded page loses its attempt id and polls without one. While its request waits for the
generation slot the engine still holds the previous run's failure, so the page toasted that stale
reason and stopped polling. Also scope the wiring test to the whole route body.
…sist failure like /images/generate

The video classifier missed the runner's own 'sd-cli exited <code>' diagnostic, so a native
video crash still read as the bare fallback. The OpenAI images route wrote its persist failure
into the unscoped slot of whichever engine was active, over a later execution's reason.
Keep the video failure classifier, the image routes' two unclassified branches, the multi-line
load diagnostic as title plus description, and View logs opening the exact log the diagnostic
names. Drop the per-attempt failure retention for lost POSTs (main's settleLostGeneration already
recovers the result), the request-start plumbing, and the tests that only covered them.
… route already has

Opening Logs from a failure toast walked every log directory a second time (about 9 ms more per
request on 500 files, a 50% rise); the route now hands its own listing over.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

A 404 recovery reselect that finished after a View logs fetch replaced the exact failure log
with the default one.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 5b423b9b5d

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

chatgpt-codex-connector[bot]

This comment was marked as resolved.

A stale sources response now bails before touching any state, a repeated identical View logs
click carries its own sequence so a mounted Logs tab refetches, and a failed video save offers
its log like a failed image save.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 27bb73bb65

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants