diff --git a/internal/runtime/provider_codex.go b/internal/runtime/provider_codex.go index 8ba69579b..f34b9339c 100644 --- a/internal/runtime/provider_codex.go +++ b/internal/runtime/provider_codex.go @@ -22,6 +22,8 @@ func (codexProvider) Materialize(ctx *providerMaterializeContext) error { func (codexProvider) Prepare(in providerInvocation) (CommandSpec, error) { argv := buildProviderArgs(in) argv = dropCodexResumeArgs(argv) + // Runs expose tools through the Agent's MCP allowlist, as chat does. + argv = append(argv, "-c", `web_search="disabled"`) // exec options must precede the `resume` subcommand, so the effort config // override is appended here rather than after the resume session ID. if effort := strings.TrimSpace(in.Executor.Effort); effort != "" && !codexHasReasoningEffort(argv) { diff --git a/internal/runtime/provider_gateway_integration_test.go b/internal/runtime/provider_gateway_integration_test.go index 6930a5432..c73aa5412 100644 --- a/internal/runtime/provider_gateway_integration_test.go +++ b/internal/runtime/provider_gateway_integration_test.go @@ -49,6 +49,15 @@ func TestNativeProviderCustomGateway(t *testing.T) { http.Error(w, "bad body", 400) return } + unsupportedSearch := false + if kind == "codex" { + tools, _ := body["tools"].([]any) + for _, raw := range tools { + tool, _ := raw.(map[string]any) + toolType, _ := tool["type"].(string) + unsupportedSearch = unsupportedSearch || strings.HasPrefix(toolType, "web_search") + } + } mu.Lock() requests++ expectedPath, header := "/v1/responses", r.Header.Get("Authorization") @@ -61,7 +70,14 @@ func TestNativeProviderCustomGateway(t *testing.T) { if r.URL.Path != expectedPath || header != expectedKey || body["model"] != "gateway-test-model" { wrong = "wrong endpoint, key or model" } + if unsupportedSearch { + wrong = "unexpected built-in web search tool" + } mu.Unlock() + if unsupportedSearch { + http.Error(w, "web_search is not supported by this gateway", http.StatusBadRequest) + return + } w.Header().Set("Content-Type", "text/event-stream") emit := func(event string, data any) { raw, _ := json.Marshal(data) diff --git a/internal/runtime/provider_test.go b/internal/runtime/provider_test.go index 1d2076505..11b67fc5f 100644 --- a/internal/runtime/provider_test.go +++ b/internal/runtime/provider_test.go @@ -55,6 +55,48 @@ func TestProvidersBuildFinalArgvWithoutDuplicateManagedFlags(t *testing.T) { } } +func TestCodexRunDisablesBuiltinWebSearch(t *testing.T) { + for _, test := range []struct { + name, driver, session string + args []string + }{ + {name: "existing executor", driver: "local", args: []string{"exec", "--json"}}, + {name: "cached search", driver: "docker", args: []string{"exec", "-c", `web_search="cached"`}}, + {name: "live search", driver: "bwrap", args: []string{"exec", "-c", `web_search="live"`}}, + {name: "resume", driver: "local", session: "session-123", args: []string{"exec", "resume", "stale"}}, + } { + t.Run(test.name, func(t *testing.T) { + command, err := providerForKind("codex").Prepare(providerInvocation{ + Executor: domain.ExecutorDefinition{Kind: "codex", Binary: "codex", Args: test.args}, + Compiled: compiledConfig{Args: codexConfigArgs("probe", nil, []domain.MCPServerDefinition{ + {ID: "docs", Transport: "http", URL: "https://mcp.example/x"}, + })}, + Prompt: "probe", + Driver: test.driver, + Options: InvocationOptions{ResumeSessionID: test.session}, + }) + if err != nil { + t.Fatal(err) + } + webSearch := "" + for i, arg := range command.Argv { + if arg == "resume" { + break // Config overrides must precede this subcommand. + } + if arg == "-c" && i+1 < len(command.Argv) && strings.HasPrefix(command.Argv[i+1], "web_search=") { + webSearch = command.Argv[i+1] + } + } + if webSearch != `web_search="disabled"` { + t.Fatalf("effective web search config = %q in %v", webSearch, command.Argv) + } + if !hasContiguousArgs(command.Argv, []string{"-c", `mcp_servers.docs.url="https://mcp.example/x"`}) || command.Argv[len(command.Argv)-1] != "probe" { + t.Fatalf("MCP configuration or prompt was lost: %v", command.Argv) + } + }) + } +} + func TestCodeBuddyPluginDirectoryCannotConsumePrompt(t *testing.T) { command, err := providerForKind("codebuddy").Prepare(providerInvocation{ Executor: domain.ExecutorDefinition{Kind: "codebuddy", Binary: "codebuddy"},