Skip to content

GPT tool-protocol compatibility: ApplyPatch and Code Mode #1383

Closed

Description

@Astro-Han

Status

Accepted on 2026-07-28.

ApplyPatch and Code Mode will ship as independent capabilities over one effective per-run tool surface. Code Mode will execute JavaScript in a short-lived Node child process outside the Maka process. Node's permission model is defense in depth; the child must also run under the current session's existing OS sandbox or a stricter equivalent.

The current tool surface remains the default until the capability-specific validation gates pass.

Problem

Maka currently gives GPT models a mostly generic direct-tool surface, even when their coding-agent training favors different protocols. In one controlled GPT-5.6 Sol DeepSWE pair, both runs passed, while Maka used 30.2 minutes, 5.36M tokens, and 133 environment actions versus Codex CLI's 18.2 minutes, 2.80M tokens, and 38 actions; a second pair showed the same time direction.

The sample is too small to assign causality, but it is sufficient to test two independent variables:

  1. whether a GPT-compatible ApplyPatch editing surface outperforms Edit/Write; and
  2. whether exec / wait orchestration outperforms direct-only tool calling.

Decision

Extend the effective per-run tool surface from #1493 with one tool-protocol compatibility profile:

Axis Values
Editing Current Edit/Write, ApplyPatch
Orchestration Direct, CodeMode, CodeModeOnly

The profile is a projection over the same effective MakaTool[], deferred activation state, and ToolRuntime. It is not a second registry, tool catalog, permission path, or execution runtime.

Every axis has an explicit per-run override. Model-specific defaults may change only after the corresponding validation gate passes.

Candidate defaults:

Model profile Editing Orchestration
GPT-5 profiles validated for patch training ApplyPatch Direct
GPT-5.6 Sol/Terra ApplyPatch CodeModeOnly
Other models Current surface Direct

These are rollout candidates, not active defaults.

Delivery

CodeModeOnly is an accepted follow-up boundary, but its issue will be opened only after CodeMode lands so its PR can start flat from the latest main.

#1493 is a prerequisite for both current slices and the later CodeModeOnly delivery. Each delivery must extend its effective-surface result rather than create a parallel name list or binding path.

ApplyPatch and Code Mode remain independently selectable and independently revertible. ExploreAgent removal is not part of these deliveries; open separate work only when a concrete cleanup requirement exists.

Shared invariants

Tool authority

  • The effective per-run tool surface from refactor(runtime): project one effective product-tool surface per run #1493 remains authoritative.
  • Every nested tool call re-enters the existing ToolRuntime; Code Mode must not call MakaTool.impl directly.
  • Existing validation, deferred gating, permission checks, sandbox policy, abort, limits, durable T1/T2 facts, telemetry, artifacts, and UI activity remain in force.
  • Provider history contains only the exec / wait calls issued by the model. Nested calls are durable runtime facts linked to their parent exec, but are never replayed as provider function calls or results.

Code Mode process boundary

  • Each exec cell runs in a short-lived Node child process, not Maka's main process and not a persistent sidecar.
  • A cell receives no direct filesystem, process, module, worker, or network authority.
  • Node --permission restrictions provide defense in depth. The OS sandbox remains the authority ceiling; if Maka cannot enforce that ceiling, Code Mode fails closed.
  • A cell that completes within the initial yield window returns directly. Otherwise exec returns an opaque cell_id, and top-level wait collects more output or terminates it.
  • Cells do not persist across turns or application restarts and do not provide REPL state.

Projection

Mode Provider top level Inside exec
Direct Active ordinary tools Unavailable
CodeMode Active ordinary tools plus exec / wait Active nestable tools
CodeModeOnly exec / wait plus direct-only exceptions Active nestable tools

AskUserQuestion, Agent/Team tools, exec, and wait are direct-only. Ordinary product and supplemental tools are nestable by default. load_tools is nestable; inside a cell it updates the existing activation state and exposes newly loaded tools to that same cell.

Validation and rollout gate

  • ApplyPatch A/B holds model, prompt, task, executor, and orchestration mode constant.
  • Code Mode A/B holds the editing surface constant and compares Direct, CodeMode, and CodeModeOnly.
  • Contract tests cover editing replacement, the projection matrix, top-level and nested admission, same-cell load_tools, nested-call durability without provider transcript pollution, cell ownership/lifecycle, and the sandbox authority ceiling.
  • No model default changes unless correctness does not regress and provider steps, context use, or wall time improve consistently.
  • Every enabled default retains an explicit rollback to the previous surface.

Non-goals

  • Shipping ApplyPatch and Code Mode in one implementation PR.
  • Removing ExploreAgent.
  • Adding provider-hosted tools.
  • Building a general-purpose scripting platform or persistent REPL.
  • Requiring provider-native programmatic calling for V1.

Activity

  1. somewan820 commented on Jul 23, 2026

    @somewan820
    Contributor

    @Astro-Han I'd like to take this issue.

  2. Astro-Han commented on Jul 23, 2026

    @Astro-Han
    ContributorAuthor

    Hi @somewan820, #1383 is closed for now until #1381 finishes. Would be happy to initial this issue once #1381 is done!

  3. changed the title [-][RFC] Native-first Programmatic Tool Calling[/-] [+][RFC] GPT tool-protocol compatibility: ApplyPatch and Code Mode[/+] on Jul 27, 2026
  4. added
    enhancement
    on Jul 27, 2026
  5. Astro-Han commented on Jul 27, 2026

    @Astro-Han
    ContributorAuthor

    #1381 is complete through #1390, #1417, and #1425, so the original blocker is gone. Reopening and revising this RFC based on the newer GPT-5.6 head-to-head evidence and the current effective-tool-surface work in #1493.

    The revision changes three assumptions: it treats ApplyPatch and Code Mode as independent axes of one model compatibility profile, targets the observed local exec / wait protocol instead of requiring provider-native programmatic calling first, and keeps their implementation and evaluation deliveries separate.

  6. changed the title [-][RFC] GPT tool-protocol compatibility: ApplyPatch and Code Mode[/-] [+]GPT tool-protocol compatibility: ApplyPatch and Code Mode[/+] on Jul 28, 2026
  7. added
    help wanted
    on Aug 22, 2026
  8. Astro-Han commented on Aug 26, 2026

    @Astro-Han
    ContributorAuthor

    Status revision — 2026-08-26

    The 2026-07-28 acceptance still holds on its core point: tool-protocol compatibility is a projection over one effective per-run tool surface, not a second registry, catalog, permission path, or execution runtime. Everything below revises what has changed since.

    1. The editing axis is retired

    #1552 was closed as superseded by #2532, which replaced the design with the AI SDK native openai.tools.applyPatch(), registered only for documented Apply Patch models on native OpenAI Responses. #2532 removed the editing-protocol projection outright — no custom parser, no per-run editing override, no provider fallback. Desktop surfacing was tracked and closed in #2601.

    Editing is therefore no longer an axis of this profile. It is an automatic model-capability gate (provider-registry.ts, applyPatchProtocol). The two-axis table above should be read as one axis, and this issue's title is now wider than its scope — I propose retitling it to Code Mode only.

    2. Code Mode's execution model changed

    This issue accepted "a short-lived Node child process outside the Maka process", with Node's permission model as defense in depth and the child running under the session's existing OS sandbox.

    What shipped is in-process QuickJS via @ai-sdk/code-mode's experimental_runCodeMode (#2549, wrapped by packages/code-mode/src/quickjs.ts; remaining cleanup in #3213). The isolation premise of the accepted decision no longer describes the implementation. #2466 required any such replacement to preserve ToolRuntime permissions, suspension, abort, durability, recovery, hidden replay, and Desktop/CLI/Headless packaging; that preservation should be stated item by item before the path becomes user-reachable.

    3. The validation gate ran in reduced form and returned "do not roll out"

    The 89-task paired TB2.1 evaluation was never executed. #2466 closed with the plan deliberately revised: a 10-task single-repetition diagnostic, equal verifier outcomes across Direct, Self, and QuickJS (7/10 each), establishing neither equivalence nor non-inferiority — and establishing that automatic rollout was not justified.

    provider steps tool calls tokens
    Direct 212 239 6.03M
    QuickJS 354 883 12.30M

    Same pass rate at roughly 1.7x steps, 3.7x tool calls, and 2x tokens.

    4. Candidate defaults are withdrawn

    The candidate table above (GPT-5.6 Sol/Terra -> ApplyPatch + CodeModeOnly) is superseded. #2466's decision is to retain Code Mode as a supported, default-off capability and to enable it automatically for no model on the current evidence.

    Subsequent internal A/B work narrows this further: current models largely do not use Code Mode well — DeepSeek V4 Flash does not — and gpt-5.6-sol is the only model observed to use it effectively, while broad adoption of that family is not currently planned.

    Taken together: there is no rollout hypothesis today, and Code Mode's measured cost is roughly double for no measured benefit outside one model family.

    5. CodeModeOnly

    Recorded here as an accepted follow-up boundary whose issue would open once Code Mode landed. Code Mode landed in August; no issue was opened, and ToolMode in packages/core/src/tool-mode.ts is 'direct' | 'code_mode' with no third value. This needs an explicit call: open it, or retire the value from this decision.

    Current state

    Open decisions

    1. Does the user-facing preference (feat(desktop): add a CodeMode preference #2578, feat(desktop): add a CodeMode preference #3850) ship at all before there is a rollout hypothesis? CodeMode: harden boundaries and measure its TB2.1 impact #2466 assigned this work here, but its own evidence argues against exposure without a model gate and a visible cost signal.
    2. Does the in-process QuickJS model satisfy the isolation requirement this issue accepted, or does that requirement change?
    3. CodeModeOnly: open or retire.

    Delivery — updated

    AI use: Claude Code assisted with source and issue investigation; the analysis and conclusions are my own.

  9. removed
    help wanted
    on Sep 17, 2026
  10. github-actions commented on Sep 26, 2026

    @github-actions

    This issue has had no human activity for 30 days and has been marked stale. It will be closed in 30 days unless someone comments.

    If the issue is still current, please confirm it against the latest main and add any information that would help move it forward. Assigned issues and issues labelled pinned are exempt from this policy.

  11. added
    stale
    on Sep 26, 2026
  12. github-actions commented on Oct 26, 2026

    @github-actions

    This issue has been closed because it received no human response during the 30-day grace period. This is not a judgement on the value of the report.

    If the issue still applies to the latest main, please comment with updated evidence so a maintainer can reopen it, or open a follow-up issue with the missing information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementstale

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions