You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add token limit handling to prevent 8k token overflow
Problem:
- GitHub Models API has an 8k token limit for entire requests
- Large git diffs can exceed this limit, causing API failures
- Users experience failures when staging large changes
Solution:
- Added token estimation using character-based heuristic (1 token ≈ 4 chars)
- Implemented truncation logic that preserves UTF-8 boundaries
- Added intelligent content prioritization when over limit
Implementation Details:
- estimateTokens(): Approximates tokens for any text content
- truncateToTokenLimit(): Safely truncates text with ellipsis indicator
- Modified GenerateCommitMessage() to:
* Estimate tokens for prompt templates + changes + examples
* Reserve tokens for templates (with buffer)
* Prioritize examples (20% of remaining tokens) when present
* Truncate changes to fit remaining budget
* Display warning when truncation occurs
Benefits:
- Prevents API failures from token overflow
- Maintains functionality by preserving maximum content
- User-friendly with clear truncation warnings
- No external dependencies, follows existing code style
- Gracefully handles both changes-only and changes+examples scenarios
0 commit comments