fix(swarm): accumulate execution_time across interrupt/resume cycles#1502
Merged
fix(swarm): accumulate execution_time across interrupt/resume cycles#1502
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Member
Author
|
/strands can you also look at the elapsed time calculation in should_continue? |
Member
Author
|
/strands can you also look at the elapsed time calculation in should_continue? |
Change execution_time calculation from assignment to accumulation (= to +=) to match the behavior in graph.py. This ensures execution_time reflects the total time across all invocations rather than being reset on resume. Add test to verify execution_time accumulates across interrupt/resume cycles.
Update elapsed time calculation in SwarmState.should_continue to include accumulated execution_time from previous invocations, matching the pattern in GraphState.should_continue. This ensures timeout checks account for total execution time across interrupt/resume cycles. Add test to verify timeout check includes accumulated time.
7d05805 to
b1b5d86
Compare
dbschmigelski
approved these changes
Jan 20, 2026
zastrowm
approved these changes
Jan 21, 2026
manoj-selvakumar5
pushed a commit
to manoj-selvakumar5/strands-sdk-python
that referenced
this pull request
Feb 5, 2026
…trands-agents#1502) Co-authored-by: Strands Agent <217235299+strands-agent@users.noreply.github.com>
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.
Motivation
When a Swarm is interrupted and resumed, two time-related calculations are incorrect:
execution_timeinSwarmResultis reset on resume instead of accumulating across invocationselapsedtime inshould_continueonly considers the current invocation, causing timeout checks to ignore time spent in previous invocationsThe correct behavior is demonstrated in
Graph, where both calculations properly account for accumulated time.Resolves #1501
Public API Changes
No public API changes. These are behavioral bug fixes that ensure:
SwarmResult.execution_timecorrectly reflects total execution time across interrupt/resume cyclesshould_continueaccount for total elapsed timeChanges
swarm.pyelapsed = self.execution_time / 1000 + time.time() - self.start_time(matches graph.py)swarm.pyself.state.execution_time +=instead of=(matches graph.py)Use Cases