Bug Description
When creating a new conversation in the OpenCode GUI (desktop app), the input dialog automatically fills with the first instruction (first user message) from the previous conversation.
Root Cause Analysis
After investigating the desktop app source code (version 1.17.11), the root cause has been identified:
The workspace-level prompt state is not cleared after a session is created from it.
Technical Details
OpenCode uses a persisted prompt state system with different scopes:
- Session scope:
session:{sessionID}:prompt ¡ª used when on a session page (has params.id)
- Workspace scope:
workspace:prompt ¡ª used when on a new session page (no params.id)
- Draft scope:
draft:{draftID}:prompt ¡ª used in the new layout draft flow
The bug flow (old layout, and potentially new layout in some cases):
- User types in the new conversation input box ¡ú prompt saved under
workspace:prompt
- User submits the message ¡ú a session is created,
submission.retarget() switches the prompt target from workspace scope to the new session scope
submission.clear() ¡ú only resets the session-scoped prompt, NOT the workspace-scoped prompt
- User clicks "New Conversation" ¡ú workspace page loads ¡ú
workspace:prompt is restored from disk with the old content ¡ú input box is pre-filled!
Key Code Locations (desktop app v1.17.11)
out/renderer/assets/main-D_cwiNV1.js:
createPromptSubmissionState (around line 112895) ¡ª clear() only resets the retargeted target, not the original workspace prompt
promptTarget() (around line 85207) ¡ª determines storage key based on scope
Persist.serverScoped() (around line 62940) ¡ª routes to serverWorkspace when no session ID
- Submission flow (around line 113160-113180) ¡ª
retarget() switches target but doesn't clear workspace scope
- Session compose submit handler (around line 113204-113208) ¡ª
clearInput doesn't reset workspace prompt
Suggested Fix
The workspace-level prompt state should be reset after it's been used to create a session. Options:
- In the
clearInput() callback after successful session creation, also call prompt.reset() for the workspace scope
- In
SessionRoute/Page component when params.id transitions from undefined to a session ID, clear the workspace-level prompt
- When navigating back to a workspace page (no
params.id), force-reset the workspace prompt if it was previously used
Steps to Reproduce
- Open OpenCode desktop GUI
- Click "New Conversation"
- Type a message in the input box
- Submit the message (wait for the AI response)
- Click "New Conversation" again
- Expected: Empty input box
- Actual: Input box is pre-filled with previously typed text
Environment
- OpenCode version: 1.17.11 (desktop)
- OS: Windows 11
Bug Description
When creating a new conversation in the OpenCode GUI (desktop app), the input dialog automatically fills with the first instruction (first user message) from the previous conversation.
Root Cause Analysis
After investigating the desktop app source code (version 1.17.11), the root cause has been identified:
The workspace-level prompt state is not cleared after a session is created from it.
Technical Details
OpenCode uses a persisted prompt state system with different scopes:
session:{sessionID}:prompt¡ª used when on a session page (hasparams.id)workspace:prompt¡ª used when on a new session page (noparams.id)draft:{draftID}:prompt¡ª used in the new layout draft flowThe bug flow (old layout, and potentially new layout in some cases):
workspace:promptsubmission.retarget()switches the prompt target from workspace scope to the new session scopesubmission.clear()¡ú only resets the session-scoped prompt, NOT the workspace-scoped promptworkspace:promptis restored from disk with the old content ¡ú input box is pre-filled!Key Code Locations (desktop app v1.17.11)
out/renderer/assets/main-D_cwiNV1.js:createPromptSubmissionState(around line 112895) ¡ªclear()only resets the retargeted target, not the original workspace promptpromptTarget()(around line 85207) ¡ª determines storage key based on scopePersist.serverScoped()(around line 62940) ¡ª routes toserverWorkspacewhen no session IDretarget()switches target but doesn't clear workspace scopeclearInputdoesn't reset workspace promptSuggested Fix
The workspace-level prompt state should be reset after it's been used to create a session. Options:
clearInput()callback after successful session creation, also callprompt.reset()for the workspace scopeSessionRoute/Pagecomponent whenparams.idtransitions from undefined to a session ID, clear the workspace-level promptparams.id), force-reset the workspace prompt if it was previously usedSteps to Reproduce
Environment