fix(gateway): prevent blank auto-resume messages#23314
Open
kaiyisg wants to merge 3 commits into
Open
Conversation
526f86f to
a7603e5
Compare
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?
Prevents gateway restart auto-resume from sending an empty internal message to the agent.
When a gateway is interrupted mid-turn, startup recovery can synthesize the next internal turn before the original user message has been persisted to the transcript. Previously that synthetic
MessageEventusedtext="", so the model could treat recovery as a user-sent blank message and reply that the message came through empty.This change records the in-flight user message on the session entry while the turn is processing. Startup auto-resume replays that captured message when available. If no captured message exists, it uses an explicit nonblank internal continuation instruction so recovery does not look like an empty user turn.
Related Issue
No issue filed. Related restart-resume work: #18896, #20776.
Type of Change
Changes Made
gateway/session.py: persistin_flight_user_messageandin_flight_marked_atonSessionEntry.gateway/session.py: addSessionStore.mark_in_flight()andSessionStore.clear_in_flight()helpers.gateway/run.py: mark the prepared inbound message as in-flight before agent processing.gateway/run.py: clear the in-flight marker after a completed turn.gateway/run.py: use captured in-flight text for restart auto-resume, with a nonblank internal fallback instruction.tests/gateway/test_restart_resume_pending.py: cover session serialization, mark/clear behavior, replaying captured text, and nonblank fallback recovery.How to Test
Commands run locally:
Results:
Note:
scripts/run_tests.sh tests/gateway/test_restart_resume_pending.pycould not run in this local checkout because the shared venv has nopip, and the wrapper tries to installpytest-splitbefore running tests.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
Observed locally in a messaging gateway: after a restart interrupted a
runturn, the old auto-resume path produced a synthetic internal turn with blank content and the bot replied that the message came through empty. This PR makes that synthetic turn nonblank and, when possible, replays the original in-flight message.