Skip to content

fix: detect tool calls as agent-initiated in Copilot plugin#22062

Closed
yepashkov wants to merge 2 commits intoanomalyco:devfrom
yepashkov:fix/copilot-premium-request-detection
Closed

fix: detect tool calls as agent-initiated in Copilot plugin#22062
yepashkov wants to merge 2 commits intoanomalyco:devfrom
yepashkov:fix/copilot-premium-request-detection

Conversation

@yepashkov
Copy link
Copy Markdown

@yepashkov yepashkov commented Apr 11, 2026

Issue for this PR

Closes #8030

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Copilot was charging premium requests for tool calls because isAgent only checked the last message role. Tool results often have role: "user", so they got flagged as user-initiated.

Fixed by checking the full message context for tool_result parts or role: "tool". If any exist, the request is marked as agent-initiated.

Changed 3 API paths in packages/opencode/src/plugin/github-copilot/copilot.ts: Completions, Responses, and Messages.

How did you verify your code works?

Ran bun turbo typecheck — all 13 packages passed. The logic follows the existing compaction detection pattern already in the same file's chat.headers hook.

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

…overcharge

The current isAgent detection only checks the last message role, which fails
when tool results are returned. Tool call responses often have role: 'user'
or contain tool_result parts, causing GitHub to incorrectly charge premium
requests for agent-initiated actions.

This fix checks the entire message context for tool calls (tool_result parts
or role: 'tool') and marks the request as agent-initiated when tools are
present, preventing incorrect premium request charges.

Fixes anomalyco#8030

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@yepashkov yepashkov force-pushed the fix/copilot-premium-request-detection branch from b617ad5 to 6b3687e Compare April 11, 2026 17:10
@rekram1-node
Copy link
Copy Markdown
Collaborator

This checks if the message history contains any tool calls at all and if so makes it agent initiated, that means as soon as the agent calls a single tool, any subsequent prompts u send are "free"

This will ofc get u BANNED this is not good.

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.

Copilot auth now sets far too many requests as "user" consuming premium requests rapidly

2 participants