Skip to content

feat(coder/modules/agentapi): add log snapshot capture on shutdown - #676

Merged
mafredri merged 7 commits into
mainfrom
mafredri/agentapi-shutdown-logs
Jan 30, 2026
Merged

mafredri merged 7 commits into
mainfrom
mafredri/agentapi-shutdown-logs

Conversation

@mafredri

Copy link
Copy Markdown
Member

Captures the last 10 messages from AgentAPI when task workspaces stop,
allowing users to view conversation history while the task is paused.

The shutdown script fetches messages, builds a payload with last 10
messages, truncates to 64KB if needed (removes old messages first, then
truncates content of the last message), and posts to the log snapshot
endpoint.

Gracefully handles non-task workspaces (skips), older Coder versions
without the endpoint (logs and continues), and empty message sets.

Enabled by default via task_log_snapshot variable. Task ID is
automatically resolved from data.coder_task when available.

Updates coder/internal#1257

Captures the last 10 messages from AgentAPI when task workspaces stop,
allowing users to view conversation history while the task is paused.

The shutdown script fetches messages, builds a payload with last 10
messages, truncates to 64KB if needed (removes old messages first, then
truncates content of the last message), and posts to the log snapshot
endpoint.

Gracefully handles non-task workspaces (skips), older Coder versions
without the endpoint (logs and continues), and empty message sets.

Enabled by default via task_log_snapshot variable. Task ID is
automatically resolved from data.coder_task when available.

Updates coder/internal#1257
@mafredri
mafredri force-pushed the mafredri/agentapi-shutdown-logs branch from 54b1c13 to f72792c Compare January 28, 2026 13:41
@mafredri
mafredri marked this pull request as ready for review January 28, 2026 13:42
@mafredri

Copy link
Copy Markdown
Member Author

Verified implementation against current main build of coderd and shutdown pull/post works as expected.

It does require the following change to terraform template for docker containers, however:

  destroy_grace_seconds = 300
  stop_timeout          = 300
  stop_signal           = "SIGINT"

Otherwise the agent gets killed while executing the script.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f72792ccbc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread registry/coder/modules/agentapi/main.tf Resolved
@DevelopmentCats DevelopmentCats added the version:minor Add to PRs requiring a minor version upgrade label Jan 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Version Bump Required

One or more modules in this PR need their versions updated.

To fix this:

  1. Run the version bump script locally:
    ./.github/scripts/version-bump.sh 
  2. Commit the changes:
    git add . && git commit -m "chore: bump module versions ()"
  3. Push your changes

The CI will automatically re-run once you push the updated versions.

@DevelopmentCats DevelopmentCats left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but we just need the version bumped in the README to 2.1.0

@mafredri

Copy link
Copy Markdown
Member Author

@DevelopmentCats thanks, I'll do that 👍🏻. Since this module is used by others, e.g. claude-code, should the agentapi version be bumped there as well? And those modules also be bumped?

@DevelopmentCats

Copy link
Copy Markdown
Collaborator

@DevelopmentCats thanks, I'll do that 👍🏻. Since this module is used by others, e.g. claude-code, should the agentapi version be bumped there as well? And those modules also be bumped?

I think the only thing you need to bump is the agent-api module here.

@DevelopmentCats DevelopmentCats left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now after module bump

@mafredri
mafredri merged commit fa30191 into main Jan 30, 2026
4 checks passed
@mafredri
mafredri deleted the mafredri/agentapi-shutdown-logs branch January 30, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

version:minor Add to PRs requiring a minor version upgrade

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants