Skip to content

Conversation

@chriswritescode-dev
Copy link

@chriswritescode-dev chriswritescode-dev commented Jan 11, 2026

Summary

Fixes a race condition where onMount() was called before the prompt ref was initialized, causing a "undefined is not an object (evaluating 'prompt.set')" error when starting a new session from inside an existing session.

Root Cause

In packages/opencode/src/cli/cmd/tui/routes/home.tsx:79-90, the onMount() hook attempted to call prompt.set() before the ref had been assigned by the <Prompt ref={(r) => { prompt = r }} /> component. This resulted in prompt being undefined during execution.

Fix

  • Changed from onMount() to createEffect() which re-evaluates when reactive dependencies change
  • Added a guard if (once || !prompt) return to check if the prompt ref exists

Fixes #7870

@github-actions
Copy link
Contributor

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

Perfect! I found a highly relevant duplicate:

Potential Duplicate Found

PR #7764 - fix: prevent prompt crash when opening new session with existing prompt
#7764

This PR appears to address the same issue: preventing a crash related to the prompt when opening/starting a new session from within an existing session. It's almost certainly covering the same race condition bug that PR #7872 is fixing.

Fixes a race condition where onMount() was called before the prompt
ref was initialized, causing "undefined is not an object (evaluating
'prompt.set')" error when starting a new session from inside an
existing session.

Changed from onMount() to createEffect() with a prompt existence
check, matching the pattern used in session/index.tsx.

Fixes anomalyco#7870
@chriswritescode-dev chriswritescode-dev force-pushed the fix/7870-prompt-race-condition branch from 0f10baa to ccde828 Compare January 11, 2026 22:57
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.

opentui: fatal: undefined is not an object (evaluating 'prompt.set')

1 participant