Skip to content

fix: guard _resolveGitState against undefined gitRepository (fixes #316425)#316430

Closed
vs-code-engineering[bot] wants to merge 2 commits into
mainfrom
fix/github-service-undefined-read-316425-6a92f1aea153cc04
Closed

fix: guard _resolveGitState against undefined gitRepository (fixes #316425)#316430
vs-code-engineering[bot] wants to merge 2 commits into
mainfrom
fix/github-service-undefined-read-316425-6a92f1aea153cc04

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

@vs-code-engineering vs-code-engineering Bot commented May 14, 2026

🔧 Error Fix

Summary

Error: TypeError: Cannot read properties of undefined (reading 'read') in githubService.ts:108 inside a derived observable computation.

The crash occurs when LocalNewSession._resolveGitState() spreads this.sessionWorkspace.folders[0].gitRepository! while gitRepository is undefined. The spread of undefined produces an object missing gitHubInfo, so when the observable chain propagates to the derived in githubService.ts:108, gitHubInfo.read(reader) throws because gitHubInfo is undefined.

This is a new regression in 1.121.0-insider, introduced when gitRepository was made optional on ISessionWorkspaceFolder (commit 1e8d5efd — "sessions: refactor ISession workspace model").

Fixes #316425
Recommended reviewer: @sandy081

Culprit Commit

1e8d5efd by @sandy081

Code Flow

graph TD
    A["$onDidChangeRepository / updateState"] --> B["observable.set() propagation"]
    B --> C["LocalNewSession._resolveGitState autorun"]
    C --> D["...folders[0].gitRepository! — gitRepository is undefined"]
    D --> E["Spread produces object WITHOUT gitHubInfo"]
    E --> F["_workspaceData.set() triggers derived chain"]
    F --> G["githubService.ts:108 — gitHubInfo.read(reader) → TypeError"]
Loading

Affected Files

File Role
copilotChatSessionsProvider.ts Producer_resolveGitState() spreads undefined gitRepository
githubService.ts Crash site — derived reads gitHubInfo.read(reader) on malformed object

How the Fix Works

Added an early guard in _resolveGitState() to return immediately when folder.gitRepository is undefined. This fixes the bug at the data producer, not the crash site. The ! non-null assertion is removed since the guard ensures gitRepository is always defined when the spread executes.

Recommended Owner

@sandy081

errors-fix-driver — cycle 6

Trigger: cron_merge_conflict · Head: 4a1a5cddde8ab354001e4aff2053c47e7476a34a (4a1a5cd)

Item Action
Merge conflict in copilotChatSessionsProvider.ts Resolved — accepted main (class removed upstream)

Push: yes — 4a1a5cd · Copilot rerequested: not applicable (PR has zero diff)

Ready gate: not marking ready — PR now has zero diff against main (LocalNewSession was removed upstream, making this fix moot). Recommend closing this PR as the underlying issue no longer applies.

Generated by errors-fix-driver · ● 32.3M ·

…16425)

When sessionWorkspace.folders[0].gitRepository is undefined, the
produce an object without gitHubInfo, which then triggered a
TypeError in the derived observable in githubService.ts.

Guard early by returning if gitRepository is absent, and remove
the non-null assertion since the guard makes it unnecessary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 14, 2026 15:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot requested review from Copilot and sandy081 May 14, 2026 15:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot marked this pull request as ready for review May 14, 2026 15:37
@vs-code-engineering vs-code-engineering Bot enabled auto-merge (squash) May 14, 2026 15:37
The guard at line 846 narrows folder.gitRepository to non-undefined,
but TypeScript does not carry that narrowing into the autorun closure.
Extract gitRepository into a const after the guard so the spread in the
closure sees the definite type.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bryanchen-d
Copy link
Copy Markdown
Contributor

Closing as superseded. The same null-safety fix for LocalNewSession._resolveGitState already landed via #317645, and the host class was subsequently moved out of copilotChatSessionsProvider.ts by #317979, so this branch can no longer be mechanically rebased onto current main. The underlying issue #316425 is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression] Cannot read properties of undefined (reading 'read') — githubService

3 participants