fix(tui_gateway): offload remote-media attach handlers to the RPC pool - #41510
Open
vondelomlo wants to merge 1 commit into
Open
fix(tui_gateway): offload remote-media attach handlers to the RPC pool#41510vondelomlo wants to merge 1 commit into
vondelomlo wants to merge 1 commit into
Conversation
## What does this PR do? Stops the gateway from freezing while a remote PDF or image upload is processed. `dispatch()` only offloads methods listed in `_LONG_HANDLERS` to the thread pool; everything else runs inline on the single reader loop, which reads the next RPC only after the current handler returns. The remote-media-relay feature (16786f3) added two genuinely long-running handlers that were left off that list: - `pdf.attach` shells out to `pdftoppm` with a 120s timeout. - `image.attach_bytes` base64-decodes and writes multi-MB uploads to disk. While either runs inline, inbound RPCs — notably `session.interrupt` and `approval.respond` — sit unread in the pipe/socket, so the UI appears hung for the full render/decode duration and the user cannot interrupt the turn or answer an approval prompt. The old `image.attach` only resolves a local path, so it stays correctly inline. Fix: register both new handlers in `_LONG_HANDLERS` so `dispatch()` routes them to the pool and frees the reader loop immediately — the exact pattern already used by `slash.exec`, `shell.exec`, and `session.compress`. ## Related Issue N/A ## Type of Change - [x] 🐛 Bug fix (non-breaking change that fixes an issue) ## Changes Made - `tui_gateway/server.py`: add `pdf.attach` and `image.attach_bytes` to the `_LONG_HANDLERS` frozenset; refresh the explaining comment to cover the media-relay handlers. - `tests/tui_gateway/test_protocol.py`: add a parametrized test proving each media handler is offloaded and a concurrent fast handler completes in <0.5s instead of blocking behind it. - `scripts/release.py`: register the contributor email in `AUTHOR_MAP`. ## How to Test 1. `scripts/run_tests.sh tests/tui_gateway/test_protocol.py` — full file green. 2. Targeted: `pytest tests/tui_gateway/test_protocol.py -k "media or dispatch" -q` — 16 pass, including `test_dispatch_media_attach_does_not_block_fast_handler[pdf.attach]` and `[image.attach_bytes]`. 3. Before the fix the new test blocks ~5s on the fast handler and fails the `<0.5s` assertion; after the fix it passes. ## Checklist ### Code - [x] I've read the Contributing Guide - [x] My commit messages follow Conventional Commits - [x] I searched for existing PRs to make sure this isn't a duplicate - [x] My PR contains only changes related to this fix - [x] I've run the relevant tests and they pass - [x] I've added tests for my changes - [x] I've tested on my platform: macOS 15.5 ### Documentation & Housekeeping - [x] I've updated relevant documentation (docstrings/comment) — or N/A - [x] I've updated cli-config.yaml.example if I added/changed config keys — N/A - [x] I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A - [x] I've considered cross-platform impact — N/A (pure dispatch routing, no platform-specific code) - [x] I've updated tool descriptions/schemas if I changed tool behavior — N/A
Contributor
|
Thanks for the focused fix. The premise still holds on current main: The related merged PR #53895 covered the separate Automated hermes-sweeper review. |
This was referenced Jul 19, 2026
19 tasks
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?
Stops the gateway from freezing while a remote PDF or image upload is processed.
dispatch()only offloads methods listed in_LONG_HANDLERSto the threadpool; everything else runs inline on the single reader loop, which reads the
next RPC only after the current handler returns. The remote-media-relay
feature (16786f3) added two genuinely long-running handlers that were left
off that list:
pdf.attachshells out topdftoppmwith a 120s timeout.image.attach_bytesbase64-decodes and writes multi-MB uploads to disk.While either runs inline, inbound RPCs — notably
session.interruptandapproval.respond— sit unread in the pipe/socket, so the UI appears hung forthe full render/decode duration and the user cannot interrupt the turn or
answer an approval prompt. The old
image.attachonly resolves a local path,so it stays correctly inline.
Fix: register both new handlers in
_LONG_HANDLERSsodispatch()routes themto the pool and frees the reader loop immediately — the exact pattern already
used by
slash.exec,shell.exec, andsession.compress.Related Issue
N/A
Type of Change
Changes Made
tui_gateway/server.py: addpdf.attachandimage.attach_bytesto the_LONG_HANDLERSfrozenset; refresh the explaining comment to cover the media-relay handlers.tests/tui_gateway/test_protocol.py: add a parametrized test proving each media handler is offloaded and a concurrent fast handler completes in <0.5s instead of blocking behind it.scripts/release.py: register the contributor email inAUTHOR_MAP.How to Test
scripts/run_tests.sh tests/tui_gateway/test_protocol.py— full file green.pytest tests/tui_gateway/test_protocol.py -k "media or dispatch" -q— 16 pass, includingtest_dispatch_media_attach_does_not_block_fast_handler[pdf.attach]and[image.attach_bytes].<0.5sassertion; after the fix it passes.Checklist
Code
Documentation & Housekeeping