Repository navigation
fix(stats): count forked sessions' copied messages once (backport #306) - #313
Merged
Merged
Conversation
OpenCode 1's Session.fork copies the parent's messages into the fork session with new ids but identical times, model, tokens, and cost, so all-history, completed, and multi-session reads counted each copy again. Drop a finished assistant row when an earlier row with the same fingerprint (created/completed time, provider, model, tokens, cost) is in a different session. Unfinished rows and same-session duplicates are kept, and a fork's own single-session read still shows its copied history. Fixes #306
…ckport #306) Remembering only the first session per fingerprint undercounted: when a parent had two identical finished messages, an early fork copied one and a later fork copied both, reading the two forks (or all history after the parent was deleted) returned one row instead of two. Count each finished fingerprint as many times as the session that has it most often. Unfinished rows are still always kept. Refs #306
2 tasks done
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
Backport of the #306 fix to the 4.x (OpenCode 1) line.
Session.forkclones each parent message into the fork with a new id but the same times, model, tokens and cost. The all-history, time-window and multi-session readers counted each copy again, so forking a $10 session without using the fork showed $20 in token/cost totals.dropForkCopiesinsrc/lib/opencode-storage.tscounts each finished fingerprint (created/completed time, provider, model, tokens, cost) as many times as the session that has it most often, and drops the extra copies. It also runs on the no-json_extractfallback of the completed-message reader. Unfinished rows are never merged.Linked Issue
Fixes #306
OpenCode Validation
Session.forksource).Before-and-after evidence
Not applicable for screenshots on OpenCode 1 (not run live). The new tests fail on the old 4.x code (5 fork-copy tests) and pass with this change.
Surface checks:
/tokens_*output: covered by unit tests only.Quality Checklist
pnpm verify