Fix null safety in response array loops and OpenCode method reference#532
Merged
Fix null safety in response array loops and OpenCode method reference#532
Conversation
- Fix TypeError: getOpenCodeSessionData was called on tokenTracker directly instead of tokenTracker.openCode where the method actually lives; this caused 'tokenTracker.getOpenCodeSessionData is not a function' warnings during backend sync for every OpenCode session file. - Fix TypeError: Cannot read properties of undefined (reading 'value') in getModelUsageFromSession: response arrays reconstructed from VS Code delta-based JSONL can contain null/undefined entries; use optional chaining (responseItem?.value) instead of bare property access. - Fix TypeError: Cannot read properties of undefined (reading 'kind') in analyzeSessionUsage and trackEnhancedMetrics: add an explicit 'if (!responseItem) continue' guard at the top of every loop that iterates over request.response or event.v arrays, covering both the delta-path and JSON-path code branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
Three distinct
WARNINGlog entries appeared during backend sync:TypeError: tokenTracker.getOpenCodeSessionData is not a function— fired for every OpenCode session file during sync.TypeError: Cannot read properties of undefined (reading 'value')— fromgetModelUsageFromSessionwhen processing VS Code Insiders JSONL delta-format files.TypeError: Cannot read properties of undefined (reading 'kind')— fromanalyzeSessionUsage/trackEnhancedMetricsfor the same files.Root Causes
1. Wrong receiver for
getOpenCodeSessionData(extension.ts)The backend facade wired
getOpenCodeSessionDataby calling it ontokenTrackerdirectly, but the method lives ontokenTracker.openCode(theOpenCodeDataAccessinstance):2. Null entries in reconstructed
responsearrays (usageAnalysis.ts)VS Code Copilot Chat now stores some sessions as JSONL delta streams (
{"kind":0/1/2,...}). When theapplyDeltareconstruction rebuildsrequests[].response, the resulting array can containnull/undefinedentries. Multiple loops iterated over these arrays and accessed.kindor.valuewithout guarding for nulls.Fixes
extension.tsgetOpenCodeSessionDatathroughtokenTracker.openCodeusageAnalysis.tsif (!responseItem) continueguard in 5response-array loops (analyzeSessionUsagedelta-path x2, JSON-path x1,trackEnhancedMetricsx2)usageAnalysis.tsresponseItem?.value(optional chain) instead ofresponseItem.valueingetModelUsageFromSession(x2)Notes on other logged messages
log()messages (not warnings), correctly noting a session file spans midnight. No change needed.type=undefined— debug log for the first 3 lines of today's JSONL files; VS Code delta-format events usekindnottype, soevent.typeisundefined. The sync service already skips those lines harmlessly. No change needed.