⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@pgrayy
Copy link
Member

@pgrayy pgrayy commented Jan 16, 2026

Motivation

When a Swarm is interrupted and resumed, two time-related calculations are incorrect:

  1. execution_time in SwarmResult is reset on resume instead of accumulating across invocations
  2. elapsed time in should_continue only considers the current invocation, causing timeout checks to ignore time spent in previous invocations

The 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_time correctly reflects total execution time across interrupt/resume cycles
  • Timeout checks in should_continue account for total elapsed time
# Before: execution_time was reset on each invocation
result = swarm("task")  # execution_time = 50ms (interrupted)
result = swarm(responses)  # execution_time = 60ms (only resume time, lost 50ms)

# After: execution_time accumulates
result = swarm("task")  # execution_time = 50ms (interrupted)
result = swarm(responses)  # execution_time >= 50ms (accumulated total)

Changes

File Line Change
swarm.py 202 elapsed = self.execution_time / 1000 + time.time() - self.start_time (matches graph.py)
swarm.py 409 self.state.execution_time += instead of = (matches graph.py)

Use Cases

  • Performance monitoring: Total execution time across multi-step workflows is now accurate
  • Timeout enforcement: Timeouts now correctly trigger based on cumulative time, not just current invocation time
  • Cost estimation: Applications using execution time for billing receive correct totals

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.
@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pgrayy
Copy link
Member Author

pgrayy commented Jan 16, 2026

/strands can you also look at the elapsed time calculation in should_continue?

@pgrayy pgrayy marked this pull request as ready for review January 16, 2026 18:19
@pgrayy
Copy link
Member Author

pgrayy commented Jan 16, 2026

/strands can you also look at the elapsed time calculation in should_continue?

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Swarm - Interrupt - Execution Time Miscalculated

2 participants