Skip to content
Skip to Content
Coder Docs

Upgrade from ESR 2.34 to 2.40

A step-by-step guide to upgrade a Coder deployment from Extended Support Release 2.34 to 2.40.

On this page

Guide overview

Guide overview

Coder provides Extended Support Releases (ESR) twice a year. This guide walks through upgrading from Coder 2.34 ESR to Coder 2.40 ESR.

Read more about the ESR release process and how Coder supports it.

You can upgrade directly from 2.34 to 2.40. We recommend that you first upgrade to the latest 2.34 patch release, which this guide assumes. If you run an older patch, also read Changes already in 2.34 patch releases. If you run 2.29, upgrade to 2.34 first with the 2.29 to 2.34 guide.

For what changed between 2.34 and 2.40, read the release notes for 2.35, 2.36, 2.37, 2.38, 2.39, and 2.40.

In this guide, coderd is the process that runs the Coder control plane.

Before you upgrade

Before you upgrade

This upgrade applies 137 database migrations in one transaction when coderd starts. A few rewrite or backfill long-lived tables and hold locks while they run. Total time ranges from under a minute to several minutes, scaling with the size of the tables in Database migrations to watch.

Complete these steps while you are still on 2.34.

  1. Back up the database.

    After a successful upgrade, the only way back to 2.34 is to restore the backup. A 2.34 coderd does not start on a database that 2.40 has migrated.

  2. Rehearse the upgrade in a staging environment that mirrors production data volume.

  3. Start pruning connection logs, if you keep more history than you need.

    Pruning takes time, so start it first. Refer to The connection logs table is rewritten.

  4. Plan downtime.

    Stop every 2.34 replica before you start 2.40. A 2.34 replica that is still running while the migrations run can deadlock with them, and the upgrade fails.

    On Kubernetes:

    1. Scale the deployment to zero with kubectl scale deployment coder -n <namespace> --replicas=0 and wait for the pods to stop.
    2. Run the upgrade with coder.replicaCount set to 1 in the Helm chart.
    3. Wait for the committed database migrations line to appear in the log.
    4. Scale back to your usual number of replicas.

    Refer to upgrade best practices for liveness probes.

  5. Close other database sessions.

    A backup job or a long reporting query that holds a lock makes the migrations wait until that session ends. This query lists long-running transactions:

    SELECT pid, usename, application_name, state, xact_start, left(query, 80)
    FROM pg_stat_activity
    WHERE xact_start < now() - interval '1 minute' AND pid <> pg_backend_pid();

    If you run this query during the upgrade, it also lists the migration itself, with an application name that starts with coder-migrate. Do not end that session.

  6. Remove server options that 2.40 does not accept.

    A flag or YAML key that 2.40 does not accept stops coderd from starting. An environment variable that 2.40 does not accept is ignored. The options are listed under AI providers are no longer configured through server options and Coder Tasks is removed. Both entries are also part of the changes marked "Act: before you upgrade".

  7. Check the SSH hostname prefix.

    coderd does not start if CODER_SSH_HOSTNAME_PREFIX contains * or ?.

  8. Complete each change marked "Act: before you upgrade".

    These are under Changes that require action: AI providers, Coder Tasks, NATS, Git authentication, and connection logs.

  9. If you use Coder Agents, complete Do before you upgrade.

  10. If you run an older 2.34 patch, read Changes already in 2.34 patch releases.

Database migrations to watch

Database migrations to watch

These tables take the longest to migrate. Size your maintenance window for whichever are largest in your deployment.

TableWhat the migrations doTakes longer with
connection_logsRewrite the whole table under an exclusive lock, which blocks reads and writes. This is typically the slowest step.A long connection log history
workspace_buildsRewrite the table to remove the task build reasons.A long build history
workspace_agent_statsLock the table, convert session counts, and rebuild an index.A large volume of retained agent stats
template_usage_statsMove per-app usage to a new table.A long template insights history
workspace_app_statsAdd an index. This table is never pruned.An older deployment
api_keysRewrite the table and remove task scopes from every API token.Many API tokens
aibridge_interceptions, boundary_logsRebuild indexes. This applies only if you use AI Gateway or Agent Firewall.More retained logs
chats, chat_messagesRewrite and index the tables. This applies only if you use Coder Agents.More chat history

Changes that require action

Changes that require action
  • Act: before you upgrade means act while you are still on 2.34. If you wait, data is deleted, coderd does not start, or a feature stops working when 2.40 starts.
  • Act: after you upgrade means act once 2.40 is running.

If the "Affects" line does not describe your deployment, skip the entry.

AI providers are no longer configured through server options

AI providers are no longer configured through server options

Affects: deployments whose server configuration contains AI Gateway (formerly AI Bridge) provider settings as flags, environment variables, or YAML. This includes any config file written by coder server --write-config on 2.34. Act: before you upgrade. Changed in: 2.38.

In 2.40, you manage providers in the Coder dashboard and the API only. Providers that you defined through server options on 2.34 are already stored in the database, so they keep working after the upgrade.

  • Check: Search your server configuration for provider settings that start with CODER_AIBRIDGE_ or CODER_AI_GATEWAY_, the matching --aibridge-* and --ai-gateway-* flags, and the aibridge and ai_gateway YAML sections.
  • Action: Remove the flags and YAML keys, or coderd does not start. Remove the environment variables too, because a key that you change there has no effect. After you upgrade, add providers and rotate keys in the dashboard or the API.

Coder Tasks is removed

Coder Tasks is removed

Affects: deployments that use Coder Tasks, and deployments that set --hide-ai-tasks, CODER_HIDE_AI_TASKS, or the hideAITasks YAML key. Act: before you upgrade. Changed in: 2.38.

The Tasks pages, the coder task commands, the /api/v2/tasks API, and the task tools in the Coder MCP server are removed, and no option turns them back on. The migrations drop the task tables, delete task notifications, and delete API tokens whose only scopes are task scopes. Workspaces that backed tasks remain as ordinary workspaces.

  • Check: Run these queries. The first counts tasks. The second lists the API tokens that the migrations delete. The api_keys table stores API tokens.

    SELECT count(*) FROM tasks;
    
    SELECT id, user_id, token_name FROM api_keys
    WHERE NOT EXISTS (SELECT 1 FROM unnest(scopes) s WHERE s::text NOT LIKE 'task:%')
       OR NOT EXISTS (SELECT 1 FROM unnest(allow_list) e WHERE e::text NOT LIKE 'task:%');
  • Action: Move users and integrations to Coder Agents with Migrating from the Tasks API to the Chats API, export any task prompts or logs you need, and reissue the listed API tokens. Remove --hide-ai-tasks, CODER_HIDE_AI_TASKS, and the hideAITasks YAML key.

Replicas exchange events over NATS on TCP port 6222

Replicas exchange events over NATS on TCP port 6222

Affects: deployments with more than one Coder replica. Act: before you upgrade. Changed in: 2.38.

Replicas pass events to each other over an embedded NATS cluster, not PostgreSQL. If port 6222 is blocked between replicas, Coder does not fall back to PostgreSQL. Events published on one replica, such as workspace updates, do not reach clients connected to another.

  • Action: If a firewall or Kubernetes NetworkPolicy sits between replicas, allow TCP port 6222 between them.
  • Action: Set CODER_CLUSTER_HOST on each replica to its routable address. If you use the Coder Helm chart, it automatically sets this to the pod IP, so no action is required.
  • Alternative: To keep using PostgreSQL, add no_nats_pubsub to CODER_EXPERIMENTS. Refer to high availability.

Git authentication follows the provider the template declares

Git authentication follows the provider the template declares

Affects: templates that declare coder_external_auth, in deployments where two providers match the same Git host or a declared provider was renamed or removed. Act: before you upgrade. Changed in: 2.37.

When Git asks for credentials in a workspace, Coder picks the external auth provider from the coder_external_auth entries that the workspace's template declares. In 2.34, it used the last provider in the server configuration whose regex matched the host. If the template declares no provider for that host, the 2.34 behavior still applies.

Coder returns no token, and Git falls back to its own credential prompt, when the template declares two or more providers that match the same host, or declares a provider that the server configuration does not contain.

  • Check: Review templates that declare coder_external_auth. Look for two declared providers whose CODER_EXTERNAL_AUTH_<N>_REGEX values match the same host, and for declared IDs that were renamed or removed from the server configuration.
  • Action: Give overlapping providers regex values that do not overlap, or fetch the token by ID with coder external-auth access-token <id>. Restore a missing provider, or update the template to declare one that is configured.

The connection logs table is rewritten

The connection logs table is rewritten

Affects: deployments with a long connection log history, and anything that reads the connection_logs table with SQL. Act: before you upgrade. Changed in: 2.39.

The migrations rewrite the whole table under a lock and rename two columns. type becomes connection_method, and slug_or_port becomes app_name_or_port. The API still returns type.

  • Check: Count the rows in the table.

    SELECT count(*) FROM connection_logs;
  • Action: The rewrite takes longer the more rows the table holds. If you keep more connection log history than you need, set CODER_CONNECTION_LOGS_RETENTION on 2.34 so that Coder prunes old rows before you upgrade. Pruning runs in the background, and each replica removes up to 1.4 million rows a day, so start well ahead of the upgrade. Update any SQL that reads the table directly.

Users with login type none are converted to password login

Users with login type none are converted to password login

Affects: deployments with login_type=none users, and scripts that create users. Act: after you upgrade. Changed in: 2.37.

The migrations convert existing none users to password users with no password set. Their API tokens keep working. They cannot log in with a password until an administrator sets one. Service accounts are not changed.

  • Check: Before you upgrade, run this query. It lists the users that the migrations convert.

    SELECT id, username, email FROM users
    WHERE login_type = 'none' AND NOT is_service_account AND NOT is_system AND NOT deleted;
  • Action: After you upgrade, set a password for each converted user who must log in with one. Update scripts that create users. --disable-login and login_type=none fail in 2.40, so use --service-account (Premium). In POST /api/v2/users, send organization_ids in place of the old organization_id field.

Prometheus metrics are renamed

Prometheus metrics are renamed

Affects: deployments with monitoring dashboards or alerts built on Coder metrics. Act: after you upgrade. Changed in: 2.38 to 2.40.

Three groups of metrics change their names or labels.

  • Check: Search your monitoring dashboards and alert rules for coder_aibridged_, coder_aibridgeproxyd_, application_name, and coder_pubsub_.
  • Action:
    • Rename coder_aibridged_* to coder_ai_gateway_* and coder_aibridgeproxyd_* to coder_ai_gateway_proxy_*. 2.40 does not emit the old names.
    • On coderd_insights_applications_usage_seconds, use the label display_name in place of application_name. Built-in apps are reported per app.
    • Every coder_pubsub_* metric has a new backend label. Aggregate over it in queries that expect one series per replica.

The CLI no longer follows redirects, and two commands ask for confirmation

The CLI no longer follows redirects, and two commands ask for confirmation

Affects: scripts and CI jobs that call the Coder CLI. Act: after you upgrade. Changed in: 2.38 and 2.39.

In 2.40, the CLI fails when the Coder URL redirects. coder update on a running workspace and coder users edit-roles --roles ask for confirmation.

  • Check: Find out whether the URL that users or CI jobs pass to coder login redirects, for example from http:// to https:// or from an old hostname. Search your scripts for coder update on running workspaces and for coder users edit-roles --roles.
  • Action: Run coder login against the final URL, or set CODER_ALLOW_REDIRECTS=true. Add -y to coder update and coder users edit-roles. The 2.34 CLI does not accept -y on coder update, so change the script at the same time as the CLI.

If you use Coder Agents

If you use Coder Agents

Skip this section if you do not use Coder Agents.

Do before you upgrade

Do before you upgrade
  • Record who has access. The migrations delete explicit agents-access role grants and make agents-access a default member role of every organization. After the upgrade, every organization member can use Coder Agents. Service accounts do not get the role by default, so they lose access until you grant it again. Note who holds the role, including service accounts.
  • Check your license. Community and Premium licenses support up to five concurrently active agents across the whole deployment, and further agents wait in a queue. Refer to licensing and usage if you need more.
  • Record usage limits. Coder Agents usage limits and cost pages are removed, and 2.40 does not enforce the limits.
  • Record model overrides. Model overrides and users' personal overrides are not carried over. The advisor keeps its limits but loses its model.
  • Allow private MCP servers. MCP servers on private, loopback, or reserved IP ranges are blocked by default. A blocked server drops out of chats with no error message. The only sign is a skipping MCP server due to connection failure warning in the coderd log. Set CODER_MCP_ALLOWED_PRIVATE_CIDRS to the ranges your MCP servers use, for example 10.0.0.0/8, in the same rollout as the upgrade. Add 127.0.0.0/8 for servers that run on the Coder host.
  • Turn on AI Gateway. Coder Agents needs AI Gateway. If you set CODER_AI_GATEWAY_ENABLED=false, turn it on again, or chat requests return 503.

Do after you upgrade

Do after you upgrade
  • Restrict access again, if you need to. Remove agents-access from each organization's default member roles with coder organizations edit --org <name> --default-org-member-roles organization-workspace-access --yes, then grant the role to the members who need it. Changing default member roles requires a Premium license. Members who lose the role cannot see their existing chats.
  • Grant agents-access to each service account that uses Coder Agents.
  • Re-create usage limits as AI Gateway group budgets and user overrides.
  • Create models in each organization. Models and MCP servers are per organization, and existing ones move to the default organization. Until an administrator creates a model in another organization, its members cannot start chats or continue existing ones there. They see No chat model is available in this organization.
  • Select your model overrides again.
  • Restart workspaces. Chats in a workspace that still runs the 2.34 workspace agent do not load workspace context such as AGENTS.md, and file edits fail. Reading files and running commands still work, and nothing in the chat says the workspace agent is outdated.
  • Turn on virtual desktop. Virtual desktop is behind an experiment in 2.40. If you used it, add chat-virtual-desktop to CODER_EXPERIMENTS. The 2.34 desktop setting is ignored, so the experiment turns the feature on for every organization. Computer use runs on the organization's default model when that model supports it. Otherwise, pick a computer use model per organization.
  • Update API integrations. The API moved from /api/experimental to /api/v2 and changed shape, so changing the path prefix is not enough. Rewrite integrations against the 2.40 API reference.

Follow the upgrade in the coderd logs

Follow the upgrade in the coderd logs

Upgrade coderd with the steps for your install method in Upgrade Coder. In 2.40, coderd logs the progress of the database migrations when it starts. Every one of these lines comes from the migrations logger, and the final line carries a status field.

# Did the upgrade finish? Prints one line with status=success or status=failure.
# --tail=-1 reads the whole log. With a label selector, kubectl otherwise returns only the last 10 lines of each pod.
kubectl logs -l app.kubernetes.io/name=coder -n <namespace> --tail=-1 | grep 'migrations:' | grep -E 'status=(success|failure)'

# Follow progress while the upgrade runs.
kubectl logs -l app.kubernetes.io/name=coder -n <namespace> --tail=-1 -f | grep 'migrations:'

If you write JSON logs with CODER_LOGGING_JSON, filter on the logger name: jq -R 'fromjson? | select(.logger_names == ["migrations"])'. The outcome line is the one from this logger with a fields.status value.

  • Success: committed database migrations with status=success. The upgrade succeeded, and the database is on the 2.40 schema.
  • Waiting: still applying database migration, repeated every 10 seconds. If the line shows state=waiting_on_lock, its blocked_by value is the PostgreSQL process ID of the session to end.
  • Failure: migration failed, transaction rolled back, no changes saved, with the name of the migration and the PostgreSQL error code. The database is still on the 2.34 schema. Fix the cause and start coderd again, or contact Coder support for help.

coderd does not answer /healthz until the migrations finish.

After you upgrade

After you upgrade
  1. Confirm the committed database migrations line in the coderd log and that /healthz answers.
  2. Upgrade external provisioners and workspace proxies to 2.40.
  3. Test login through your identity provider.
  4. Test git clone of a private repository in a workspace. Git authentication now follows the provider that the template declares.
  5. Test a workspace build from your main templates.
  6. In a deployment with more than one replica, confirm that a change made through one replica appears for a user connected to another. Replicas now exchange events over NATS.
  7. Restart workspaces so that they run the 2.40 workspace agent. If you use Coder Agents, do this first, because chats cannot edit files until the workspace restarts.
  8. Complete each change marked "Act: after you upgrade", and Do after you upgrade if you use Coder Agents.

Other notable changes

Other notable changes

These changes need action only if you depend on the behavior described.

API and CLI

API and CLI
  • API responses and coder list -o json return ***REDACTED*** for the values of workspace agent environment variables (2.40).
  • JSON request bodies larger than 4 MiB are rejected with 413 (2.37).
  • GET /api/v2/aibridge/interceptions and the coder aibridge commands are removed. Use the AI Gateway sessions endpoints (2.35).
  • GET /api/v2/insights/templates reports app usage per app, and type is replaced by method (2.39).
  • coder update --use-parameter-defaults asks for a value when a workspace's saved option does not exist in the template (2.40).
  • CLI credentials in the operating system keyring are stored per origin. Users who logged in with an http:// URL or an explicit :443 port log in again (2.39).
  • The oauth2 experiment is replaced by the CODER_OAUTH2_PROVIDER_ENABLE option. If you enabled the experiment, set the option to true, or the OAuth2 provider stays off (2.38).

Templates and workspaces

Templates and workspaces
  • coder templates push sets a template's display name, description, and icon from the README front matter on every push (2.38).
  • The workspace app proxy does not forward the Coder-Session-Token header or the coder_session_token query parameter to apps (2.40).
  • Parameter forms skip template resources that no parameter, preset, or workspace tag depends on, which makes them faster on large templates. If a form shows an empty default, option list, preset value, or tag after the upgrade, set CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION=true on coderd and report the template to Coder support (2.38).

Platform

Platform
  • The Coder dashboard needs Chrome 111, Firefox 128, Safari 16.4, or later (2.38).

Changes already in 2.34 patch releases

Changes already in 2.34 patch releases

If you run an older 2.34 patch, these changes also reach you when you upgrade to 2.40.

PatchChangeWhat to do
2.34.2OIDC and GitHub login do not fall back to email matching for a user already linked to a different identity.Affected users get 403. If your identity provider's issuer or subject values changed, run coder server fix-oidc-links.
2.34.2OIDC login is rejected when email_verified is absent or not a boolean.Make your identity provider send it as a boolean, or set CODER_OIDC_IGNORE_EMAIL_VERIFIED.
2.34.2coderd refuses unsafe CODER_SSH_CONFIG_OPTIONS and CODER_WORKSPACE_HOSTNAME_SUFFIX values.Remove ProxyCommand, ProxyJump, Match, Include, and similar keys.
2.34.2X-Forwarded-Host is honored only from proxies in CODER_PROXY_TRUSTED_ORIGINS.List every reverse proxy there.
2.34.3API tokens do not extend their expiry on use.Check the expiry of tokens used by automation, and rotate any that are close to it.
2.34.7The client IP is taken from the rightmost untrusted X-Forwarded-For entry.List every proxy hop in CODER_PROXY_TRUSTED_ORIGINS.
2.34.8Sharing with a user requires that user to be a member of the organization.Add the user to the organization, or share through a group.
2.34.9Workspace agents get 401 when the workspace owner is suspended or dormant.Reactivate the owner.
2.34.9Terraform module files imported in a fixed window on August 31, 2026 are purged.Push a new version of each affected template.
2.34.13 and 2.34.18Bundled Terraform moves from 1.14 to 1.16, then to 1.17.Ship Terraform 1.17 in air-gapped installs and custom provisioner images.
2.34.19Builds fail when an external app URL has an unsafe scheme, or no scheme or host.Check external app URLs in your templates.