Skip to content

fix(trace-opencode): support opencode 1.14.x delta event stream#11

Open
Evan Burrell (evan-burrell) wants to merge 1 commit into
braintrustdata:mainfrom
evan-burrell:feature/opencode-1-14-event-stream
Open

fix(trace-opencode): support opencode 1.14.x delta event stream#11
Evan Burrell (evan-burrell) wants to merge 1 commit into
braintrustdata:mainfrom
evan-burrell:feature/opencode-1-14-event-stream

Conversation

@evan-burrell

Copy link
Copy Markdown

Closes #9. (Re-opened from #10 on the renamed branch feature/opencode-1-14-event-stream.)

Summary

  • opencode 1.14.x dropped message.updated / message.part.updated from the plugin event bus and now streams via message.part.delta + session.idle. The existing LLM-span path never fired against 1.14.x → Braintrust showed LLM calls: 0 for every turn.
  • Add a message.part.delta handler that accumulates text-field deltas per messageID, then synthesize an LLM span on session.idle when the old message.updated path didn't already emit one. Old path stays intact for opencode <1.14; a per-turn guard prevents double-emit when both fire.
  • Provider/model captured from chat.message is reset unconditionally each turn so Turn N+1 doesn't inherit Turn N's model identity. Empty-response turns (no deltas at all) skip the LLM span entirely — absence is the signal. Non-text delta fields (future tool_input streaming) are filtered so they can't corrupt assistant text.
  • Shared synthesis lives in src/delta-synthesis.ts so the test-driving EventProcessor and the production hook stay in sync.

Test plan

  • bun test — 92 pass / 0 fail (8 new tests added for the 1.14.x flow: delta-only synthesis, transition case, system-prompt prepend, no-model leak across turns, empty-response skip, non-text field filter, epoch-0 start preservation, turn-span output fallback)
  • npx tsc --noEmit — clean
  • npm run check — clean (biome lint + format)
  • bun build src/index.ts --outdir dist --target bun --format esm — clean
  • Manual smoke against opencode 1.14.48 in cloudflare/sandbox: confirm LLM calls: >= 1 per turn in the Braintrust dashboard
  • Smoke test against opencode <1.14 (if available): confirm message.updated-driven path still emits with token counts and the synthesis path stays dormant

Closes braintrustdata#9.

opencode 1.14.x stopped delivering message.updated and message.part.updated
to plugins; it now streams via message.part.delta and signals turn end via
session.idle. LLM-span emission was gated on the old events, so no LLM
spans landed in Braintrust against 1.14.x — root and turn spans appeared,
but every turn showed "LLM calls: 0".

Add a delta accumulator (per messageID, text-field only) and synthesize an
LLM span on session.idle when the existing path didn't already emit one.
The old path remains intact for opencode <1.14, and a per-turn guard
prevents double-emit when both paths fire. Provider/model captured from
chat.message resets unconditionally so a turn without a model object
doesn't inherit the previous turn's identity.

Shared synthesis lives in src/delta-synthesis.ts so the test-driving
EventProcessor and the production hook can't drift.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No LLM spans emitted on opencode 1.14.x — event stream renamed (message.updated and message.part.updated never fire)

1 participant