Track OpenCode child sessions under root sessions#343
Open
ozymandiashh wants to merge 1 commit into
Open
Conversation
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.
Summary
Addresses the OpenCode portion of #336 by tracking agent/subagent work that OpenCode stores in child sessions.
OpenCode records sessions in SQLite with a
session.parent_idhierarchy. Before this PR, CodeBurn discovered only root sessions and then parsed only messages whosemessage.session_idmatched that root. That meant work done by OpenCode child or grandchild sessions could be invisible in CodeBurn, including token usage, tool calls, bash commands, and costs.This PR keeps discovery root-only to avoid double counting, but changes parsing so a root session includes its unarchived child-session subtree.
Root cause
The existing parser used root-session queries like this:
That works for a flat session, but not for OpenCode's parent-child session shape:
Because the query only matched the root session id, CodeBurn ignored the child and grandchild rows even though they belong to the same user-visible OpenCode task.
What changed
messageandpartreads now use a recursivesession_treeCTE starting from the discovered root session.parent_id IS NULLdiscovery query. This prevents double counting.sessionId, so downstream session summaries stay grouped under the root task.opencode:<message-session-id>:<message-id>. This avoids collisions between root and child messages.Example behavior
Given this SQLite session tree:
Before:
After:
Tests added
sessionId.taskand grandchild bash commands are surfaced.Validation
npx vitest run tests/providers/opencode.test.ts tests/provider-registry.test.ts- 49/49 tests passed.npx tsc --noEmit --pretty false- passed.npm run build- passed.git diff --check- passed.Scope and privacy notes
I did not use real local OpenCode history or reporter data. The validation uses synthetic SQLite fixtures only, so no local project names, prompts, paths, session IDs, usage values, or private product details are included.
This PR intentionally does not change OpenCode zero-usage router-call handling from #342. If #342 merges first, this branch may need a small rebase because both PRs touch
src/providers/opencode.ts, but the behaviors are separate.