Repository navigation
fix: tool-arg schema coercion + mlx agent session fixes - #330
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ea1bbf252
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a73add36e1
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b01a9b39e
ℹ️ 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".
Bare-text tool formats (Qwen3.5/3.8 chatml <parameter=...>, K2 xml, Muse-Glimmer <atem:parameter>) cannot tell 900 from "900", so the chatml parser emitted every scalar as a JSON string. Strict clients such as grok-build then fail with `invalid type: string "900", expected usize`. Port vLLM's _fix_arg_types / coerce_to_schema_type as tools::coerce and run it once at every chat NAPI exit (sync, ChatSessionCall.result, and the stream pump's terminal chunk), including qianfan_ocr. Parsers record each argument's verbatim text so a string-typed schema keeps the value as written. K2 values typed by arg_type are never re-typed. Coerced integers stay within Number.MAX_SAFE_INTEGER. Requests without tool schemas are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Typed scalars (JSON, LFM2, nested JSON) the schema already admits are returned unchanged; schema-priority interpretation now applies only to bare text and to typed values the schema does not admit. allOf branches intersect with each other and the enclosing type (integer within number); an empty intersection leaves the value as parsed. Both are documented as deliberate differences from vLLM. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An Option<Enum> schema ({"anyOf":[{"$ref":...},{"type":"null"}]})
resolved to null-only, so valid typed strings like "true" were rewritten.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
DeepSeek V4.1 (from main) exposes chat only through chat_napi_surface!, so all of its exits already carry tool_schemas. DSML marks every parameter string="true"|"false", so it is a model-typed format like K2 arg_type and stays off the raw-text path: an admitted value is kept, a value the schema does not admit is coerced. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ll chunk A turn cancelled after it started but before prefill reset the flat cache (prefix miss) or failed closed (prefix hit), destroying the live session, and the prefill loop skipped the cancel poll for chunk 0, so the first 2048-token chunk always ran. The turn now returns PREFILL_CANCELLED right after the non-mutating prefix decision, before any reset, and the chunk loop polls before every chunk. The same reset-before-cancel-check exists byte for byte in the Qwen3.5 MoE DFlash2, Muse-Glimmer DFlash and Gemma4 assistant flat-draft turns; they get the same fix and their own tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The H2 pre-dispatch disconnect check only covered non-streaming requests. A streaming request whose client left while it was queued still reset the session and started a native turn (cache reset, first prefill chunk) before the stream noticed the abort. Both /v1/messages and /v1/responses now return before dispatch for either mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Callers that force a tool (grok's session_title side call: one tool, max_tokens 100) lost the whole budget to reasoning and finished with length and no call. A named tool, Responses 'required' and Anthropic 'any' now render with reasoningEffort none, thinking budget 0 and no reasoning output. auto, none and an absent tool_choice are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
grok's web_search is an xAI server-side tool and image_gen, image_edit, image_to_video and reference_to_video post to the xAI base URL, which a served launch points at mlx serve. In the live session each call failed with a 400 and cost a whole agent turn. Served launches now pass --disable-web-search (unless the user already did; clap rejects a repeat) and set GROK_IMAGE_GEN/GROK_IMAGE_EDIT/GROK_VIDEO_GEN=0 unless exported. Subagents inherit both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mlx serve loads lazily, so the first agent request waited for the whole model load (73.6 s before the first token in the live session, 27.2 s of it with serve idle before the first prompt arrived). mlx serve gains --preload <name>, which starts InferenceHost.loadModel right after the listening banner (a failure is logged and the server keeps running), and mlx agent passes it for the -m model when that model is a discovered local one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The default agent trace filter named only mlx_core::inference and mlx_core::decode, and Targets drops any target with no directive, so every warn/error from the rest of mlx_core (memory, model code) and from mlx_paged_attn was lost. The default now floors mlx_core and mlx_paged_attn at warn; the more specific info directives still win. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The eval mirrors mlx agent / mlx delegate, so it now passes --disable-web-search, sets the media-tool env switches and starts its mlx serve with --preload for the default model, through shared helpers that the report's cliInvocation also uses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ffb990b to
1a3a2cf
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a3a2cf0de
ℹ️ 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".
… schemas into combinators 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: cba9a15114
ℹ️ 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".
…container branch ambiguous Co-Authored-By: Claude Opus 5.5 <[email protected]>
A base64url token starts with '-' about 1 time in 64, and parseArgs then reads it as a flag, so mlx serve exits before reporting a port and mlx agent fails to start. Seen in the gated agent e2e smoke. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…turn Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A user cancel during a DFlash2 prefill failed closed through ResetScope::Command, which cleared every session's parked state and the live anchor and purged the paged prefix cache. Agent clients cancel often, so one cancelled subagent turn threw away every other session's state. A cancel now drops only the state the turn was building: the live flat state and the live paged requests, keeping the state store and the paged prefix cache. A cancel the prefill sees before its first chunk is polled before the draft context is taken, so the state the resume moved in stays live and keyed under the turn's salt. Every other error still fails closed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The turn's KV budget is 9/10 of the live headroom, so a freed parked byte raises it by only 9/10 of a byte. Eviction credited frees 1:1 and could stop while parked bytes were left, sending the reserve down the growth path. Evict against the least headroom whose budget covers the need. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The prefix event always passed evicted_depth 0, so a miss on a lineage whose parked state was evicted read as cross_session. The store now remembers the last 64 resume points that eviction removed (block chain hashes plus the tail tokens) and the turn reports the deepest one on its prompt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…led verify ran The eager verify gives the same bits, so a silent fall back passed the test. Assert the compiled-verify counter for every turn and its forced cycles, and that the verify was never disabled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts on the calibrated host only merge_projections claimed only the M = 8 tier differs from the separate projections; the route probe shows the merged context k|v also differs at 1 row on the Qwen3.8 draft geometry. The probe's width assertion depends on the GPU's kernel tiers and core count, so it now runs on the calibrated host only, like the exact partitions; slot and padding invariance still run everywhere. Also drops plan labels from test docs and messages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ted_segment doc A capture window of at most 32 rows runs through gated_delta_update_fused segment by segment, and no test split that entry. Add the split identity at every row of 17..=32-row windows (max_ulps 0 on rows, final and captured states). routed_segment mixes entries by segment length; its doc claimed it was the layer's routing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s the flat caches A continuous-batching admission installs the owner's history and then activates the sequence, which replaced the flat caches; a DFlash2 end state left by an exclusive turn was dropped instead of parked like at the other paged sites. Dense and MoE now park it in install_owner_state and in activate_scheduled_recurrent when no scheduled sequence is active. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n reads headroom Co-Authored-By: Claude Opus 5.5 <[email protected]>
…apture is armed Every chat prompt that ends with the generation suffix arms C(R), and moving keep_from to R - window changed the live draft append widths, which change draft K/V bits on the tiled quantized kernels. The live context now always appends as an unarmed prefill; a capture that needs rows that schedule only records runs its own schedule on a shadow context up to R. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…chor A cancel after the first prefill chunk of a resumed turn dropped that session's whole state, so the retry, carrying the same prefix, prefilled cold. The prefill and decode write only rows past the resume point, so the live anchor at or below it still resumes exactly: it now parks with the full-attention caches trimmed to its row before the rest of the live state is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er turns Parked states took memory that before them stayed free for the turn's transients, so the reserve now evicts until the live headroom also covers a first-order estimate of them (the larger of one prefill chunk and the decode cycle plus its capped pool). With unreadable limits parked KV has no bound, so every entry holding KV is evicted. Paged, vision and MTP turns on a DFlash2 model evict parked states for their own KV and transients before they start. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e default dir Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n timeout The prompt sentinel 'hello from mlx agent' sent the 0.8B model into long skill/tool searches; a degenerate decode inside a buffered tool call then ran past the 240 s kill. Use a neutral word, disable subagents and plan mode, and kill the whole process group so mlx serve does not stay alive with the model loaded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
v0.3.1 accepts string-typed integer, number and boolean tool arguments and carries the workflow listing fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…is declined A continuous-batching admission bypasses ChatBackend::run_paged_turn's eviction, and the page-pool grow's headroom probe reads live Metal memory that parked DFlash2 states hold. With no live turns a declined grow rejected the request as context_length_exceeded even when evicting those states would let it fit. The scheduler now asks the backend to release memory outside the pool after a declined grow and retries the grow once; the default releases nothing, so other families keep the existing path. Qwen3.5 dense and MoE evict every parked state that holds bytes, keeping the live state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A base64url token starts with '-' about once in 64 launches, and serve's parseArgs then rejects `--auth-token <token>` as an ambiguous value. The replay now passes `--auth-token=<token>`, like the mlx agent launcher and the installed-agent eval. Co-Authored-By: Claude Opus 5.5 <[email protected]>
capture_keeps_route_bits_and_owns_state hard-coded each case's route. On the GitHub macOS runner the fused prefill pipeline cannot hold one value head per threadgroup, so the forward falls back to the chain and the uncaptured-route assertion failed ([Chain] vs [FusedPrefill]). The test now asserts the intended route only where its kernel launches (the existing launch probes, plus the prefill-fusion switch), otherwise asserts that the declined route did not run, and checks the captured forward against the route the host actually took. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…to bf16 rounding On a GPU where the fused GDN kernels decline (the CI runner), the forward takes the chain route. A capture inside a 64-row chunk then comes from other chunk products than the shorter forward: measured 0.5-0.6% of the state range (about one bf16 step). Check the chain route within 1/64 of the range; every other route stays bit-exact. A 1/1024 bound fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
grok prints 'grok --resume <id>' on exit, but mlx agent does not put a grok binary on PATH. Set GROK_RESUME_COMMAND=mlx agent (a user value wins); the grok-build fork prints it in place of grok. Co-Authored-By: Claude Opus 5.5 <[email protected]>
v0.3.2 prints GROK_RESUME_COMMAND in its resume hints, so the exit hint reads 'mlx agent --resume <id>'. Co-Authored-By: Claude Opus 5.5 <[email protected]>
b6542c2 to
9e688fc
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e688fc6f9
ℹ️ 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".
For {"enum":["00042",7]} (no type), the ChatML text 00042 was coerced to
42, which is not a member. Keep the raw text when it equals a string
member of the property's enum.
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: e192fe541f
ℹ️ 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".
{"anyOf":[{"enum":["00042"]},{"type":"integer","enum":[7]}]} admits the
string 00042, but the guard only read a top-level enum, so the bare text
became 42. Search the same branches schema_types reads.
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: 3e4d36af35
ℹ️ 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".
…strings
{"type":"integer","enum":["7",7]} allows only the number 7, but the
enum-string guard kept the bare text as "7". Apply the guard only when
schema_types admits a string (or the schema is untyped).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
Tool-call arguments are now converted to the types in the request's tool schema before they reach JS. With schema
{limit: {type: integer}}, a Qwen3.5/3.8 chatml<parameter=limit>900</parameter>now arrives as the number900, not the string"900".Why
Bare-text tool formats (Qwen chatml
<parameter=…>, K2xml, Muse-Glimmer<atem:parameter>) look the same whether the model meant900or"900", so the chatml parser turned every scalar into a JSON string. Strict clients then fail. grok-build's serde, for example, reportsinvalid type: string "900", expected usize.How
tools::coerceis a port of vLLM's_fix_arg_types/coerce_to_schema_type. It readstype,enum,anyOf/oneOf/allOfand type-name aliases, and goes into nestedpropertiesanditems.arg_type, that type is kept and the schema doesn't change it.Number.MAX_SAFE_INTEGER, because NAPI would turn them into BigInt andJSON.stringifywould throw.chat_napi_surfacemacro and qianfan_ocr.Verified
cargo test -p mlx-core --lib -- tools:: muse_glimmer:: k2_horizon::finalize engine::with--test-threads=1: 847 passed. 23 of them are new coercion tests.coerce_callsmakes the chatml live-repro test fail ("300000"instead of300000).cargo clippy -p mlx-core --all-targets -D warnings,cargo fmt --check,yarn build:nativeandyarn typecheckall pass. No.d.ctschange.--test-threads=8). They fail the same way on base038c45d24and pass when run serially.Also fixes (from the live mlx agent log)
Source: a live
mlx agentsession (Qwen3.8-27B GGUF + DFlash2, 1 main + 1 planner + 4 research subagents). Impact numbers are measured frominference.log, traces and client logs.qwen3_5dense, plus the identical Qwen3.5 MoE DFlash2, Muse-Glimmer DFlash and Gemma4 assistant flat-draft turns): the cancel is checked before the cache reset and before the first prefill chunk. Before this, a cancel always ran the first 2048-token chunk and wiped the flat cache. In the log, 55.8 s of prefill was thrown away and about 7-8 s of GPU ran after ctrl_c./v1/messages,/v1/responses). 2 turns started 4-8 s after the client cancelled. Each one is a 10-40k-token cache-miss prefill (16-72 s) that nobody receives, and it resets the flat cache.tool_choicerenders with thinking off (named tool,required, Anthropicany). grok'ssession_titleside call (max_tokens 100) spent all 100 tokens on reasoning in 4 of 5 calls and fell back to placeholder titles: 17.5 s wasted (20.4 s for all 5 title calls).mlx agentturns off grok'sweb_searchand xAI media tools against localmlx serve(--disable-web-search,GROK_IMAGE_GEN/IMAGE_EDIT/VIDEO_GEN=0; a value the user already exported wins). 2 turns where every call failed: 32.9 s TTFT, 41.0 s server time, 20,518 tokens re-prefilled. One researcher used 3 of its 4 turns before falling back to local files.mlx serve --preload <name>;mlx agentpreloads its-mmodel so the load overlaps grok startup. The first token arrived 73.6 s after the first prompt, and serve had been idle for 27.2 s before that prompt arrived.warn/errorfrom all ofmlx_coreandmlx_paged_attn(infostays limited to inference/decode). Before this, memory and wired-limit warnings, cancel reasons and fallback warnings were filtered out of the agent log. No runtime cost; it only makes problems visible in the log.evals/agent-installed) now launches the agent the waymlx agentdoes (same flags, env and preload).string="true"|"false"). A new test checks that values the schema admits stay as they are and that the rest are coerced.Companion grok-build fix (PR #1): the built-in
deep-researchworkflow is no longer listed with a CI-onlyCARGO_MANIFEST_DIRpath, and its listing shows the launch shape (source {"type":"name",...}, args {"query": ...}). In the log this cost about 3 extra main turns (24-44 s of server time) while the model read a missing file and putqueryinsidesource.Decisions made in this PR:
requiredtool_choicerenders with thinking off. No grammar-constrained decoding.Companion client PR: mlx-node/grok-build#1.
DFlash2: one cache state per agent session
Before, Qwen3.5/3.8 DFlash2 kept one flat cache for the whole model. Each turn from a different agent session missed and prefilled its full prompt again. In the logged session this cost ~515 s of 1002 s server time.
0b8d90f7fgolden-trace harness (bitwise traces on tiny fixtures).4c0176f36turn trace, replay point, and one shared dense/MoE DFlash2 turn (qwen3_5/dflash2_turn.rs).31a9c7285content-keyed multi-slot state store: park, restore by move, resume at the end state (E) or at a captured point (C(R)).aaa032b14,249440314a user cancel never runsResetScope::Command. It drops only the live state and parks the resumed anchor; other errors still fail closed.f6eb13517..5e65d262breview fixes: eviction budget,evictedmiss reason, CB activation parks the state, the armed capture keeps the unarmed draft append schedule.Gate results (Qwen3.8-27B GGUF, M5 Max)
gated_delta,dflash2*, MoEdflash2_decode,dflash2_attention)-D warningsand fmt cleanGate rows that do not pass, and why I accept them:
Test and release changes
__test__/cli/agent-e2e.test.ts: the old sentinel ("hello from mlx agent") sent the 0.8B model into long skill searches, which sometimes ran past the 240 s kill (same rate on main). The test now uses a neutral word,--no-subagents --no-plan, and kills the process group on timeout somlx servedoes not stay alive with the model loaded. 3/3 local runs pass (19-96 s).scripts/dflash2-agent-replay.tsloads only the recorded sessions from the default dir.MLX_AGENT_MIN_RELEASEis nowmlx-agent-v0.3.2:GROK_RESUME_COMMAND.mlx agentsets it tomlx agent, so the hint readsmlx agent --resume <id>, notgrok --resume <id>(nogrokis on PATH).Review fixes after the DFlash2 push
MLX_CONTINUOUS_BATCHING=1, a refused page-pool grow now evicts parked DFlash2 states and retries once (dense + MoE). Before, parked states could causecontext_length_exceededfor a request that fits after eviction. The scheduler hook is a no-op for other families.--auth-token=<tok>as one argument.capture_keeps_route_bits_and_owns_statenow expects the route the host can run. On the chain route, a capture inside a 64-row chunk matches a shorter forward to about one bf16 step (0.5-0.6% of the state range, checked within 1/64); every other route stays bit-exact.Live check: the original prompt in
splashmlx agent --trace -p "Deepresearch this project, help me understand it"on Qwen3.8-27B GGUF + DFlash2 with this branch (1 main + 4 subagents, 110 requests, stopped after ~40 min):read_filetype errors (invalid type: string "900")TTFT from this run is not reported: other jobs shared the machine during it.
🤖 Generated with Claude Code