Commit 1e00c59
bcode
fix(laminar): drain OTel processors before process.exit() to stop losing final agent spans
Eval traces were missing the final LLM span on ~27% of runs (gemini-3-flash
76%, glm-5.1 34%, mimo 14%, gpt-5.5 1%, claude 0%). Root cause is a
process-exit race: the plugin event hook in packages/opencode/src/plugin/index.ts:249
is invoked fire-and-forget (`void hook["event"]?.(...)`), so the bcode-laminar
`session.idle` handler's `processor.forceFlush()` Promise is discarded, and
the unconditional `process.exit()` in the top-level `finally` (index.ts:252)
kills in-flight gRPC exports.
Model-dependence comes from emit shape: tool-only-then-final-text models
(glm-5.1, gemini-3-flash) make one extra tool-less LLM round at the end whose
lone `ai.streamText.doStream` span ends 50-200ms before idle and is the
freshest unflushed thing in the BatchSpanProcessor queue at exit. Tool-call+
text-in-same-step models (claude-opus, gpt-5.5) fold the final answer into a
step that ended seconds earlier and was already flushed in a prior batch.
Fix: in the top-level `finally` of index.ts, before `process.exit()`, fetch
the global OTel TracerProvider via `@opentelemetry/api`, duck-check
`forceFlush`, and race it against a 3 s timeout so a wedged exporter cannot
hang bcode on exit. Generic to any OTel-based plugin.
Does not touch the deeper bug (the fire-and-forget `event` hook); that is
the proper upstream fix to anomalyco/opencode.1 parent 90424e2 commit 1e00c59
1 file changed
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
248 | 263 | | |
249 | 264 | | |
250 | 265 | | |
| |||
0 commit comments