Repository navigation
feat(gguf): split GGUFs load, every header tensor is read or refused - #372
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2c44b0364
ℹ️ 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".
9c69511 to
ab16bca
Compare
1c1ef3e to
7ba810f
Compare
A split qwen35 / qwen35moe GGUF loads from its first part: every part is found beside it, checked as one GGUF (Splash GgufFile) and read with one page-cache decision; gguf-source.json and the cache marker list every part. The plan refuses any header tensor the loader does not read (Splash Problems::addUnread) and merges the header eog ids and <|endoftext|> into the asset generation_config.json. parse_gguf takes Splash's header rules, and `mlx download` range-reads each target's header and runs the native check (checkGgufHeaders) before any weight byte is fetched. Co-Authored-By: Claude Opus 5.5 <[email protected]>
readGgufArchitecture went back to a 64 KiB seeking window, so a skipped metadata array is never read or kept. Only readGgufHeader keeps bytes, capped at 128 MiB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ab16bca to
aaedeaa
Compare
Stage S37 of the Splash int8 KV alignment (stack #344). Base: S36b (#372). The desktop app now restarts the inference sidecar the way Splash restarts its engine (`server/supervision.py` `RestartPolicy.after`). It also refuses a request that was in flight at two crashes in a row (`Quarantine`, `request_caused`, `backend.py` `_admit`). The Control Panel broker uses the same restart policy. TypeScript only: no Rust, no `#[napi]` change. ``` before: crash ──► count = ready>=60s ? 1 : count+1 ──► 78 or count>=5: give up └─► else wait 1, 2, 4, 8 s (no record of which request was running) after: sidecar: request ──► fingerprint ──► refused? ──► 400 request_quarantined (never admitted) └─► dispatch: write <traceDir>/inference-<gen>.turns/<seq> = fp ... turn ... finally: unlink MAIN: crash ──► permanent (78 | entry missing)? ──► stop ├─► served >= 60 s from Ready (model loads paused, not erased)? ──► streak = 0, short = 0 ├─► else short += 1; short == 6 ──► stop ├─► fault-signal death of a ready child we did not stop? │ ──► Quarantine.after(fps left in the dir) ──► 'quarantined' event └─► wipe the dir, restart after 0, 5, 10, 20, 40 (60) s next fork: env MLX_TURN_JOURNAL=<dir>, MLX_QUARANTINED=<fp,fp> user Start / Restart: fresh policy and quarantine ``` ## Changes - `supervisor/state.ts`: `RestartPolicy {backoffBaseMs 5_000, probationMs 60_000}`, `backoffDoublings` (4), `crashLoopFailures` (6), `restartAfter` (Splash `RestartPolicy.after`), `stopCause` (`_stop_message`), `isPermanentExit`, `quarantineAfter` (`Quarantine.after`), `requestCaused` (`request_caused`; SIGSEGV, SIGBUS, SIGILL, SIGABRT, SIGFPE, SIGTRAP taken from `os.constants.signals`). An invalid policy throws when the supervisor or broker is built. - `supervisor/index.ts`: the probation clock starts at Ready and pauses while the background `/health` says `loading`. Service earned before a load is kept, so a crash during a later load still counts it (Splash `served_seconds` runs from Ready to the failure). A missing entry is the one permanent launch failure (Splash `EngineLaunchFailed`). Any other spawn error is an ordinary short failure. The quarantine is counted only on the restart path, before the relaunch (Splash `_count_failure`). A transport `error` on a live child (a V8 fatal error) is judged with the intent from before the error. Each generation gets its own `inference-<gen>.turns` dir, wiped at spawn and removed at every exit. - `child-node.ts`: a signal death is reported as its number in `code`, which is what `utilityProcess` already reports. - `env.ts`: `MLX_TURN_JOURNAL` and `MLX_QUARANTINED` are forced last, so a value from the shell cannot hide the journal or lift a quarantine. - New `inference/turn-journal.ts` (shared leaf: env names and a fingerprint parser without regex) and `supervisor/journal.ts` (MAIN reads the dir). - Sidecar: `sidecarHostOptions(env)` passes `turnJournal` to `createInferenceHost`. `mlx serve` and `mlx launch claude` pass nothing. - `packages/server`: new `turn-journal.ts` with `requestFingerprint`: SHA-256 over model, messages and config with sorted keys. It leaves out `cacheOwnerId`, `cacheRootOwnerId`, `modelAlias` and `reportPerformance` (Splash `_UNFINGERPRINTED`), and hashes image bytes by content. It also has `TurnJournal` (`refuses`, `begin`). The option goes host → server → handler → router. - `/v1/messages` and `/v1/responses` refuse right after the body maps, before admission and before any lazy model load or swap (Splash `_admit` refuses before `runtime.submit`). They journal the same fingerprint from dispatch until the dispatch `finally`. - `/v1/messages` fingerprints the config after the title fast path and the server thinking budget, before the per-model output-token clamp. `/v1/responses` fingerprints the body's own mapping plus `previous_response_id`, which stands for the stored chain read later. - `/v1/systemone` refuses in the router and journals inside the decision lane. - `sendRequestQuarantined` sends 400 `invalid_request_error` / `request_quarantined`. The Anthropic dialect has no `code`. - Snapshot and events: `streak` and `shortLivedFailures` replace `consecutiveCrashes`. `'gave-up'` now carries a `message`. A new `'quarantined' {refused, total}` event is logged by MAIN. Tray: "Inference: restarting (failure N)" and "Inference: stopped restarting". - Broker: `restartAfter`, with service counted from the fork. Exit 78 or a fork that throws ENOENT stops it at once. Events: `streak` and `message`. Control Panel restarts change from 1, 2, 4, 8 s with a stop at the 5th crash to at once, 5, 10, 20, 40 s with a stop at the 6th short failure. ## Deleted `planRestart`, `nextCrashCount`, `consecutiveCrashes`, and the old policy fields `maxConsecutiveCrashes`, `baseDelayMs`, `maxDelayMs` and `healthyForMs`. No compat layer. ## Tests - New: `supervisor-policy.test.ts` (fake transport, fake timers, real numbers), `__test__/server/turn-journal.test.ts`. Updated: `supervisor-state`, `supervisor` (real processes, fixture ops `journal` and `segv`), `broker`, `tray-view`, `sidecar`. - Named mutations. Each went red with the mutation on and green with it off, through a runtime switch that has since been removed (`MUTATIONS.md`): - M1: backoff exponent `streak − 1` - M2: probation `>=` → `>` - M3: missing entry not permanent - M4: served clock starts before Ready - M5: `start()` keeps the policy and quarantine - M6: suspects accumulate instead of being replaced - M7: `requestCaused` intent clause dropped - M8: `child_process` passes a null code on a signal death - M9: `MLX_QUARANTINED` not forked - M10: stale journal dir not wiped - M11: fingerprint length `>= 64` - M12: messages `begin` skipped at dispatch - M13: `endTurn` skipped in `finally` - M14: `begin` before the `streamSignal.aborted` return - M15: responses refusal skipped - M16: image fingerprinted by length only - M17: a `loading` probe does not pause the served clock - M18: systemone journaled at handler entry, which counts a decision still waiting for a load or the lane - M19: a `loading` probe erases the service earned before it (`keeps the service earned before a model load that crashes`) - M20: messages refusal moved back after the lazy load (`a quarantined request is refused before any model load`) - M21: responses refusal moved back after the lazy load (same test) - M22: `previous_response_id` left out of the fingerprint (`the fingerprint ignores identity and reporting and keeps the content`) - Gates on the round 2 fix (TS only): `yarn typecheck`, `yarn tsc -b --force`, `vp lint --type-aware --type-check` and `vp fmt --check` on the 4 touched files, `vp test __test__/server` 61 files passed, 2 skipped; 1,436 tests passed, 7 skipped. - Gates on the round 1 fix (TS only: `yarn typecheck`, `yarn tsc -b --force`, lint and fmt on the 2 touched files, `vp test packages/desktop/__test__` 34 files / 532 tests passed; earlier full gates below): - `cargo fmt --check`, `cargo clippy --workspace --all-targets -D warnings`, `yarn build:native` (`index.d.cts` unchanged), `yarn typecheck`, `yarn tsc -b --force`: clean. - `vp lint --type-aware --type-check` on the 27 touched `.ts` files and `vp fmt --check` on the touched files (27 checked): clean. - `vp test packages/desktop/__test__ __test__/server`: 95 files passed, 2 skipped (env-gated e2e). 1,966 tests passed, 7 skipped. ## Gaps 1. No memory start-failure class (`MEMORY_START_FAILURES`, `kStartRetryWindow`). The sidecar's start loads no model. 2. A signal death is read from `code`. Node's own fatal exit codes 4, 5, 6 and 10 are the same numbers as SIGILL, SIGTRAP, SIGABRT and SIGBUS on Darwin, so such an exit with a turn in flight counts. 3. Splash's `REQUEST_FAILURE_CODES` (`engine_execution_failed` and the others) have no producer here. The swallowed native error behind `lying` keeps the child up; Splash would relaunch and count it. 4. The fingerprint covers mapped messages and config, not prompt tokens: the endpoint has no tokens before the model load. `/v1/messages` hashes `max_tokens` before the per-model output-token clamp (Splash hashes the clamped `logical_max_output_tokens`), so two bodies that differ only above the clamp are two fingerprints. `/v1/responses` hashes `previous_response_id`, not the stored chain's content. 5. No Retry-After 503 `engine_recovering` and no `/status` `recovering`. While the sidecar restarts, clients see the connection refused. 6. The policy and the quarantine last until the user starts or restarts inference or relaunches the app. In Splash they last until the server restarts. 7. The refusal carries no crash trace. `inference-<gen>.trace.log` is the swallowed-error trace, not a crash trace. The tray and `app.log` show the exit and the stderr tail. 8. With a journal, `/v1/responses` maps the body twice (once for the fingerprint, once after the chain is read). 9. A failed journal write runs the turn unjournaled, with one stderr line. 10. The Control Panel counts service from the fork (it has no Ready). Splash has no Control Panel. 11. `kStop` and `kFlush` are not ported. `killGraceMs` covers the drain. 12. `/v1/rerank` and `/v1/audio/*` are not journaled (they read their own bodies; audio is multipart). 13. The journal entry spans the JS dispatch, not Splash's StartEvent through the terminal event. 14. `mlx serve` and `mlx launch claude` run inference in-process: no restart policy and no quarantine. ## Not in this PR (live, not run) - L1: restart timing in the app (`kill -SEGV` the sidecar six times: back at once, then after 5, 10, 20 and 40 s, then "stopped restarting"). - L2: quarantine end to end (the same streamed turn killed twice, then 400 `request_quarantined`; a body that differs gets 200; Restart Inference clears it). - Steps: `LIVE.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aaedeaa436
ℹ️ 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".
| const folder = dirname(target[0]); | ||
| const config = folder === '.' ? 'config.json' : `${folder}/config.json`; | ||
| if (opts.paths.includes(config)) { | ||
| await writeFile(join(dir, 'config.json'), new Uint8Array(await (await fetch(config)).arrayBuffer())); | ||
| } |
There was a problem hiding this comment.
Include the assets-repo config in GGUF preflight
When a weights-only Qwen3.5 repo is downloaded with --assets-repo, the scratch directory never receives that base repo's config.json: this condition only considers files selected from the primary repo, and checkGgufTargets runs before sidecar planning. Consequently, native_import_plans treats the target as standalone and runs validate_qwen35_standalone_geometry, rejecting headers missing fields such as ssm.conv_kernel even though loading with the supplied authoritative config skips that validation. Resolve the effective config, including the --assets-repo fallback, before running the header check so valid config-backed downloads are not refused.
Useful? React with 👍 / 👎.
Stage S36b of the Splash int8 KV alignment (stack #344). Base: S30 (#371).
This PR makes split qwen35 / qwen35moe GGUFs load, and refuses any header tensor the loader does not read. It also adds a header-only check that
mlx downloadruns before it fetches any weight byte. Splash:GgufFileover every part,GgufImageProblems::addUnread,install/upstream.pygguf_target+model-check,install/gguf.pyflint_stop_tokens.Changes
resolve_main_partsfinds the parts by name beside part 1, before it resolves any link (Hugging Face snapshot links point to blobs that have other names).check_split_partsapplies the SplashGgufFilerules:split.countmust equal the number of files, a later part'ssplit.no(U16 / U32) must equal its place,split.tensors.countmust equal the total, and no tensor name may repeat.merge_split_headersbuilds the one header the plan reads.GgufCheckpoint.main/PreloadInput.mainnow hold a list of parts (GgufMain,PreloadMain). Each part is read with its own header, and the page-cache decision is taken once from the bytes of all parts.gguf-source.jsonnow lists every part (mainandmain_identityare arrays). The cache marker adds onepart_hex=line per extra part, and the sweep checks each of them. The cache key andsource_identity_sha256cover every part. The format goes from 8 to 9, so older entries age out.refuse_unread_qwen35_tensorsruns last inplan_gguf_import. A tensor is accepted only if the loader reads it: the per-layer norms, the GDN or full-attention mixer chosen byfull_attention_interval, the dense or MoE FFN, and the three global tensors. Thenextn_predict_layersblocks after the decoder are exempt. Faults are reported in SplashProblemsform, for exampleattn_q.bias (unused) in 1 layer.nextn_predict_layersmust agree with the inline MTP block.tokenizer.ggml.eog_token_ids(a non-empty integer list, otherwise refused) and the vocabulary id of<|endoftext|>(Splash Qwen.stopTokens) are merged into the assetgeneration_config.jsoneos_token_id, and its other keys are kept. The merge is skipped when the conversion writes into the GGUF's own folder.parse_gguf_reader(SplashGgufFile::parse):#[napi] checkGgufHeaders(dir). It applies SplashfindTargetGgufs(one file, or the parts of one name), the file and split rules, and then, for qwen35 / qwen35moe, the import plan every load runs. gemma4, clef and muse-glimmer refuse a split. Other architectures pass.mlx download.checkGgufTargetsgroups the selected GGUFs into targets, and a split target must hold every part. For each part it range-reads[0, end of the tensor table)withreadGgufHeader(new@mlx-node/lm/gguf-metadatasubpath). It also fetches the target folder'sconfig.jsonwhen that file is selected, then runscheckGgufHeaders. The native addon is imported only when a GGUF target is selected. On a refusal, the completion marker is restored and nothing is fetched.readGgufHeaderkeeps every byte it reads, up to 128 MiB (SplashMetadata.MAX_BYTES). Discovery (readGgufArchitecture, now overreadGgufSourceArchitecture) keeps the old 64 KiB seeking window, so a skipped metadata array is never read or held.ggufSplitPartreplaces the split regex, and the qwen3_5 / qwen3_5_moe rows havesplit: true. The XL and Bonsai name tests run on the stem, so part 1 of a split XL GGUF is found and later parts are never listed.docs/cli.md,docs/models.mdanddocs/convert-quantize.mdcover split loads, the unread-tensor rule, the parts listed ingguf-source.json, and the header check before download.Deleted
reject_splitinsideGgufFileHandle::open. It now runs inGgufSourceSet::openfor one-file mains and for the companion.main/main_identityshape ofgguf-source.json(reader and writer).PreloadFiletuple for the main GGUF. The companion keeps it.supportedGgufName.general.alignment ... .max(1), replaced by the Splash rule.Tests
Rust:
split_gguf_loads_like_one_file(dense and MoE: the 3-part load is bit-equal to the one-file load, including the reload from the asset dir; checkpoint bytes are the sum of the parts),split_parts_follow_the_gguf_file_rules,split_reads_share_one_page_cache_decision,sweep_reads_every_part_of_a_split_entry,plan_refuses_unread_qwen35_tensors,header_eog_ids_join_generation_config,check_gguf_headers_reads_header_only_copies,parse_gguf_refuses_what_splash_refuses,ple_table_rows_bf16_and_f16_at_width_160.TS:
__test__/cli/download-model-gguf-check.test.ts(withtiny-gguf.ts), plus new cases inmodel-discovery.test.tsandgguf-metadata.test.ts(chunk edges, the 16385-tensor refusal, a 248k-entry token array, discovery past a 32 MiB skipped array reads < 1 MiB).Named mutations (
MUTATIONS.md). Each one is red with its switch on and green with it off:<|endoftext|>not looked upsplit.noplace check skippedpart_hex=checkGgufHeadersnot calledGates: see the table below.
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warnings--lib, one binary,RUST_TEST_THREADS=1yarn build:nativeindex.d.ctscopies in syncyarn typecheck,yarn tsc -b --force(23 projects)vp testonpackages/lm/__test__,__test__/cli,packages/cli/__test__,packages/dashboard/__test__, plus the agentmodels/family-completeness/catalog-native-freeand desktopchild-entriestestsvp fmt --checkandvp lint --type-aware --type-checkon the touched filespackages/lm/__test__files, a per-file lint reports TS2591 (no node types) on imports this PR does not change, because no tsconfig covers that folderGaps
index_ggufkeeps its own split checks. Gating a change there would mean loading Flash Next.mlx convertstill reads one file.ffn_gate_up_expsis refused, not loaded. The name map, quant entries, t64 plan and packed-row split are not verified on the native k-quant route, and no known qwen35moe GGUF carries this tensor.checkGgufHeadersdoes refuse them.require_quantized) are not ported.storedTable).eog_token_idsis refused. Ids outside u32 are refused too, where Splash accepts negative ids.general.alignment, while Splash applies part 1's to every part.checkGgufHeadersplans only qwen35 / qwen35moe, and unknown architectures pass (SplashwithFamilyrefuses them).Not in this PR (live, not run)
checkGgufHeaderson every local qwen35 / qwen35moe GGUF (header bytes only).LIVE.md.🤖 Generated with Claude Code