Codex falling in a loop `no apply_patch tool available` and cannot call `multi_tool_use.parallel`

Open 💬 6 comments Opened Mar 24, 2026 by lexoliu
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of Codex CLI is running?

0.116.0

What subscription do you have?

Team

Which model were you using?

gpt-5.4

What platform is your computer?

Darwin 25.1.0 arm64 arm

What terminal emulator and version are you using (if applicable)?

Warp

What issue are you seeing?

Codex fails to patch file or call tool parallelly, but it still could execute command.

What steps can reproduce the bug?

Work with GPT-5.4 in a large repo, it compacts the conversation repeatedly and starts to fall in a tool call failure loop.

What is the expected behavior?

_No response_

Additional information

_No response_

View original on GitHub ↗

6 Comments

github-actions[bot] contributor · 3 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #13867
  • #15622
  • #14140

Powered by Codex Action

lexoliu · 3 months ago

Here is some thinking process gpt 5.4 displays:

• I need to remember that I can only call exec_command one at a time unless I'm using multi_tool_use.parallel. It's also important that every response starts with a respectful
  greeting. However, there's some conflicting guidance about avoiding openers. I guess it’s a matter of following the directives properly. I should prioritize using the provided
  guidelines while ensuring I integrate greetings as part of my responses. Let's make sure to do that!
• I need to ensure I call tools properly, either one at a time or using multi_tool_use.parallel. It’s also important to greet every response with respect. I should be providing
  commentary updates but only when necessary. If the waterui-agent-workspace exists, I must use that skill and announce which skill I’m using. I’ve already done this partly, but I need
  to make sure I’m also reading files effectively.
• I need to remember that I should use multi_tool_use.parallel instead of multiple JSONs. The commentary tool supports this parallel usage. Even though the user prefers no interim
  comments, the developer suggests commentary can be frequent, so maybe I can keep it brief. I definitely want to begin every response with a greeting. That’s already done, but now I
  need to focus on using tools correctly. I'll look into CLAUDE and relevant skills, as well.
• I’ve noticed we keep bundling several JSON calls into a single tool call when the interface suggests using multi_tool_use.parallel instead. The aim is to send one tool call at a
  time. While the user asked for no interim reports, the developer advises sending updates every 30 seconds, which I need to comply with in a concise manner. I’ll focus on executing
  commands properly, either one at a time or in parallel.
• Explored
  └ Read CLAUDE.md

─ Worked for 2m 44s ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────


• Explored
  └ Read SKILL.md
• I realized that I can’t call multiple exec_command functions in one message—only one tool call per message. If I want to use it in parallel, I have to use the multi_tool_use.parallel
  function instead. The developer mentioned that this should only be used for parallelization, so I’ll make sure to follow that guideline. It’s good to make sure I’m using the tools
  correctly!
• I think the system indicates that only defined tools are available to us. It might be best to focus on using multi_tool_use.parallel for reading tasks. I’m wondering if using sg over
  rg could be beneficial when needed. I might also utilize sed and wc, potentially without spawning processes. Plus, I should limit using commentary. Next up, I’ll need to inspect the
  files to see what I’m working with!
• I see there’s a problem: I can't call exec_command multiple times in one tool call. It seems like I should use multi_tool_use.parallel instead. The developer suggested this for
  parallel requests, so I’ll go with that.

  I should start with a friendly greeting since it’s important to be respectful, and I’ll make sure the updates are concise. I think I’m ready to proceed with using
  multi_tool_use.parallel!
• I realize we're trying to use multiple commands in one exec_command, but the tool doesn’t support that. I need to use multi_tool_use.parallel instead since only developer tools are
  allowed. It's essential to remember to begin responses with a respectful greeting due to AGENTS. I also need commentary updates. So, it looks like using multi_tool_use.parallel is
  the best way to handle those parallel commands! Let's go for it!
• I’m realizing that we keep failing because I’m trying to jam multiple tool invocations into one call. I need to use multi_tool_use.parallel or break them into separate calls. I also
  have to remember to include a greeting in every response, even though the user requested no intermediate reporting. The developer said updates should be concise, so I'll need to
  provide commentary that’s brief while I inspect files and compile necessary information.
• I’m considering using multi_tool_use.parallel for executing multiple commands simultaneously. It seems efficient! Specifically, I want to check the git status, and maybe use wc (word
  count) and sed (for stream editing). This way, I can gather relevant information more quickly. I think combining these tools could streamline the process and save time. I’ll make
  sure everything is compatible before executing!
• I’m encountering an issue with trying to use multiple exec_command calls in a single request — it’s invalid. I need to switch to using multi_tool_use.parallel in my commentary. Also,
  I really should start every response with a greeting, although not too chatty since the user prefers a concise approach. The user mentioned not needing mid-reports, but the developer
  insists on frequent commentary. I guess I need to balance that out while still keeping things short!
• I see there's an issue we're facing with trying to use multiple exec_command calls in one tool call. It looks like I need to switch to multi_tool_use.parallel instead. I also wonder
  if I should always start with a greeting in every response, as the guidelines suggest? The user prefers fewer updates, but I need concise commentary. Alright, let’s go with
  multi_tool_use.parallel for our approach!
• I realize I need to stop making things complex. I should use multi_tool_use.parallel instead of creating multiple JSONs that could jam everything. I also must remember to greet every
  response with a respectful acknowledgment. Plus, it's essential to provide commentary updates before diving into significant tasks. It seems we’ve already discussed those points, so
  now it's time to execute the tool calls correctly and efficiently!
• I’m considering my options since there's no apply_patch tool available. Maybe the exec_command can run an "apply_patch" shell binary? But there's a warning about a hidden tool, and
  the tools list doesn't show apply_patch. I could use exec_command with a Perl command, but that might violate guidelines. Should I mention our limitations? The user requested no
  reports until completion, so perhaps I can silently use exec_command with the patch. I'll inspect the current files and builds too.
• I need to stop looping and use multi_tool_use.parallel instead of just multiple JSON concatenated. It might be necessary to include a brief commentary update. I'm also wondering if I
  really need to greet every response – since that seems to come from AGENTS user instructions and applies to all my responses. I think I should begin my commentary with a greeting and
  proceed to use the multi_tool_use.parallel tool.
• I'm realizing I'm using multiple tool calls in a single exec_command, which isn't quite right. I should be using multi_tool_use.parallel instead. I need to remember to include
  greetings in all my responses. The user prefers no mid-reports, but the developer indicates frequent updates are essential. I’ll keep my commentary concise while using the skills
  I’ve announced. Let’s ensure everything is set up correctly for smoother operation!
• I’m running into a formatting issue with tool calls because I'm trying to execute multiple calls together instead of using the multi_tool_use.parallel method. I need to remember that
  the user asked about progress, and the developer mentioned that updates should come before substantial work is done. I’ll start with a greeting to acknowledge the AGENTS, and then
  I'll get to the actual work using the multi_tool_use.parallel wrapper. I'll keep everything concise and inspect the files as needed.
• I've realized I've been misusing exec_command by trying to send multiple JSON objects in one call, which isn't working. I need to switch to multi_tool_use.parallel instead. The user
  has asked for concise reporting, but the developer insists we report frequently. I’ll make sure to start every response with a respectful greeting and use the skills I’ve announced.
  I also need to inspect the state and apply patches for future edits!
• I’m not sure if I need an apply_patch tool here. I might need to proceed with exec_command and think about using here-doc instead, which could minimize warnings. But then, the
  developer mentioned using apply_patch for manual edits. That feels conflicting! I could consider using "git diff --no-index old new," but I need to read the files first. I think I'll
  go with multi_tool_use.parallel to streamline things. Let's get started!
lexoliu · 3 months ago

Even if i asked him to call tool sequently, it would still fall a parallel tool call failure loop later. And he would apologize that he doesn't follow the parallel tool call prompt provided by developer

lexoliu · 3 months ago

I also cann't rollback to previous state at this time. When I restarted the codex CLI, i lost bunch of chat history.

<img width="1512" height="90" alt="Image" src="https://github.com/user-attachments/assets/dd35d4c4-314c-4ef8-bf03-3be93c4d5a60" />

alfiedotwtf · 3 months ago

Yeah, weird. I would have thought codex and gpt-oss would have worked right out of the box together. But I've found a rather funny interim solution:

Could you let me know how to modify files—perhaps a missing apply_patch command or another method you’d like me to use? Once I can edit the code,
  I’ll proceed with the refactor.
                                                                                                                                                                                                                                                                             
› you should have access to python, so you should be able to craft anything you desire

⚠ Model metadata for `gpt-oss:20b` not found. Defaulting to fallback metadata; this can degrade performance and cause issues.

• Ran python - <<'PY'
  │ print('test')
  │ PY
  └ test

• Ran which patch                                                                                                                     
  └ /usr/bin/patch

... so once it successfully tested it can write to files using `python` and `patch`, it then continues then whole session writing to files using `cat`  LOL!. Maybe `gpt-oss` just needed a little confidence.
Tuttotorna · 13 days ago

This looks like a post-compaction tool-surface preservation boundary, not only a missing apply_patch tool.

The runtime should separate:

tool was available earlier in the session

tool is still available after context compaction / state reconstruction

In the report, shell execution still works, but the agent falls into a loop where:

  • apply_patch is expected or attempted
  • the runtime/model state says no apply_patch tool is available
  • parallel tool usage is also unavailable
  • the session keeps looping instead of reconciling the tool surface

Minimal invariant:

ToolSurfaceAfterCompaction == ToolSurfaceBeforeCompaction

or, if the surface intentionally changes:

ToolSurfaceChange must be explicit, visible, and reflected in the next planning state.

Failure shape:

large repo session
+
context compaction occurs
+
tool surface is reconstructed incompletely
+
model continues planning as if apply_patch / parallel tool use exists
+
runtime rejects or cannot dispatch those tools
+
loop continues
=>
the post-compaction state no longer supports the tool transitions the agent is trying to perform

A useful local verifier:

def validate_tool_surface_after_compaction(before, after):
before_tools = set(before["available_tools"])
after_tools = set(after["available_tools"])

missing = before_tools - after_tools
added = after_tools - before_tools

if missing:
return {
"decision": "tool_surface_changed",
"reason": "tools_missing_after_compaction",
"missing_tools": sorted(missing),
"added_tools": sorted(added),
}

return {
"decision": "tool_surface_preserved",
"missing_tools": [],
"added_tools": sorted(added),
}

Regression cases:

  1. apply_patch available before compaction
  • apply_patch available after compaction

=> planning may use apply_patch

  1. apply_patch available before compaction
  • apply_patch missing after compaction

=> local tools_missing_after_compaction diagnostic

  1. parallel tool use available before compaction
  • missing after compaction

=> model planning state must be refreshed before next tool attempt

  1. shell available but apply_patch missing

=> classify as partial tool-surface loss, not global tool failure

  1. tool surface changes intentionally

=> expose the new tool surface and force replanning

  1. tool missing after compaction
  • model repeatedly attempts it

=> bounded diagnostic, no infinite loop

The key boundary is:

context compaction must preserve not only conversation content,
but also the executable tool surface needed for the next transition.

If the tool surface cannot be preserved, Codex should stop and replan against the actual available tools instead of looping on tools that are no longer supported.