Files
crewAI/lib
Lucas Gomide a64b41dd42 fix: keep usage listener on pause, guard cross-kickoff handler leakage
Two related races in flow.usage_metrics aggregation:

1. Paused kickoff dropped its listener. When kickoff_async returned a
   HumanFeedbackPending, the finally detached the listener even though
   the bus dispatches LLM event handlers on a thread pool that emit
   does not wait on. Any pre-pause LLM call whose handler future was
   still queued would silently lose its tokens.

   Fix: track a paused_for_feedback flag in kickoff_async and skip the
   detach when set. The listener stays attached on the instance so late
   events continue to accumulate.

2. Stale handlers from a prior kickoff could bleed into a later one.
   The handler closure captured flow_ref and wrote into
   flow._aggregated_usage_metrics. If a handler from kickoff #1 was
   still queued when kickoff #2 reset the accumulator, it would
   contaminate the new run's totals.

   Fix: snapshot a per-flow _usage_epoch in the handler closure at
   attach time. kickoff_async bumps the epoch before attaching, so any
   in-flight handler from a prior kickoff sees its stale snapshot and
   bails out.
2026-06-11 14:59:04 -03:00
..
2026-06-10 20:45:29 -07:00
2026-06-10 20:45:29 -07:00