Skip to content

fix(reference-script): recognize the sglang serve entrypoint - #1938

Merged
chaojhou merged 1 commit into
mainfrom
fix/reference-script-sglang-serve
Oct 16, 2026
Merged

chaojhou merged 1 commit into
mainfrom
fix/reference-script-sglang-serve

Conversation

@jiejingzhangamd

Copy link
Copy Markdown
Collaborator
  • Description: --reference-script matched only sglang.launch_server for SGLang. The SGLang cookbook (and SGLang's own warning, "'sglang serve' is the recommended entrypoint") use sglang serve, so a recipe copied from the cookbook produced no flags and the CLI exited 2. The marker list now includes sglang serve, and the start of the flags is found by one rule for every framework (_flags_start): after python3 -m <module>, or after serve when the token before it is the vllm / sglang CLI. That replaces the vLLM-only branch in _extract_server_args and removes its now-unread framework parameter. Without the shared rule, sglang and serve would have been read as positionals and sglang recorded as the model.
  • Linked issue(s): Fixes --reference-script does not recognize the 'sglang serve' entrypoint #1933
  • Tests: added test_parse_sglang_serve_entrypoint_as_the_cookbook_writes_it (multi-line cookbook form: flags kept, --host/--port/--model-path dropped, model and env lifted) and test_parse_serve_entrypoint_does_not_take_the_cli_name_for_the_model; both fail on main. The 9 test files that touch reference scripts: 449 passed. ruff clean; code-metrics PASSED.
    Real recipe check: the GLM-5.2 MXFP4 MI355X cookbook recipe used in an 8 h run, in sglang serve form, parses to the same 30 arg tokens, SGLANG_OPT_USE_TOPK_V2=1 and model as the hand-converted python3 -m sglang.launch_server form (identical: True); on main the serve form yields 0 tokens.
  • Size/complexity triggers crossed: none. _extract_server_args cognitive complexity drops 54 → 40; the baseline entry is lowered accordingly.
  • If this simplifies or refactors: the per-framework prefix branch in _extract_server_args is replaced by one entrypoint rule; existing vLLM / -m recipes parse unchanged (existing tests).
  • Observable effect: an operator can pass an SGLang cookbook command (sglang serve ...) to --reference-script as-is. Before, it was rejected with "yields neither a flag nor an export" (or carried exports only) and had to be rewritten to python3 -m sglang.launch_server by hand.
  • Breaking changes: no
  • PR addresses single concern: yes
  • Root cause is upstream, ticket filed: no

🤖 Generated with Claude Code

The SGLang cookbook and SGLang itself now launch with `sglang serve`, but
--reference-script only matched `sglang.launch_server`, so a recipe copied
from the cookbook yielded no flags and the CLI exited 2.

Find where flags start with one rule for every framework: after
`python3 -m <module>`, or after `serve` when the token before it is the
vllm or sglang CLI. This replaces the separate vLLM branch, drops the
now-unread framework parameter of _extract_server_args, and keeps `sglang`
from being taken as the positional model.

Fixes #1933

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HktBcjPwjE7QgkA8MgKH6q
@jiejingzhangamd
jiejingzhangamd requested a review from a team as a code owner October 16, 2026 07:05
@github-actions

Copy link
Copy Markdown

Code metrics gate: PASSED

Judged: the 3 files this change touches. Files it does not touch never fail it; anything found there is listed under Outside this change for information.

Dimension Limit New Worse Baseline out of date Baseline entries vs base
Cyclomatic complexity fails > 20 0 0 0 72 +0
Cognitive complexity fails > 30 0 0 0 284 +0
Function length (lines) fails > 80 0 0 0 449 +0
Nested block depth fails > 5 0 0 0 27 +0
Module length (lines) warns > 800, fails > 1200 0 0 0 53 +0
Duplicated lines per file fails > 0 0 0 0 118 +0
Dead code (vulture) fails > 0 0 0 0 2 +0
Check Findings Effect
Comments 0
English only 0
Production code imports test code 0
Repeated literals 0
A1 Private name of another package 0
A8 Flag argument 0
A9 Tuple return 0
A10 Raw vocabulary comparison 0
A11 Hidden global write 0
A12 Pure forwarder 0
A12 Single-implementation abstraction 0
97 findings in files this change does not touch

Outside this change (informational): 97

Unit Dimension Baseline Now
src/hyperloom/orchestrator/enablement/recipe/projections.py project_launch_evidence Cognitive complexity absent 36
src/hyperloom/orchestrator/state/shared_state.py resolve_graded_comparison Cognitive complexity absent 34
src/hyperloom_kb/collect/mapping.py _experience Cognitive complexity absent 31
src/hyperloom_kb/schema.py FieldDeclaration.__post_init__ Cognitive complexity absent 32
src/kernelforge/cli/forge_loop_command.py _prepare_measurement_driver Cognitive complexity absent 36
src/kernelforge/cli/forge_loop_command.py _read_kb_warm_start Cognitive complexity absent 40
src/kernelforge/loop/runner.py IterationLoop._collect_session_candidate Cognitive complexity absent 44
src/kernelforge/loop/runner.py IterationLoop._rule_on_attempt Cognitive complexity absent 38
src/hyperloom_kb/tests/test_cli.py Duplicated lines per file absent 18
src/hyperloom_kb/tests/test_global_identity_and_pull.py Duplicated lines per file absent 13
src/hyperloom_kb/tests/test_local_state.py Duplicated lines per file absent 18
src/hyperloom/inference_optimizer/cli/__init__.py _reexport_session_environment Function length (lines) absent 112
src/hyperloom/inference_optimizer/cli/__init__.py _resolve_agent_lineup Function length (lines) absent 89
src/hyperloom/inference_optimizer/cli/__init__.py _resolve_run_topology Function length (lines) absent 92
src/hyperloom/inference_optimizer/cli/__init__.py _resume_session Function length (lines) absent 171
src/hyperloom/inference_optimizer/cli/__init__.py _seed_fresh_session Function length (lines) absent 183
src/hyperloom/inference_optimizer/multi_node/cli.py _restart_multinode Function length (lines) absent 107
src/hyperloom/inference_optimizer/multi_node/scripts/launch_multinode.py _build_parser Function length (lines) absent 84
src/hyperloom/inference_optimizer/multi_node/scripts/launch_multinode.py _spawn_rank_actors Function length (lines) absent 90
src/hyperloom_kb/http_service.py RequestHandler._dispatch Function length (lines) absent 91
src/hyperloom_kb/sync.py GlobalSync.pull Function length (lines) absent 86
src/kernelforge/cli/forge_loop_command.py _RunReporter.build_result Function length (lines) absent 91
src/kernelforge/cli/forge_loop_command.py _prepare_measurement_driver Function length (lines) absent 140
src/kernelforge/cli/forge_loop_command.py _read_kb_warm_start Function length (lines) absent 154
src/kernelforge/loop/knowledge_integration.py _measure_warmstart_field Function length (lines) absent 83

...and 72 more; the job log lists every row.

Verdict computed by the gate scripts in /home/runner/work/_temp/code-metrics-gate, not by this tree's copy.

Thresholds and sources: [tool.hyperloom.code_metrics] in pyproject.toml. Tools: complexipy 8.0.1, jscpd 5.4.1, ruff 0.16.2, vulture 2.16.

@chaojhou

Copy link
Copy Markdown
Collaborator

PR #1938 -- fix(reference-script): recognize the sglang serve entrypoint

What it does: --reference-script only matched sglang.launch_server for SGLang, so a recipe copied from the SGLang cookbook in its recommended sglang serve form yielded no flags and the CLI exited 2. sglang serve is now an entrypoint marker, and one rule (_flags_start) finds where the flags begin for every framework: after python3 -m <module>, or after serve when the token before it is the vllm / sglang CLI. This replaces the vLLM-only branch in _extract_server_args and removes its unread framework parameter; cognitive complexity drops 54 -> 40 and the baseline entry is lowered. Run against base and head, sglang serve ... and uv run sglang serve ... now parse to their flags and model, while vllm serve ..., a path-qualified vllm serve, python3 -m sglang.launch_server ... and ATOM recipes parse exactly as before.

Blocking issues: none

Checked: reference_script.py (_entrypoint_markers, _find_entrypoint_line, _flags_start, _extract_server_args, parse_reference_script); cli/bootstrap.py _resolve_reference_recipe and every consumer of the parsed model (SharedState.reference_model in the current_setting.sh render, enablement/lane.py:582); every caller of _extract_server_args; the new tests and the description | Ran: parse_reference_script from extracted base and head trees on vLLM, SGLang (-m and serve forms, path-qualified, uv run, docker run, numactl) and ATOM recipes, comparing flags and model; CI at bf66a4c (green) | Base: a3fc0ba | Head: bf66a4c

LGTM

@chaojhou
chaojhou merged commit dd6a92d into main Oct 16, 2026
40 checks passed
@chaojhou
chaojhou deleted the fix/reference-script-sglang-serve branch October 16, 2026 15:12
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.

--reference-script does not recognize the 'sglang serve' entrypoint

2 participants