Skip to content

fix(agent): flush buffered Responses parts from the first part - #7556

Open
garvit-arora wants to merge 1 commit into
apache:mainfrom
garvit-arora:fix/7477-flush-first-buffered-part
Open

garvit-arora wants to merge 1 commit into
apache:mainfrom
garvit-arora:fix/7477-flush-first-buffered-part

Conversation

@garvit-arora

Copy link
Copy Markdown
Contributor

Summary

Since #7427, receive() writes buffered completed Responses parts only after 25 ms without a stream event. Because the tokio::time::sleep(25 ms) was created again on every loop iteration, a provider that emits events less than 25 ms apart never wrote anything: a completed text part followed by a long tool-argument stream stayed in memory until the stream ended.

If the Host died in that window, the next start found no persisted part for the attempt and assess_recovery blocked the Run. The issue's measurements show 10 ms and 20 ms event gaps never writing, while 40 ms gaps wrote after about 85 ms.

This anchors the flush deadline to the first buffered part instead of restarting it after every event, matching the local experiment in the issue. The deadline is cleared when the buffer drains, so a later batch gets its own 25 ms window.

Fixes #7477

Verification

  • cargo check -p maka-agent-native --lib --locked — passed.
  • cargo test -p maka-agent-native --lib coalesced_flush --locked — 1 passed. The test asserts the deadline is anchored to the first buffered part and does not move when later events arrive.
  • cargo fmt --all -- --check — passed.

I did not run the mock Responses SIGKILL reproduction from the issue (macOS/WebSocket fixture); CI covers the crate build and tests.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: DeepSeek V4.1 Flash Free via OpenCode implemented the deadline change and its unit test.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a breaking change or persisted-data migration?

  • Yes — describe user/data impact, in-place migration, and upgrade_compat.rs coverage under Summary above
  • No

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

The coalesced-closure timer was recreated after every stream event, so a provider that emits events less than 25 ms apart never wrote completed parts. A crash in that window left no persisted part and recovery blocked the Run. Anchor the 25 ms deadline to the first buffered part instead.

Generated-by: DeepSeek V4.1 Flash Free (OpenCode)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(agent): Responses parts stay unwritten while stream events arrive under 25 ms apart, so a mid-stream crash fails the Run

1 participant