subc: bash_status reply can exceed the daemon's 4 MiB delivered-frame limit when the output ends in a long line
Summary
A bash_status reply for a finished background task can be larger than 4 MiB. The subc daemon then refuses the reply frame (frame_too_large), and the caller gets an error instead of the task status. This occurs when the task output ends in a long line, because the terminal preview keeps that line whole.
We saw this on a live OpenCode 2 service with v0.68.0. The daemon refused three bash_status replies of about 6.4 MB for one finished test task with about 100 MB of output. We reproduced it on v0.68.0 and on main at df341f683.
This is not #215. That issue is about the 64 MiB frame body limit, and v0.50.1 repaired it. The limit here is the 4 MiB limit for a frame that the daemon delivers to a client.
Cause
Line numbers are at v0.68.0.
- For a finished piped task,
bash_statusserializes the task snapshot (crates/aft/src/commands/bash_status.rs:282). The snapshot getsoutput_previewfrom the terminal render cache (crates/aft/src/bash_background/registry.rs:3250). cap_final_output_preservingapplies the preview budget to ordinary context lines only. It copies the required lines (test verdict lines and the last line of each stream) whole:essentials.copy(input, line_range)(crates/aft/src/bash_background/output.rs:381) andcapped.append(essentials)(:456). The budget calculation subtracts the required lines from the context budget (:394), but nothing limits the required lines. The compressor samples up to a 6 MiB tail. Thus one long last line can put almost 6 MiB intooutput_preview.- The subc reply path sizes replies against
MAX_FRAME_BODY_LEN, which is 64 MiB (crates/aft/src/subc/task_scope_runtime.rs:67).subc-protocol0.37.4 also hasMAX_DELIVERED_FRAME_LEN(4 MiB, header included). Its documentation says that a module sizes what it sends to a client against that limit. AFT does not use this constant, on v0.68.0 or onmain. - The 50 KiB cap and the spill file in
tool_output.rsapply to the renderedtextonly. They do not changeoutput_preview.
Reproduction
We used a release build in standalone NDJSON mode, with a fresh HOME, fresh XDG folders and a fresh storage folder. Each case starts a piped background task with compressed: true that exits 1. After the task ends, we call bash_status and measure the reply.
| Task output | Last line | Reply (native NDJSON) | Reply (through tool_call) |
|---|---|---|---|
| 100 MiB of 64-byte numbered lines | 64 B | 8,930 B | 16,789 B |
| 100 MiB of numbered lines, then one long line | 8 MiB | 6,292,788 B | 6,344,004 B |
| One line | 4,190,208 B | 4,191,365 B | 4,242,580 B |
| One line | 4,193,280 B | 4,194,437 B | 4,245,652 B |
The values in bold are larger than 4,194,304 bytes. main at df341f683 gave the same values. In the 6.29 MB reply, output_preview holds 6,291,645 bytes.
The OpenCode 2 bridge and plugin do not retry a frame_too_large refusal. The caller gets a tool error.
Possible repair
- Apply the preview byte budget to the whole preview, including the required lines. For a required line that is too long, keep a bounded head or tail. Point to the capture path and to
output_offsetpaging for the rest. - Before the module sends a reply to a client, check the encoded reply against
MAX_DELIVERED_FRAME_LENminus the header length. If it is too large, send a small reply with the status and a recovery pointer. This also covers other large fields, such aspty_rawor a batch of completions.
Thanks, confirmed, and your table reproduced exactly: a 6,291,836-byte preview, and a reply body just over the 4 MiB delivered-frame limit. Both causes were as you described. The status preview budget didn't cover the required lines, and AFT sized client replies against the 64 MiB body limit instead of MAX_DELIVERED_FRAME_LEN.
The fix has two parts. The status preview's byte budget now covers everything, required lines included. An over-long verdict or final line keeps its start and end with AFT's existing ...<truncated N bytes>... marker, and the full output stays available through the capture path and offset paging, as before. Every correlated reply (response, error and stream) is also checked against the pinned delivered-frame limit before it's sent. One that would exceed it is replaced by the existing response_too_large fallback, which keeps the task id, status and exit code. Pushes and reverse requests are only measured for now and logged if oversized. Your cases are regression tests. It will ship in the next AFT release, and I'll update here when it's out.
Retest on PR #1536 at commit abd64ed00, with the reproduction script from this issue on a release build. The six subsequent commits on the PR (head d273f2eb3) do not change the files of this repair.
| Output | v0.68.0 reply, native / tool_call bytes | PR reply, native / tool_call bytes |
|---|---|---|
| 100 MiB of 64-byte lines | 8,930 / 16,789 | 8,930 / 16,789 |
| 100 MiB that ends in an 8 MiB line | 6,292,788 / 6,344,004 | 17,492 / 33,903 |
| One 4,193,280-byte line | 4,194,437 / 4,245,652 | 17,317 / 33,698 |
| One 4,194,304-byte line | 4,195,461 / 4,246,676 | 17,317 / 33,698 |
At that commit, all replies are much smaller than the 4 MiB delivered-frame limit. These are standalone replies. I did not measure frames that a daemon sends.