**Repo**: `coder/agentapi` **Scope**: Add state file support to AgentAPI binary so conversation history survives restarts. **Changes**: - Add `--state-file <path>` flag to `agentapi server` command - Add `--load-state` flag (default true when state-file set) - Add `--save-state` flag (default true when state-file set) - Add `--pid-file <path>` flag so shutdown scripts can signal the correct process - Implement `Conversation.SaveState(path string) error` - Use atomic write: write to temp file, then rename to target path - Implement `LoadState(path string) (*Conversation, error)` - Save state on SIGTERM, SIGINT, SIGHUP (skip if not dirty) - Add SIGUSR1 handler to save without exit (for shutdown script coordination, can be called periodically) - Track dirty flag: set on conversation change, clear on save - State file format (JSON for schema compatibility): ```json { "version": 1, "messages": [...], "initial_prompt": "...", "initial_prompt_sent": true } ``` **Files** (in agentapi repo): - `lib/screentracker/conversation.go` - `cmd/server.go` **Acceptance criteria**: - [x] State saved to file on graceful shutdown - [x] State loaded from file on startup when flag set - [x] SIGUSR1 saves state without exiting process - [x] SIGTERM skips save if not dirty (no changes since last save) - [x] State file written atomically (temp file + rename) - [x] `/messages` endpoint returns restored history after restart - [x] Version field allows future format migrations **Dependencies**: None **References**: - [PRD: Start/Pause/Resume the Task Workspace](https://www.notion.so/coderhq/Start-Pause-Resume-the-Task-Workspace-2aad579be59280e5a15ef6bb6a93f246) - [RFC: Tasks: Start/Pause/Resume Lifecycle](https://www.notion.so/coderhq/Tasks-Start-Pause-Resume-Lifecycle-2cdd579be592805a929fc36d0c82d65d): AgentAPI State Persistence
Activity
feat(registry/coder/modules/agentapi): add state persistence
mafredri commentedon Mar 3, 2026
This has been released as agentapi v0.12.0.
feat(coder/modules/agentapi): add state persistence support (#736)