fix: resolve critical token tracking bug caused by PowerShell $args collision#111
fix: resolve critical token tracking bug caused by PowerShell $args collision#111
Conversation
Summary by CodeRabbit
WalkthroughDocumentation clarifies that token savings require an explicit get_session_stats() call and renames session logs to session tracking files; PowerShell helper Invoke-MCP renamed its Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (4)
Comment |
Commit Message Format IssueYour commit messages don't follow the Conventional Commits specification. Required Format:Valid Types:
Examples:Breaking Changes:Add Please amend your commit messages to follow this format. Learn more: Conventional Commits |
1 similar comment
Commit Message Format IssueYour commit messages don't follow the Conventional Commits specification. Required Format:Valid Types:
Examples:Breaking Changes:Add Please amend your commit messages to follow this format. Learn more: Conventional Commits |
Performance Benchmark Results |
Renamed parameter from $Args to $ToolArguments in invoke-mcp.ps1 to avoid
collision with PowerShell's automatic $args variable.
The $Args collision caused all MCP tool arguments to serialize as empty {}
objects, resulting in 100% token tracking failure (49,578+ operations with
0 tokens tracked).
Investigation process:
- Created 3 expert AI agents for multi-angle analysis
- Used Gemini CLI (2M token context) for comprehensive codebase analysis
- Performed deep web research on PowerShell automatic variables
- All approaches independently converged on the same root cause
Changes:
- Line 73: Renamed $Args → $ToolArguments
- Lines 84-87: Removed unnecessary [PSCustomObject] casting
- PowerShell Hashtables serialize correctly to JSON objects natively
Evidence from MCP invocation logs:
Before: Arguments content: {...} but Request: {"arguments":{}} (EMPTY)
After: Arguments content: {...} and Request: {"arguments":{...}} (POPULATED)
This fixes the recurring issue partially addressed in:
- d38efe0 (removed casts but missed parameter name issue)
- 1a3da5e (PR #110 - attempted fix but root cause remained)
f415b8a to
72b4e42
Compare
Performance Benchmark Results |
Fixes ESLint @typescript-eslint/ban-ts-comment error at line 633 in src/server/index.ts. The @ts-expect-error directive is preferred over @ts-ignore because it will error if the suppressed issue is resolved, preventing dead suppression comments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Performance Benchmark Results |
Fixes Prettier formatting errors in 4 files to pass CI lint check: - src/core/token-counter.ts - src/server/index.ts - src/validation/tool-schemas.ts - src/validation/validator.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Performance Benchmark Results |
|
This PR is included in version 4.0.1. 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
This PR fixes the critical token tracking bug that caused 100% failure rate (49,578+ operations with 0 tokens tracked).
Root Cause
The PowerShell parameter named
$Argsininvoke-mcp.ps1conflicted with PowerShell's automatic$argsvariable, causing all MCP tool arguments to become empty{}objects.Investigation Process
The Fix
File:
hooks/helpers/invoke-mcp.ps1Line 73: Renamed parameter from
$Args→$ToolArguments$argsvariableLines 84-87: Removed unnecessary
[PSCustomObject]castingEvidence
Before Fix (from MCP invocation logs):
After Fix:
Documentation Improvements
File:
README.mdAdded comprehensive section explaining where users can find actual token savings:
current-session.txtonly shows operation counts, NOT savingsget_session_stats()tool for savings datatotalTokensSavedfieldImpact
get_session_stats()Testing
✅ Live testing in
C:\Users\cheat\.claude-global\hooks\helpers\invoke-mcp.ps1shows:Related Issues
This fixes the recurring token tracking issue that was partially addressed in commits:
The
$Argscollision was the underlying cause that previous fixes didn't identify.