Skip to content

Conversation

@mafredri
Copy link
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
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.

Copy link

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

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 on lines 18 to +21

data "coder_workspace_owner" "me" {}

data "coder_task" "me" {}

Choose a reason for hiding this comment

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

P1 Badge Bump provider version for coder_task data source

This module now declares data "coder_task" "me" {} but still allows coder provider >= 2.12. Tasks usage elsewhere in the repo pins coder to >= 2.13 (see registry/coder-labs/templates/tasks-docker/main.tf) alongside coder_task, which suggests the data source was introduced after 2.12. If a user is still on 2.12 (currently permitted by this module), Terraform will error with an unknown data source. Consider bumping required_providers.coder.version to >= 2.13 (or gating the data source) so non-task users on 2.12 aren’t broken.

Useful? React with 👍 / 👎.

Comment on lines +30 to +33
if ! command_exists jq; then
echo "Warning: jq is not installed. Task log snapshot requires jq to capture conversation history."
echo "Install jq to enable log snapshot functionality when the workspace stops."
fi
Copy link
Member

Choose a reason for hiding this comment

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

In this case, the shutdown script will exit 1. I'm guessing that's OK?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, exit 1. I would say it's fine. That error will also complain about jq not being installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants