fix(relay): recover corrupted session stacks after failed turn cleanup - #78087
Open
burak33bb wants to merge 1 commit into
Open
fix(relay): recover corrupted session stacks after failed turn cleanup#78087burak33bb wants to merge 1 commit into
burak33bb wants to merge 1 commit into
Conversation
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.
What does this PR do?
Recover Relay sessions after turn finalization encounters a corrupted LIFO
scope stack.
Interrupted tool calls, provider failures, and incomplete delegated-agent
cleanup can leave an unknown nested scope above the turn scope. Relay then
rejects finalization with:
end_turn()caught and logged this exception, but retained the corruptedRelaySessionin the runtime registry. Every subsequent turn reused the samebroken context, causing repeated finalization failures and sessions that
appeared to hang until the gateway was restarted.
Trying additional scope pops is unsafe because Hermes does not own or know the
handle currently at the top of the native stack. This change instead discards
the affected runtime session and its delegated child sessions. The next turn
creates a clean Relay context while preserving the Hermes conversation and
persisted session state.
This complements #74864, which prevents one known concurrent-turn cause of
scope corruption. This PR handles recovery after corruption has already
occurred, including interruption and provider/delegation cleanup paths.
Related Issue
Fixes #78068.
Also mitigates #78060.
Type of Change
Changes Made
RelayRuntime.discard_session_tree()to atomically remove a corruptedsession and its delegated descendants without attempting further scope pops.
end_turn().and delegated-child invalidation, and verifies the next acquire creates a
fresh Relay session.
How to Test
Run the focused Relay suites:
Confirm the runtime suite reports
15 passedand the command exits withstatus 0.
Run lint on the changed files:
Confirm Ruff reports
All checks passed!.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs