fix(agent_loop): cap accumulated_text + document streaming non-redelivery contract#3106
Merged
Conversation
…d semantics
A reviewer raised the concern that pushing intermediate tool_use text
into `accumulated_text` could cause a double display when the streaming
path falls back to it for an empty final EndTurn — first via the live
stream, then again as `final_response`.
Verification (grep on bridge.rs):
* Streaming success arm (~bridge.rs:3032 `Ok(())`) calls only
`record_delivery` + `send_lifecycle_reaction`. It does NOT invoke
`send_response(buffered_text)`. The buffered fallback only fires on
the `Err(stream_error)` adapter-failure arm — that is recovery, not
a duplicate emit.
* `signal_response_complete` is a phase-change ping, not a re-emit of
response text.
* `final_response` (which may carry the accumulated_text fallback) is
consumed for session persistence, memory extraction, and hooks —
never pushed back onto `stream_tx`.
Conclusion: the concern is a false positive against the current wiring.
This commit pins the contract in code so a future refactor of the
bridge cannot quietly introduce a double display: the comment explains
the post-stream-fallback semantics and flags the exact invariant that
must hold (stream success arm must NOT re-emit `final_response` unless
the empty-text fallback is suppressed).
…owth `accumulated_text` is appended on every iteration that emits text alongside tool_use blocks. Across long autonomous loops or retry storms this buffer could grow to megabytes per active session, pinning heap until the loop ends. Fix: * Introduce `ACCUMULATED_TEXT_MAX_BYTES = 64 KiB` (≈10× a Slack message limit, comfortably above any realistic user-facing reply). * New `push_accumulated_text` helper centralises the append: it preserves the existing buffered prefix when the cap is hit, seals the buffer with ASCII padding so subsequent calls short-circuit, and emits exactly one `warn!` on the transition (no log spam). * Both the non-streaming and streaming agent loops now route their intermediate-text capture through the helper. Tests: cover separator behaviour, exact-cap sealing, prefix preservation, short-circuit after seal, and unchanged behaviour under the cap.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Summary
Follow-up review concerns from #3091 (already merged).
accumulated_textin the runtime agent loop so future readers understand it is not redelivered to the channel.accumulated_textgrowth at 64 KB to prevent unbounded memory growth during long tool-use chains, with a regression test.Cherry-picks: f273085, a1fc59d
Test plan