fix: guard against undefined gitRepository in _resolveGitState (fixes #316628)#316629
Open
vs-code-engineering[bot] wants to merge 1 commit into
Open
Conversation
…316628) The _resolveGitState method in LocalNewSession spreads this.sessionWorkspace.folders[0].gitRepository with a non-null assertion. When the initial workspace folder has no gitRepository (it is optional on ISessionFolder), the spread of undefined produces an object without gitHubInfo, violating the ISessionGitRepository type contract. Downstream, _startPolling in github.contribution.ts accesses .gitHubInfo.get() on this malformed object, triggering the TypeError. The fix conditionally creates the updated gitRepository only when the original exists, preserving undefined otherwise so consumers correctly short-circuit. 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.
🔧 Error Fix
Summary
Error:
TypeError: Cannot read properties of undefined (reading 'get')Location:
src/vs/sessions/contrib/github/browser/github.contribution.ts:114(_startPolling)Impact: 43 affected users on 1.121.0-insider across Mac, Windows, Linux
The
LocalNewSession._resolveGitState()method spreadsthis.sessionWorkspace.folders[0].gitRepository!with a non-null assertion. When the initial workspace folder has nogitRepository(it is optional onISessionFoldersince the refactor in 1e8d5ef), the spread ofundefinedproduces an object withoutgitHubInfo, violating theISessionGitRepositorytype contract. Downstream,_startPollingingithub.contribution.tsaccesses.gitHubInfo.get()on this malformed object, triggering the TypeError.Fixes #316628
Recommended reviewer:
@sandy081Culprit Commit
1e8d5efdby@sandy081— "sessions: refactor ISession workspace model — ISessionFolder, ISessionGitRepository"This refactoring made
gitRepositoryoptional onISessionFolderbut did not update the non-null assertion inLocalNewSession._resolveGitState(), leaving a path where undefined is spread into a partialISessionGitRepositoryobject.Code Flow
flowchart TD A["copilotChatSessionsProvider: _refreshSessionCacheMultiChat"] -->|fires onDidChangeSessions| B["sessionsManagementService: onDidChangeSessionsFromSessionsProviders"] B -->|fires event| C["github.contribution: _onDidChangeSessions"] C -->|iterates added sessions| D["github.contribution: _startPolling"] D -->|accesses session.workspace.get?.folders gitRepository?.gitHubInfo.get| E["CRASH: gitHubInfo is undefined"] F["LocalNewSession._resolveGitState"] -->|spreads undefined gitRepository!| G["Produces malformed ISessionGitRepository without gitHubInfo"] G -->|stored in _workspaceData observable| DAffected Files
src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsProvider.tsLocalNewSession._resolveGitState()spreads undefined gitRepositorysrc/vs/sessions/contrib/github/browser/github.contribution.ts_startPollingaccesses.gitHubInfo.get()src/vs/sessions/services/sessions/common/session.tsISessionGitRepository.gitHubInfois non-optionalRepro Steps
LocalNewSessionwith a workspace whosefolders[0].gitRepositoryis undefined_resolveGitStatesuccessfully opens a git repository and the autorun fires...this.sessionWorkspace.folders[0].gitRepository!produces{branchName, upstreamBranchName, uncommittedChanges}(missinggitHubInfo,uri, etc.)_refreshSessionCacheMultiChatfiresonDidChangeSessionswith this session_startPollingaccesses.gitRepository?.gitHubInfo.get()—gitRepositoryis truthy (non-empty object) so optional chain doesn't short-circuit, butgitHubInfois undefined → crashHow the Fix Works
Chosen approach (
copilotChatSessionsProvider.ts:858): Replace the non-null assertion spread with a conditional — only create the updatedgitRepositorywhen the original exists, preservingundefinedotherwise. This fixes at the data producer (where the malformed object is created), not the crash site. After this change, line 858 cannot produce anISessionGitRepositorywithoutgitHubInfobecause whenthis.sessionWorkspace.folders[0].gitRepositoryis undefined,gitRepositoryis set toundefined(not a partial object), and consumers correctly short-circuit via?.gitRepository?..Recommended Owner
@sandy081— authored the culprit refactoring commit that madegitRepositoryoptional without updating the spread site.errors-fix-driver — cycle 4
Trigger: cron_merge_conflict · Head (pre-push):
b865d521ffe189d734be0f09577ee81afed2ce7c(b865d52)copilotChatSessionsProvider.ts(statedirty)main's version. TheLocalNewSessionclass this PR patches was refactored out ofcopilotChatSessionsProvider.tsintolocalChatSessionsProvider.ts, somainno longer carries the conflicting code. Resolved tree is byte-identical tomain— verified locally with an emptygit diff origin/main HEAD.main. The relocated_resolveGitStateinlocalChatSessionsProvider.tsfalls back to{ ..., gitHubInfo: constObservable(undefined) }when a folder has nogitRepository, so no code path can emit anISessionGitRepositorywithoutgitHubInfo; the crash site ingithub.contribution.tsis unreachable with a malformed object.Community PR Approvalsisin_progress(a gating check, not a failure). No real or transient failures.Push: declared this cycle — a merge-resolution commit bringing the branch tree in line with
main(3106-file catch-up + conflict resolution) to clear the persistentdirtystate. The push handler bundled the change and returned success but no SHA to cite; confirm on the branch. Copilot rerequested: n/a — zero net diff vsmain, nothing new to review.Ready gate: not ready — superseded. #316628 is already fixed on
mainand the patchedLocalNewSessionclass was refactored away, so this PR contributes no net change (empty diff vsmain). The driver cannot close PRs and will not mark a zero-value PR ready. Recommend@sandy081close this PR as superseded / obsolete.