Skip to content

[BUG] Workflow - Title: Thread pool configuration variables MIN_THREADS and CPU_THRESHOLD are defined but not used #327

@mcosicaws

Description

@mcosicaws

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

1.18.0

Tools Package Version

0.2.16

Tools used

Workflow

Python Version

3.13.2

Operating System

macOS 15.7

Installation Method

pip

Steps to Reproduce

The workflow documentation mentions:

  • "Automatic thread pool scaling (2-8 threads)" - but scaling is not implemented
  • "CPU usage monitoring and optimization" - but CPU monitoring doesn't exist
  • "Dynamic thread pooling" - but thread pool size is fixed at MAX_THREADS

These features appear to be planned but not implemented.

Expected Behavior

The workflow tool defines environment variables STRANDS_WORKFLOW_MIN_THREADS and STRANDS_WORKFLOW_CPU_THRESHOLD but does not use them. Only STRANDS_WORKFLOW_MAX_THREADS actually affects workflow execution.

Configuration Variables

File: strands_tools/workflow.py

Lines 133-135:

MIN_THREADS = int(os.getenv("STRANDS_WORKFLOW_MIN_THREADS", "2"))
MAX_THREADS = int(os.getenv("STRANDS_WORKFLOW_MAX_THREADS", "8"))
CPU_THRESHOLD = int(os.getenv("STRANDS_WORKFLOW_CPU_THRESHOLD", "80"))

Actual Behavior

MIN_THREADS (default: 2):

  • Stored in self.min_workers (line 163)
  • Never referenced again in the code
  • Python's ThreadPoolExecutor doesn't have a min_workers parameter
  • Threads are created lazily on-demand, not pre-created

MAX_THREADS (default: 8):

  • Works correctly - passed to ThreadPoolExecutor(max_workers=max_workers) (line 165)
  • Controls the maximum number of concurrent tasks

CPU_THRESHOLD (default: 80):

  • Defined with comment "CPU usage threshold for scaling down"
  • Never referenced anywhere in the code
  • No CPU monitoring or dynamic scaling implemented

Thread Pool Behavior:

  • Threads are created lazily (on-demand) as tasks are submitted
  • No threads exist when executor is created
  • Threads are created up to MAX_THREADS limit
  • Once created, threads are reused for subsequent tasks

Example:

  • ThreadPoolExecutor created with max_workers=8

  • Current threads: 0

  • Submit 3 tasks

  • Current threads: 3 (created on-demand)

  • Submit 10 more tasks

  • Current threads: 8 (capped at max_workers)

  • Remaining 5 tasks wait in unbounded queue

Additional Context

Line 162-165: TaskExecutor initialization

def __init__(self, min_workers=MIN_THREADS, max_workers=MAX_THREADS):
    self.min_workers = min_workers  # Stored but never used
    self.max_workers = max_workers
    self._executor = ThreadPoolExecutor(max_workers=max_workers)  # Only max_workers used

No references to:

  • self.min_workers after line 163
  • CPU_THRESHOLD anywhere in the code
  • CPU monitoring or dynamic scaling logic

Possible Solution

Option 1: Remove unused variables

  • Remove MIN_THREADS and CPU_THRESHOLD from the code
  • Update documentation to reflect only MAX_THREADS is used

Option 2: Implement the features

  • MIN_THREADS: Pre-create minimum number of threads for faster task startup
  • CPU_THRESHOLD: Implement dynamic scaling based on CPU usage
    • Monitor CPU usage
    • Scale down thread pool when CPU exceeds threshold
    • Scale up when CPU is below threshold

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions