Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions tests/test_agent_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,17 @@ def policy(messages):
async def run():
agent = _agent(PolicyModel(policy), [fake_compose(0.4)])
await agent.invoke_async("make a deck")
working = [t["status"] for t in background.tasks(agent)]
dispatched = [t["status"] for t in background.tasks(agent)]
await _until(lambda: background.undelivered(agent))
return agent, working
return agent, dispatched

agent, working = asyncio.run(run())
agent, dispatched = asyncio.run(run())

refused = [r for m in agent.messages for r in tool_results(m)][-1]
assert refused["status"] == "error" and "delivered automatically" in result_text(refused)
assert working == ["working"]
# Strands publishes "working" from its runtime thread after the dispatch ack, so the
# turn can end while the snapshot still says "queued".
assert dispatched in (["queued"], ["working"]), "the refused cancel did not touch the task"
assert [t["status"] for t in background.undelivered(agent)] == ["completed"]


Expand Down Expand Up @@ -245,7 +247,8 @@ def test_cancel_all_cancels_a_pending_task():
async def run():
agent = _agent(PolicyModel(compose_policy), [fake_compose(10.0), lookup])
await agent.invoke_async("make a deck")
assert [t["status"] for t in background.pending(agent)] == ["working"]
# "working" is published from Strands' runtime thread, possibly after the turn ends.
await _until(lambda: [t["status"] for t in background.pending(agent)] == ["working"])
started = time.monotonic()
await background.cancel_all(agent)
await _until(lambda: not background.pending(agent), timeout=2)
Expand Down
Loading