Repository navigation
Finalize a session before logging on session.idle - #59
Open
CristinaT21 wants to merge 1 commit into
Open
CristinaT21 wants to merge 1 commit into
CristinaT21 wants to merge 1 commit into
Conversation
|
|
Member
|
Thanks for the contribution @CristinaT21. Could you sign our CLA, so that we can accept the changes? (see #59 (comment)) |
This branch has not been deployed
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.
On OpenCode 1, the
session.idlehandler awaitsclient.app.log("Flushing spans")before itfinalizes the session:
app.logis an HTTP round trip to the OpenCode server. If the next prompt for the samesession arrives in that window,
chat.messagestarts the new turn first, andfinalizeSessionTracingthen ends that new turn and clears the session's trace state. Thenew turn's generations are dropped, because
traceGenerationreturns when there is no turn.The trace shows a turn that lasts a few milliseconds with no generation, while OpenCode ran
and billed the step.
This PR finalizes before logging, so nothing is awaited between
session.idleand ending theturn. The OpenCode 2 handler already ends the turn without awaiting anything first.
How we hit it: we run OpenCode 1.18.32 as a server and send prompts with
prompt_async.We ran a two-turn session against a local Langfuse 4.66.0, sending the second prompt as soon as
the first turn returned. In both runs, the second turn's generation was missing (3 of 4
generations recorded), and the Langfuse cost was short by that step. With this change, every
generation was recorded in each of 5 runs: back to back, with a second prompt sent while the
first turn was still running, and with a 3 s pause. In each run the Langfuse cost matched
OpenCode's exactly.
Test:
keeps a turn that starts while the previous idle is still loggingholds the fakeclient's
app.logopen, starts the next turn while the idle is still logging, and checks thatthe next turn's generation is exported. Without the change it fails with
expected [ 'idle-race-assistant-1' ] to include 'idle-race-assistant-2'.Verification:
pnpm run format:check,pnpm run lint,pnpm run knip,tsc --noEmit -p tsconfig.test.json: cleanpnpm run test:integration: 69 passed. Locally,decodes the tags plugin optionhit thedefault 5 s timeout on its first dynamic import (Docker on Windows). It passes with
--testTimeout=60000, and the change doesn't touch it.🤖 Generated with Claude Code