Repository navigation
test(gateway): a real gateway in front of a real protocol child, over loopback - #160
Open
earakely-scale wants to merge 2 commits into
Open
earakely-scale wants to merge 2 commits into
earakely-scale wants to merge 2 commits into
Conversation
… loopback Two loopback servers: a protocol environment and a Gateway with it as its only backing server. Two MCP clients with different AgentEnv-Role headers reach the child's tools as two callers, each with the gateway's per-session key rather than its connection id, stable across calls on one session; a tool that never asked for the caller keeps its schema and answers as before; a refusal returned by the child's on_tool_call reaches the client through the gateway as isError with its payload intact; a /step call carries the role and no session; a client on the child directly gets its header role and its own connection id. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…a session is read The marker on the installed dispatch is read by _check_tool_binding to refuse a second handler on one app; no downstream guard reads it. caller_from_request takes the _meta session whenever one is present, with or without a _meta role entry, and falls back to the connection id only for a direct caller. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Comment on lines
+71
to
+75
| env = _Items() | ||
| child_server, child_url = await _serve(env.create_app().streamable_http_app()) | ||
| gw = Gateway(host="127.0.0.1", port=0, server_name="t", | ||
| internal_mcp_servers=[InternalMCPServer("items", f"{child_url}/mcp")]) | ||
| gw_server, gw_url = await _serve(gw._asgi_app()) |
There was a problem hiding this comment.
Failed tests leave servers running
Both servers start before _stack enters its try block. If gateway setup raises, the child server stays open. An error during gateway shutdown also skips child shutdown. These leftover servers and tasks can add cleanup warnings and obscure the original test failure.
Register cleanup immediately after each server starts, using nested try/finally blocks or AsyncExitStack, so both servers close even when setup or teardown fails.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tst/integration/env/gateway/role_forwarding_local_test.py
Line: 71-75
Comment:
**Failed tests leave servers running**
Both servers start before `_stack` enters its `try` block. If gateway setup raises, the child server stays open. An error during gateway shutdown also skips child shutdown. These leftover servers and tasks can add cleanup warnings and obscure the original test failure.
Register cleanup immediately after each server starts, using nested `try/finally` blocks or `AsyncExitStack`, so both servers close even when setup or teardown fails.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#153 binds a
ToolContextper tool call inside the protocol, and #145 makes the gateway stamp the caller's role and session on each proxied call. Each was tested on its own side with the other faked. This adds the test that puts a real gateway in front of a real protocol child over loopback, in the integration-local tier:AgentEnv-Roleheaders reach the child's tools as two callers, each with the gateway's per-session key rather than the gateway's connection id, stable across calls on one session;ToolContextparameter keeps its schema and is served as before, with the caller still readable throughToolContext.current();on_tool_callreaches the client through the gateway asisErrorwith its payload intact;/stepcall carries the role and no session; a client connecting to the child directly gets its header role and its own connection id;Two protocol docstrings are corrected on the way, with no code change: the marker on the installed dispatch is read by the mount's own second-handler check, not by a downstream boot guard, and
caller_from_requesttakes a_metasession whenever one is present, with or without a_metarole entry.Testing
tst/integration/env/gateway/role_forwarding_local_test.pywithpackages/agentenv-protocol/tests: 429 passed, clean under-W error::DeprecationWarning.🤖 Generated with Claude Code
The PR appears safe to merge, with a non-blocking improvement needed to clean up servers after test failures.
Fix with agent prompt
Summary
Adds a loopback integration test with a real gateway and protocol child.
Diagram
Reviews (1) · Last reviewed commit: "docs(protocol): say what the dispatch ma..." · Reviewed by Greptile