-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Repo: coder/agentapi
Scope: Add state file support to AgentAPI binary so conversation history survives restarts.
Changes:
- Add
--state-file <path>flag toagentapi servercommand - Add
--load-stateflag (default true when state-file set) - Add
--save-stateflag (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):
{ "version": 1, "messages": [...], "initial_prompt": "...", "initial_prompt_sent": true }
Files (in agentapi repo):
lib/screentracker/conversation.gocmd/server.go
Acceptance criteria:
- State saved to file on graceful shutdown
- State loaded from file on startup when flag set
- SIGUSR1 saves state without exiting process
- SIGTERM skips save if not dirty (no changes since last save)
- State file written atomically (temp file + rename)
-
/messagesendpoint returns restored history after restart - Version field allows future format migrations
Dependencies: None
References:
- PRD: Start/Pause/Resume the Task Workspace
- RFC: Tasks: Start/Pause/Resume Lifecycle: AgentAPI State Persistence
35C4n0r