fix(cli): stream agent output as plain text instead of Rich markup - #544
Open
michaelxu2288 wants to merge 1 commit into
Open
michaelxu2288 wants to merge 1 commit into
michaelxu2288 wants to merge 1 commit into
Conversation
stream_process_output is the only reader of an agent's stdout pipe in
`agentex agents run`, and it printed every line with
console.print(f"[dim]{prefix}:[/dim] {decoded_line}"), so the agent's
own output was parsed as Rich markup:
- A line with an unmatched closing tag, such as "[INST] hi [/INST]" or
"loaded [/etc/hosts]", raised MarkupError. That reached the outer
handler and ended the loop, which is the freeze the function's
docstring warns about: nothing drains the pipe any more and the agent
blocks once it fills.
- Bracketed words were eaten as styles: "[info] starting" printed as
" starting", "deps: [pkg==1.0]" as "deps: ".
- Markup rendering of long lines is slow and blocks the event loop while
it runs: an 82,000-character line took 28.9 s here, which is also why
test_large_line_within_the_limit_is_streamed_in_full times out on
slower machines.
Print a Text with a dim prefix and the line as plain text instead. The
read loop, limits and error handling are unchanged.
Verified by driving stream_process_output with an in-memory reader: on
main the first markup-like line stops streaming and nothing after it is
printed; here every line prints verbatim and the 82,000-character line
prints in 0.01 s. Two new tests cover the reader surviving markup-like
output and printing it verbatim; tests/lib/cli/test_run_handlers_streaming.py
passes (7 tests, 1.5 s).
This branch has not been deployed
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.
Problem
In
agentex agents run,stream_process_outputis the only reader of an agent's stdout pipe. It printed each line withso the agent's own output was parsed as Rich markup. That has three effects:
[INST] hi [/INST](common in prompt dumps) orloaded [/etc/hosts], raisesMarkupError. The error reaches the outer handler and ends the loop. This is the freeze the function's docstring warns about: nothing drains the pipe any more, and the agent blocks once the pipe fills.[info] startingprints asstarting, anddeps: [pkg==1.0]prints asdeps:.test_large_line_within_the_limit_is_streamed_in_fulltimes out on slower machines.Fix
Print a
rich.text.Textwith the dim prefix and the line appended as plain text. The read loop, the limits and the error handling are unchanged. Child output loses Rich's automatic number/string highlighting; I think plain is the right default for raw logs.Verification
I drove
stream_process_outputwith an in-memory reader:main[INST] hi [/INST],loaded [/etc/hosts],[info] starting,deps: [pkg==1.0],after the markupOutput streaming for TEST stopped on MarkupError(...); nothing printedtests/lib/cli/test_run_handlers_streaming.py:uv run pytest -n 0 tests/lib/cli/test_run_handlers_streaming.py: 7 passed in 1.5 s, including the 82k-character test.ruff checkandpyrightare clean.This PR appears safe to merge; no actionable issues were found.
What we checked:
Text, and the new tests check both intact output and a child that finishes after flooding the pipe.Summary
The CLI now prints agent output as plain text while keeping its prefix dim. Markup-like content stays visible, and the reader can keep draining output after those lines.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Agent stdout] --> B[Read and decode line] B --> C[Build plain Text with dim prefix] C --> D[Print to console] D --> BReviews (1) · Last reviewed commit: "fix(cli): stream agent output as plain t..."