From 66c00555165f659b1510c52f92b8014b2477d111 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 17:30:47 +0000 Subject: [PATCH] mcpx: effect probe for proto.askTimeout (#8473 chain 4) A 2025-11-25 client that declared form elicitation is asked over its stream and never answers. At the default the request is still held after six seconds; with MCPX_PROTO_ASK_TIMEOUT=1s it ends with the stopped-waiting error. The exemption goes and the pin drops to 190. Refs #8473 Co-Authored-By: Claude Opus 5.5 --- pkgs/mcpx/internal/e2e/effect_test.go | 82 +++++++++++++++++++ .../e2e/feature_coverage_exemptions.txt | 1 - pkgs/mcpx/internal/settings/effect.go | 4 +- 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/pkgs/mcpx/internal/e2e/effect_test.go b/pkgs/mcpx/internal/e2e/effect_test.go index 321d3e0aba..ddf9094de7 100644 --- a/pkgs/mcpx/internal/e2e/effect_test.go +++ b/pkgs/mcpx/internal/e2e/effect_test.go @@ -1,6 +1,7 @@ package e2e_test import ( + "bufio" "encoding/json" "fmt" "net" @@ -68,6 +69,7 @@ var implementedEffectProbes = map[string]string{ "proto.askPoll": "TestAskPollCeilingIsReachableFromTheEnvironment", "proto.askRounds": "TestAskRoundsLimitIsReachableFromTheEnvironment", "proto.askTTL": "TestAskTTLBoundsAnInterruptibleCallFromTheEnvironment", + "proto.askTimeout": "TestAskTimeoutReleasesAHeldRequestFromTheEnvironment", "daemon.address": "TestDaemonAddressIsReachableFromTheEnvironment", "daemon.autostart": "TestDaemonAutostartIsReachableFromTheEnvironment", "http.bodyLimit": "TestHTTPBodyLimitsRejectOversizedBodies", @@ -124,6 +126,7 @@ var effectProbeFuncs = map[string]func(*testing.T){ "TestAskPollCeilingIsReachableFromTheEnvironment": TestAskPollCeilingIsReachableFromTheEnvironment, "TestAskRoundsLimitIsReachableFromTheEnvironment": TestAskRoundsLimitIsReachableFromTheEnvironment, "TestAskTTLBoundsAnInterruptibleCallFromTheEnvironment": TestAskTTLBoundsAnInterruptibleCallFromTheEnvironment, + "TestAskTimeoutReleasesAHeldRequestFromTheEnvironment": TestAskTimeoutReleasesAHeldRequestFromTheEnvironment, "TestDaemonAddressIsReachableFromTheEnvironment": TestDaemonAddressIsReachableFromTheEnvironment, "TestDaemonAutostartIsReachableFromTheEnvironment": TestDaemonAutostartIsReachableFromTheEnvironment, "TestHTTPBodyLimitsRejectOversizedBodies": TestHTTPBodyLimitsRejectOversizedBodies, @@ -428,6 +431,85 @@ func TestAskTTLBoundsAnInterruptibleCallFromTheEnvironment(t *testing.T) { } } +// proto.askTimeout bounds how long the daemon's /mcp holds one request +// while the question it put to its client goes unanswered. A 2025-11-25 +// client that declared form elicitation calls a tool that asks; it is sent +// elicitation/create on the stream and never answers. +// Oracle: at the default (10m) the stream carries no final frame within +// six seconds; with MCPX_PROTO_ASK_TIMEOUT=1s it ends inside that window +// with the stopped-waiting error. +func TestAskTimeoutReleasesAHeldRequestFromTheEnvironment(t *testing.T) { + final := func(env ...string) string { + t.Helper() + e := askEnv(t) + e.setenv(env...) + e.run("refresh") + ep := e.endpoint(t) + init := mcpPost(t, ep, "", map[string]any{ + "jsonrpc": "2.0", "id": 1, "method": "initialize", + "params": map[string]any{ + "protocolVersion": "2025-11-25", + "capabilities": map[string]any{"elicitation": map[string]any{"form": map[string]any{}}}, + }, + }) + session := init.Header.Get("Mcp-Session-Id") + _ = init.Body.Close() + if session == "" { + t.Fatal("a legacy client needs a session") + } + resp := mcpPost(t, ep, session, map[string]any{ + "jsonrpc": "2.0", "id": 2, "method": "tools/call", + "params": map[string]any{"name": "mcpx_call", + "arguments": map[string]any{"namespace": "ask", "tool": "need_repo"}}, + }) + frames := make(chan map[string]any, 8) + go func() { + defer close(frames) + sc := bufio.NewScanner(resp.Body) + for sc.Scan() { + var frame map[string]any + if line := sc.Text(); strings.HasPrefix(line, "data: ") && + json.Unmarshal([]byte(strings.TrimPrefix(line, "data: ")), &frame) == nil { + frames <- frame + } + } + }() + defer func() { _ = resp.Body.Close() }() + asked := false + stop := time.After(6 * time.Second) + for { + select { + case frame, open := <-frames: + if !open { + t.Fatalf("the stream ended without a final frame (asked: %v)", asked) + } + if frame["method"] == "elicitation/create" { + asked = true // and never answered + continue + } + if frame["id"] != nil && (frame["result"] != nil || frame["error"] != nil) { + if !asked { + t.Fatalf("the call ended before its client was asked: %s", dumpJSON(t, frame)) + } + return dumpJSON(t, frame) + } + case <-stop: + if !asked { + t.Fatal("the client was never asked") + } + return "" + } + } + } + + if got := final(); got != "" { + t.Fatalf("at the default proto.askTimeout the request should still be held after six seconds, got %s", got) + } + if got := final("MCPX_PROTO_ASK_TIMEOUT=1s"); !strings.Contains(got, "did not finish before mcpx stopped waiting") { + t.Fatalf("proto.askTimeout=1s should end the request with the stopped-waiting error, got %q", got) + } +} + // TestDaemonAddressIsReachableFromTheEnvironment is the effect probe // for daemon.address (#8468 chain 1). The exemption it replaced said // a bind address is a network identity the harness cannot vary diff --git a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt index 893b6997fc..3aa950bb00 100644 --- a/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt +++ b/pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt @@ -61,7 +61,6 @@ setting script.runtime no integration-test exercise yet; burn-down #8474 (settin setting script.runtimeOrder no integration-test exercise yet; burn-down #8474 (settings script family); needs an EffectProbes entry + e2e test setting script.runtimes no integration-test exercise yet; burn-down #8474 (settings script family); needs an EffectProbes entry + e2e test setting script.suffix no integration-test exercise yet; burn-down #8474 (settings script family); needs an EffectProbes entry + e2e test -setting proto.askTimeout no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting proto.elicitationPerMinute no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting proto.mcpPath no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test setting proto.native no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test diff --git a/pkgs/mcpx/internal/settings/effect.go b/pkgs/mcpx/internal/settings/effect.go index 444d109d07..5d6d547486 100644 --- a/pkgs/mcpx/internal/settings/effect.go +++ b/pkgs/mcpx/internal/settings/effect.go @@ -72,6 +72,7 @@ var EffectProbes = map[string]string{ "proto.askPoll": "TestAskPollCeilingIsReachableFromTheEnvironment", "proto.askRounds": "TestAskRoundsLimitIsReachableFromTheEnvironment", "proto.askTTL": "TestAskTTLBoundsAnInterruptibleCallFromTheEnvironment", + "proto.askTimeout": "TestAskTimeoutReleasesAHeldRequestFromTheEnvironment", "daemon.address": "TestDaemonAddressIsReachableFromTheEnvironment", "daemon.autostart": "TestDaemonAutostartIsReachableFromTheEnvironment", "http.bodyLimit": "TestHTTPBodyLimitsRejectOversizedBodies", @@ -167,7 +168,6 @@ var EffectExemptions = map[string]string{ "proto.native": "protocol negotiation/wire behaviour between mcpx and a peer: era fixtures cover negotiation end-to-end, but no per-setting with/without probe exists yet", "proto.serveMCP": "protocol negotiation/wire behaviour between mcpx and a peer: era fixtures cover negotiation end-to-end, but no per-setting with/without probe exists yet", "proto.mcpPath": "protocol negotiation/wire behaviour between mcpx and a peer: era fixtures cover negotiation end-to-end, but no per-setting with/without probe exists yet", - "proto.askTimeout": "protocol negotiation/wire behaviour between mcpx and a peer: era fixtures cover negotiation end-to-end, but no per-setting with/without probe exists yet", "proto.elicitationPerMinute": "daemon proto rate limit: its effect appears only when an upstream server exceeds the per-minute elicitation bound, a flood the e2e harness's fake server does not drive deterministically; the limiter itself is covered by internal/mcpclient and internal/daemon ratelimit tests", "proto.samplingPerMinute": "daemon proto rate limit: its effect appears only when an upstream server exceeds the per-minute sampling bound, a flood the e2e harness's fake server does not drive deterministically; the limiter itself is covered by internal/mcpclient and internal/daemon ratelimit tests", "proto.samplingSessionPerMinute": "daemon proto rate limit: its effect appears only when one session exceeds the per-minute sampling bound, a flood the e2e harness's fake server does not drive deterministically; the limiter itself is covered by internal/mcpclient and internal/daemon ratelimit tests", @@ -290,7 +290,7 @@ var EffectExemptions = map[string]string{ // EffectExemptionPin is the ratchet: the exemption count at the time // the guard landed. It may only ever be lowered, and only in the PR // that removes an exemption by adding the probe that replaces it. -const EffectExemptionPin = 191 // Shrunk 2026-11-18 (#8473 chain 3): proto.askTTL gained a /v1/ask deadline probe. Earlier shrunk 2026-11-18 (#8473 chain 2): proto.askRounds gained a two-round MCP e2e probe. Earlier shrunk 2026-11-18 (#8468 chain 2): daemon.autostart gained its probe. Earlier shrunk 2026-11-17: (#8467 settings core-paths burn-down) paths.plugins gained its probe. Earlier shrunk 2026-11-17: (#8469) 14 http.* and transport.* settings gained their probes. Earlier shrunk 2026-11-17: (#8470 burn-down) stats.top gained its probe. Earlier shrunk 2026-11-17 (#8467 settings core-paths burn-down): paths.cache gained its probe. Earlier shrunk 2026-11-17 (#8467 settings core-paths burn-down): paths.scripts gained its probe. Earlier shrunk 2026-11-17 (#8468 chain 1): daemon.address gained its probe. Earlier shrunk 2026-11-17 (#8473 chain 1): proto.askPoll gained its probe. Deliberate +1 (2026-11-14, #1917 remainder shepherd of PR #7818) for script.language: covered by deterministic internal/runner tests (TestEffectiveScriptLanguage, TestExplicitPythonLanguageRunsInlineSnippet); the e2e harness script fixtures are TypeScript-only. Earlier deliberate +3 (2026-11-09, #2716) for proto.elicitationPerMinute, proto.samplingPerMinute and proto.samplingSessionPerMinute: daemon rate limits whose effect needs an over-limit sampling/elicitation flood no e2e fixture drives deterministically; the limiter is covered by internal/mcpclient and internal/daemon ratelimit tests. Earlier deliberate raises: +1 for daemon.roots and +8 for model.*: model settings are covered by internal/model and daemon unit tests; settings-driven e2e probes are not yet present. Deliberate +1 (2026-11-03, #1925 slice 3) for sampling.answerLocally: same model-layer coverage, daemon unit tests in internal/daemon/sampling_local_test.go. Deliberate +1 (2026-11-03, #5242) for plugin.disabledTools: read by the opencode plugin host (JS side); the Go e2e harness does not drive the plugin host, the same basis as every other plugin.* exemption. Deliberate +5 (2026-11-04, #1915 stage 2): import graph, missing, dynamic, cross-project and network policies are covered by deterministic internal/preflight tests, but the e2e harness has no isolated Deno graph fixture yet. Deliberate +2 (2026-11-05, #1911): checker error and unsupported-runtime policies are covered by deterministic internal/preflight stub-runtime tests; the e2e harness has no isolated Deno checker fixture. +const EffectExemptionPin = 190 // Shrunk 2026-11-18 (#8473 chain 4): proto.askTimeout gained a held-request probe. Earlier shrunk 2026-11-18 (#8473 chain 3): proto.askTTL gained a /v1/ask deadline probe. Earlier shrunk 2026-11-18 (#8473 chain 2): proto.askRounds gained a two-round MCP e2e probe. Earlier shrunk 2026-11-18 (#8468 chain 2): daemon.autostart gained its probe. Earlier shrunk 2026-11-17: (#8467 settings core-paths burn-down) paths.plugins gained its probe. Earlier shrunk 2026-11-17: (#8469) 14 http.* and transport.* settings gained their probes. Earlier shrunk 2026-11-17: (#8470 burn-down) stats.top gained its probe. Earlier shrunk 2026-11-17 (#8467 settings core-paths burn-down): paths.cache gained its probe. Earlier shrunk 2026-11-17 (#8467 settings core-paths burn-down): paths.scripts gained its probe. Earlier shrunk 2026-11-17 (#8468 chain 1): daemon.address gained its probe. Earlier shrunk 2026-11-17 (#8473 chain 1): proto.askPoll gained its probe. Deliberate +1 (2026-11-14, #1917 remainder shepherd of PR #7818) for script.language: covered by deterministic internal/runner tests (TestEffectiveScriptLanguage, TestExplicitPythonLanguageRunsInlineSnippet); the e2e harness script fixtures are TypeScript-only. Earlier deliberate +3 (2026-11-09, #2716) for proto.elicitationPerMinute, proto.samplingPerMinute and proto.samplingSessionPerMinute: daemon rate limits whose effect needs an over-limit sampling/elicitation flood no e2e fixture drives deterministically; the limiter is covered by internal/mcpclient and internal/daemon ratelimit tests. Earlier deliberate raises: +1 for daemon.roots and +8 for model.*: model settings are covered by internal/model and daemon unit tests; settings-driven e2e probes are not yet present. Deliberate +1 (2026-11-03, #1925 slice 3) for sampling.answerLocally: same model-layer coverage, daemon unit tests in internal/daemon/sampling_local_test.go. Deliberate +1 (2026-11-03, #5242) for plugin.disabledTools: read by the opencode plugin host (JS side); the Go e2e harness does not drive the plugin host, the same basis as every other plugin.* exemption. Deliberate +5 (2026-11-04, #1915 stage 2): import graph, missing, dynamic, cross-project and network policies are covered by deterministic internal/preflight tests, but the e2e harness has no isolated Deno graph fixture yet. Deliberate +2 (2026-11-05, #1911): checker error and unsupported-runtime policies are covered by deterministic internal/preflight stub-runtime tests; the e2e harness has no isolated Deno checker fixture. // CheckEffectCoverage returns one violation per way the probe and // exemption maps fail to cover reg exactly: a setting with neither,