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 overviewCoder 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 upgradeThis 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.
-
Back up the database.
After a successful upgrade, the only way back to 2.34 is to restore the backup. A 2.34
coderddoes not start on a database that 2.40 has migrated. -
Rehearse the upgrade in a staging environment that mirrors production data volume.
-
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.
-
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:
- Scale the deployment to zero with
kubectl scale deployment coder -n <namespace> --replicas=0and wait for the pods to stop. - Run the upgrade with
coder.replicaCountset to1in the Helm chart. - Wait for the
committed database migrationsline to appear in the log. - Scale back to your usual number of replicas.
Refer to upgrade best practices for liveness probes.
- Scale the deployment to zero with
-
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. -
Remove server options that 2.40 does not accept.
A flag or YAML key that 2.40 does not accept stops
coderdfrom 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". -
Check the SSH hostname prefix.
coderddoes not start ifCODER_SSH_HOSTNAME_PREFIXcontains*or?. -
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.
-
If you use Coder Agents, complete Do before you upgrade.
-
If you run an older 2.34 patch, read Changes already in 2.34 patch releases.
Database migrations to watch
Database migrations to watchThese tables take the longest to migrate. Size your maintenance window for whichever are largest in your deployment.
| Table | What the migrations do | Takes longer with |
|---|---|---|
connection_logs | Rewrite the whole table under an exclusive lock, which blocks reads and writes. This is typically the slowest step. | A long connection log history |
workspace_builds | Rewrite the table to remove the task build reasons. | A long build history |
workspace_agent_stats | Lock the table, convert session counts, and rebuild an index. | A large volume of retained agent stats |
template_usage_stats | Move per-app usage to a new table. | A long template insights history |
workspace_app_stats | Add an index. This table is never pruned. | An older deployment |
api_keys | Rewrite the table and remove task scopes from every API token. | Many API tokens |
aibridge_interceptions, boundary_logs | Rebuild indexes. This applies only if you use AI Gateway or Agent Firewall. | More retained logs |
chats, chat_messages | Rewrite 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,
coderddoes 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 optionsAffects: 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_orCODER_AI_GATEWAY_, the matching--aibridge-*and--ai-gateway-*flags, and theaibridgeandai_gatewayYAML sections. - Action: Remove the flags and YAML keys, or
coderddoes 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 removedAffects: 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_keystable 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 thehideAITasksYAML key.
Replicas exchange events over NATS on TCP port 6222
Replicas exchange events over NATS on TCP port 6222Affects: 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_HOSTon 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_pubsubtoCODER_EXPERIMENTS. Refer to high availability.
Git authentication follows the provider the template declares
Git authentication follows the provider the template declaresAffects: 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 whoseCODER_EXTERNAL_AUTH_<N>_REGEXvalues 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 rewrittenAffects: 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_RETENTIONon 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 loginAffects: 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-loginandlogin_type=nonefail in 2.40, so use--service-account(Premium). InPOST /api/v2/users, sendorganization_idsin place of the oldorganization_idfield.
Prometheus metrics are renamed
Prometheus metrics are renamedAffects: 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, andcoder_pubsub_. - Action:
- Rename
coder_aibridged_*tocoder_ai_gateway_*andcoder_aibridgeproxyd_*tocoder_ai_gateway_proxy_*. 2.40 does not emit the old names. - On
coderd_insights_applications_usage_seconds, use the labeldisplay_namein place ofapplication_name. Built-in apps are reported per app. - Every
coder_pubsub_*metric has a newbackendlabel. Aggregate over it in queries that expect one series per replica.
- Rename
The CLI no longer follows redirects, and two commands ask for confirmation
The CLI no longer follows redirects, and two commands ask for confirmationAffects: 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 loginredirects, for example fromhttp://tohttps://or from an old hostname. Search your scripts forcoder updateon running workspaces and forcoder users edit-roles --roles. - Action: Run
coder loginagainst the final URL, or setCODER_ALLOW_REDIRECTS=true. Add-ytocoder updateandcoder users edit-roles. The 2.34 CLI does not accept-yoncoder update, so change the script at the same time as the CLI.
If you use Coder Agents
If you use Coder AgentsSkip 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-accessrole grants and makeagents-accessa 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 failurewarning in thecoderdlog. SetCODER_MCP_ALLOWED_PRIVATE_CIDRSto the ranges your MCP servers use, for example10.0.0.0/8, in the same rollout as the upgrade. Add127.0.0.0/8for 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 return503.
Do after you upgrade
Do after you upgrade- Restrict access again, if you need to. Remove
agents-accessfrom each organization's default member roles withcoder 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-accessto 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-desktoptoCODER_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/experimentalto/api/v2and 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 logsUpgrade 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 migrationswithstatus=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 showsstate=waiting_on_lock, itsblocked_byvalue 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 startcoderdagain, or contact Coder support for help.
coderd does not answer /healthz until the migrations finish.
After you upgrade
After you upgrade- Confirm the
committed database migrationsline in thecoderdlog and that/healthzanswers. - Upgrade external provisioners and workspace proxies to 2.40.
- Test login through your identity provider.
- Test
git cloneof a private repository in a workspace. Git authentication now follows the provider that the template declares. - Test a workspace build from your main templates.
- 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.
- 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.
- Complete each change marked "Act: after you upgrade", and Do after you upgrade if you use Coder Agents.
Other notable changes
Other notable changesThese changes need action only if you depend on the behavior described.
API and CLI
API and CLI- API responses and
coder list -o jsonreturn***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/interceptionsand thecoder aibridgecommands are removed. Use the AI Gateway sessions endpoints (2.35).GET /api/v2/insights/templatesreports app usage per app, andtypeis replaced bymethod(2.39).coder update --use-parameter-defaultsasks 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:443port log in again (2.39). - The
oauth2experiment is replaced by theCODER_OAUTH2_PROVIDER_ENABLEoption. If you enabled the experiment, set the option totrue, or the OAuth2 provider stays off (2.38).
Templates and workspaces
Templates and workspacescoder templates pushsets 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-Tokenheader or thecoder_session_tokenquery 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=trueoncoderdand 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 releasesIf you run an older 2.34 patch, these changes also reach you when you upgrade to 2.40.
| Patch | Change | What to do |
|---|---|---|
| 2.34.2 | OIDC 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.2 | OIDC 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.2 | coderd refuses unsafe CODER_SSH_CONFIG_OPTIONS and CODER_WORKSPACE_HOSTNAME_SUFFIX values. | Remove ProxyCommand, ProxyJump, Match, Include, and similar keys. |
| 2.34.2 | X-Forwarded-Host is honored only from proxies in CODER_PROXY_TRUSTED_ORIGINS. | List every reverse proxy there. |
| 2.34.3 | API 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.7 | The client IP is taken from the rightmost untrusted X-Forwarded-For entry. | List every proxy hop in CODER_PROXY_TRUSTED_ORIGINS. |
| 2.34.8 | Sharing 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.9 | Workspace agents get 401 when the workspace owner is suspended or dormant. | Reactivate the owner. |
| 2.34.9 | Terraform 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.18 | Bundled 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.19 | Builds fail when an external app URL has an unsafe scheme, or no scheme or host. | Check external app URLs in your templates. |