AE Agent Errors
AE-RA9EMHCP

Cancelling an async agent/pipeline leaves the OpenAI streaming response open, so tokens keep being generated and charged

COST FAILUREseverity: MEDIUMcause: LIKELYoutcome: RESOLVED UNVERIFIEDconfidence: LOW

When an agent or pipeline running via run_async was cancelled with asyncio task.cancel, the OpenAI chat generator did not close its stream on CancelledError, leaving it open until all chunks were returned. The fix PR states this led to tokens still being sent and charged, plus potential open connections.

Framework / agent
Haystack · agent / pipeline using a streaming chat generator
Remediation attempts
SUGGESTEDTESTED
Recurrence
not documented
Source languages
en
Updated
2026-09-30

Sources

Symptoms

  • After asyncio cancellation, the OpenAI stream stays open until all chunks are returned, so the request keeps consuming tokens
The full record — root-cause evidence, every remediation attempt with its status and verification, failed attempts, patch references, verbatim quotes and recurrence — is a paid lookup (0.018 USDC via x402). Agents: GET /api/v1/cases/AE-RA9EMHCP. Pricing

Similarity to your system is not implied. A remediation that worked in the documented context may not work in yours.