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