Skip to content

goose: wire session resume on workspace restart #744

@mafredri

Description

@mafredri

Problem

Goose has native SQLite-based session persistence (~/.local/share/goose/sessions/sessions.db) and supports resuming named sessions via goose run --resume --name <name>. However, start.sh always starts a fresh session with no resume logic. It also doesn't pass --type goose to agentapi.

The module currently passes the task prompt via --instructions "$PROMPT_FILE". On resume, this must be skipped to avoid re-sending the task into an active conversation.

Desired outcome

  • On cold start (no prior session): Goose creates a named session and processes the task prompt.
  • On warm start (prior session exists): Goose resumes the named session. The task prompt (--instructions) is not re-sent.
  • --type goose is passed to agentapi server.
  • 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.

Claude Code's start.sh is the reference implementation for this pattern (session detection, conditional resume, prompt skipping).

Key upstream behaviors

  • goose run --resume --name X when session X doesn't exist: Goose warns and creates a new session (block/goose#3904). This is a safe fallback.
  • The SQLite DB uses WAL mode, meaning sessions.db-wal and sessions.db-shm sidecar files must be on the same persistent volume.
  • sqlite3 CLI may not be installed in all workspace images. Session detection should not depend on it, or should degrade gracefully.
  • block/goose#6236 reported subprocess panics when resuming without a TTY. AgentAPI provides a PTY but this combination should be tested.

Version bump

minor

Refs #696, 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