[PR #11723] fix: replace non-null assertions on find() with proper null checks #13910

Open
opened 2026-02-16 18:18:44 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11723

State: open
Merged: No


What does this PR do?

Replaces 5 unsafe find()! non-null assertion patterns across the codebase with proper null checks. These patterns crash at runtime with "Cannot read property of undefined" when the search predicate doesn't match any element.

The most impactful fix is in local.tsx, which is the direct cause of the fatal TUI crash reported in #11262 ("Cannot read property 'name' of undefined").

Each location is handled with an appropriate strategy for its context:

  • local.tsx:57 — Falls back to first agent and updates store (prevents TUI fatal crash)
  • provider.ts:1051 — Throws descriptive error if provider module has no create* export
  • compaction.ts:99 — Throws descriptive error if parent message is missing
  • summary.ts:124 — Logs warning and returns early if message not found
  • tui.ts:348 — Returns 400 if event type not found (defensive, Zod should prevent this)

Fixes #11702

How did you verify your code works?

  • tsgo --noEmit — typecheck passes across all 12 packages
  • bun test — 835 tests pass (5 pre-existing failures in llm.test.ts/retry.test.ts unrelated to this change)
  • bun run build — builds successfully for all platforms
  • Verified each fix handles the null case with the appropriate strategy for its context
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11723 **State:** open **Merged:** No --- ### What does this PR do? Replaces 5 unsafe `find()!` non-null assertion patterns across the codebase with proper null checks. These patterns crash at runtime with "Cannot read property of undefined" when the search predicate doesn't match any element. The most impactful fix is in `local.tsx`, which is the direct cause of the fatal TUI crash reported in #11262 ("Cannot read property 'name' of undefined"). Each location is handled with an appropriate strategy for its context: - **`local.tsx:57`** — Falls back to first agent and updates store (prevents TUI fatal crash) - **`provider.ts:1051`** — Throws descriptive error if provider module has no `create*` export - **`compaction.ts:99`** — Throws descriptive error if parent message is missing - **`summary.ts:124`** — Logs warning and returns early if message not found - **`tui.ts:348`** — Returns 400 if event type not found (defensive, Zod should prevent this) Fixes #11702 ### How did you verify your code works? - `tsgo --noEmit` — typecheck passes across all 12 packages - `bun test` — 835 tests pass (5 pre-existing failures in llm.test.ts/retry.test.ts unrelated to this change) - `bun run build` — builds successfully for all platforms - Verified each fix handles the null case with the appropriate strategy for its context
yindo added the pull-request label 2026-02-16 18:18:44 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13910