Skip to content

[Error] unhandlederror-Cannot read properties of undefined (reading 'currentModeKind') #310356

Closed

Description

@vs-code-engineering

Error Message

unhandlederror-Cannot read properties of undefined (reading 'currentModeKind')

Stack Trace

    at cC.renderWelcomeViewContentIfNeeded (./src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts:1005:0)
    at cC.lockToCodingAgent (./src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts:2159:0)
    at Bx.updateWidgetLockState (./src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts:788:0)
    at async Bx.showModel (./src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts:738:0)
    at async r (./src/vs/workbench/services/progress/browser/progressService.ts:54:0)

Raw Stack Trace (minified)
TypeError: Cannot read properties of undefined (reading 'currentModeKind')     at cC.renderWelcomeViewContentIfNeeded (out/vs/sessions/sessions.desktop.main.js:2372:45741)     at cC.lockToCodingAgent (out/vs/sessions/sessions.desktop.main.js:2372:69162)     at Bx.updateWidgetLockState (out/vs/sessions/sessions.desktop.main.js:3093:75968)     at async Bx.showModel (out/vs/sessions/sessions.desktop.main.js:3093:75248)     at async r (out/vs/sessions/sessions.desktop.main.js:1328:15530)

Details

Property Value
Bucket ID f916ce76-a205-e82c-e095-b596bcfefdb2
Version 1.115.0-insider
Commit 41dd792b
Last Seen Tue Apr 14 2026 16:38:45 GMT+0000 (Coordinated Universal Time)
Platforms Windows, Mac
Product Agents

This issue was automatically created from the VS Code Errors Dashboard

Activity

  1. added
    bug
    error-telemetry
    on Apr 16, 2026
  2. vs-code-engineering commented on Apr 16, 2026

    @vs-code-engineering
    ContributorAuthor

    🔍 Error Investigation

    Summary

    renderWelcomeViewContentIfNeeded() accesses this.input.currentModeKind (line 1006 of chatWidget.ts) without a null guard. The input getter returns this.inputPartDisposable.value! — a non-null assertion that fails at runtime when the ChatInputPart hasn't been created yet (widget not rendered) or has been disposed. This is triggered through the async showModel() → updateWidgetLockState() → lockToCodingAgent()/unlockFromCodingAgent() call chain, where the widget lifecycle can change during awaited session loading. 205 hits across 135 users spanning versions 1.113–1.117 indicate a persistent async lifecycle race.

    Culprit Commit

    No specific culprit commit was identified. The issue body has no commit range analysis, and the error telemetry shows hits across 5+ insider versions since v1.113 (2026-03-31), indicating a pre-existing race condition in the widget lifecycle rather than a single regression commit. The lockToCodingAgent / unlockFromCodingAgent methods have always called renderWelcomeViewContentIfNeeded() without guarding for an uninitialized input part.

    Code Flow

    sequenceDiagram
        participant VP as ChatViewPane
        participant SM as showModel()
        participant CS as ChatService
        participant CW as ChatWidget
        participant RW as renderWelcomeViewContentIfNeeded()
    
        VP->>SM: showModel(token, modelRef)
        SM->>CS: await acquireOrLoadSession()
        Note over CS: ⚠️ Async gap: widget<br/>may be disposed or<br/>not yet rendered
        CS-->>SM: session reference
        SM->>VP: updateWidgetLockState(sessionType)
        VP->>CW: lockToCodingAgent(name, displayName, agentId)
        CW->>RW: renderWelcomeViewContentIfNeeded()
        RW->>CW: this.input.currentModeKind
        Note over CW: 💥 this.input is undefined<br/>(inputPartDisposable.value is null)
    
    Loading

    Affected Files

    File Role
    src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts Crash site (line 1006) and root cause — renderWelcomeViewContentIfNeeded() accesses this.input without null guard; lockToCodingAgent() (line 2161) and unlockFromCodingAgent() (line 2181) call it unsafely
    src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts Trigger — showModel() (line 745) awaits async session loading then calls updateWidgetLockState() which invokes lock/unlock on the widget

    Repro Steps

    1. Open VS Code Insiders (Agents product) with a chat session type that resolves to a coding agent (e.g., a contributed session)
    2. Rapidly open/close the chat view pane, or trigger a session commit event while the pane is being disposed
    3. The async showModel() starts loading a session, the widget gets disposed during the await, and lockToCodingAgent runs on the stale widget
    4. The error is non-deterministic — it depends on the timing of widget disposal vs. async session resolution

    Fix Proposal

    Fix location: src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts → renderWelcomeViewContentIfNeeded()

    Approach: Add an early return guard at the top of renderWelcomeViewContentIfNeeded() to check whether the input part has been initialized:

    if (!this.inputPartDisposable.value) {
        return;
    }

    This is consistent with the existing defensive pattern already used elsewhere in the widget — for example, unlockFromCodingAgent() uses this.inputEditor?.updateOptions(...) (line 2187) with optional chaining. The same safety should apply to renderWelcomeViewContentIfNeeded().

    Additionally, lockToCodingAgent() and unlockFromCodingAgent() could check this._isDisposed before proceeding, since these methods may be called from an async context after the widget has been disposed.

    Recommended Owner

    @roblourens — already assigned; active maintainer of the chat widget and sessions infrastructure (most recent commits to both affected files)

    Generated by errors-investigate · ● 9.7M · ◷

  3. added this to the 1.117.0 milestone on Apr 16, 2026
  4. added
    unreleased
    insiders-released
    and removed
    unreleased
    on Apr 16, 2026
  5. added
    ai-generated
    ai-analyzed
    on Apr 28, 2026
  6. locked and limited conversation to collaborators on May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-analyzedai-generatedbugerror-telemetryinsiders-releasedrecent-regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions