Skip to content

Integrations: MCP big lists and input-required rounds, LangChain parallel asks, tracekit last, gateway listing errors - #753

Merged
LoopGlitch26 merged 10 commits into
mainfrom
agent/rel170-integrations
Nov 12, 2026
Merged

LoopGlitch26 merged 10 commits into
mainfrom
agent/rel170-integrations

Conversation

@LoopGlitch26

@LoopGlitch26 LoopGlitch26 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Fixes these integration findings from the 1.7.0 pre-release review:

#687 moves to draft #756, design first.

What and why

#685, MCP client: lists too big for a signer frame (tracekit/integrations/mcp.py)

  • list_* sent the whole page in observe. A tools/list over the signer's 1 MiB frame (230 tools with 40-field schemas is enough) made list_tools raise quota_exceeded whatever the fail mode. The page now goes through result_field(True, …), as the MCP gateway does: a page over half a frame is recorded as its digest. The input-required observe does the same.
  • mcp's own ClientSession.call_tool lists the tools again (validate_tool_result) to check a result against the output schema. Under instrument() that list was recorded as untrusted input the model read, and a big one made the call fail after the tool ran. That list never reaches the model, so it is no longer recorded: the session's send runs under the existing DECIDED_UPSTREAM flag, which instrument()'s patched list_tools already passes through. I chose not recording it over recording it as "internal": it is the smaller change, and there is no record kind for internal input.

#718, MCP input-required rounds (tracekit/integrations/mcp.py)

  • A pending round was keyed on (tool, arguments, request_state). A server that reuses a state let call B's result be signed under abandoned call A's id and decision, and B was completed "ok" at round 1.
  • Pending rounds are now keyed by the asyncio task driving the call (a WeakKeyDictionary), which is the call's identity in practice: mcp's Client.call_tool drives every round from one task, and concurrent calls run in separate tasks. A round continues only the call its own task left waiting, with the same tool, arguments and the state that call got.
  • A task that makes another call on the session first ends the waiting call, completed with the input request it returned. A task that ends between rounds leaves the call to the signer's decided_not_completed gap. The weak keys also retire the old lean: note about pending entries living for the session's life.

#687 (several asks in one LangChain ToolNode) is not in this PR. The patches here kept exposing new cases: a tool's own interrupt(), RetryPolicy, async sibling cancellation, and a resume in another process. So this PR keeps main's langchain.py and autowire.py. docs/limits.md now says exactly what main does: each resume answers one pause and the run pauses again; under ainvoke a pause may show an already-approved call; a call that ran on an earlier resume is gated again and denied TK-APPROVAL-UNBOUND; an allowed call beside the asks runs again on each resume. The redesign is draft #756 (design first, after 1.7.0). An earlier version of this branch found a tracekit why fork-replay leak, where a real tool ran during replay. It came from that version's own hook and isn't on main, so nothing ships for it.

tracekit last (tracekit/cli.py): it said an open run "finishes when the session ends" for OpenCode, Kilo, goose and Antigravity, which install no session-end hook. For those it now says: still open: Tracekit's <agent> hooks get no session end, so it finishes after the signer's idle timeout. For Cline (#732, merged meanwhile), a run is one task, so it says it finishes when the Cline task completes, or after the signer's idle timeout (a cancelled task sends no hook).

MCP gateway (tracekit/mcp_gateway.py, docs/mcp-gateway.md)

  • The repeated-cursor error now says what happened (tools/list page 2 returned a cursor an earlier page had returned, so the listing would never end; fix the upstream's cursor). It used to name the 100-page cap, which the listing never reached.
  • The docs now say one listing has 600 s for all upstreams and pages together. While checking that, I found that a listing past the budget gave the agent upstream error: TimeoutError: ; the gateway connects to an upstream that went away again on the next call. It now says upstream 'up': tools/list timed out (one listing has 600 s for every upstream and page), catching concurrent.futures.TimeoutError too: before Python 3.11 that is a separate class.

Evidence

Regression tests. Each one fails on the old code. I checked them in a scratch copy of origin/main (c5a3923) with only the new tests added: all 8 failed. The digest fix alone, without the re-list flag, still fails the call_tool test.

  • tests/test_contract_mcp.py: BigLists (real signer: a 300-tool, about 1.4 MB list is recorded as its digest; call_tool with no list first records no input.observed) and InputRequiredRounds (a lowlevel server that reuses its state: two concurrent calls give exactly 2 decisions, each completed under its own; a call left after round 1 completes before the next call is decided).
  • tests/test_instrument.py: tracekit last against open opencode, kilo, goose, antigravity and cline runs on a real dev signer.
  • tests/test_mcp_gateway.py: the repeated-cursor and budget messages, and the budget error with a concurrent.futures.TimeoutError that isn't the built-in one (as on Python 3.10).

The reviewer's probes, re-run on this branch (before the fix: list_tools raised: RPCError quota_exceeded: the observe request is 1842028 bytes…; 3 decisions for 2 concurrent calls):

probe_mcp_big_list.py            listed (tools, bytes): (400, 1880054)   N=230: (230, 1081054)
probe_mcp_state.py   sequential  A: decide dec-1, complete dec-1 (its input request); B: decide dec-2, complete dec-2
                     concurrent  decide dec-1, decide dec-2; complete dec-1, complete dec-2 (each its own final result)
probe_mcp_real_signer.py         one call: decision, input.observed input_required, tool.result (no mcp:srv/tools record)
                                 A then B: A's tool.result under A's decision, B's under B's

Gates in the worktree on the final head, with origin/main merged in (make test-ts lint build test): TS tests 162, pass 152, fail 0; pyflakes clean; Successfully built tracekit_ai-1.6.0.tar.gz and tracekit_ai-1.6.0-py3-none-any.whl; pytest 4978 passed, 394 skipped, 10 xfailed, 0 failed.

The branch merges origin/main (with #732) instead of rebasing onto it. The branch was already pushed, and rebasing would have needed a force-push.

…llel asks, tracekit last, gateway listing errors

- MCP client (#685): a list page over half a signer frame is recorded as its digest (result_field, as the
  gateway does), so list_tools no longer fails with quota_exceeded; mcp's own re-list inside call_tool
  (validate_tool_result) is no longer recorded as input the model read.
- MCP input-required rounds (#718): a pending round is keyed by the asyncio task driving the call, so a
  server that reuses request_state can't move one call's result under another's decision; a call the task
  leaves between rounds completes with the input request it returned.
- LangChain (#687): a call whose approval is already answered doesn't pause again, so in a
  tracekit_tool_node with two asks the approved call runs on resume (16 of 16 on invoke and ainvoke); the
  call still waiting is refused.
- tracekit last: OpenCode, Kilo, goose and Antigravity runs finish at the signer's idle timeout, not when
  the session ends.
- MCP gateway: the repeated-cursor error says what happened; a listing past its shared 600 s budget names
  the upstream; docs/mcp-gateway.md documents the budget.
…, so no call runs in a pass that then pauses

ToolNode runs a message's calls in one node, which LangGraph runs again from its start on each resume. A call that
ran in a pass that then paused ran again or read as refused: an allowed sibling of one ask ran twice, and with three
or more asks a call that ran was refused on the next pass while an approved one never ran.

A gated ToolNode (tracekit_tool_node, or one instrument() wired) now decides a pass's calls together first
(TracekitMiddleware._pass) and pauses once, before any runs, while an approval is unanswered; the payload's
`approvals` lists every waiting one. On resume each allowed or approved call runs once and each rejected or
unanswered one is refused. The hook is ToolNode's class-level node function and acts only while the node's wrapper
is the gate's, so tracekit why's replay copy (its own wrapper) runs no real tool. Replaces the lean note.
…utor's call stays the executor's

LangGraph pairs resume values with a node's interrupt() calls by order. Once an approval was answered the gate
stopped pausing, so a tool that asked the person itself got the approval's resume value and ran without asking.
The gate now pauses for an ask in every pass of its node, answered or not (a ToolNode pass once, when any call
asks), so a tool's interrupt() always comes after it. A call whose tool paused the run after its consume goes on,
consumed once, on resume (main refused it as TK-APPROVAL-CONSUMED); in a held ToolNode pass, calls that already
ended are given back, not decided, asked, run or recorded again. Both are kept in memory; docs and limits say what a
resume in another process does.

_pass leaves a tool executor's calls to the executor. The MCP gateway's listing timeout also catches
concurrent.futures.TimeoutError, a separate class before Python 3.11.
…to its own PR

The multi-call ToolNode changes (#687) keep exposing new cases (RetryPolicy re-raising a kept exception, async
sibling cancellation), so this PR keeps main's langchain.py, autowire.py, their tests and doc. The held-pass design
moves to a draft PR for after 1.7.0. docs/limits.md says what main does with several asks in one ToolNode. The
fork-replay leak found earlier came from this branch's own hook and isn't on main.
…ngGraph row

- MCP: a multi-round call its task leaves (the elicitation callback fails, the
  rounds run out, the caller moves on) is never completed later; it was
  completed "ok" with its input request when the task made another call, though
  its caller had got an exception. It ends as the signer's decided_not_completed
  gap at run close, as the docs say.
- MCP gateway: only the listing's own time running out (Upstreams._run's wait,
  now UpstreamTimeout) is reported as the listing's budget; a TimeoutError the
  upstream call or the reconnect raises keeps the upstream error and its advice.
- Tests: a round's input requests over half a frame are recorded as a digest.
- Limits: the LangGraph parallel-asks row says what happens under invoke and
  ainvoke alike, with what-to-dos checked against the code; a row for MCP rounds
  sent from different tasks.

Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…er; a reconnect with no session names the upstream; MCP docs say which decisions wait and which calls end a waiting one

Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
…thing was sent; a call that ends as its wait is cancelled gives its answer; docs on the reconnect's time and which decisions wait

Signed-off-by: LoopGlitch26 <53336715+LoopGlitch26@users.noreply.github.com>
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