Skip to content

A retry answering an upstream's question arrived looking like a first try - #91

Merged
blakebauman merged 1 commit into
mainfrom
fix/forward-mrtr-continuation
Aug 26, 2026
Merged

blakebauman merged 1 commit into
mainfrom
fix/forward-mrtr-continuation

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Second finding from the /spec-drift sweep. Small fix, plus a larger thing it exposed that is documented rather than changed.

The fix

MCP's multi-round-trip pattern: a server needing more input answers with an input-required result carrying its questions and an opaque requestState; the exchange completes when the original request is retried with inputResponses filled in and that state echoed back.

A client MUST echo back the exact value of that field when retrying the original request. Clients MUST NOT inspect, parse, modify, or make any assumptions about the requestState contents.

The pattern is otherwise stateless, so that field carries the whole of the server's context across the round trip.

fold rebuilt request params at three sites and silently dropped both fields, so an upstream saw a first attempt every time: it asked again, the client retried, and the loop ran to the SDK's ten-attempt ceiling re-prompting a human on each pass.

The shape is the interesting part — the two resources/read branches that forward params whole were always correct; only the branch that rebuilds them was broken. Tests pin the minted-ui:// branch specifically by asserting the URI the upstream observed, since a generic resources/read test passes either way.

Each of the three sites has a uniquely-identifying failing test under mutation.

What the fix does not change — and why the README now says so

Writing this up exposed that fold does not relay multi-round-trip at all; it absorbs it.

mcp/client.go:79 installs the SDK's multi-round-trip middleware unless MultiRoundTrip.Disabled is set, and fold has never set it. So in the ordinary case fold answers an upstream's question itself — from the caller's bridged session, via elicitation or sampling — and issues the retry below the router. The caller sees one completed call and never sees the question.

For a handshake-era caller talking to a modern upstream, that is the only thing that can work: it is era translation rather than proxying. It is also not a relay, and three consequences follow, none yet addressed:

  • a client declaring no elicitation handler has the call failed rather than being asked
  • resources/read cannot complete such an exchange at all, because reads ride the shared root session and it carries no handlers — observed surfacing as "Resource not found" after the probe loop
  • a caller that could have answered for itself is never given the chance

Turning fold into a relay is one line in the client options and a large change to what bridged sessions are for, so it waits on the same decision as roadmap item 13 — which was itself designed against the server-initiated mechanism this pattern replaced.

I had this wrong first. My initial README paragraph claimed fold "relays both directions unchanged". It does not, and the test agent caught it. The paragraph now describes what fold actually does, and README "Not implemented" carries the three consequences.

A corollary worth knowing when reading the tests: the end-to-end test (TestMultiRoundTripCompletesInOneRetry) passes with the bug present, because the retry is generated below the router. The three ...ReachesUpstream tests are the ones holding the fix.

An invariant recorded while it still holds by accident

The spec forbids caching a result produced by an input-required retry — such results "depend on inputs that are not part of the cache key". fold satisfies that today only because its one cache holds list results and this pattern applies to tools/call, prompts/get, and resources/read. A response cache on any of those would break it on day one, so the rule is now written in cachehint.go where whoever adds one will see it.

Verification

  • go test -race ./... green; lint 0 issues; gofmt / vet clean
  • conformance 40/40; bench 0.200 ms added p50
  • Tests use real SDK peers on both sides, including an upstream that genuinely returns InputRequiredResult
  • requestState opacity asserted across 9 hostile values × 3 methods — whitespace, JSON-shaped, quotes/backslash/NUL, non-ASCII, decomposed combining marks (proving no NFC normalisation), values shaped like a namespaced tool name and a minted URI, and 16 KiB
  • Interaction with sanitizeRequestMeta asserted: a request carrying both a forged connection key and a continuation arrives with the key stripped and the continuation intact

🤖 Generated with Claude Code

… try

MCP's multi-round-trip pattern has a server answer with an
input-required result rather than blocking: it returns the questions it
needs answered and an opaque requestState, and the exchange completes
when the original request is retried with inputResponses filled in and
that state echoed back. The specification is emphatic about the echo — a
client MUST return the exact value and MUST NOT inspect, parse, modify,
or assume anything about it — because the pattern is otherwise stateless
and that field carries the whole of the server's context across the
round trip.

fold rebuilt request params at three sites (tools/call, prompts/get, and
the minted ui:// branch of resources/read) and silently dropped both
fields. An upstream therefore saw a first attempt every time, asked
again, and the client retried — to its ten-attempt ceiling, re-prompting
a human on each pass. The other two resources/read branches were always
correct, because they forward the params they were handed rather than
building new ones; that difference is the whole of the bug.

Writing this up exposed a larger thing the fix does not change, now in
README "Not implemented" rather than left to be discovered. fold's
upstream client runs the SDK's multi-round-trip middleware, which is
installed unless explicitly disabled and fold has never disabled it. So
in the ordinary case fold does not relay an upstream's question at all:
it answers it from the caller's bridged session and issues the retry
below the router, and the caller sees one completed call. For a
handshake-era caller talking to a modern upstream that is the only thing
that can work, and it is era translation rather than proxying. Three
consequences follow: a client declaring no elicitation handler has the
call failed rather than being asked, resources/read cannot complete such
an exchange at all because reads ride the shared root session and it
carries no handlers, and a caller that could have answered for itself is
never given the chance. Making fold a relay is one line in the client
options and a large change to what bridged sessions are for, so it waits
on the same decision as roadmap item 13.

An invariant is recorded in cachehint.go while it still holds by
accident: the specification forbids caching a result produced by an
input-required retry, and fold satisfies that only because its one cache
holds list results. A response cache on tools/call would break it on the
first day.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit fd330d8 into main Aug 26, 2026
8 checks passed
@blakebauman
blakebauman deleted the fix/forward-mrtr-continuation branch August 26, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant