Skip to content

[BUG] Swarm - Interrupt - Execution Time Miscalculated #1501

@pgrayy

Description

@pgrayy

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

Latest

Python Version

Latest

Operating System

Mac

Installation Method

pip

Steps to Reproduce

Occurs on any invocation of Swarm. For an example of invoking swarm, see the integ tests here.

Expected Behavior

When a swarm is interrupted, the execution_time is reset on the resume invocation (src). It should instead be a sum across an interrupt/resume cycle. For an example of how this should look, you can check out the execution_time calculation in graph (src, test).

Actual Behavior

When a swarm is interrupted, the execution_time is reset on the resume invocation (src). It should instead be a sum across an interrupt/resume cycle. For an example of how this should look, you can check out the execution_time calculation in graph (src, test).

Additional Context

No response

Possible Solution

No response

Related Issues

No response


Implementation Requirements

Root Cause

In src/strands/multiagent/swarm.py line 409:

self.state.execution_time = round((time.time() - self.state.start_time) * 1000)

This uses = assignment which resets execution_time on each invocation, rather than accumulating it across interrupt/resume cycles.

Reference Implementation

The correct behavior is demonstrated in src/strands/multiagent/graph.py line 589:

self.state.execution_time += round((time.time() - start_time) * 1000)

This uses += to accumulate execution time across all invocations, which is the expected behavior.

Technical Approach

  1. Code Fix - Change line 409 in swarm.py from = to +=:

    self.state.execution_time += round((time.time() - self.state.start_time) * 1000)
  2. Unit Test - Add a test similar to test_graph_interrupt_on_before_node_call_event (found at tests/strands/multiagent/test_graph.py line 2096) that verifies:

    • First invocation records first_execution_time
    • After resume, multiagent_result.execution_time >= first_execution_time

Files to Modify

File Change
src/strands/multiagent/swarm.py Line 409: change = to +=
tests/strands/multiagent/test_swarm.py Add test for execution_time accumulation across interrupt/resume

Acceptance Criteria

  • execution_time in SwarmResult accumulates across interrupt/resume cycles (not reset)
  • New unit test verifies execution_time after resume is >= execution_time from first invocation
  • All existing swarm tests pass
  • Code follows existing patterns in graph.py

Metadata

Metadata

Assignees

Labels

area-multiagentMulti-agent relatedbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions