fix(trace-opencode): support opencode 1.14.x delta event stream#11
Open
Evan Burrell (evan-burrell) wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9. (Re-opened from #10 on the renamed branch
feature/opencode-1-14-event-stream.)Summary
message.updated/message.part.updatedfrom the plugin event bus and now streams viamessage.part.delta+session.idle. The existing LLM-span path never fired against 1.14.x → Braintrust showedLLM calls: 0for every turn.message.part.deltahandler that accumulates text-field deltas per messageID, then synthesize an LLM span onsession.idlewhen the oldmessage.updatedpath didn't already emit one. Old path stays intact for opencode <1.14; a per-turn guard prevents double-emit when both fire.chat.messageis 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 (futuretool_inputstreaming) are filtered so they can't corrupt assistant text.src/delta-synthesis.tsso the test-drivingEventProcessorand 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— cleannpm run check— clean (biome lint + format)bun build src/index.ts --outdir dist --target bun --format esm— cleanLLM calls: >= 1per turn in the Braintrust dashboardmessage.updated-driven path still emits with token counts and the synthesis path stays dormant