Skip to content

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

Open
zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x:fix/non-null-assertion-find
Open

fix: replace non-null assertions on find() with proper null checks#11723
zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x:fix/non-null-assertion-find

Conversation

@zerone0x
Copy link
Contributor

@zerone0x zerone0x commented Feb 2, 2026

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

Replace unsafe `find()!` patterns that crash at runtime when the search
predicate doesn't match. Each location now handles the missing case
appropriately: fallback to first agent in TUI, descriptive errors in
provider/compaction, early return in summary, and 400 response in TUI
event route.

Fixes anomalyco#11702

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

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.

Non-null assertions on find() results can cause runtime crashes

1 participant