Repository navigation
fix: expose codex apply_patch for local models (#9114) - #9121
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b1441135b
ℹ️ 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".
| "support_verbosity": False, | ||
| "default_verbosity": None, | ||
| "apply_patch_tool_type": None, | ||
| "apply_patch_tool_type": "function", |
There was a problem hiding this comment.
Gate the unsupported function apply-patch variant
Codex 0.144.0-alpha.4, which _codex_supports_model_catalog() accepts as newer than 0.110.0, rejects the generated catalog before launching with unknown variant 'function', expected 'freeform'. Consequently, users on this supported Codex version cannot start any Unsloth Codex session after the catalog is regenerated; use the recognized freeform value or raise the version gate to the first Codex release that accepts function.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed. The catalog now emits freeform, and focused compatibility tests execute the native tool through Codex 0.147.0, 0.148.0, and 0.151.0.
|
Confirmed the catalog in unsloth_cli/commands/start.py still emits apply_patch_tool_type as None, so local models launched through unsloth codex never get the native editing tool, and the one-line flip plus the assertion in unsloth_cli/tests/test_start.py is the right fix. Could you drop the unrelated reformatting in the three test files so this stays to the catalog change? |
|
apply_patch_tool_type |
tools in the request |
|---|---|
null (main today) |
exec_command, write_stdin, update_plan, request_user_input, view_image, ... no apply_patch |
"freeform" |
same list plus apply_patch, as {"type": "custom", "format": {"type": "grammar", "syntax": "lark", ...}} |
"function" (this PR) |
no request, config load dies first |
unsloth codex points Codex at Studio's /v1/responses (start.py writes wire_api = "responses" against the Studio base URL). That endpoint converts to a ChatCompletionRequest through _build_chat_request on both paths (inference.py:17980 non-streaming, inference.py:18138 streaming), and _translate_responses_tools_to_chat forwards function tools only:
if tool.get("type") != "function":
continuemodels/inference.py:2352-2360 documents the same: other tool types "are accepted for SDK compatibility but ignored on the llama-server passthrough". Nothing under studio/ handles apply_patch or the patch envelope.
llama-server drops it a second time even if Studio forwarded it. tools/server/server-chat.cpp:261-263 in ggml-org/llama.cpp:
if (type != "function") {
SRV_WRN("unsupported Responses tool type '%s' skipped\n", type.c_str());So the Lark grammar is never read, the tool never enters the templated prompt, and the model's actual tool list, which is what #9114 is about, is unchanged.
Closing #9114 needs the translator to carry the freeform tool through, or a deliberate decision to keep local models on the shell-intercept path. A catalog constant cannot do it at any value.
unsloth_cli/codex_fallback_prompt.md:132: the only patching instruction the model gets describes a call no tool in the request accepts
Line 132, pinned as base_instructions at start.py:2478:
- Use the `apply_patch` tool to edit files (NEVER try `applypatch` or `apply-patch`, only `apply_patch`): {"command":["apply_patch","*** Begin Patch\n...*** End Patch"]}
The file is delivered verbatim as the request's instructions (20750 bytes, byte-identical to the vendored file). The tools that arrive alongside it, captured from codex-cli 0.147.0 on this catalog, take these parameters:
exec_command cmd, justification, login, max_output_tokens, prefix_rule, sandbox_permissions, shell, tty, workdir, yield_time_ms
write_stdin chars, max_output_tokens, session_id, yield_time_ms
update_plan explanation, plan
request_user_input questions
view_image path
None accepts command; the shell tool here is exec_command, which takes cmd. So on main today the model's one patching instruction describes a call it cannot make, which is a plausible driver of the symptom in #9114, "the system prompt mentions it, but it's not in my actual tool list", and it is independent of the catalog value.
Setting the field does not resolve it, it adds a contradiction. The description Codex sends with the freeform tool is:
The `apply_patch` tool can be used to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.
The model would receive both strings. This is not vendor drift: the file matches models-manager/prompt.md at 0.144.0 and 0.147.0, and upstream pairs that prompt with apply_patch_tool_type: None in its own unknown-model fallback (models-manager/src/model_info.rs). The prompt upstream pairs with freeform, carried by gpt-5.2 in models-manager/models.json, replaces the JSON example with that same sentence.
start.py:2436 states the intent to keep this metadata aligned with Codex's unknown-model fallback. The prompt and the tool type are one pair upstream, so both have to move together. start.py:219 already ships tool-call healing because small GGUFs emit malformed calls; handing one contradictory instructions about a grammar-constrained format makes that worse.
unsloth_cli/tests/test_start.py:857: the test pins the value Codex rejects
assert catalog["models"][0]["apply_patch_tool_type"] == "function"The assertion restates the literal written at start.py:2483, with no reference to Codex's schema, so it passes on a catalog Codex cannot load. Nothing else in the suite checks the catalog against Codex's types: the codex tests in this file mock _codex_supports_model_catalog and never invoke a real binary. That is the gap that let an invalid value through.
Point it at "freeform", and assert against the set of values Codex accepts rather than a bare literal, since upstream has already narrowed this field once. A check that the generated catalog actually parses with the installed Codex would catch the whole class.
mahiatlinux
left a comment
There was a problem hiding this comment.
Review posted as a comment above.
|
Reviewed and extended this beyond the catalog literal. The original issue is real, but the original fix was incomplete and used a value that current Codex rejects. Before and afterBefore this PR, The PR originally changed the value to The final implementation now:
End-to-end verificationI ran Codex 0.151.0 against an actual Unsloth Studio server using Successful operations covered create, modify, two hunks in one file, delete, nested paths, spaces in paths, Unicode names and content, LF, and CRLF. Missing-context and malformed patches failed without changing the target. A workspace-write attempt outside the working tree did not create the sentinel. Existing The first real Gemma attempt produced an invalid hunk and Codex rejected it. That exposed the missing patch-format guidance and led to the grammar-preserving function bridge plus valid example. A Qwen2.5 Coder 3B Q8 run imitated tool text instead of making a structured call, which is model behavior rather than a transport failure. Compatibility and tests
Final-head focused CI: Full fork CI for the exact final source HEAD: results. It completed with 38 passes and 4 expected skips. Seven checks reproduced failures already present on current |
|
@codex review |
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. |
|
Codex Review: Didn't find any major issues. 👍 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". |
|
All reviewed and fixed, LGTM. full fork CI results |
Summary
Fixes #9114 by exposing Codex's native
apply_patchtool for Unsloth-served local models.Root cause
The generated Codex model catalog set
apply_patch_tool_typetoNone, so Codex did not register the native editing tool.Validation
git diff --checkpassed.pytestis not installed.