Skip to content

fix(copilot): read VS Code chatSessions so Copilot Chat users see cost (#555)#563

Open
ozymandiashh wants to merge 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/copilot-chatsessions-cost
Open

fix(copilot): read VS Code chatSessions so Copilot Chat users see cost (#555)#563
ozymandiashh wants to merge 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/copilot-chatsessions-cost

Conversation

@ozymandiashh

Copy link
Copy Markdown
Contributor

Summary

Fixes #555. VS Code GitHub Copilot Chat users with no OTel agent-traces.db and no ~/.copilot/session-state/ saw $0.00 cost (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/*.jsonl
  • globalStorage/emptyWindowChatSessions/*.jsonl

The existing sources (legacy session-state, OTel SQLite, legacy GitHub.copilot-chat/transcripts) either don't exist for these users or carry no tokens, so cost collapsed to zero.

What changed

  • New fourth source in src/providers/copilot.ts. These files are a VS Code delta-journal, not flat records: a kind:0 snapshot followed by kind:1 path-set edits ({"k":[...],"v":...}) and kind:2 array appends ({"k":["requests"],"v":[...]}). The parser replays the journal to reconstruct requests[], then reads result.metadata.promptTokens / outputTokens (fallback completionTokens) and prices on result.metadata.resolvedModel.
  • Prototype-pollution-safe replay: __proto__ / prototype / constructor path segments are rejected and intermediate maps use Object.create(null) (clears the repo's no-bracket-assign-hot-paths semgrep rule).
  • No double counting: prefer OTel (skip chatSessions discovery when an OTel source is present) and skip a workspace's legacy transcripts when that same workspace has chatSessions.
  • New env overrides CODEBURN_COPILOT_GLOBAL_STORAGE_DIR (+ existing CODEBURN_COPILOT_WS_STORAGE_DIR) keep discovery testable.
  • Docs updated in docs/providers/copilot.md.

Testing

  • npx vitest run tests/providers/copilot.test.ts -> 43/43. New chatSessions block covers: the reporter's real request object (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.
  • End-to-end against the reporter's exact After updating to 0.9.14 it doesn't show any cost #555 data:
    call: project=myproject model=claude-sonnet-4-6 in=32543 out=60 cost=$0.098529
    TOTAL  calls=1  in=32543  out=60  cost=$0.098529   (was 0 / $0.00)
    
  • npx tsc --noEmit clean; semgrep hot-path rule -> 0 findings.
  • Full suite: the only failing test is the pre-existing overview.test.ts thousands-separator case, which fails on non-US locales independent of this change (reproduces on main).

Notes

  • This journal has no cache-token field, so cache read/write show as 0 for Copilot Chat unless the OTel store is enabled (documented).

)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After updating to 0.9.14 it doesn't show any cost

1 participant