From fd19b858018f97f5e7acac9b3990061be7d9967c Mon Sep 17 00:00:00 2001 From: SaladDay <1203511142@qq.com> Date: Thu, 8 Oct 2026 19:16:32 +0000 Subject: [PATCH] Use the Codex RPC budget for MCP checks --- .../agent/codex/mcp_http_preflight.go | 5 +- .../agent/codex/mcp_http_preflight_test.go | 52 +++++++++++++++++++ .../agent/codex/preparation_helpers_test.go | 7 +++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/apps/daemon/internal/agent/codex/mcp_http_preflight.go b/apps/daemon/internal/agent/codex/mcp_http_preflight.go index 9a17434e5..7c21f846c 100644 --- a/apps/daemon/internal/agent/codex/mcp_http_preflight.go +++ b/apps/daemon/internal/agent/codex/mcp_http_preflight.go @@ -5,16 +5,13 @@ import ( "encoding/json" "errors" "reflect" - "time" ) // config/read loads the same cwd and CLI layers without MCP discovery. Native // mcpServerStatus/list instead opens eager discovery connections; do not use it // to decide whether undeclared servers are safe to contact. func verifyMCPConfig(ctx context.Context, rpc *JSONRPCClient, plan SessionPlan) error { - check, cancel := context.WithTimeout(ctx, 5*time.Second) - defer cancel() - raw, err := rpc.Request(check, "config/read", map[string]any{"cwd": plan.Cwd, "includeLayers": false}) + raw, err := rpc.Request(ctx, "config/read", map[string]any{"cwd": plan.Cwd, "includeLayers": false}) if err != nil { // Native configuration errors and responses can contain operator secrets. return errors.New("codex: cannot verify public MCP configuration") diff --git a/apps/daemon/internal/agent/codex/mcp_http_preflight_test.go b/apps/daemon/internal/agent/codex/mcp_http_preflight_test.go index d3a15c88b..9dd07ed5d 100644 --- a/apps/daemon/internal/agent/codex/mcp_http_preflight_test.go +++ b/apps/daemon/internal/agent/codex/mcp_http_preflight_test.go @@ -1,11 +1,13 @@ package codex import ( + "context" "encoding/json" "os" "path/filepath" "strings" "testing" + "time" "github.com/MiniMax-AI/OpenAgentCore/apps/daemon/internal/agent" "github.com/MiniMax-AI/OpenAgentCore/internal/agentdaemon/proto" @@ -124,6 +126,56 @@ func TestPublicMCPHTTPPreflightRedactsNativeErrors(t *testing.T) { } } +func TestPublicMCPHTTPPreflightUsesDefaultRequestBudget(t *testing.T) { + req, cfg, root := preparationFixture(t) + req.ExecutionControls = nil + t.Setenv("OAC_TEST_PREPARATION_MCP_DELAY", "6s") + if _, err := testExecutor(t, "complete", req, cfg); err != nil { + t.Fatalf("valid MCP configuration after remote metadata work: %v", err) + } + assertPreparationOnly(t, root) + waitPreparationMethod(t, root, "config/read") +} + +func TestPublicMCPHTTPPreflightBudgetFailuresStayRedacted(t *testing.T) { + for _, mode := range []string{"request-timeout", "owner-cancel"} { + t.Run(mode, func(t *testing.T) { + client, server, cleanup := NewTestClient() + defer cleanup() + ctx, cancel := context.WithCancel(t.Context()) + defer cancel() + if mode == "request-timeout" { + client.cfg.RequestTimeout = 100 * time.Millisecond + } + done := make(chan error, 1) + go func() { + done <- verifyMCPConfig(ctx, client.JSONRPCClient, SessionPlan{Cwd: "/synthetic-private/workspace"}) + }() + var request JsonRpcRequest + if err := json.NewDecoder(server.FromClient).Decode(&request); err != nil { + t.Fatal(err) + } + if request.Method != "config/read" { + t.Fatal("unexpected preflight request", request.Method) + } + if mode == "owner-cancel" { + cancel() + } + select { + case err := <-done: + if err == nil || err.Error() != "codex: cannot verify public MCP configuration" { + t.Fatal("budget failure was accepted or exposed", err) + } + case <-time.After(2 * time.Second): + t.Fatal("preflight ignored its configured budget or parent cancellation") + } + if mode == "request-timeout" && ctx.Err() != nil { + t.Fatal("request budget changed the parent context", ctx.Err()) + } + }) + } +} + func TestPublicMCPHTTPPreparationChecksBeforeNewAndResumedThread(t *testing.T) { for _, mode := range []string{"new", "resume", "reject", "reject bearer reference"} { t.Run(mode, func(t *testing.T) { diff --git a/apps/daemon/internal/agent/codex/preparation_helpers_test.go b/apps/daemon/internal/agent/codex/preparation_helpers_test.go index f0214989a..cf62218c9 100644 --- a/apps/daemon/internal/agent/codex/preparation_helpers_test.go +++ b/apps/daemon/internal/agent/codex/preparation_helpers_test.go @@ -227,6 +227,13 @@ func TestPreparationFakeCodexProcess(t *testing.T) { } result = map[string]any{"data": []any{map[string]any{"skills": listed, "errors": []any{}}}} case "config/read": + if delay := os.Getenv("OAC_TEST_PREPARATION_MCP_DELAY"); delay != "" { + duration, err := time.ParseDuration(delay) + if err != nil { + os.Exit(6) + } + time.Sleep(duration) + } data, err := os.ReadFile(os.Getenv("OAC_TEST_PREPARATION_MCP_CONFIG")) if err != nil || json.Unmarshal(data, &result) != nil { os.Exit(6)