Skip to content

Extract the API-only Studio boot into one script - #8029

Merged
danielhanchen merged 1 commit into
mainfrom
ci/extract-studio-boot
Aug 6, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/extract-studio-boot

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Twenty-one steps across eight workflows ran the same five-line body, varying only in three values. .github/scripts/boot-studio-api-only.sh takes those as flags: --port, --log, --pid-var.

- name: Reset auth + boot Unsloth (API-only)
  run: |
    rm -rf ~/.unsloth/studio/auth
    mkdir -p logs
    UNSLOTH_API_ONLY=1 unsloth studio -H 127.0.0.1 -p "$STUDIO_PORT" \
      > logs/studio_tools.log 2>&1 &
    echo "STUDIO_PID=$!" >> "$GITHUB_ENV"

becomes

- name: Reset auth + boot Unsloth (API-only)
  run: |
    bash .github/scripts/boot-studio-api-only.sh \
      --port "$STUDIO_PORT" --log logs/studio_tools.log

105 lines of duplicated YAML down to 31.

Why this one is worth extracting

Three parts of that body are easy to get subtly wrong, and each failure is quiet:

  • rm -rf, not unsloth studio reset-password. The boot re-seeds a fresh .bootstrap_password only when the auth directory is absent. A caller that "resets" instead keeps the old password, and the test then authenticates against stale state rather than the state it thinks it created.
  • The pid has to reach $GITHUB_ENV. The step that stops the server is a different step with a different shell, so $! alone dies with the step that made it.
  • Both streams go to the log. The server writes its startup diagnostics to stderr, so a redirect without 2>&1 produces an empty log on exactly the failure a reader needs it for.

One departure from the plan

The plan said to extend .github/scripts/serve-unsloth-run.sh. That is the wrong home. It boots unsloth run --disable-tools and its entire body is banner API-key parsing and /v1/models resolution; these twenty-one boot unsloth studio --api-only with auth wiped and no banner at all. They share the word "boot" and nothing else. Each script's header now says which is which, so the next person does not have to work it out twice.

The script also deliberately does not wait for health. The callers' waits differ: some poll /api/health and stop, others go straight on to rotate the bootstrap password and load a model in the same step. Folding the simple case in would leave the rest calling a helper that does half their work.

Not converted

  • Three boots inside Playwright retry loops, which re-boot mid-loop and reassign the pid in the running shell.
  • Three boot-briefly-and-kill steps that keep the pid in a local shell variable rather than $GITHUB_ENV and never wipe auth. Converting those would change the pid contract for no gain.

Verification

Every call site asks for exactly what its old inline body did. A checker reconstructs (port, log, pid-var) from each pre-change body at origin/main and compares it to the arguments now passed: 21 call sites checked, 0 mismatches, 0 left unconverted.

That check had to walk steps positionally. Keying on (job, step name) looked right and was not: the consolidated workflows have two steps with the same name in the same job (phase 1 and phase 3), so a dict kept only the last and silently compared phase 1's call against phase 3's body, reporting two mismatches that did not exist.

The background process still outlives the step. Moving the launch one shell level deeper is the one behavioural risk here, so it was tested rather than assumed, against a stub unsloth on PATH with HOME pointed at a scratch directory:

[boot] unsloth studio --api-only on 127.0.0.1:18999, pid 3240372, log logs/x.log
STUDIO_TEST_PID=3240372          <- pid reaches $GITHUB_ENV
fake unsloth args: studio -H 127.0.0.1 -p 18999
to stderr                        <- stdout AND stderr captured
orphan survives script exit: yes
auth wiped: good

shellcheck clean. actionlint reports nothing new across the eight workflows.

Each caller's paths: filter gains the script, so an edit to it re-runs the workflows that call it. That is the trap #8015 hit: centralising a body moves it out from under filters that only name the workflow file.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: f348925e9e

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

Twenty-one steps across eight workflows ran the same five-line body, varying
only in port, log filename and the name of the environment variable the pid
lands in. .github/scripts/boot-studio-api-only.sh takes those three as flags.

Three parts of that body are easy to get subtly wrong, which is the argument
for one definition rather than twenty-one:

  rm -rf, not `reset-password`. The boot only re-seeds a fresh
  .bootstrap_password when the auth directory is absent, so a caller that
  resets keeps the old password and the test authenticates against stale state.

  The pid has to reach $GITHUB_ENV, because the step that stops the server is a
  different step with a different shell.

  Both streams go to the log. The server writes startup diagnostics to stderr,
  so a redirect without 2>&1 leaves an empty log on exactly the failure someone
  needs it for.

Not folded into serve-unsloth-run.sh, despite the plan saying so. That script
boots `unsloth run --disable-tools` and its body is banner-key parsing and
/v1/models resolution; these boot `unsloth studio --api-only` with auth wiped
and no banner. The two share the word boot and nothing else, and each header
now says which is which.

Deliberately does not wait for health: the callers' waits differ, some polling
/api/health and stopping while others go on to rotate the password and load a
model in the same step.

Left alone: three boots inside Playwright retry loops, which re-boot mid-loop
and reassign the pid in the running shell, and three boot-briefly-and-kill
steps that keep the pid in a local variable rather than $GITHUB_ENV.

Each caller's paths filter gains the script, so an edit to it re-runs the
workflows that call it -- the trap #8015 hit when the install body moved out
from under those filters.
@danielhanchen
danielhanchen force-pushed the ci/extract-studio-boot branch from f348925 to 0da5b90 Compare August 6, 2026 14:04
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

3 similar comments
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 0da5b90b2c

ℹ️ 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 7e47cc0 into main Aug 6, 2026
22 of 23 checks passed
@danielhanchen
danielhanchen deleted the ci/extract-studio-boot branch August 6, 2026 14:40
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