fix(opencode): read the 2.x session_v2 + session_message generation - #1436
ozymandiashh wants to merge 2 commits into
Conversation
|
Isnt this close contraproductive? |
|
Fair question. The cap is not about this PR, it is about fairness across contributors: when one person has five PRs waiting, new ones from them go to the back of the queue instead of the front. Issues and draft PRs are always fine. A sixth ready PR is not, until one of the five lands. The part that is on us: those five were open because review is slow, not because they are bad. I am going through them today. #1434 just merged, so this one reopens now and the OpenCode 2.x fix goes in next. |
OpenCode 2.x (mainline since 2.0.3) writes sessions to session_v2 and messages to session_message (tagged by `type`, ordered by `seq`, payload JSON in `data`), while the legacy session/message/part tables freeze at upgrade — so every post-upgrade session was invisible. Branch per database on sqlite_master: when the v2 tables exist they win and the legacy tables are ignored (the generations are never joined); otherwise the legacy path is untouched. v2 payloads normalize into the shared message/part shape, so tokens, cost, model refs, tools, bash commands, user attribution, child-session walks and session-level token rollups all behave exactly as before. Fixes getagentseal#1293 (schema and generation rules confirmed there by ejwill).
iamtoruk
left a comment
There was a problem hiding this comment.
Verified against a real 1.x database: export is byte-identical before and after, $109.91 / 4,009 calls / 177 sessions. Built a 2.x fixture from ejwill's DDL and the v2.0.3 payload schemas; the branch reads it correctly, tokens, cost, model, tools and bash all land. Generations never joined. Good work.
Two things before this lands.
Compaction messages carry cost and tokens in 2.0.3 (CompactionUsage in packages/schema/src/session-message.ts). The type !== 'assistant' filter drops them, and the "skips non-user/assistant" test pins that as correct. On 1.x these were role: assistant and we counted them, so this silently undercounts every compacted 2.x session. My fixture lost $0.42 and 181k tokens on one turn. Treat compaction like assistant for cost and tokens, and flip that test.
Needs a CHANGELOG bullet under Unreleased / Fixed.
Unrelated note for #1362: the v2 queries add two more time_archived IS NULL, so that fix now has five places to strip, not three.
Rebased cleanly onto main, pushed as pr1436-rebased if you want to start from that.
…ngelog Compaction rows carry their own CompactionUsage in 2.0.3 and counted as assistant messages on 1.x; dropping them undercounted every compacted 2.x session (iamtoruk's fixture lost $0.42 / 181k tokens on one turn). A `running` compaction has no usage and still yields nothing.
8157a89 to
da55154
Compare
|
Both addressed in da55154, on top of your
opencode + kilo-code suites green (57/57), typecheck clean. |
Summary
OpenCode 2.x (mainline since 2.0.3, per #1293) writes sessions to
session_v2and messages tosession_message(tagged by atypecolumn, ordered byseq, payload JSON indata). The legacysession/message/parttables freeze at upgrade, so every post-upgrade session was invisible to CodeBurn.src/providers/sqlite-session-parser.tsbranches per database onsqlite_master: when the v2 tables exist they win and the legacy tables are ignored entirely — the generations are never joined, exactly as ejwill laid out in how can see the usage of the opencode v2? #1293. Otherwise the legacy path is byte-for-byte unchanged (kilo-code, which shares this parser, is unaffected: it has no v2 tables).{input, output, reasoning, cache:{read, write}}object), cost, model refs ({id, providerID}→provider/model), tools, bash commands, user attribution, theparent_idchild-session walk, and the session-level cost/token rollup fallback (same columns onsession_v2) all behave exactly as on legacy.docs/providers/opencode.mddocuments the two generations and the branch rule.Test plan
tests/providers/opencode.test.ts: v2-only discovery+parse (tokens/cost/model/tools/user message), non-user/assistanttypefiltering (compaction/idle/model-switched), child-session walk, upgraded DB with both generations (v2 wins, frozen legacy session invisible), and thesession_v2rollup fallback.Fixes #1293.