fix(copilot): read VS Code chatSessions so Copilot Chat users see cost (#555)#563
Open
ozymandiashh wants to merge 1 commit into
Open
fix(copilot): read VS Code chatSessions so Copilot Chat users see cost (#555)#563ozymandiashh wants to merge 1 commit into
ozymandiashh wants to merge 1 commit into
Conversation
) VS Code GitHub Copilot Chat users with no OTel agent-traces.db and no ~/.copilot/session-state/ saw $0.00 cost: codeburn never read VS Code's core chat persistence, the only on-disk source carrying their token counts. Add a fourth Copilot source that reads the VS Code chat delta-journals at workspaceStorage/<hash>/chatSessions/*.jsonl and globalStorage/emptyWindowChatSessions/*.jsonl. The files are a kind:0 snapshot / kind:1 path-set / kind:2 array-append journal; we replay it (prototype-pollution-safe: __proto__/prototype/constructor segments are rejected and containers use Object.create(null)) and read each request's result.metadata.promptTokens / outputTokens (falling back to completionTokens) and resolvedModel for pricing. Dedup so users with multiple sources are not double-counted: prefer OTel (skip chatSessions discovery when an OTel source is present), and skip a workspace's legacy GitHub.copilot-chat/transcripts when that workspace has chatSessions. New env overrides CODEBURN_COPILOT_GLOBAL_STORAGE_DIR and the existing CODEBURN_COPILOT_WS_STORAGE_DIR keep discovery testable. Tests cover the reporter's real request shape (promptTokens 32543 / outputTokens 60 -> non-zero cost), empty sessions, emptyWindow discovery, append-then-edit replay, requestId dedup, prototype-pollution paths, the transcript skip, and the OTel-prefer skip.
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
Fixes #555. VS Code GitHub Copilot Chat users with no OTel
agent-traces.dband no~/.copilot/session-state/saw$0.00cost (calls counted, tokens all zero). Root cause: the provider never read VS Code's core chat persistence, which is the only on-disk source carrying their token counts:workspaceStorage/<hash>/chatSessions/*.jsonlglobalStorage/emptyWindowChatSessions/*.jsonlThe existing sources (legacy
session-state, OTel SQLite, legacyGitHub.copilot-chat/transcripts) either don't exist for these users or carry no tokens, so cost collapsed to zero.What changed
src/providers/copilot.ts. These files are a VS Code delta-journal, not flat records: akind:0snapshot followed bykind:1path-set edits ({"k":[...],"v":...}) andkind:2array appends ({"k":["requests"],"v":[...]}). The parser replays the journal to reconstructrequests[], then readsresult.metadata.promptTokens/outputTokens(fallbackcompletionTokens) and prices onresult.metadata.resolvedModel.__proto__/prototype/constructorpath segments are rejected and intermediate maps useObject.create(null)(clears the repo'sno-bracket-assign-hot-pathssemgrep rule).chatSessionsdiscovery when an OTel source is present) and skip a workspace's legacy transcripts when that same workspace haschatSessions.CODEBURN_COPILOT_GLOBAL_STORAGE_DIR(+ existingCODEBURN_COPILOT_WS_STORAGE_DIR) keep discovery testable.docs/providers/copilot.md.Testing
npx vitest run tests/providers/copilot.test.ts-> 43/43. NewchatSessionsblock covers: the reporter's real request object (promptTokens 32543/outputTokens 60-> non-zero cost), empty sessions,emptyWindowdiscovery, append-then-edit replay,requestIddedup, prototype-pollution paths, the transcript-skip, and the OTel-prefer skip.npx tsc --noEmitclean; semgrep hot-path rule -> 0 findings.overview.test.tsthousands-separator case, which fails on non-US locales independent of this change (reproduces onmain).Notes