fix(discord): add typing_loop_max_lifetime deadline guard for orphaned typing loops - #90179
Open
JinUltimate1995 wants to merge 3 commits into
Open
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.
…d typing loops Issue NousResearch#90151: the persistent typing loop in DiscordAdapter.send_typing had no natural exit condition other than stop_typing() or a non-429 error. If stop_typing never reached the adapter (crashed run, thread-vs-parent key mismatch), the loop ran forever until gateway restart. Adds a configurable max-lifetime deadline (discord.typing_loop_max_seconds, default 600s, 0 disables). The loop now exits cleanly when the deadline elapses, bounding the post-typing sleep so it wakes up in time to honor the guard.
Collaborator
Duplicate of #90087 for the Responses turn-boundary and MCP auth.env repairs. This PR additionally contains Discord typing-loop work, which should be submitted as a focused follow-up rather than bundled with those already-open fixes. |
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
Issue #90151: the persistent typing loop in
DiscordAdapter.send_typinghad no natural exit condition other thanstop_typing()or a non-429 error. Ifstop_typingnever reached the adapter (e.g. a crashed run, or a thread-vs-parent-channel key mismatch), the loop ran forever and Discord kept showing the "…is typing" badge until the gateway restarted.Adds a configurable max-lifetime deadline (
discord.typing_loop_max_seconds, default 600s, 0 disables). The loop now exits cleanly when the deadline elapses, bounding the post-typing sleep so it wakes up in time to honor the guard.Changes
hermes_cli/config_defaults.py— adds the newtyping_loop_max_secondskey (default 600).plugins/platforms/discord/adapter.py:_load_typing_loop_max_seconds()config loader.self._typing_loop_max_secondsin__init__._typing_loopand bounds the post-typing sleep by the deadline.tests/gateway/test_discord_typing_max_lifetime.py— new test file:test_loop_expires_after_max_lifetime— verifies the loop exits once the deadline elapses.test_stop_typing_still_works_with_deadline— verifiesstop_typingstill cancels cleanly.test_zero_max_seconds_disables_deadline— verifies setting 0 disables the guard.Related
Closes #90151.
Complements #85425 (cleanup race) and #85435 (reap bounding) — those address related races, but the core max-lifetime problem remained unaddressed.
Test Results
test_discord_send.py: 11/11 pass.tests/gateway/test_discord_*.py: 262/262 pass.Type of Change