-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: add session tracking for GitHub Copilot premium request optimization #7011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ation - Add session tracking to VsCodeLmHandler to monitor conversation state - Track message count per session to identify first vs subsequent messages - Add comprehensive tests for session management functionality - This helps understand GitHub Copilot API usage patterns for optimization Fixes #7010
* Check if this is the first message in the current session | ||
* @returns true if this is the first message or no session exists | ||
*/ | ||
private isFirstMessage(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The private method 'isFirstMessage' is never used. Consider removing it to reduce dead code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed my own code. Found several issues. Would not recommend merging without fixes.
this.sessionMessageCount.set(this.currentSessionId, currentCount + 1) | ||
|
||
// Log session tracking for debugging | ||
const isFirst = currentCount === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical Issue: This implementation tracks sessions but doesn't actually use the information to optimize premium request consumption. The issue #7010 specifically mentions using X-Initiator headers with values of 'user' for first messages and 'agent' for subsequent ones. While the VS Code LM API may not expose HTTP headers directly, the session tracking alone doesn't solve the problem described in the issue.
Is there a way to leverage this session information to actually reduce premium request usage, or should we document this limitation more clearly?
* Check if this is the first message in the current session | ||
* @returns true if this is the first message or no session exists | ||
*/ | ||
private isFirstMessage(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isFirstMessage() method is defined but never used. Was this intended to help determine when to set different header values? Consider either using this method in the message creation logic or removing it if it's not needed.
@@ -44,13 +45,17 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan | |||
private client: vscode.LanguageModelChat | null | |||
private disposable: vscode.Disposable | null | |||
private currentRequestCancellation: vscode.CancellationTokenSource | null | |||
private sessionMessageCount: Map<string, number> = new Map() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory Leak Risk: The sessionMessageCount Map could grow indefinitely if sessions are started but never properly ended. Consider implementing: (1) A maximum session limit, (2) TTL-based cleanup for stale sessions, or (3) Periodic cleanup of old sessions.
@@ -300,4 +300,157 @@ describe("VsCodeLmHandler", () => { | |||
await expect(promise).rejects.toThrow("VSCode LM completion error: Completion failed") | |||
}) | |||
}) | |||
|
|||
describe("session tracking", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are comprehensive but don't cover: (1) Session timeout/cleanup scenarios, (2) Maximum session limit handling, or (3) Concurrent session edge cases. Consider adding tests for these scenarios to ensure robustness.
My company uses Copilot, so I’m really glad this issue is getting fixed since my premium requests are consumed quickly. |
Closing in favor of #7072 |
Summary
This PR adds session tracking to the VS Code Language Model handler to better understand and optimize GitHub Copilot premium request usage patterns.
Problem
As described in #7010, the GitHub LM API is designed to count only a single premium request per user session, but Roo-Code currently uses 1 premium request per message. Other tools optimize this by using the
X-Initiator
header with values ofuser
for the first message andagent
for subsequent messages.Solution
While the VS Code Language Model API doesn't directly expose HTTP headers like
X-Initiator
, this PR implements session tracking to:This provides the foundation for understanding how Roo-Code interacts with the GitHub Copilot API and can help identify optimization opportunities.
Changes
VsCodeLmHandler
classTesting
Notes
The VS Code Language Model API is a high-level abstraction that manages the GitHub Copilot communication internally. While we can't directly set HTTP headers, this session tracking provides valuable insights into usage patterns and lays the groundwork for future optimizations.
Fixes #7010
Important
Adds session tracking to
VsCodeLmHandler
for optimizing GitHub Copilot premium requests by counting messages per session and logging session states.VsCodeLmHandler
to optimize GitHub Copilot premium requests.startSession()
,endSession()
, andgetSessionMessageCount()
methods invscode-lm.ts
.createMessage()
to handle session tracking and logging.vscode-lm.spec.ts
.This description was created by
for b5115b8. You can customize this summary. It will automatically update as commits are pushed.