Parallel tool spans include time waiting for the rest of the batch
Describe the Bug
On @flue/runtime and @flue/opentelemetry 2.2.2 (latest npm releases on September 28, 2026), a fast tool’s OpenTelemetry span stays open until the rest of its parallel batch finishes.
Self-contained reproduction and raw OTel data. It uses Flue’s start() API and the scripted fauxProvider from the react-chat example. One model response requests two tools that execute real sleep 1 and sleep 5 subprocesses. No API keys or external services are needed.
| Tool | Subprocess | Flue durationMs |
OTel span |
|---|---|---|---|
sleep 1 |
1,010 ms | 1,019 ms | 5,023 ms |
sleep 5 |
5,004 ms | 5,021 ms | 5,024 ms |
The fast tool’s completion event is timestamped about four seconds after its subprocess finishes. Completion publication is deferred until the batch finishes, and OpenTelemetry uses that publication timestamp to end the span. Consequently, span durations disagree with the recorded individual tool durations.
Expected Behavior
Each span should end when its own tool completes: approximately one and five seconds, respectively. Delayed publication should preserve the actual completion timestamp, independently of when the batch becomes durable or its results become available.
Steps to Reproduce
Requires Node.js 22.19+ and POSIX sleep. Tested on Linux with Node.js 26.9.0.
- Clone the repro and install its pinned dependencies:
git clone https://gist.github.com/hsheth2/e26dd6365fe4f77dcf629aa34fcec86a.git flue-tool-span-repro cd flue-tool-span-repro npm ci - Run
npm run repro. - Inspect the printed timings and generated
otel-data.json. The script verifies that both subprocesses ran concurrently, then fails an assertion because the fast tool’s span exceeds two seconds.
Source: withastro/flue