Skip to content

fix: race condition causing prompt.set undefined error#7871

Closed
chriswritescode-dev wants to merge 2 commits into
anomalyco:devfrom
chriswritescode-dev:fix/7870-prompt-race-condition
Closed

fix: race condition causing prompt.set undefined error#7871
chriswritescode-dev wants to merge 2 commits into
anomalyco:devfrom
chriswritescode-dev:fix/7870-prompt-race-condition

Conversation

@chriswritescode-dev

Copy link
Copy Markdown

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
  • Moved randomizeTip() outside the effect (previously called in onMount)
  • Matches the safer pattern already used in session/index.tsx:191-196

Fixes #7870

Add new provider using @anthropic-ai/claude-agent SDK for agent execution
with built-in tool support and MCP server integration.

- New claude-agent provider with models (sonnet-4, opus-4, haiku-3.5)
- Adapter for SDK message format to opencode MessageV2
- Permission and question bridges to integrate with opencode systems
- Tool MCP bridge to expose opencode tools to SDK
- Session handler for SDK query processing
- Config schema for provider-specific options (permissionMode, mcpServers, etc.)
- Conditional processing in session prompt loop for SDK provider
- Session metadata support for SDK resume capability

Changes are gated by isClaudeAgentProvider() checks to avoid
affecting normal AI SDK flows.
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
@github-actions

Copy link
Copy Markdown
Contributor

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

No duplicate PRs found

@chriswritescode-dev

Copy link
Copy Markdown
Author

Removing to clean up commit history

@chriswritescode-dev
chriswritescode-dev deleted the fix/7870-prompt-race-condition branch January 11, 2026 22:50
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