fix(gateway): turn-start detection uses role+content matching (ignoring metadata) - #90087
Open
JinUltimate1995 wants to merge 2 commits into
Open
fix(gateway): turn-start detection uses role+content matching (ignoring metadata)#90087JinUltimate1995 wants to merge 2 commits into
JinUltimate1995 wants to merge 2 commits into
Conversation
…ronment
For stdio catalog entries using auth.type: api_key, the credentials
declared in auth.env were saved to .env by _prompt_env_vars() but never
wired into the generated mcp_servers.<name> configuration. Without an
env-backed reference, _build_safe_env() excluded them and the stdio child
started without its API key, causing silent authentication failures.
Now _build_server_config translates each auth.env variable into a safe
${VAR} reference for stdio transports, mirroring how HTTP api_key
manifests get a Bearer header template.
Fixes NousResearch#89316.
…atching (ignoring metadata) The prefix-matching logic used full dict equality (==), which fails when the agent modifies messages during the conversation loop — timestamps are added, content may be truncated, and fields like finish_reason/reasoning are stamped on. This caused _turn_transcript_messages to return ALL messages instead of only the current turn, bloating the run.completed SSE event's messages field. Fix: compare role + content (with prefix tolerance for truncated strings), ignoring metadata fields. Fixes NousResearch#89891.
Collaborator
1 task
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
Fixes #89891:
_response_messages_turn_start_indexinapi_server.pyused full dict equality to match the prefix, which fails when the agent modifies messages during the conversation loop.This caused
_turn_transcript_messagesto return ALL messages instead of only the current turn, bloating therun.completedSSE event.Root Cause
The agent modifies messages during the conversation loop:
_repair_message_sequencemerges/rewrites messages_drop_trailing_empty_response_scaffoldingremoves trailing messagesfinish_reason,reasoning,timestamp, etc.)After these modifications, the prefix match fails and returns 0, causing all messages to be returned instead of just the current turn.
Fix
Compare role + content (with prefix tolerance for truncated strings), ignoring metadata fields. This handles:
Changes Made
gateway/platforms/api_server.py: Replace dict equality with_match()helper that compares role + contenttests/gateway/test_api_server.py: AddTestTurnStartDetectionclass with 8 regression testsHow to Test
pytest tests/gateway/test_api_server.py::TestTurnStartDetection -v— 8 passedpytest tests/gateway/test_api_server.py -q— 117 passedType of Change