Skip to content

Claude handle undercounted credits for cancelled requests#322822

Draft
pwang347 wants to merge 12 commits into
mainfrom
pawang/fixClaudeCancel
Draft

Claude handle undercounted credits for cancelled requests#322822
pwang347 wants to merge 12 commits into
mainfrom
pawang/fixClaudeCancel

Conversation

@pwang347

@pwang347 pwang347 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Copilot AI review requested due to automatic review settings June 24, 2026 20:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves per-turn Copilot credit accounting for Claude-backed chat sessions by ensuring credits that become known after a turn is cancelled/disconnected are still attributed to the correct (now-terminal) turn, rather than being dropped and undercounted.

Changes:

  • Report copilot_usage.total_nano_aiu to the agent host even when a /v1/messages streaming request is abandoned mid-stream, if the proxy already observed usage before cancellation.
  • Allow ChatUsage actions to amend usage on terminal turns (not just the active turn), and merge usage so “credit-only” updates don’t erase previously reported usage data.
  • Add reducer tests covering cancellation + late usage attribution and idempotent “running total” updates.
Show a summary per file
File Description
src/vs/platform/agentHost/test/node/reducers.test.ts Adds tests for ChatUsage attribution to terminal turns and idempotent credit updates.
src/vs/platform/agentHost/node/claude/claudeProxyService.ts Reports already-observed credits on streaming cancellation paths to avoid undercounting.
src/vs/platform/agentHost/node/claude/claudeAgentSession.ts Tracks turn lifecycle and re-emits credit usage when credits arrive after a turn ends.
src/vs/platform/agentHost/common/state/protocol/channels-chat/reducer.ts Applies ChatUsage to active or terminal turns and merges usage rather than replacing it.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 4

Comment thread src/vs/platform/agentHost/node/claude/claudeAgentSession.ts Outdated
Comment thread src/vs/platform/agentHost/test/node/reducers.test.ts Outdated
Comment thread src/vs/platform/agentHost/test/node/reducers.test.ts Outdated
Comment thread src/vs/platform/agentHost/common/state/protocol/channels-chat/reducer.ts Outdated
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.

2 participants