fix: prevent subagent telemetry from overwriting main agent footer context#2765
Merged
tanzhenxin merged 1 commit intomainfrom Apr 1, 2026
Merged
fix: prevent subagent telemetry from overwriting main agent footer context#2765tanzhenxin merged 1 commit intomainfrom
tanzhenxin merged 1 commit intomainfrom
Conversation
…ntext Root cause: PR #1835 accidentally overwrote PR #1912's correct telemetry isolation during a merge conflict resolution. This restores the original guard logic so subagent GeminiChat instances (which don't receive a telemetryService param) no longer write to the global uiTelemetryService. - Remove unused uiTelemetryService import from geminiChat.ts - Guard telemetry calls with this.telemetryService checks - Add test verifying subagent isolation Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Contributor
📋 Review SummaryThis PR correctly fixes a telemetry isolation bug where subagent token counts were leaking into the main agent's footer context display. The fix restores the original guard logic from PR #1912 that was accidentally overwritten during a merge conflict resolution in PR #1835. The implementation is clean, well-tested, and properly isolates subagent telemetry from the global singleton. 🔍 General Feedback
🎯 Specific Feedback🟢 Medium
🔵 Low
✅ Highlights
|
Contributor
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Fix subagent token counts leaking into the main agent's footer context usage display. When multiple subagents run concurrently, the footer would flicker between their different token counts instead of showing the main agent's actual context usage.
Root cause: a bad merge in PR #1835 (
feat/context-usage) overwrote PR #1912's correct telemetry isolation, replacingthis.telemetryServiceguard with a(this.telemetryService ?? uiTelemetryService)fallback that let subagents write to the global singleton. This PR restores the original guard logic and removes the now-unuseduiTelemetryServiceimport fromgeminiChat.ts.Screenshots / Video Demo
Dive Deeper
How the bug was introduced
PR feat(arena): Add agent collaboration arena with multi-model competitive execution #1912 (
feature/arena-agent-collaboration, merged 2026-03-18 11:36 UTC) correctly introducedtelemetryServiceas an optional param onGeminiChat, with the intent that subagent chats passundefinedto avoid polluting the main agent's display:PR feat: add /context command to display context window token usage breakdown #1835 (
feat/context-usage, merged 2026-03-18 13:58 UTC) merged main into its branch after feat(arena): Add agent collaboration arena with multi-model competitive execution #1912 landed. The merge conflict ingeminiChat.tswas resolved incorrectly — it kept the olduiTelemetryServicedirect call.A follow-up commit (
bb99755b21"fix: resolve TypeScript errors") noticedthis.telemetryServiceexisted but wasn't used, and "fixed" it by creating the hybrid(this.telemetryService ?? uiTelemetryService)— reintroducing the global fallback.The fix
Restore PR #1912's original logic: only call
setLastPromptTokenCount/setLastCachedContentTokenCountwhenthis.telemetryServiceis provided. The main agent'sGeminiChat(created inclient.ts) explicitly passesuiTelemetryService, so its footer continues to work. SubagentGeminiChatinstances (created inagent-core.tswith no telemetry param) simply don't update the global singleton.Reviewer Test Plan
Unit tests pass:
Verify main agent footer still works:
Verify the fix:
Testing Matrix
Linked issues / bugs
Related to PR #1912 and PR #1835 — this restores the telemetry isolation that #1912 introduced but #1835 accidentally overwrote during a bad merge conflict resolution.
🤖 Generated with Qwen Code