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
7 changes: 7 additions & 0 deletions pkgs/mcpx/internal/cli/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,13 @@ func (a *App) MCPServer(ctx context.Context) (*mcpserver.Server, error) {
// below reads -- so neither surface's cadence changes.
if a.daemonStore != nil {
srv.TaskStore = a.daemonStore
// Retention follows the same settings the daemon's taskStore()
// reads on /v1 access (#6247): without this, a tasks.ttl /
// tasks.maxAge change made through /v1/settings never reached
// the MCP surface's cached store pointer.
srv.TaskRetention = func() (time.Duration, time.Duration) {
return a.Settings().Duration("tasks.ttl"), a.Settings().Duration("tasks.maxAge")
}
Comment on lines +529 to +531

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the retention provider through WithExtras

In the production App.MCPServer construction path, this provider is discarded before the server is returned: serve.go:607-622 appends the generated /v1 tools and calls srv.WithExtras(extras), whose new Server literal in mcpserver/server.go:383-403 does not copy TaskRetention. Consequently, the returned MCP server still has a nil provider, so /v1/settings retention changes never reach MCP-only traffic despite this fix. Preserve the provider through that reconstruction and add a regression covering the extras construction path; the new test assigns the provider directly and bypasses it.

AGENTS.md reference: pkgs/mcpx/internal/AGENTS.md:L9-L10

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commits 3ebac48 + 9e7f4e1 (gofmt): WithExtras now copies TaskRetention — and, same seam and same class, TaskStore and TaskAudit, which the reconstruction was also dropping (silently giving the production extras server a private store, breaking #1555 sharing whenever extras exist). New regression TestRetentionSurvivesWithExtras builds the server exactly as App.MCPServer does (inject store + provider, then WithExtras) and verifies MCP-only traffic picks up the retention change in the injected store.

@codex review

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 9e7f4e101f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

} else {
// A standalone server (mcpx serve) keeps a private store;
// wire its audit seam to the durable log or its task
Expand Down
22 changes: 20 additions & 2 deletions pkgs/mcpx/internal/mcpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ type Server struct {
// means the standalone behaviour: a private in-memory store.
TaskStore *taskStore

// TaskRetention, when set, supplies the current tasks.ttl /
// tasks.maxAge retention settings and is consulted on every
// task-store access, so a /v1/settings change reaches MCP task
// traffic without an intervening /v1 task request (#6247). A
// function, because the settings are hot: a value copied here
// would never follow a change (the MaxCompletions pattern). The
// daemon wires it when it injects its store; nil keeps the
// store's construction-time configuration.
TaskRetention func() (ttl, maxAge time.Duration)

// TaskAudit, when set, is the audit seam a private task store
// (the TaskStore == nil path in tasks()) is wired with, so a
// standalone server's task lifecycle records reach a log instead
Expand Down Expand Up @@ -379,8 +389,16 @@ func (s *Server) WithExtras(extras []Extra) *Server {
// Notify comes along. Dropping it silently turned off every push
// capability the moment a single extra tool existed, and a client
// cannot detect a server that declared nothing.
Notify: s.Notify,
Ask: s.Ask,
Notify: s.Notify,
Ask: s.Ask,
// The task-store wiring comes along (#6247): dropping it here
// silently gave the extras server a private store and a nil
// retention provider, so the production MCPServer() path —
// which builds extras after injecting the daemon's store —
// lost both the shared store (#1555) and retention refresh.
TaskStore: s.TaskStore,
TaskRetention: s.TaskRetention,
TaskAudit: s.TaskAudit,
ExtrasOnly: s.ExtrasOnly,
OwnInstructions: s.OwnInstructions,
Instance: s.Instance,
Expand Down
9 changes: 9 additions & 0 deletions pkgs/mcpx/internal/mcpserver/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ func (s *Server) tasks() *taskStore {
}
}
}
// Retention settings are hot (#6247): refresh them on every access,
// exactly as the daemon's taskStore() accessor does for /v1, so MCP
// traffic alone keeps the shared store's retention current after a
// /v1/settings change. Configure ignores nonpositive values, so a
// provider returning zeros leaves the current configuration alone.
if s.TaskRetention != nil {
ttl, maxAge := s.TaskRetention()
s.taskStore.Configure(ttl, maxAge)
}
return s.taskStore
}

Expand Down
72 changes: 72 additions & 0 deletions pkgs/mcpx/internal/mcpserver/tasks_shared_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mcpserver_test

import (
"context"
"encoding/json"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -77,6 +78,77 @@ func TestInjectedStoreIsTheStoreTheMCPSurfaceUses(t *testing.T) {
}
}

// Issue #6247: a tasks.maxAge change must reach MCP task traffic on its
// own — no intervening /v1 task request. The MCP surface refreshes the
// shared store's retention from TaskRetention on every access, so a task
// that turns terminal after the change carries the new (tiny) retention
// deadline instead of the hour the provider returned before it.
func TestMCPOnlyTrafficPicksUpRetentionChange(t *testing.T) {
store := tasks.New()
s := sharedStoreServer(store)

maxAge := time.Hour
s.TaskRetention = func() (time.Duration, time.Duration) { return 0, maxAge }

// Baseline MCP task under the old retention: nothing explodes, and
// the store is the injected one.
first := startSharedTask(t, s)
if done := waitTask(t, s, first, terminal); done["status"] != "completed" {
t.Fatalf("baseline task: %v", done)
}

// The settings change (the /v1/settings write in production). From
// here the test exercises only the MCP path.
maxAge = 2 * time.Second

id := startSharedTask(t, s)
if done := waitTask(t, s, id, terminal); done["status"] != "completed" {
t.Fatalf("post-change task: %v", done)
}
got, ok := store.Get(id)
if !ok {
t.Fatalf("post-change task %s missing from the store", id)
}
if got.ExpiresAt == nil {
t.Fatalf("post-change task %s has no retention deadline", id)
}
if remaining := time.Until(*got.ExpiresAt); remaining > 10*time.Second {
t.Errorf("post-change task keeps the old retention: expires in %v, want the new 2s maxAge to bound it", remaining)
}
}

// Issue #6247, extras construction path: App.MCPServer injects the
// store and the retention provider and *then* calls WithExtras, whose
// reconstruction must preserve both — a provider dropped there leaves
// the production server exactly as broken as before the fix.
func TestRetentionSurvivesWithExtras(t *testing.T) {
store := tasks.New()
s := sharedStoreServer(store)

maxAge := time.Hour
s.TaskRetention = func() (time.Duration, time.Duration) { return 0, maxAge }
s = s.WithExtras([]mcpserver.Extra{{
Tool: mcpserver.Tool{Name: "extra_tool", Description: "an extra"},
Call: func(context.Context, json.RawMessage) (string, error) { return "ok", nil },
}})

maxAge = 2 * time.Second
id := startSharedTask(t, s)
if done := waitTask(t, s, id, terminal); done["status"] != "completed" {
t.Fatalf("task through the extras server: %v", done)
}
got, ok := store.Get(id)
if !ok {
t.Fatalf("task %s is not in the injected store after WithExtras", id)
}
if got.ExpiresAt == nil {
t.Fatalf("task %s has no retention deadline", id)
}
if remaining := time.Until(*got.ExpiresAt); remaining > 10*time.Second {
t.Errorf("extras server kept the old retention: expires in %v, want the new 2s maxAge", remaining)
}
}

func TestInjectedStoreKeepsMCPTasksAcrossReopen(t *testing.T) {
path := filepath.Join(t.TempDir(), "tasks.db")
store, err := tasks.Open(path)
Expand Down