Uh oh!
There was an error while loading. Please reload this page.
feat(coder/modules/agentapi): add state persistence - #736
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
636bc8c to
955441dCompare001c89d to
8a32b14CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
AgentAPI can save and restore conversation state across workspace restarts. The base module exports env vars (AGENTAPI_STATE_FILE, AGENTAPI_SAVE_STATE, AGENTAPI_LOAD_STATE, AGENTAPI_PID_FILE) that the binary reads directly. No consumer module start scripts need changes. New variables: - enable_state_persistence (bool, default true) - state_file_path (string, defaults to $HOME/<module_dir_name>/state.json) - pid_file_path (string, defaults to $HOME/<module_dir_name>/agentapi.pid) State persistence requires agentapi >= v0.12.0. A shared version_at_least function in scripts/lib.sh gates both the env var exports in main.sh and SIGUSR1 in the shutdown script. The version is queried from the real binary (agentapi --version) rather than the Terraform variable, so it works correctly when install_agentapi is false. Shutdown script now performs a three-phase shutdown: 1. SIGUSR1 to trigger state save (gated on version + persistence enabled) 2. Log snapshot capture (existing behavior, now fault-tolerant via subshell) 3. SIGTERM for graceful termination with wait loop Also bumps agentapi module version to 2.2.0. Refs: internal#1257, internal#1256, registry#696
8a32b14 to
1435939Compare
DevelopmentCats
left a comment
There was a problem hiding this comment.
LGTM aside from what has already been pointed out.
@35C4n0r You might have some better insight on this since agentapi.
35C4n0r
left a comment
There was a problem hiding this comment.
Code LGTM!
I'd test it once before approving.
Uh oh!
There was an error while loading. Please reload this page.
No consumer modules ship agentapi >= v0.12.0 yet, so the feature was silently skipped at runtime while emitting a misleading warning on every workspace start. Modules can opt in explicitly when ready.
mafredri
commented
Feb 24, 2026
FYI I flipped |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The subshell EXIT trap references $tmpdir which is local to capture_task_log_snapshot. When the trap fires during subshell exit, the variable is out of scope, causing a nounset error after the snapshot posts successfully.
It seems that agentapi can block for longer than 5s sometimes: ``` Shutting down AgentAPI Sending SIGUSR1 to AgentAPI (pid 44876) to save state Fetching messages from AgentAPI on port 3284 curl: (28) Operation timed out after 5001 milliseconds with 0 bytes received Error: Failed to fetch messages from AgentAPI (may not be running) Error: Cannot capture log snapshot without messages Log snapshot capture failed, continuing shutdown Sending SIGTERM to AgentAPI (pid 44876) Warning: AgentAPI (pid 44876) still running after 5s Shutdown complete ```
…stead of /tmp Bootstrap scripts used fixed /tmp paths with generic names like /tmp/main.sh, making them easy to collide with or accidentally overwrite. Write them into $HOME/<module_dir_name>/scripts/ instead, following the pattern used by the agent-helper module. Also fix install.sh hardcoding port 3284 instead of using ARG_AGENTAPI_PORT. Refs #736
Uh oh!
There was an error while loading. Please reload this page.
AgentAPI can save and restore conversation state across workspace restarts.
The base module exports env vars (AGENTAPI_STATE_FILE, AGENTAPI_SAVE_STATE,
AGENTAPI_LOAD_STATE, AGENTAPI_PID_FILE) that the binary reads directly.
No consumer module start scripts need changes.
New variables:
State persistence requires agentapi >= v0.12.0. A shared version_at_least
function in scripts/lib.sh gates both the env var exports in main.sh and
SIGUSR1 in the shutdown script. Old binaries get a warning and graceful
skip instead of breakage.
Shutdown script now performs a three-phase shutdown:
Also bumps agentapi module version to 2.2.0 and claude-code to 4.7.6.
Closescoder/internal#1257
Refs coder/internal#1256
Refs #696