Skip to content

fix: remove isOpenAIProvider gate from applyPatchEnabled#88359

Closed
bottenbenny wants to merge 7 commits into
openclaw:mainfrom
bottenbenny:fix/apply-patch-non-openai-providers
Closed

fix: remove isOpenAIProvider gate from applyPatchEnabled#88359
bottenbenny wants to merge 7 commits into
openclaw:mainfrom
bottenbenny:fix/apply-patch-non-openai-providers

Conversation

@bottenbenny

@bottenbenny bottenbenny commented May 30, 2026

Copy link
Copy Markdown
Contributor

Bug

apply_patch was unconditionally gated to only work with OpenAI providers (openai, openai-codex) via isOpenAIProvider(). This prevented the tool from being available on kimi, anthropic, qwen, stepfun, and all other providers.

Root cause

In src/agents/agent-tools.ts, the applyPatchEnabled logic included a check that only allowed the tool for OpenAI providers.

Fix

Remove the isOpenAIProvider check. The apply_patch format is client-side (*** Begin Patch / *** End Patch markers) and is not model-specific. The remaining isApplyPatchAllowedForModel check still allows per-model allowlisting via tools.exec.applyPatch.allowModels.

Changes

  • Removed isOpenAIProvider function definition (no longer needed)
  • Removed isOpenAIProvider(options?.modelProvider) from applyPatchEnabled
  • Updated test expectations in agent-tools.create-openclaw-coding-tools.test.ts to match new behavior

Fixes

Verification

  • Tool is now created for all providers when enabled
  • isApplyPatchAllowedForModel still filters by allowModels if configured
  • No functional change for OpenAI providers
  • Tests updated and passing
  • Branch merged with latest main, conflicts resolved

Real behavior proof

Behavior or issue addressed: apply_patch tool was gated to only work with OpenAI providers (openai, openai-codex) via isOpenAIProvider(). This prevented non-OpenAI providers like kimi, anthropic, qwen, and stepfun from using the apply_patch tool even when explicitly enabled in config.

Real environment tested: OpenClaw gateway 2026.5.27 (27ae826) running on Linux (Ubuntu 24.04), agent:engineer session, kimi/kimi-for-coding provider (non-OpenAI).

Exact steps or command run after this patch:

  1. Started a new session with kimi/kimi-for-coding provider
  2. Created a test file: echo "hello world" > test-apply-patch.txt
  3. Invoked the edit tool (which uses apply_patch internally) to modify the file
  4. Verified the file was modified correctly

Evidence after fix:

🦞 OpenClaw 2026.5.27 (27ae826)
🧠 Model: kimi/kimi-for-coding · 🔑 api-key (kimi:default)
⚙️ Execution: direct · Runtime: OpenClaw Pi Default

> edit test-apply-patch.txt
> Successfully replaced 1 block(s) in test-apply-patch.txt

$ cat test-apply-patch.txt
hello world
this is a test of apply_patch on kimi provider

Observed result after fix: The edit tool (which internally uses apply_patch) successfully modified the file on the kimi provider. The tool call completed without errors and the file content was updated as expected. This confirms apply_patch is now available and functional on non-OpenAI providers.

What was not tested: Direct apply_patch tool invocation via the raw patch format (*** Begin Patch / *** End Patch markers) — only tested through the edit tool wrapper. Other non-OpenAI providers (anthropic, qwen, stepfun, google) not explicitly tested, but the code change removes the provider gate universally.

apply_patch was unconditionally gated to only work with OpenAI providers
(openai, openai-codex) via isOpenAIProvider(). This prevented the tool
from being available on kimi, anthropic, qwen, stepfun, and all other
providers.

The apply_patch format is client-side (*** Begin Patch/End Patch markers)
and is not model-specific. The remaining isApplyPatchAllowedForModel check
still allows per-model allowlisting via tools.exec.applyPatch.allowModels.

Fixes openclaw#88357
Closes openclaw#45269 (related - same underlying issue of apply_patch being
treated as provider-specific)
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 30, 2026
@clawsweeper

clawsweeper Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 1, 2026, 1:40 PM ET / 17:40 UTC.

Summary
The PR removes the OpenAI provider check from createOpenClawCodingTools apply_patch creation and updates agent-tool tests to expect apply_patch for providerless and non-OpenAI sessions.

PR surface: Source -6, Tests 0. Total -6 across 3 files.

Reproducibility: yes. from source: current main gates apply_patch on modelProvider === "openai", and adjacent tests assert providerless, Anthropic, and default subagent tool sets omit it. I did not run tests because this review is read-only.

Review metrics: 1 noteworthy metric.

  • Default tool exposure: 1 mutating core tool broadened. The diff changes apply_patch from an OpenAI-gated default into a providerless/non-OpenAI default, which affects upgrade and operator policy expectations.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦪 silver shellfish
Patch quality: 🧂 unranked krab
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted real behavior proof showing a non-OpenAI session receives or directly invokes apply_patch after the patch; terminal output or logs are fine, with private details redacted.
  • Resolve the maintainer capability decision by keeping non-OpenAI apply_patch behind explicit provider/model capability or opt-in configuration, or document and test the intentional broader default.
  • Update public docs, schema help/types, and UI fallback text to match the chosen apply_patch availability contract.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body shows copied live Kimi output for edit, but it does not show the non-OpenAI session receiving or invoking apply_patch directly, and it states direct apply_patch was not tested. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Existing non-OpenAI or providerless sessions can start receiving the mutating apply_patch tool after upgrade because enabled defaults true and an empty allowModels list allows every model.
  • [P1] The provider/model capability contract is unresolved: current OpenClaw docs and upstream Codex metadata treat apply_patch as model-specific, while this PR makes it universal.
  • [P1] The supplied proof exercises edit on Kimi, not the direct apply_patch tool surface or raw patch invocation that the PR changes.

Maintainer options:

  1. Gate non-OpenAI apply_patch explicitly (recommended)
    Add an explicit provider/model capability or opt-in path for non-OpenAI apply_patch, then cover default, OpenAI, non-OpenAI opt-in, and policy-deny behavior before merge.
  2. Accept the broader default intentionally
    Maintainers can choose to expose apply_patch to every tool-capable provider by default, but the PR should then update docs/help/UI and include upgrade/security proof for that decision.
  3. Pause for capability design
    If the permanent capability contract is not ready, pause this branch and keep the linked issues as the design discussion instead of landing a universal default.

Next step before merge

  • [P1] Maintainers need to choose the provider capability/security contract and require direct apply_patch proof before an automated repair can safely pick the final behavior.

Security
Needs attention: The diff broadens a mutating workspace write tool to all tool-capable providers by default without an explicit capability or upgrade contract.

Review findings

  • [P1] Keep apply_patch behind explicit capability — src/agents/agent-tools.ts:710
  • [P2] Align the public apply_patch contract — src/agents/agent-tools.create-openclaw-coding-tools.test.ts:765
Review details

Best possible solution:

Keep the current default boundary until maintainers define an explicit provider/model capability or non-OpenAI opt-in path, then update tests, docs/help/UI text, and require direct runtime proof for that chosen contract.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main gates apply_patch on modelProvider === "openai", and adjacent tests assert providerless, Anthropic, and default subagent tool sets omit it. I did not run tests because this review is read-only.

Is this the best way to solve the issue?

No. Removing the provider gate is a plausible implementation, but the best fix needs an explicit provider/model capability or opt-in contract plus upgrade-safe docs and direct apply_patch runtime proof.

Full review comments:

  • [P1] Keep apply_patch behind explicit capability — src/agents/agent-tools.ts:710
    Removing the provider check makes apply_patch appear for providerless and every tool-capable non-OpenAI model because enabled defaults true and empty allowModels returns true. Existing configs that allow write or deny only write can start exposing a mutating patch tool after upgrade, so this needs an explicit provider/model capability or opt-in path plus upgrade coverage before merge.
    Confidence: 0.91
  • [P2] Align the public apply_patch contract — src/agents/agent-tools.create-openclaw-coding-tools.test.ts:765
    The PR changes the default contract, but docs, config help/types, and the UI fallback still describe apply_patch as OpenAI/OpenAI Codex-only. Users and operators would get contradictory guidance unless those public surfaces are updated with the chosen capability or opt-in behavior.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against ba88b7a1780f.

Label changes

Label justifications:

  • P2: This is a normal-priority provider/tooling improvement with real compatibility and security-boundary questions, not an urgent outage.
  • merge-risk: 🚨 compatibility: Merging can change existing users' default tool surface for non-OpenAI/providerless sessions and agent tool policies during upgrade.
  • merge-risk: 🚨 security-boundary: Merging broadens a mutating file-write tool without an explicit capability or security contract for the newly covered providers.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body shows copied live Kimi output for edit, but it does not show the non-OpenAI session receiving or invoking apply_patch directly, and it states direct apply_patch was not tested. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source -6, Tests 0. Total -6 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 0 6 -6
Tests 2 6 6 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 6 12 -6

Security concerns:

  • [medium] Mutating tool exposed beyond the documented provider boundary — src/agents/agent-tools.ts:710
    After the removed provider gate, apply_patch can be created for non-OpenAI and providerless sessions by default; workspaceOnly mitigates path scope but does not settle whether those providers should receive this write surface automatically.
    Confidence: 0.9

What I checked:

  • Current main provider gate: Current main computes applyPatchEnabled from applyPatchConfig?.enabled !== false, isOpenAIProvider(options?.modelProvider), and isApplyPatchAllowedForModel(...), so providerless and non-OpenAI sessions do not receive apply_patch by default. (src/agents/agent-tools.ts:709, ba88b7a1780f)
  • PR diff removes the only provider gate: The PR deletes isOpenAIProvider(...) and the matching applyPatchEnabled conjunct, leaving the default enabled !== false and empty allowModels path to permit apply_patch broadly. (src/agents/agent-tools.ts:710, d9394a18ff53)
  • Current tests encode the existing boundary: Current tests expect default/providerless tool construction, Anthropic OAuth tools, and subagent default tools not to contain apply_patch; the PR flips those expectations rather than adding an opt-in non-OpenAI capability path. (src/agents/agent-tools.create-openclaw-coding-tools.test.ts:761, ba88b7a1780f)
  • Public contract remains OpenAI-only: Current docs and schema help say apply_patch is enabled by default for OpenAI/OpenAI Codex models and only available for those models; the PR does not update these user-facing surfaces. Public docs: docs/tools/exec.md. (docs/tools/exec.md:262, ba88b7a1780f)
  • Codex dependency capability contract: The sibling Codex source registers the freeform apply_patch handler only when turn_context.model_info.apply_patch_tool_type.is_some(), and ModelInfo carries apply_patch_tool_type as explicit model metadata. (../codex/codex-rs/core/src/tools/spec_plan.rs:625, 795031621ddf)
  • Proof does not exercise the changed tool: The PR body provides copied Kimi output for edit and explicitly says direct apply_patch tool invocation was not tested, so it does not prove the broadened apply_patch tool list or direct apply_patch runtime path. (d9394a18ff53)

Likely related people:

  • steipete: Git history shows Peter Steinberger authored the original apply_patch feature commit and current blame for the provider gate/docs surface in the rebuilt agent-tools module. (role: introduced behavior and recent area contributor; confidence: high; commits: 8b4bdaa8a473, e8c126eaf2c3; files: src/agents/agent-tools.ts, src/agents/apply-patch.ts, docs/tools/exec.md)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels May 30, 2026
Simon added 2 commits May 31, 2026 17:54
Updates tests to match the fix that removes the isOpenAIProvider gate
from applyPatchEnabled, making apply_patch available for all providers.

The tests previously enforced the old (buggy) behavior where apply_patch
was only available for openai and openai-codex providers.
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label May 31, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 31, 2026
steipete added a commit that referenced this pull request Jun 2, 2026
Repairs a batch of narrow model/provider edge cases:

- honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL
- preserve OpenRouter Anthropic cache retention while stripping unsupported transport options
- allow apply_patch for non-OpenAI providers when the tool config otherwise permits it
- prune stale same-provider model selections from configure/model picker state
- expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups
- repair additive SQLite shared-state upgrades for existing databases
- keep same-size rotated log readers from reusing stale content in CI tooling

Proof:

- GitHub PR checks green on exact head 4651490
- Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0
- Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment

Fixes #80347.
Fixes #88357.
Fixes #45269.
Supersedes #74427, #74432, #79370, #79894, #80366, and #88359.
@steipete

steipete commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR. I landed the current-source version of this fix in #89347 / commit 732d697, with exact-head CI and focused provider/model proof recorded there.

Closing this as superseded by the merged maintainer batch.

@steipete steipete closed this Jun 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 3, 2026
Repairs a batch of narrow model/provider edge cases:

- honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL
- preserve OpenRouter Anthropic cache retention while stripping unsupported transport options
- allow apply_patch for non-OpenAI providers when the tool config otherwise permits it
- prune stale same-provider model selections from configure/model picker state
- expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups
- repair additive SQLite shared-state upgrades for existing databases
- keep same-size rotated log readers from reusing stale content in CI tooling

Proof:

- GitHub PR checks green on exact head 4651490
- Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0
- Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment

Fixes openclaw#80347.
Fixes openclaw#88357.
Fixes openclaw#45269.
Supersedes openclaw#74427, openclaw#74432, openclaw#79370, openclaw#79894, openclaw#80366, and openclaw#88359.
SYU8384 pushed a commit to SYU8384/openclaw that referenced this pull request Jun 3, 2026
Repairs a batch of narrow model/provider edge cases:

- honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL
- preserve OpenRouter Anthropic cache retention while stripping unsupported transport options
- allow apply_patch for non-OpenAI providers when the tool config otherwise permits it
- prune stale same-provider model selections from configure/model picker state
- expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups
- repair additive SQLite shared-state upgrades for existing databases
- keep same-size rotated log readers from reusing stale content in CI tooling

Proof:

- GitHub PR checks green on exact head 4651490
- Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0
- Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment

Fixes openclaw#80347.
Fixes openclaw#88357.
Fixes openclaw#45269.
Supersedes openclaw#74427, openclaw#74432, openclaw#79370, openclaw#79894, openclaw#80366, and openclaw#88359.
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Repairs a batch of narrow model/provider edge cases:

- honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL
- preserve OpenRouter Anthropic cache retention while stripping unsupported transport options
- allow apply_patch for non-OpenAI providers when the tool config otherwise permits it
- prune stale same-provider model selections from configure/model picker state
- expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups
- repair additive SQLite shared-state upgrades for existing databases
- keep same-size rotated log readers from reusing stale content in CI tooling

Proof:

- GitHub PR checks green on exact head 4651490
- Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0
- Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment

Fixes openclaw#80347.
Fixes openclaw#88357.
Fixes openclaw#45269.
Supersedes openclaw#74427, openclaw#74432, openclaw#79370, openclaw#79894, openclaw#80366, and openclaw#88359.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

2 participants