Skip to content

fix(app): guard session-header current() against undefined when options is empty#16478

Merged
adamdotdevin merged 1 commit intoanomalyco:devfrom
cyberprophet:fix/session-header-current-undefined
Mar 7, 2026
Merged

fix(app): guard session-header current() against undefined when options is empty#16478
adamdotdevin merged 1 commit intoanomalyco:devfrom
cyberprophet:fix/session-header-current-undefined

Conversation

@cyberprophet
Copy link
Contributor

@cyberprophet cyberprophet commented Mar 7, 2026

Issue for this PR

Closes #16459
Closes #16467

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

session-header.tsx has a current memo that can return undefined:

const current = createMemo(() => options().find((o) => o.id === prefs.app) ?? options()[0])

options() is temporarily empty during two scenarios:

  1. Startup — before platform.checkAppExists resolves for each installed app
  2. Project switching — race condition between cleanup and re-render

When options() is empty, options()[0] is undefined, so current() is undefined. The component then accesses current().id, current().label, and current().icon without a null check, throwing TypeError: Cannot read properties of undefined (reading 'id') and crashing the entire UI with the "Something went wrong" screen.

The fix adds a third fallback using fileManager() (which is always defined) so current() is never undefined:

const current = createMemo(
  () =>
    options().find((o) => o.id === prefs.app) ??
    options()[0] ??
    ({ id: "finder", label: fileManager().label, icon: fileManager().icon } as const),
)

This is the same pattern as PR #16475 / #16476 which fix the structurally identical crash in TextShimmer (issue #16473).

How did you verify your code works?

Screenshots / recordings

No visual change — this only prevents a crash, the UI behavior when options() is non-empty is identical.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…ns is empty

When options() is temporarily empty (during startup or project switching),
options()[0] returns undefined, causing current().id to throw a TypeError.

Add a fileManager()-based fallback so current() always returns a valid object.

Fixes anomalyco#16459
Fixes anomalyco#16467
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 7, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@cyberprophet
Copy link
Contributor Author

E2E Linux Failure Analysis

The e2e (linux) failure is not caused by this PR's changes.

Failed test: e2e/commands/panels.spec.ts:10 › review panel can be toggled via keybind
Flaky test: e2e/session/session-undo-redo.spec.ts:131 › slash undo/redo traverses multi-step revert stack

Both failures reproduce identically on the dev branch across the last 3 consecutive commits (runs 22799518867, 22799515032, 22799345432) — none of which touch session-header.tsx.

This PR only modifies a single line in packages/app/src/components/session/session-header.tsx (the current memo fallback), which has no interaction with the review panel keybind or undo/redo logic.

Re-running CI to confirm.

@cyberprophet cyberprophet force-pushed the fix/session-header-current-undefined branch from 216d497 to 99d5e6a Compare March 7, 2026 14:32
@cyberprophet
Copy link
Contributor Author

E2E Failure Confirmed Pre-existing (Not This PR)

Re-ran CI twice. Both runs fail with identical tests:

Test Status
e2e/commands/panels.spec.ts:10 › review panel can be toggled via keybind ❌ failed (3 retries)
e2e/session/session-undo-redo.spec.ts:131 › slash undo/redo traverses multi-step revert stack ⚠️ flaky

These same tests fail on dev branch across 5 of the last 8 runs (runs 22799518867, 22799515032, 22799345432, 22798448488) — all on commits that do not touch session-header.tsx.

This PR's diff is a single-line change to the current memo in session-header.tsx. It has no code path that could affect the review panel keybind or undo/redo message visibility logic.

@jon23d
Copy link

jon23d commented Mar 7, 2026

It may be worth comparing this to jon23d#1. I compiled it and ran the binary with:

bun install
./packages/opencode/script/build.ts --single
./packages/opencode/dist/opencode-linux-x64/bin/opencode web --host 0.0.0.0

I was able to start a session successfully after that.

@adamdotdevin adamdotdevin merged commit f0beb38 into anomalyco:dev Mar 7, 2026
17 of 23 checks passed
@cyberprophet cyberprophet deleted the fix/session-header-current-undefined branch March 7, 2026 16:03
manno23 pushed a commit to manno23/opencode that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants