Repository navigation
fix(test): wait for the background task's working snapshot - #628
Open
ShotaroKataoka wants to merge 3 commits into
Open
ShotaroKataoka wants to merge 3 commits into
ShotaroKataoka wants to merge 3 commits into
Conversation
…of reading it once Strands' in-process engine publishes each task update with call_soon on its runtime thread. A task is marked working in the first step of its execution, but that notification is queued behind the callback that hands the dispatch ack back to the agent's thread. The agent thread can then finish the turn before the runtime thread stores the "working" snapshot in agent.state, and a status read right after invoke_async sees "queued" (#626). The two tests that read the status once now poll for "working" with the file's _until helper. The refusal test still checks that the status right after the turn is queued or working, never cancelled. Production code is unaffected: session_runtime only uses background.pending(), which counts queued and working alike. Closes #626
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
test_a_call_to_the_manage_tool_by_name_is_refused_and_the_task_keeps_runningread the task status once, right afterinvoke_async, and sometimes saw['queued'](#626). The cause is in how Strands publishes task updates, not in the test's timing budget.Strands' in-process engine runs on its own runtime thread and publishes every update with
loop.call_soon(self._run_notification, …). The task is markedworkingin the first step of_execute, but that notification is queued behind the callback that hands the dispatch ack back to the agent's thread. When the GIL goes to the agent thread first, the turn (refused manage call, final text) can finish before the runtime thread stores theworkingsnapshot inagent.state.test_cancel_all_cancels_a_pending_taskhas the same single read of["working"]and could flake the same way.Production is not affected:
session_runtimeonly usesbackground.pending(), which countsqueuedandworkingalike.Changes
tests/test_agent_background.pyworkingwith the file's_untilhelper (timeout 5 s) instead of reading it once.working. It acceptsqueuedorworkingright after the turn (nevercancelled) and checks that the task endscompleted. It does not wait forworking: the task takes 0.4 s, so it can reachcompletedbefore a poll seesworking.Testing
_run_notificationforworkingby 0.1 s makes both tests onmainfail withassert ['queued'] == ['working']. With this change the whole file passes under the same probe.ruff check tests/test_agent_background.pyNotes
No CHANGELOG entry: test-only change.
Closes #626
🤖 Created by Kiro Crew