Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions apps/daemon/internal/agent/codex/mcp_http_preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
52 changes: 52 additions & 0 deletions apps/daemon/internal/agent/codex/mcp_http_preflight_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions apps/daemon/internal/agent/codex/preparation_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading