Skip to content

Conversation

@avrum
Copy link
Collaborator

@avrum avrum commented Feb 11, 2026

Problem

When navigating between agents in Cooper's UI, the app goes completely black (no crash, just blank screen). The main.log shows hundreds of ReferenceError: parseAgentFrontmatter is not defined errors.

Additionally, clicking MCP servers crashes with TypeError: Cannot read properties of undefined (reading '0') when server.tools is undefined.

Root Cause

Black Screen (Agent Navigation)

parseAgentFrontmatter is used at 5 locations in src/main/main.ts (lines 879, 1577, 1875, 2731, 2842) but was never imported — only getAllAgents was imported from ./agents. There was also a duplicate getAllAgents import.

The bundler (electron-vite/esbuild) renames the agents.ts export to parseAgentFrontmatter$1 in the bundle, but the unimported direct references in main.ts remain as parseAgentFrontmatter (undefined at runtime). This causes a ReferenceError flood every time sessions are resumed or agents are loaded.

Combined with no React ErrorBoundary in the renderer, cascading failures result in a total black screen.

MCP Panel Crash

server.tools[0] is accessed without checking if server.tools is defined. The MCPServerConfigBase type declares tools: string[] but runtime data can have tools: undefined, causing a TypeError when opening the MCP panel.

Changes

  1. src/main/main.ts: Added parseAgentFrontmatter to the import from ./agents and removed the duplicate getAllAgents import
  2. src/renderer/components/ErrorBoundary.tsx: New ErrorBoundary component to catch uncaught render errors and show a recovery UI instead of a black screen
  3. src/renderer/main.tsx: Wrapped the app with ErrorBoundary
  4. src/renderer/App.tsx: Added optional chaining for server.tools access at two locations to prevent TypeError when MCP server config has undefined tools

ErrorBoundary Recovery UI

Instead of a black screen, users now see this recovery screen when an uncaught render error occurs:

┌──────────────────────────────────────────────────────────────────┐
│                                                                  │
│                                                                  │
│                     Something went wrong                         │
│                                                                  │
│       An unexpected error occurred. You can try dismissing       │
│                   this or reloading the app.                     │
│                                                                  │
│      ┌──────────────────────────────────────────────────┐        │
│      │ ReferenceError: parseAgentFrontmatter is not     │        │
│      │ defined                                          │        │
│      │   at resumeSession (main/index.js:22290:31)      │        │
│      │   at async startEarlySessionResumption           │        │
│      │   (main/index.js:21684:5)                        │        │
│      └──────────────────────────────────────────────────┘        │
│                                                                  │
│                  [ Dismiss ]    [ Reload ]                        │
│                                                                  │
└──────────────────────────────────────────────────────────────────┘

The component:

  • Shows the error message in a scrollable box (max 8rem)
  • Dismiss — attempts to recover by clearing the error state
  • Reload — reloads the entire app via window.location.reload()
  • Logs full error + component stack to console for debugging

Verification

  • Build passes ✅
  • All 395 unit tests pass ✅
  • TypeScript no longer reports TS2304: Cannot find name 'parseAgentFrontmatter' errors
  • Bundle now correctly resolves all parseAgentFrontmatter references to the same function
  • MCP panel handles servers with undefined tools gracefully ✅

- Add parseAgentFrontmatter to the import from ./agents in main.ts
  (was used at 5 locations but never imported, causing ReferenceError
  at runtime that flooded logs and led to black screen)
- Remove duplicate getAllAgents import on line 168
- Add React ErrorBoundary component wrapping the app to prevent
  future uncaught render errors from causing blank screens
server.tools can be undefined at runtime even though the type
declares string[]. Add optional chaining and fallback defaults
at both locations (lines 3360 and 4570) to prevent TypeError
when clicking MCP servers panel.
@idofrizler idofrizler merged commit e210f75 into staging Feb 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants