Skip to content

Add per-attempt logs for managed SGLang - #19166

Merged
danielhanchen merged 6 commits into
unslothai:mainfrom
Imagineer99:feat/managed-sglang-logs
Nov 24, 2026
Merged

danielhanchen merged 6 commits into
unslothai:mainfrom
Imagineer99:feat/managed-sglang-logs

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Managed SGLang startup failures can be hard to diagnose once a user retries. This change captures a separate runtime log for each launch attempt and makes View logs open that exact file in Settings, including after a later attempt succeeds.

  • Redact credentials and private paths before writing engine output to disk.
  • List saved attempts in the existing log picker. Installing the engine alone does not create a log entry. Retained files remain available after unload or removal.
  • Bound log size and retention, and let the engine continue when its log cannot be written. External Connections keep their existing behavior.

Verification

214 backend and 69 frontend checks passed, along with frontend type checking. Real SGLang runs exercised startup failure, successful retry, lookup of the failed attempt, and unload on Windows using the private WSL guest and with Unsloth running inside WSL. macOS and AMD checks were simulated. Bare-metal Linux was not exercised.

This PR introduces the shared capture and Settings integration used by the dependent vLLM change.

Screenshots

Settings > Logs, with SGLang attempt logs placed in the Studio home. Before (merge base), the picker lists only server logs. After, the SGLang attempts appear under their own heading.

Settings Logs picker before and after

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T12:42:47.752314Z 034d7d4 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.

@danielhanchen

Copy link
Copy Markdown
Member

The (Python 3.13, g-l) red here is from this PR, not main. studio/backend/tests/test_log_bounds.py passes on main, but on this branch it fails:

TestFamiliesAreBounded.test_every_python_written_family_prunes: assert not ['sglang (sglang-*.log)']
TestFamiliesAreBounded.test_a_new_family_cannot_be_added_unnoticed: assert not ['sglang']

The new sglang family registered in debug_log_sources.FAMILIES is written, but no pruner names its sglang-*.log glob, so those logs would grow for the life of the install. Pruning them where they are opened (keep the newest N, as the other managed-engine logs do) should clear both cases.

The other reds on this PR (lint, rest, rest-2, frontend, Core zoo) come from its base being older than the fixes now on main. A rebase onto main should clear them.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 055bc4eb66

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 24, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 034d7d4b3d

ℹ️ 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 af0221b into unslothai:main Nov 24, 2026
6 of 71 checks passed
danielhanchen added a commit that referenced this pull request Nov 24, 2026
…in (#19272)

## Problem

`studio/frontend/tests/load-refusal-header.test.ts` fails on main in
`Frontend unit tests`, so every open PR inherits it:

```
not ok - Images, Video and chat raise the refusal under its title, with the owner's settings link
  AssertionError: features/chat/hooks/use-chat-model-runtime.ts missing: ? modelMemorySettingsAction()
                : (engineSettingsAction(message) ?? logsAction);
```

## Cause

#19166 (per-attempt logs for managed SGLang) is correct. When a managed
engine fails to load, the chat toast now offers that engine's own log
first:

```ts
const action = refusal
  ? modelMemorySettingsAction()
  : (managedLogsAction ?? engineSettingsAction(message) ?? logsAction);
```

A refusal still gets the owner's model memory settings link. The test
pinned the whole non-refusal chain as one literal string, so adding an
action at its head broke it.

## Fix

That one literal is replaced with a structural check of what the test is
about:

- a refusal shows `modelMemorySettingsAction()`;
- any other failure still falls back to `engineSettingsAction(message)
?? logsAction`.

Actions ahead of those, like a managed engine's own log, are allowed.
The Images, Video and chat pins for the refusal check and its title are
unchanged.

## Verification

- `load-refusal-header.test.ts`: 7 pass here. On main, 1 of them fails.
- Making a refusal show `logsAction` fails the test.
- Dropping `engineSettingsAction(message)` from the chain fails the
test.
- The `use-chat-model-runtime.ts` from before #19166 still passes.
danielhanchen added a commit that referenced this pull request Nov 24, 2026
## Problem

`studio/backend/tests/test_log_bounds.py` fails on main in the backend
`(Python 3.13, g-l)` shard. It also shows on staging runs, for example
for #19113:

```
TestFamiliesAreBounded::test_every_python_written_family_prunes
  these log families are written but never pruned: sglang (sglang-*.log)
TestFamiliesAreBounded::test_a_new_family_cannot_be_added_unnoticed
  new log families: sglang
```

## Cause

#19166 (per-attempt logs for managed SGLang) added the `sglang` family,
and its logs are pruned: `ManagedEngineLog.open` calls
`prune_log_dir(directory, f"{engine}-*.log", protect = path)` after
opening each attempt's file. The guard could not see that, for two
reasons:

- it only reads `run.py`, `log_retention.py`, `llama_cpp.py` and
`lemonade_server.py`;
- it looks for the literal glob `sglang-*.log`, which an f-string never
contains.

The reviewed list also did not name the new family. So this is a guard
gap, not unbounded logs.

## Fix

- `managed_engine_log.py`: prune with the `pattern` it already reads
from `MANAGED_ENGINE_LOG_FAMILIES`. It is the same value, but now the
family table is the one place the glob is defined.
- `test_log_bounds.py`:
- managed engine families are proved by running the code.
`test_a_managed_engine_log_prunes_its_family_on_open` is parametrised
over `MANAGED_ENGINE_LOG_FAMILIES`. It fills a temp studio home with
`DEFAULT_KEEP + 5` old logs and opens a new one, then checks:
    - exactly `DEFAULT_KEEP` remain;
    - the new handle is kept;
    - the oldest is gone.
- the source scan skips these families instead of grepping for their
glob;
- `sglang` joins the reviewed list. A future managed engine still fails
`test_a_new_family_cannot_be_added_unnoticed` until someone adds it
there, and the behavioral test covers it automatically.

## Verification

- `test_log_bounds.py` and `test_managed_engine_logs.py`: 17 passed. On
main, 2 fail.
- Sabotage:
- replacing the `prune_log_dir` call with `pass` fails
`test_a_managed_engine_log_prunes_its_family_on_open[sglang]`;
- adding a `vllm` entry to `MANAGED_ENGINE_LOG_FAMILIES` fails
`test_a_new_family_cannot_be_added_unnoticed`.
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 24, 2026
Depends on unslothai#19166. Review the [five-file vLLM
diff](Imagineer99/unsloth@0a27ec2...a2c4c9e).
Both PRs target upstream main, so GitHub also shows the shared SGLang
changes here until the dependency lands. If unslothai#19166 is squash-merged,
this branch will need a rebase.

Enable per-attempt logging for managed vLLM using the shared capture and
Settings viewer. Each process launch gets its own redacted log,
including automatic retries for Mamba limits and drafter compatibility.
A failure's **View logs** action keeps pointing to the corresponding
attempt after a retry.

### Verification

29 backend checks passed and two were skipped. All 74 frontend checks
and frontend type checking passed. Real vLLM runs exercised startup
failure, successful retry, exact failed-log lookup, and unload on
Windows using the private WSL guest and with Unsloth running inside WSL.
macOS and AMD checks were simulated. Bare-metal Linux was not exercised.


### Screenshots

Settings > Logs, with two SGLang and two vLLM attempt logs placed in the
Studio home. Before (merge base), the picker lists only the server log.
After, it groups the SGLang and vLLM attempts under their own headings.

![Settings Logs picker before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/19167/pr19167_logs-ebbd1dc386af.png)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
danielhanchen added a commit that referenced this pull request Nov 24, 2026
#19296)

## Problem

`studio/backend/tests/test_managed_engine_readiness_poll.py` fails on
main (6 of 9 tests) and on every PR based on it, for example #19284 and
#19285, which do not touch Studio:

```
>   child_env["WSL_UTF8"] = "1"
E   TypeError: 'NoneType' object does not support item assignment
```

## Cause

Two PRs merged within an hour of each other, each green on its own base:

- #19167 added `vllm` to `MANAGED_ENGINE_LOG_FAMILIES`, so a vLLM start
now captures logs and, on the WSL path, sets `child_env["WSL_UTF8"] =
"1"` on the environment `_wsl_command` returns (the SGLang half of this
came in #19166).
- #19242 added this test file. Its `_wsl_command` stub returned
`(command, None)`, and its base predated #19167, so vLLM did not capture
logs there and the `None` was never touched.

The code is right: the real `_wsl_command` always returns
`wsl_host.guest_command(...)`, whose second element is the `wsl.exe`
environment dict, and `test_managed_engine_logs.py` already stubs it
with `dict(os.environ)`. The stub was the part that did not match the
contract.

## Fix

- The stub returns `dict(os.environ)`, the same shape the real launcher
hands back.
- The fixture sets `UNSLOTH_STUDIO_HOME` to `tmp_path`, since the vLLM
start now opens a per-attempt log under the Studio home and the tests
should not write into the real one.

No product code changes.

## Verification

- `tests/test_managed_engine_readiness_poll.py`: 9 passed (6 failed on
main before the change).
- Reverting only the stub's return value back to `None` brings back the
same 6 failures.
- `test_managed_engine_logs.py`, `test_engine_ports.py` and this file
together: 50 passed; this file under `-n 4`, 3 repeats: 27 passed.
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.

2 participants