Record the conversation history as each generation's input - #36
Merged
Conversation
bezbac
enabled auto-merge (squash)
September 4, 2026 11:17
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.
Addresses the conversation-history part of #24. Builds on the analysis in #29, thank you @DavidTraina.
This PR takes a different route to the same goal, described below.
Fixes LFE-15253
Problem
A generation's
inputheld only what arrived since the previous one: the new user message, or the previous assistant message plus the tool results after it. Earlier turns were never repeated, so opening a generation in Langfuse never showed the prompt the model actually received.What this does
The conversation now comes from OpenCode itself.
client.session.messages()serves the whole session,buildSessionHistorymaps it to ChatML, and each generation takes the messages before its own assistant message as its input.step-startparts, so the real order survives: tool calls, their results, then the next step — instead of collapsing a multi-step turn into one message.session.idleand refetched, so nothing needs releasing by hand.step-startfetches only when the cache is cold.Why read the store instead of accumulating in the plugin
#29 accumulates the history in plugin state, which is smaller and needs no I/O. Both produce byte-identical inputs in normal operation. The store wins in the cases where the plugin did not watch the session from its first message:
session.revert, which removes messages from the store: the plugin handles 14 event types and none of them is revert-related, so an accumulator cannot un-remember. A refresh drops them by construction.Tests
pnpm run test:integration, 20 passing. Two new cases: a later turn's generation carrying the prior turn, and the history staying complete when the plugin restarts mid-session. The test harness now models OpenCode's message store, which is what makes the restart case testable at all. Existing multi-generation expectations were updated to include the history. format, lint and knip are clean.Reference PRs - Other integrations:
See Claude Cloud Plugin: langfuse/claude-observability-plugin#80