Skip to content

[Error] unhandlederror-PerfSampleError: by <<renderer>> in (anonymous)#workbench.desktop.main.js:414:16444 #314404

Description

@vs-code-engineering

Error Message

unhandlederror-PerfSampleError: by <<renderer>> in (anonymous)#workbench.desktop.main.js:414:16444

Stack Trace

    at (anonymous) (./src/vs/base/common/objects.ts:172:28)
    at safeStringify (./src/vs/base/common/objects.ts:170:16)
    at saveCachedSessions (./src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.ts:888:0)
    at (anonymous) (./src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.ts:534:0)
    at _deliver (./src/vs/base/common/event.ts:1352:9)
    at _deliverQueue (./src/vs/base/common/event.ts:1371:9)
    at fire (./src/vs/base/common/event.ts:1384:1)
    at flush (./src/vs/platform/storage/common/storage.ts:614:7)
    at focus (./src/vs/workbench/browser/workbench.ts:259:46)

Raw Stack Trace (minified)
 	 at (anonymous) (out/vs/workbench/workbench.desktop.main.js:414:16444) 	 at WO (out/vs/workbench/workbench.desktop.main.js:414:16402) 	 at saveCachedSessions (out/vs/workbench/workbench.desktop.main.js:1075:2676) 	 at (anonymous) (out/vs/workbench/workbench.desktop.main.js:1074:2208) 	 at _deliver (out/vs/workbench/workbench.desktop.main.js:405:3178) 	 at _deliverQueue (out/vs/workbench/workbench.desktop.main.js:405:3306) 	 at fire (out/vs/workbench/workbench.desktop.main.js:405:3399) 	 at flush (out/vs/workbench/workbench.desktop.main.js:852:105978) 	 at (anonymous) (out/vs/workbench/workbench.desktop.main.js:4909:114720) 	 at _deliver (out/vs/workbench/workbench.desktop.main.js:405:3178) 	 at _deliverQueue (out/vs/workbench/workbench.desktop.main.js:405:3306) 	 at fire (out/vs/workbench/workbench.desktop.main.js:405:3399) 	 at (anonymous) (out/vs/workbench/workbench.desktop.main.js:403:11761) 	 at (anonymous) (out/vs/workbench/workbench.desktop.main.js:403:11919) 	 at _deliver (out/vs/workbench/workbench.desktop.main.js:405:3178) 	 at fire (out/vs/workbench/workbench.desktop.main.js:405:3399) 	 at (anonymous) (out/vs/workbench/workbench.desktop.main.js:403:11562) 	 at _deliver (out/vs/workbench/workbench.desktop.main.js:405:3178) 	 at fire (out/vs/workbench/workbench.desktop.main.js:405:3399) 	 at (anonymous) (out/vs/workbench/workbench.desktop.main.js:403:11761) 	 at _deliver (out/vs/workbench/workbench.desktop.main.js:405:3178) 	 at fire (out/vs/workbench/workbench.desktop.main.js:405:3399) 	 at c (out/vs/workbench/workbench.desktop.main.js:1034:881) 	 at onResponse (out/vs/workbench/workbench.desktop.main.js:1034:1713) 	 at onBuffer (out/vs/workbench/workbench.desktop.main.js:1034:1409) 	 at (anonymous) (out/vs/workbench/workbench.desktop.main.js:1033:1628) 	 at _deliver (out/vs/workbench/workbench.desktop.main.js:405:3178) 	 at _deliverQueue (out/vs/workbench/workbench.desktop.main.js:405:3306) 	 at fire (out/vs/workbench/workbench.desktop.main.js:405:3399) 	 at ke (out/vs/workbench/workbench.desktop.main.js:403:15279) 	 at (anonymous) 	 at emit (node:<REDACTED: user-file-path>:2:45640) 	 at onMessage (node:<REDACTED: user-file-path>:2:121218)

Details

Property Value
Bucket ID 82c96c3f-83a9-9a0d-5954-404a4184ad55
Version 1.118.1
Commit 034f571d
Last Seen Mon May 04 2026 23:40:25 GMT+0000 (Coordinated Universal Time)
Platforms Windows, Mac, Linux
Product VSCode

This issue was automatically created from the VS Code Errors Dashboard

Activity

  1. added
    bug
    error-telemetry
    ai-generated
    on May 5, 2026
  2. vs-code-engineering commented on May 5, 2026

    @vs-code-engineering
    ContributorAuthor

    Stable Release Anomaly Details

    Property Value
    Anomaly type spike
    Spike factor 52.5x increase
    Previous stable 1.117.0
    Current stable 1.118.1

    Related Buckets (coalesced)

    Bucket Users Spike
    82c96c3f (representative) 105 52.5x
    a55719d8 166 20.75x
    cde3b512 142 4.58x
    a78b9c92 64 64x

    Analysis

    This is a performance regression in agentSessionsModel.ts — safeStringify (objects.ts) is called during saveCachedSessions which serializes agent session state. This fires on storage flush (triggered by window focus), blocking the renderer.

    Key call path: safeStringify (objects.ts) → saveCachedSessions (agentSessionsModel.ts:888) → event.fire → flush (storage.ts:614) → focus (workbench.ts:259)

    Combined, 477 users are affected across all related buckets. The session serialization becomes expensive as agent session data grows.

    Generated by errors-stable-scan · ● 7.4M · ◷

  3. vs-code-engineering commented on May 5, 2026

    @vs-code-engineering
    ContributorAuthor

    🔍 Error Investigation

    Summary

    The PerfSampleError is a performance profiling error thrown when saveCachedSessions() calls safeStringify() (which wraps JSON.stringify) to serialize agent session data during a storage flush triggered by window focus. The profiling system detects that the serialization takes too long on the main thread and fires the error as telemetry. The massive spike in 1.118.1 (1519 hits / 105 users vs 73 / 13 in 1.118.0) correlates with increased agent session usage and larger data payloads being serialized synchronously.

    Culprit Commit

    This is a pre-existing performance issue, not a regression introduced by a single commit. The bucket shows hits as far back as v1.111.0 (March 2026), with a significant spike in v1.118.1. The spike is due to increased adoption of agent sessions resulting in larger data being serialized synchronously on the main thread during onWillSaveState, not a specific code change that broke logic.

    Code Flow

    sequenceDiagram
        participant Focus as "Window Focus"
        participant Storage as "StorageService.flush"
        participant Model as "AgentSessionsModel"
        participant Cache as "AgentSessionsCache"
        participant Stringify as "safeStringify"
    
        Focus->>Storage: focus event triggers flush
        Storage->>Model: onWillSaveState fires
        Model->>Cache: saveCachedSessions(sessions)
        Cache->>Stringify: safeStringify(serialized)
        Note over Stringify: JSON.stringify blocks main thread<br/>Profiler detects long execution<br/>PerfSampleError fired
    
    Loading

    Affected Files

    File Role
    src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.ts Root cause — synchronous serialization of large session data
    src/vs/base/common/objects.ts Crash site — safeStringify / JSON.stringify
    src/vs/platform/storage/common/storage.ts Trigger — flush() fires onWillSaveState
    src/vs/workbench/browser/workbench.ts Trigger — window focus initiates flush

    Repro Steps

    1. Open VS Code with a workspace that has multiple agent sessions (coding agent sessions with file changes)
    2. Run several agent sessions to accumulate data in the sessions model
    3. Switch away from VS Code and switch back (triggering window focus)
    4. The storage flush serializes all session data synchronously; with enough sessions/metadata, the profiler fires PerfSampleError

    Fix Proposal

    Fix location: src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.ts → saveCachedSessions()
    Approach: Reduce the amount of data serialized synchronously on the main thread. Options include:

    1. Limit the size of metadata and changes fields before serialization (e.g., only store summary counts for changes, truncate metadata)
    2. Use incremental/chunked serialization that doesn't block the main thread
    3. Cap the number of sessions cached (e.g., only cache the N most recent sessions)
    4. Move serialization off the main thread using a worker

    Recommended Owner

    @bpasero — primary contributor to agentSessionsModel.ts (multiple recent commits including session caching, metadata, and architecture)

    Generated by errors-investigate · ● 9.4M · ◷

  4. added
    ai-analyzed
    on May 5, 2026
  5. added a commit that references this issue on May 6, 2026
    c84372f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-analyzedai-generatedbugerror-telemetryrecent-regressionstable-anomaly

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions