Skip to content

opencode: enable session resume by default and fix prompt re-delivery #742

@mafredri

Description

@mafredri

Problem

Two issues:

  1. Resume is off by default. The module has full resume wiring (--continue, --session, --type opencode all present in start.sh) but the continue variable in main.tf defaults to false. Out of the box, sessions are never resumed.

  2. Prompt is re-sent on resume. In build_opencode_args(), the initial prompt is added to AGENTAPI_ARGS via -I "$PROMPT" unconditionally when ARG_AI_PROMPT is set, regardless of whether ARG_CONTINUE is true. When a session is resumed, the task prompt gets re-injected into an already-active conversation, potentially re-triggering the original task.

To reproduce: set continue = true and ai_prompt = "some task". Start the module, have a conversation, stop, restart. The agent resumes the session but the task prompt is re-sent as a new message.

OpenCode's --continue gracefully creates a new session when no prior sessions exist, so the default flip is safe for first-run scenarios.

Desired outcome

  • continue defaults to true.
  • The initial prompt is only sent on cold start, not when resuming an existing session.
  • Expose enable_state_persistence in main.tf (default true) and pass it through to the module "agentapi" block so the Coder UI preserves chat history across restarts, matching the agent's resumed session.

Version bump

minor

Refs coder/internal#1258

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions