models - bedrock - remove signaling #429
Merged
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.
Description
The bedrock model provider runs converse stream in a separate thread so as not to block the async event loop. This stream thread pushes events onto a queue for the main thread to read and subsequently yield up to the agent caller. For each new event, the worker thread waits until the main thread signals that it is done yielding. This was an idea taken from the iterative tool implementation that would allow for a form of return of control. The problem however is if the main thread terminates before the stream thread completes, the stream thread can get blocked waiting for a signal.
The fix is to remove signaling. Unlike iterative tool invocation, return of control is not needed for model event streaming. The stream thread can continue queuing events from the model invocation while the main thread reads the events at its leisure. There is no harm in letting the events buffer on the queue. Bedrock is doing this anyway server side.
Related Issues
Identified during 0.3.0 bug bash.
Documentation PR
N/A
Type of Change
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepare
hatch test tests_integ/models/test_model_bedrock.py
func_c
is intentionally setup to raise an exception. If it does so before func_a and func_b complete, the stream threads from the func_a and func_b bedrock model instances will get stuck on thesignal.wait
. Removing signaling fixed the issue. The stream thread is allowed to complete even if the main thread goes down.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.