Repository navigation
Keep the drafterless retry intact when the arch gate narrows the argv - #8667
Conversation
_spec_start is a positional index captured just before the speculative flags are appended. #7670's arch gate rebinds cmd with tokens REMOVED from the prefix (--split-mode / --tensor-split), which slides the spec block left and leaves the index pointing past it. The fallback then kept spec_flags[:N], re-running the drafter that had just failed (llama.cpp accumulates spec types, so --spec-default cannot undo it), and sliced N tokens out of the middle of the tail. With the four-token narrowing that included --api-key, so the retry launched llama-server with no key at all. Re-locate the block instead of trusting the index, searching back from the hint first since narrowing can only move it left. A future narrowing site is then safe by construction rather than by remembering to adjust the index.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ac2d4cf9f
ℹ️ 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".
| # narrowed cmd since, which slides the block left and would | ||
| # otherwise slice --api-key and friends out of the tail. | ||
| _spec_at = _subsequence_index(cmd, spec_flags, _spec_start) | ||
| _fb_tail = cmd[_spec_at + len(spec_flags) :] |
There was a problem hiding this comment.
Update the startup-retry guard for the relocated slice
The existing test_the_startup_retry_drops_the_mtp_the_extras_and_the_env_carry in studio/backend/tests/test_metal_paravirtual_guard.py still searches _load_model_source() for the literal _fb_tail = cmd[_spec_start and fallback_cmd = cmd[:_spec_start]. With this change neither substring exists, so str.index() deterministically raises ValueError before the test reaches its assertions, causing the backend test suite to fail. Update that guard to locate the new _spec_at-based reconstruction.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, that guard would have failed the suite. Fixed in 498cc64: the slice anchors now read _fb_tail = cmd[_spec_at and fallback_cmd = cmd[:_spec_at], which is the same region as before, so the strip_spec, env.pop and MTP/DSpark assertions all still bind. Confirmed by reverting each of them in turn against the updated anchors: dropping the _SPEC_ENV_VARS pop, flipping strip_spec off, and removing the env = _launch_spec_env kwarg each fail the test, and reverting the call sites back to _spec_start fails it too. tests/test_metal_paravirtual_guard.py is 119 passed; the three arch gate suites plus the new file are 317 passed; tests/test_mtp_drafter_companion.py is 217 passed. It was the only place in the tree still naming _spec_start.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
_spec_startis a positional index intocmd, captured immediately before the speculative flags are appended. #7670 (merged as5a3e9fc7a) added five rebinds that remove tokens from the prefix ahead of it, so the stored index now points past the block it is supposed to mark.Its two consumers slice on that index:
With N tokens removed below the index, the drafterless retry keeps
spec_flags[:N]and loses N tokens out of the middle of the tail.Why this could not happen before #7670
The only rebind in that window was
cmd = _fa_cmd, and_with_flash_attn_offis length-preserving by design. The file states the invariant twice, at_with_flash_attn_off("every form is flipped in place (length preserved for downstream slices)") and again at its helper ("rewritten in place so the list length is preserved for downstream slices"). Everything else in the window iscmd.extend, which appends and cannot shift an index below_spec_start. #7670 is the first code to remove tokens from the prefix.Impact
Two things go wrong, and the second is the reason this is not just a correctness bug.
The retry re-runs the drafter that just failed.
spec_flagsbegins with--spec-type mtpor--model-draft <path>, so a surviving prefix of it means the fallback carries the mode that just failed. llama.cpp accumulates spec types, so appending--spec-defaultcannot undo it. The code's own comment at the fallback site says exactly this must not happen.Tokens are cut out of the middle of the tail. In the four-token narrowing, the deleted run is:
--api-keylands in the tail, so the fallback would start llama-server with no key at all.Observed against
mainat5a3e9fc7a, driving the real_without_flagsand the verbatim slice arithmetic:Reachability
Manual mode, multi-GPU ROCm host, a mixed-arch gate that narrows, a user ratio
--tensor-split 3,1, and an MTP drafter requested. The survivors arm drops 2 tokens, and any later drafter-load failure builds the corrupted argv. The auto path via the arch-crash retry is equally reachable:--split-mode tensor/--tensor-splitare emitted outside the manual block, so they reach argv in auto mode too. Note the comment near the retry ("No ratio can be live where this runs") is about the_tensor_splitattribute, while_without_tensor_splitscans argv, so it does not protect this.The fix
Re-locate the block rather than trust the index.
_subsequence_indexsearches back from the hint first, since narrowing can only move the block left, then forward as a defensive fallback. A future narrowing site is safe by construction instead of relying on every author remembering to adjust an index.Adjusting the index at each of the five removal sites would also work, but it puts the burden on the next person to add a sixth site, and this defect is what that burden looks like when it is missed once.
Tests
studio/backend/tests/test_spec_start_after_arch_narrowing.py, six cases: the un-narrowed control,--api-keysurvival under the four-token narrowing, the failed drafter not being re-run under all three narrowings, no token lost under any narrowing, a block that moved right, and an absent block not raising.Mutation check, reverting
_subsequence_indexto the stale index:Counts, serial:
test_mtp_drafter_companion.py: 217 passedThere is no AMD hardware on any runner, so this drives the real helpers over a fabricated argv rather than a live host.
Follows up #7670.