From baa7b73898c0479fbc05de26dc8c88a3a9c49615 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 17:19:25 +0000 Subject: [PATCH] mcpx: cap the ask-abandon body read; move the audience window to defaults.json Two guard tests went red on main once mcpx tests ran on schedule: - TestNoUnboundedBodyReaders: handleAskAbandon (#8922) decoded its optional body with no size ceiling. It now reads through http.MaxBytesReader at the call body limit, like every other route. This is also what failed the mcpx nix build. - TestNoPackageRedeclaresADefault: elicit's DefaultAudienceWindow (#2438) was an inline 2*time.Minute. It now comes from defaults.json (elicit.audienceWindow, 2m), an internal bound kept out of the settings registry. Co-Authored-By: Claude Opus 5.5 --- pkgs/mcpx/internal/daemon/routes_proto.go | 6 ++++-- pkgs/mcpx/internal/defaults/defaults.go | 10 ++++++++++ pkgs/mcpx/internal/defaults/defaults.json | 3 ++- pkgs/mcpx/internal/elicit/presence.go | 9 ++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pkgs/mcpx/internal/daemon/routes_proto.go b/pkgs/mcpx/internal/daemon/routes_proto.go index 7617201938..e5db54b2e3 100644 --- a/pkgs/mcpx/internal/daemon/routes_proto.go +++ b/pkgs/mcpx/internal/daemon/routes_proto.go @@ -906,8 +906,10 @@ func (s *Server) handleAskAbandon(w http.ResponseWriter, r *http.Request) { var body struct { TaskCancelled bool `json:"taskCancelled"` } - if r.Body != nil { - _ = json.NewDecoder(r.Body).Decode(&body) + // The decode is capped like every other body read here; a missing + // or malformed body leaves the zero value (not cancelled). + if limited := http.MaxBytesReader(w, r.Body, defaults.HTTPCallBodyLimit); r.Body != nil { + _ = json.NewDecoder(limited).Decode(&body) } if body.TaskCancelled { s.reg.markAskTaskCancelled(id) diff --git a/pkgs/mcpx/internal/defaults/defaults.go b/pkgs/mcpx/internal/defaults/defaults.go index c6bbd326fa..7b043cfec9 100644 --- a/pkgs/mcpx/internal/defaults/defaults.go +++ b/pkgs/mcpx/internal/defaults/defaults.go @@ -110,6 +110,9 @@ type Defaults struct { // state and are never pruned. RetentionMaxAge string `json:"retentionMaxAge"` RetentionMaxTerminalRows int `json:"retentionMaxTerminalRows"` + // AudienceWindow is how recent an answerer heartbeat must be for + // an audience to count as present (#2438). + AudienceWindow string `json:"audienceWindow"` } `json:"elicit"` // Proto governs how mcpx speaks the protocol to its own clients: which // era mechanisms it offers, and how long it will hold a call open while @@ -657,6 +660,13 @@ var ( // question is kept in the broker store before an open prunes it // (#1677, design #1675 Phase 2: the recorded 30 days). ElicitRetentionMaxAge = mustDur(builtin.Elicit.RetentionMaxAge, "elicit.retentionMaxAge") + // ElicitAudienceWindow is how recent an answerer heartbeat must be + // for an audience to count as present (#2438). Answerer surfaces + // poll on a one-second cadence (mcpx elicit watch) or per user + // refresh, so two minutes is generous without letting a long-gone + // answerer count. An internal bound: defaults.json only, absent + // from the settings registry. + ElicitAudienceWindow = mustDur(builtin.Elicit.AudienceWindow, "elicit.audienceWindow") // ElicitRetentionMaxTerminalRows caps how many terminal questions // the broker store keeps, oldest first out (#1677). ElicitRetentionMaxTerminalRows = builtin.Elicit.RetentionMaxTerminalRows diff --git a/pkgs/mcpx/internal/defaults/defaults.json b/pkgs/mcpx/internal/defaults/defaults.json index 3f3f63f345..aa5503de8a 100644 --- a/pkgs/mcpx/internal/defaults/defaults.json +++ b/pkgs/mcpx/internal/defaults/defaults.json @@ -120,7 +120,8 @@ "handlerTimeout": "5m", "inputRounds": 8, "retentionMaxAge": "720h", - "retentionMaxTerminalRows": 1000 + "retentionMaxTerminalRows": 1000, + "audienceWindow": "2m" }, "proto": { "native": true, diff --git a/pkgs/mcpx/internal/elicit/presence.go b/pkgs/mcpx/internal/elicit/presence.go index 1b2803ae07..9c8b351c12 100644 --- a/pkgs/mcpx/internal/elicit/presence.go +++ b/pkgs/mcpx/internal/elicit/presence.go @@ -3,6 +3,8 @@ package elicit import ( "os" "time" + + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) // Answerer presence: the broker's truthful no-audience signal (#2438, @@ -25,10 +27,11 @@ import ( // answer. // DefaultAudienceWindow is how recent an answerer heartbeat must be -// for the audience to count as present. Answerer surfaces poll on a -// one-second cadence (mcpx elicit watch) or per user refresh, so two +// for the audience to count as present. The value lives in +// defaults.json (elicit.audienceWindow, 2m): answerer surfaces poll on +// a one-second cadence (mcpx elicit watch) or per user refresh, so two // minutes is generous without letting a long-gone answerer count. -const DefaultAudienceWindow = 2 * time.Minute +var DefaultAudienceWindow = defaults.ElicitAudienceWindow // NoteAnswerer records that an answerer able to serve aud was seen // now. An empty audience means an unfiltered answerer -- one polling