# How to Upgrade

Source: https://agenta.ai/docs/self-host/upgrade-and-migrate/upgrading

This guide walks you through upgrading your self-hosted Agenta instance and applying any necessary database schema migrations. Choose the section that matches your deployment method.

## Understanding Agenta Versioning

Agenta follows semantic versioning with new releases every week. Stay updated by:
- Following our [GitHub repository](https://github.com/Agenta-AI/agenta) releases
- Reading our [changelog](https://agenta.ai/docs/changelog) for detailed updates

:::caution Upgrading an open source instance to the multi-organization release
The multi-organization release flips OSS from invite-only to open signup. If your instance is reachable beyond a trusted network, set `AGENTA_ACCESS_ALLOWED_OWNER_EMAILS` (and optionally `AGENTA_ACCESS_ALLOWED_DOMAINS`) before upgrading. See [Migrate to Multi-Organization OSS](https://agenta.ai/docs/self-host/upgrade-and-migrate/multi-org-migration.md).
:::

## Upgrading to 0.133.0: the LLM gateway is on by default

From this release, agent model calls go through the LLM gateway by default. The provider key stays in the API and never reaches the sandbox. The classic prompt playground and the completion and chat apps do not use the gateway and do not change.

Check each item that applies to your deployment:

- **The gateway stays off if your env file says so.** The env templates of earlier releases set `AGENTA_LLM_GATEWAY_ENABLED=false`. An env file with that line keeps the gateway off. To turn it on, set the line to `true` or remove it, then recreate the containers.
- **To turn the gateway off,** set `AGENTA_LLM_GATEWAY_ENABLED=false` in the env file, or `llmGateway.enabled: false` in your Helm values, and recreate the containers. Agents then read the provider key from the vault and put it into the sandbox.
- **The sandbox must reach the Agenta API, and the API must reach the model provider.** See [Network requirements for agent runs](https://agenta.ai/docs/self-host/reference/networking.md#network-requirements-for-agent-runs).
- **Daytona:** set `AGENTA_API_URL` to an address that a Daytona sandbox can reach, such as `https://agenta.example.com/api`. A `localhost` address stops every Daytona run before the sandbox starts. See [Make the Agenta API reachable from the sandbox](https://agenta.ai/docs/self-host/agents/daytona.md#5-make-the-agenta-api-reachable-from-the-sandbox).
- **Plain HTTP installs:** delete `AGENTA_GATEWAYS_INSECURE_HTTP_ALLOWED` from your env file; it is removed. Plain HTTP to the deployment's own `AGENTA_API_URL` needs no setting. Deploy the new runner image together with the new services image: an older runner refuses a plain HTTP gateway address on a LAN host.
- **Helm:** delete `gatewayEgress.insecureHttpAllowed` from your values file. The schema refuses the key, so `helm upgrade` fails while it is there.
- **Helm, custom provider on a private address** (for example Ollama or vLLM at `http://10.0.0.7:11434/v1`): set `gatewayEgress.insecureAllowed: true`. The chart leaves the egress guard on, so the gateway refuses private addresses. The example values files set it to `true`. The Docker Compose templates set `AGENTA_GATEWAYS_INSECURE_EGRESS_ALLOWED=true` already.
- **Helm with ingress-nginx and Daytona:** raise the read timeout of the gateway paths to 1820 seconds. See [Long model calls through an ingress](https://agenta.ai/docs/self-host/deploy/deploy-to-kubernetes.md#long-model-calls-through-an-ingress).
- **Docker Compose with your own copy of `nginx.conf`** (`--profile with-nginx`): copy the `/api/gateways/` location block from the new `hosting/docker-compose/oss/nginx/nginx.conf`. Without it, nginx cuts a model answer after 30 seconds of silence and limits the gateway calls from one address to 10 requests per second.
- **Custom providers:** if a run fails with `Open the provider <slug> in Settings and save it once.`, open that provider in **Settings**, then save it.
- **Several connections for one provider:** an agent that names no connection now fails when its project has more than one connection for the agent's provider. The run fails with `multiple connections for provider '<provider>' (<connections>); name one in the config`. Before this release, the agent used one of the connections. In the agent's model picker, choose the model under one of the connections.
- **Pi on Bedrock** runs only through the gateway. With the gateway off, a Pi agent on a Bedrock connection fails. An agent on Bedrock through the gateway needs a connection with a Bedrock API key.

## Upgrading to 0.133.0: API keys become personal keys and service accounts

This release splits API keys into two kinds. A personal API key acts as the member who made it. A service account key acts as an Agenta service account, a project member that is not a person. See [API keys and service accounts](https://agenta.ai/docs/administration/access-control/api-keys-and-service-accounts.md). The upgrade converts every existing key.

### Take a database dump first

The conversion moves and deletes keys. Its down migration is lossy: it removes the service accounts and the keys act as their creators again, but the keys the conversion deleted do not come back. Take a dump of your core database before you start the upgrade.

### What the conversion does

- For each person who has keys in a project, the upgrade creates one service account named `API keys of` followed by that person's email, with the description "Made from old API keys". It gets the person's role in the project, or Admin for the Owner. The person's keys in that project become keys of this service account. They keep their value and work as before.
- Keys whose creator no longer has access to the project (removed member, deleted user, no creator) are deleted.
- Hidden keys are deleted. Older releases made them for the app containers that version 0.36.4 removed, and the UI never showed them. A service account that holds only hidden keys is deleted with them. A hidden key or a service account that a schedule, a subscription, an evaluation or a session runs as is kept. The preview below still lists these keys and accounts, because a later step of the upgrade (revision `oss000000074`) deletes them.
- The migration prints its report in the migration log before it writes: per project, the service accounts it creates, the keys it moves, and each key it deletes with its prefix and creator.
- Personal API keys start empty. Members create them in **Settings** → **Personal API keys**.

### Preview the conversion

To see the report before you upgrade, restore the dump into a separate database, upgrade only that copy to revision `oss000000072` with the new API image, and run the preview script from the Agenta repository against it:

```bash
uv run api/scripts/service_accounts_preview.py --postgres-uri \
    postgresql+asyncpg://user:password@host:5432/agenta_ee_core
```

The script is read only. It prints the same report the migration prints.

### What changes for API keys

- Organization actions (invites, role changes, member removal, SSO and billing settings, organization credentials and licenses) accept a personal API key, with its member's role. They return `403` for a service account key, for a key that an old pod created during the rollout, and for an agent run. A converted key is a service account key, so a script that used an old key for these actions stops working: create a personal key for it.
- Your profile and API key management also accept only a personal API key or a browser session. A script that reads your profile or creates keys with an old key stops working: create a personal key for it.
- A converted key keeps working after the person who made it leaves the project, because it belongs to their `API keys of` service account. When a person leaves, delete that service account in **Settings** → **Service accounts** to stop their old keys.
- A service account key can set up Slack and Telegram connections and choose the agents that answer in them. It cannot link a Telegram account to a person. A sender who is not linked to an Agenta user acts with the service account's role.
- Automations, schedules and evaluations that an old key created keep running as the key's service account.

### During a rolling upgrade

- A key that an old pod creates during the rollout acts as its creator, as keys did before. The next release converts these keys too.
- An old pod pauses an automation that a new pod saved with a service account key, with the reason `missing_principal`. After the upgrade, resume the automations paused for this reason since the upgrade started. The new pods read their service-account principal, so the resume succeeds. An automation whose principal is gone (a deleted user or service account) stays paused; save it as an active member or service account first.

## Upgrading past 0.131.3: the `web` service is removed

The release after 0.131.3 removes the `web` service (image `agenta-web`), the old desktop web app. The `web-mobile` service (image `agenta-web-mobile`) is now the only web app. It answers every path that the API and services do not: `/` redirects to `/m`, and old desktop links (`/w/...`, `/auth/...`, links in emails and in traces logged by older SDKs) redirect to the matching `/m` page. The API, workers, services, runner and databases do not change.

If you deploy with the compose files or the Helm chart from this repository, and every image runs the same tag, upgrade as usual. On Railway, upgrade with `deploy-from-images.sh`. Read on only for the deployment you run.

### Docker Compose

`run.sh` removes the old `web` container on its own. If you start the stack with `docker compose` directly, add `--remove-orphans` once so the old container stops:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh --profile with-traefik up -d --remove-orphans
```

Without `--remove-orphans`, the old `web` container keeps running, because the new compose file no longer lists it. The bundled Traefik still sends `/` and `/m` to `web-mobile`, so the new app opens. The old container uses memory, and with your own Traefik rules it can answer `/` and `/m` with the old app. To remove it, run the command above again, or remove the container by name. For example, on the open source compose file:

```bash
docker rm -f agenta-oss-gh-web-1
```

To list the container names of your stack, run `ps --all` with the same compose file and env file:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh ps --all
```

If you keep your own compose file or reverse proxy, update the compose file and the `agenta-web-mobile` tag in the same change:

- Delete the `web` service.
- Route every path that `/api` and `/services` do not claim to `web-mobile` on port `3000`. Do not strip a prefix: the app owns `/m`.
- Set `agenta-web-mobile` to the new release tag. An older `agenta-web-mobile` image does not answer `/`, so the root returns `404` until both change.
- If your proxy routes a store host to SeaweedFS (`AGENTA_STORE_TRAEFIK_ENABLE=true` with `AGENTA_STORE_DOMAIN`), keep that route above the new catch-all. With Traefik, set the same priorities as the compose files in this repository: `3000` on the store router, `2000` on the `api` and `services` routers, and `1000` on `web-mobile`. For example, on the `seaweedfs` service:

  ```yaml
  labels:
      - "traefik.http.routers.store.rule=Host(`${AGENTA_STORE_DOMAIN:-store.localhost}`)"
      - "traefik.http.routers.store.priority=3000"
  ```

  Without an explicit priority, Traefik ranks the store router by the length of its rule, which is below `1000`, so the store host answers with the web app. The `api` and `services` routers match their paths on every host, so a store request under `/api/` or `/services/` also needs the store router above `2000`. Agent sessions then start without their session folder and drive, and the API logs `xml.etree.ElementTree.ParseError` with a `500` on `/sessions/mounts/sign`.

### Helm

`helm upgrade` deletes the `web` Deployment and Service. `ingress.paths.web` keeps its name and its `pathType`, and now routes `/` to `web-mobile`. A top-level `web` block in your values file is ignored, so the upgrade does not fail on it. Two keys under `web` need a move to keep their effect:

- `web.service.annotations`, for example the GKE `cloud.google.com/neg` annotation, goes to `webMobile.service.annotations`.
- `web.image.tag` goes to `webMobile.image.tag` if you pin image tags.

### Railway

`deploy-from-images.sh` now requires `AGENTA_WEB_MOBILE_IMAGE` and no longer reads `AGENTA_WEB_IMAGE`:

```bash
export AGENTA_API_IMAGE="ghcr.io/agenta-ai/agenta-api:<new-tag>"
export AGENTA_WEB_MOBILE_IMAGE="ghcr.io/agenta-ai/agenta-web-mobile:<new-tag>"
export AGENTA_SERVICES_IMAGE="ghcr.io/agenta-ai/agenta-services:<new-tag>"
export AGENTA_RUNNER_IMAGE="ghcr.io/agenta-ai/agenta-runner:<new-tag>"

./hosting/railway/oss/scripts/deploy-from-images.sh
```

`upgrade.sh` redeploys `web-mobile` from `hosting/railway/oss/web-mobile/Dockerfile`, which starts from the `latest` image. Use `deploy-from-images.sh` to pin every service to the same tag.

The gateway now sends `/` to `web-mobile`. The scripts do not delete the `web` service. It keeps running with no route to it. Delete it in the Railway project when you no longer need to roll back.

### Roll back

- **Docker Compose:** restore the compose file and image tags of the previous release, then start the stack with them. If you use your own compose file, restore its `web` service and its route to `/`.
- **Helm:** run `helm rollback agenta --namespace agenta` to the previous revision (use the namespace of your install). It recreates the `web` Deployment and Service and the `/` route to them.
- **Railway:** check out the previous release of this repository and run its `deploy-from-images.sh` with the previous image tags, including `AGENTA_WEB_IMAGE`. Its gateway routes `/` to `web` again.

## Upgrading to 0.131.1: one image for every install

From this release, open source and Enterprise installs run the same API, services and runner images, under the public names `ghcr.io/agenta-ai/agenta-api`, `agenta-services` and `agenta-runner`. A [license key](https://agenta.ai/docs/self-host/reference/license-keys.md) decides the plan. Without a key, an instance is on the Community plan, with the [limits by plan](https://agenta.ai/docs/self-host/reference/license-keys.md#limits-by-plan). See [Editions](https://agenta.ai/docs/misc/opensource.md) for what each plan gives.

### Take a database dump first

On an open source database, the first start adds tables and rows, and this cannot be undone in place. Take a dump of your core and tracing databases before you start the upgrade. To go back, restore the dump and deploy the images you ran before the upgrade.

### Upgrade

Pull the new images and restart, as in the [standard upgrade](#standard-upgrade-process) or the [Helm chart upgrade](#helm-chart-upgrade). Keep your compose files, Helm values and Railway template as they are. You do not change images, env files or databases.

Do not change or remove `AGENTA_LICENSE`. It picks the default database names (`agenta_oss_*` or `agenta_ee_*`), not the plan. A different value, or no value, can point the install at other, empty databases.

### What the first start does on an open source database

The migration job:

1. Reads the version of the core database, and stops if it is older than v0.104.0 (see below).
2. Runs the shared migrations.
3. Writes a project membership row for every member in every project of their organization. The open source code gave every organization member every project. The full schema checks access per project, so these rows keep every member's access as it was.
4. Adds the Enterprise tables, and one subscription for each organization.
5. Runs the tracing migrations.

If the job stops partway, the next start runs the steps that did not finish. You do not run `entrypoints.memberships_check --materialize` yourself.

On an Enterprise database, the job runs the new migrations only, and writes no membership rows.

If your env file sets `ALEMBIC_AUTO_MIGRATIONS=false`, the job skips the membership rows and the Enterprise tables at start. Run the [manual migration command](#manual-migration-process) once before people use the instance.

### Installs older than v0.104.0

The migration job cannot upgrade a database older than v0.104.0. It stops before it changes anything and logs:

```text
The core database is at legacy revision <revision>, which is older than v0.104.0. This image cannot upgrade it. Upgrade to v0.129.x first, then start this version. If this is a new install whose first start was interrupted, delete its databases and start again.
```

Upgrade to the latest 0.129.x release, let its migrations finish, then upgrade to 0.131.1.

### The limits apply to new projects and organizations only

Without a key, the instance runs on the Community plan. Projects and organizations that exist before the upgrade stay. The [limits by plan](https://agenta.ai/docs/self-host/reference/license-keys.md#limits-by-plan) apply to new projects and organizations. See [Upgrade an open source instance](https://agenta.ai/docs/self-host/reference/license-keys.md#upgrade-an-open-source-instance) for the full list of changes.

The first time the instance admin opens the app after the upgrade, the app offers to register the instance for a free key, once. **Skip** hides the offer for the whole instance. You can register later from **Settings > License**.

### Enterprise: images

The Enterprise compose files and Helm chart now pull the public API, services and runner images. The Enterprise compose files still pull the private Enterprise build of the classic web app (`ghcr.io/agenta-ai/internal-ee-agenta-web`). The Helm chart pulls the public `ghcr.io/agenta-ai/agenta-web` for both licenses, so an EE Helm install needs no pull secret. To keep the private build on Helm, set `web.image.repository`. The private `internal-ee-agenta-api`, `internal-ee-agenta-services` and `internal-ee-agenta-runner` names still receive the same images, so older compose files and values keep working.

## Upgrading to 0.128.2: old workspace ids stop working

This release stops reading the old workspace data. The tables stay in the database until a later release drops them. It adds two data migrations: one for projects, one for usage meters (Enterprise). Both repeat the 0.127.0 migrations for data that 0.126.0 pods wrote during that upgrade.

### Take a database dump first

The two data migrations change data in one direction and have no down migration. Take a dump of your core database before you start the upgrade.

### Upgrade from 0.127.0

Run 0.127.0 on every pod before you start 0.128.2. A rolling upgrade from 0.126.0 or older is not supported. To go back to 0.127.0, set `ALEMBIC_AUTO_MIGRATIONS=false` (in Helm, `alembic.autoMigrations: false`) and deploy the 0.127.0 images; 0.127.0 reads the data that 0.128.2 leaves. One exception: 0.128.2 no longer deletes the old workspace membership of a member it removes, and 0.127.0 still reads those rows. Before 0.127.0 serves traffic, run once:

```sql
DELETE FROM workspace_members wm USING workspaces w
WHERE w.id = wm.workspace_id
  AND NOT EXISTS (
    SELECT 1 FROM organization_members om
    WHERE om.organization_id = w.organization_id AND om.user_id = wm.user_id
  );
```

### Old workspace ids are unknown ids

Since 0.127.0, the API answers the organization id where it answered a workspace id. From 0.128.2, it also accepts only the organization id there. A request with `?workspace_id=<old workspace id>` returns `401`. A bookmark with an old workspace id in the URL still opens: the app replaces that id with the organization id. An invitation link with an old workspace id is refused as an unknown invitation; invitations expire after 7 days, so links sent before 0.127.0 have expired if 0.127.0 ran for a week. The admin API answers `404` for an old workspace id.

### Each organization keeps one default project

The upgrade again keeps one default project per organization, by the same rule as 0.127.0. A browser request without `project_id` opens the default project of the user's oldest organization membership.

### Enterprise: split daily counts are merged

The upgrade adds the per-user traces-retrieved counts that 0.126.0 pods wrote in a separate bucket during the 0.127.0 upgrade into the user's count. As in 0.127.0, the migration waits for a running usage report to finish (up to 15 minutes) and blocks new reports while it runs. Billed meters do not change.

## Upgrading to 0.127.0: workspaces are removed

This release stops creating workspaces. The API answers the organization id wherever it answered a workspace id. It adds two data migrations: one for projects, one for usage meters (Enterprise).

### Take a database dump first

The two data migrations change data in one direction and have no down migration. Take a dump of your core database before you start the upgrade. To undo the data changes, restore that dump.

### Downgrade to 0.126.0

To go back to 0.126.0, first set `ALEMBIC_AUTO_MIGRATIONS=false` (in Helm, `alembic.autoMigrations: false`). The 0.126.0 migration job does not know the new revisions and fails, which stops the API from starting. Then deploy the 0.126.0 images. The data stays as 0.127.0 left it, and 0.126.0 reads it, with one exception in Enterprise: 0.126.0 pods count a user's traces retrieved in a separate bucket, so that daily count can be split between the two buckets. Turn `ALEMBIC_AUTO_MIGRATIONS` back on when you upgrade again.

### Upgrade from 0.126.0

Run 0.126.0 on every pod before you start 0.127.0. The rolling upgrade was tested from 0.126.0. Pods of 0.125.0 can also read the new data. A rolling upgrade from 0.124.x or older is not supported: those pods cannot read projects and organizations without a workspace.

### The API answers the organization id

Where a response carries a workspace id (`workspace_id` in projects, `workspaces` in organizations, `default_workspace` in organization details, the items of `GET /workspaces/`), it now carries the organization id, and a workspace name is the organization name. Member lists in organization details carry each member's organization role. Links in invitation and notification emails carry the organization id. Routes still accept a workspace id of the same organization in place of the organization id.

### Workspace create and rename return 410

`POST /organizations/{organization_id}/workspaces/` and `PUT /organizations/{organization_id}/workspaces/{workspace_id}` return `410` with `Workspaces were removed. Projects belong to the organization.` and change nothing.

### Each organization keeps one default project

The upgrade keeps one default project per organization: the default project of the organization's `default` workspace, else of its oldest workspace. Other projects of the organization lose their default flag. Project access does not change. An API key or run credential of the kept default project can act on organization settings, as the default project's keys could before; a key of a project that lost the flag can no longer do so. A project whose workspace belonged to another organization stays in its own organization and loses that workspace.

### Enterprise: per-user quotas during the upgrade

The usage meters of the per-user traces-retrieved quota are re-keyed without the workspace. The counts carry over. While 0.126.0 pods still run next to the new ones, those pods count a user's traces retrieved that day in a separate bucket, so the user's daily count can be split between the two until the 0.126.0 pods are gone; a later release merges the buckets. Billed meters do not change. The migration waits for a running usage report to finish (up to 15 minutes) and blocks new reports while it runs.

An operator plan override with `"scope": "workspace"` now means the organization scope; the API logs one warning when it loads such an override. The upgrade adds the counts such an override wrote to the organization count.

## Upgrading to 0.125.0

This release changes where new mounts store their files and prepares the removal of workspaces. It adds two database migrations.

### Upgrade from 0.124.0

Finish the upgrade to 0.124.0 on every pod before you start 0.125.0. Pods older than 0.124.0 compute mount paths from the project and cannot read mounts that 0.125.0 creates, and their mount creations fail until they are replaced. A Helm rolling upgrade straight from 0.123.x or older can therefore fail some mount creations and miss some files until all old pods are gone. Docker Compose is not affected.

### New mounts store their files under the organization

New mounts store their files under `mounts/<organization_id>/<mount_id>`. Mounts created before 0.125.0 keep `mounts/<project_id>/<mount_id>`. Nothing is copied or moved.

### Deleting a workspace row in the database keeps its projects

Deleting a workspace row directly in the database no longer deletes its projects. The admin API still deletes a workspace's projects with the workspace. During the rolling upgrade, a workspace that a 0.124.0 pod deletes through the admin API keeps its projects.

### The API accepts the organization id where it accepts a workspace id

Routes and query parameters that take a workspace id also accept the organization id, and a workspace id of the same organization. Creating and renaming a workspace still need a workspace id. Responses for existing data do not change, with two exceptions. A member who has no workspace membership row now sees one item with the organization id in the workspace list. A browser request without `project_id` (with or without `workspace_id`) now needs membership in the default project it opens; a workspace membership row alone no longer gives access.

## Upgrading to 0.124.0

This release changes who can open a project, makes every run act as a named user, API key or installation, and adds five database migrations. Read the subsections for your edition.

### Open source: organization members see every project

Every organization member is now a member of every project in the organization, with their organization role. Before, a member saw only the projects where they had a project membership. A role change now sets the organization role. Roles change only through the API for now; the app has no control for it yet.

### Project create, rename and delete need a permission

Creating and renaming a project needs the owner or admin role. Deleting a project needs the owner role. A user without the permission gets `403` with `You do not have permission to perform this action. Please contact your Organization Owner`. In an Enterprise organization whose plan has no role-based access control, every member can still create, rename and delete projects, as before.

### `AGENTA_DEMOS` is removed

`AGENTA_DEMOS` and `AGENTA_EXTRAS_DEMOS` no longer exist, and new signups are not added to demo projects. The upgrade deletes the existing demo project memberships. A user who joined an organization only through its demo projects also loses that organization and workspace membership. A user with any other project membership in the organization keeps it. Delete them from your env file. In Helm values, delete `agenta.extras` (the chart schema no longer accepts it).

### Enterprise: run the preflight before the upgrade

The upgrade adds a unique index on project memberships. It stops when the database holds two membership rows for the same user and project. Before you upgrade, run the preflight from a checkout of the new release, with `POSTGRES_URI_CORE` set to your core database. In 0.124.0 the preflight reads `AGENTA_LICENSE` to run the Enterprise steps, so keep `AGENTA_LICENSE=ee` in this command:

```bash
cd api
export POSTGRES_URI_CORE=postgresql+asyncpg://username:password@localhost:5432/agenta_ee_core
AGENTA_LICENSE=ee uv run --no-sync python -m entrypoints.memberships_check --apply
```

It deletes the newer row of each duplicate pair, keeps the oldest, and prints each deleted row with its role. Demo rows (`is_demo`) are not part of this step; the upgrade deletes them. It also adds the project rows that members of an organization without the RBAC entitlement need. It adds these rows only before the upgrade: after the upgrade has run, `--apply` skips this step and says so. To see what it would change first, run it with `--report` instead of `--apply`; that writes a `report.json` and changes nothing.

If the upgrade stops with `project_members has <n> duplicate (project_id, user_id) groups`, run the `--apply` command above, then run the upgrade again.

### Open source: if the upgrade stops on duplicate memberships

The same unique index is added on open source. If the upgrade stops with `project_members has <n> duplicate (project_id, user_id) groups`, run the preflight from a checkout of the new release, with `POSTGRES_URI_CORE` set to your core database, then run the upgrade again:

```bash
cd api
export POSTGRES_URI_CORE=postgresql+asyncpg://username:password@localhost:5432/agenta_oss_core
uv run --no-sync python -m entrypoints.memberships_check --apply
```

It keeps the oldest row of each duplicate pair and prints each deleted row with its role. Use `--report` first to see what it would change.

### API keys act only in their own project

An API key now acts only in the project it belongs to. A request with the key to another project, such as `PATCH /projects/{id}` or `DELETE /projects/{id}`, returns `403`. Before, the key used its creator's role in the other project. Browser sessions do not change.

Workspace and organization management with an API key (invite, resend invite, role change, member removal, workspace update) needs a key of the workspace's default project. A key of another project in that workspace returns `403`.

### Automations and evaluations run as the user or key that started them

A schedule or subscription runs as the user or API key that created it. When that user leaves the project, loses the role, or is deleted, or the key is deleted, the next run is refused and the automation is paused with the reason. To run it again, create it again under an active user or API key. The upgrade pauses schedules and subscriptions that have no creator.

Archiving an agent pauses its schedules and subscriptions. Unarchiving does not resume them.

An evaluation runs as the person or key that started it, and a rerun runs as the person who started the rerun.

### Deploy the API, workers and services together

Upgrade the API, the workers and the services to the same release at the same time. The services check the new run credentials. With old services, a refused run fails with a `500` instead of `403 access_denied`.

### Work in progress during the upgrade

Messages queued and approvals waiting when the upgrade runs are cancelled once. Send the message or answer the approval again. A run that was in progress fails once. While the `oss000000046` migration runs, agent sends can wait up to about 30 seconds.

## Upgrading to 0.121.0

This release removes a set of environment variables and a Helm key, makes the mobile app (`/m`) part of every deployment, and changes three API behaviors. Read each subsection that matches your deployment. The standard upgrade process below still applies.

### Removed environment variables

The variables below no longer exist. Agenta ignores them, and the behavior in the right column is always on. If your env file, Helm values or Railway variables set one of them, delete it. The change affects you only if you had set one to `false`; at its default each one already behaved as described.

| Variable                                      | Behavior that is now always on                                                                                                                                                    |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `AGENTA_MOBILE_GATE`                          | A phone that opens a desktop route is redirected to `/m`. A user with **Developer Mode** off (in **Settings > Preferences**) is also sent to `/m` for the pages that exist there. |
| `AGENTA_MOBILE_REVERSE_GATE`                  | A desktop browser may open `/m`. It is not sent back to `/w`.                                                                                                                     |
| `AGENTA_MOBILE_ENABLED`                       | The `web-mobile` service runs on every deployment. See [The mobile app always ships](#the-mobile-app-always-ships).                                                               |
| `AGENTA_SESSIONS_QUEUE`                       | Agent messages go through the durable session queue. A message sent while a turn runs is queued instead of refused.                                                               |
| `AGENTA_SESSIONS_STEER`                       | A message sent while a turn runs can be delivered into that turn.                                                                                                                 |
| `AGENTA_SESSIONS_DURABLE_APPROVALS`           | Approval requests are stored in the database. Answering one through the API needs an `Idempotency-Key` header (see [API behavior changes](#api-behavior-changes)).                |
| `AGENTA_SESSIONS_DURABLE_STOP`                | **Stop** is stored as a durable command and delivered to the runner.                                                                                                              |
| `AGENTA_RECORDS_DURABLE`                      | The runner retries a failed session record write.                                                                                                                                 |
| `AGENTA_RECORDS_SMART_TRUNCATION`             | A session record that is too large is truncated with its structure kept, instead of losing its body.                                                                              |
| `AGENTA_SESSIONS_RECONSTRUCT`                 | The runner rebuilds the conversation history of a turn from the stored session records.                                                                                           |
| `NEXT_PUBLIC_SESSIONS_LAST_MESSAGE_ONLY`      | The web app sends only the newest message of each turn. The runner rebuilds the rest (see the previous row).                                                                      |
| `NEXT_PUBLIC_AGENT_CHAT_SLICE`                | The streaming agent chat page is used.                                                                                                                                            |
| `NEXT_PUBLIC_AGENT_TEMPLATE_BUILDER`          | Choosing an agent template opens the playground with the template loaded.                                                                                                         |
| `NEXT_PUBLIC_AGENT_PLAYGROUND_ONBOARDING`     | Agent onboarding runs inside the playground.                                                                                                                                      |
| `NEXT_PUBLIC_AGENT_FILE_UPLOADS`              | File attachments in the agent chat and uploads in the file drive are shown. They need the [durable object store](https://agenta.ai/docs/self-host/reference/configuration.md#store-durable-object-store).            |
| `NEXT_PUBLIC_AGENT_CONNECT_STEP`              | Creating an agent from the start page first asks the user to connect the accounts the agent needs.                                                                                |
| `AGENTA_WORKFLOWS_ORDERED_OPERATIONS_ENABLED` | Workflow commits accept ordered operations. A commit that leaves the configuration unchanged creates no new revision.                                                             |

The runner rebuilds history from the records that the `records` loop of `worker-streams` stores. If you run `worker-streams` with an explicit `AGENTA_WORKER_STREAMS` list, make sure one instance includes `records`, or agents lose the earlier turns of a conversation.

### The mobile app always ships

The mobile web app is served at `/m` and has no off switch. The web app redirects phones to it, so `/m` must be reachable on every deployment.

#### Docker Compose

The `web-mobile` service starts with the stack. `run.sh --no-mobile` is removed, and `run.sh` stops with `Unknown parameter` if a script still passes it. Do not scale `web-mobile` to zero: phones would be redirected to a route with nothing behind it.

If you run your own reverse proxy instead of the bundled Traefik or nginx, route `/m` and every path under `/m/` to the `web-mobile` service on port `3000`, before the catch-all route to `web`.

#### Helm

The `webMobile.enabled` key is removed, and the `web-mobile` Deployment always renders. `webMobile.enabled: false` in a values file now fails schema validation, so `helm upgrade` stops. `webMobile.enabled: true` is accepted and does nothing. Delete the key from your values file before you upgrade.

#### Railway

`bootstrap.sh` now always creates the `web-mobile` service, and `AGENTA_RAILWAY_WITH_MOBILE` is ignored. An environment bootstrapped without mobile has no `web-mobile` service, and `configure.sh` stops with `Service 'web-mobile' is missing`. Both `deploy-from-images.sh` and `upgrade.sh` run `configure.sh`, so both stop.

Re-run the bootstrap script first, against the same project and environment as the deployment. It is idempotent and only adds what is missing. The project and environment default to the `staging` environment of `agenta-oss-railway`, and the new service gets `AGENTA_WEB_MOBILE_IMAGE` (default `latest`), so set all three:

```bash
export RAILWAY_PROJECT_NAME="agenta-oss"
export RAILWAY_ENVIRONMENT_NAME="production"
export AGENTA_WEB_MOBILE_IMAGE="ghcr.io/agenta-ai/agenta-web-mobile:v0.121.0"

./hosting/railway/oss/scripts/bootstrap.sh
```

Then deploy with `deploy-from-images.sh`, with every image at the same tag. It requires `AGENTA_WEB_MOBILE_IMAGE`. `upgrade.sh` redeploys `web-mobile` from `hosting/railway/oss/web-mobile/Dockerfile`, which starts from the `latest` image.

```bash
export AGENTA_API_IMAGE="ghcr.io/agenta-ai/agenta-api:v0.121.0"
export AGENTA_WEB_MOBILE_IMAGE="ghcr.io/agenta-ai/agenta-web-mobile:v0.121.0"
export AGENTA_SERVICES_IMAGE="ghcr.io/agenta-ai/agenta-services:v0.121.0"
export AGENTA_RUNNER_IMAGE="ghcr.io/agenta-ai/agenta-runner:v0.121.0"

./hosting/railway/oss/scripts/deploy-from-images.sh
```

### Channels

Channels connect an agent to Slack or Telegram. They need no feature flag on the server. Six environment variables are optional and turn on the hosted integrations, where users connect without creating their own Slack app or Telegram bot:

| Variable                                                                                      | Hosted integration                                                                                                                            |
| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `SLACK_CLIENT_ID`, `SLACK_CLIENT_SECRET`, `SLACK_SIGNING_SECRET`                              | The hosted Slack app install. It stays off until all three are set.                                                                           |
| `TELEGRAM_HOSTED_BOT_TOKEN`, `TELEGRAM_HOSTED_BOT_USERNAME`, `TELEGRAM_HOSTED_WEBHOOK_SECRET` | The shared Telegram bot. It stays off until all three are set. See [Set up the hosted Telegram bot](https://agenta.ai/docs/self-host/channels/telegram-hosted-bot.md). |

Without them, users can still connect their own Slack app or Telegram bot. The variables and where to set them are listed in [Channels](https://agenta.ai/docs/self-host/reference/configuration.md#channels).

Channel replies are sent by the `sessions` loop of `worker-streams`. Run that loop in exactly one `worker-streams` replica. With two or more, a progress update can overwrite a final reply, and a Telegram reply can arrive twice. The Helm chart and the Compose files run one replica by default. On Helm, a rolling update briefly runs the old and the new pod together. To avoid that overlap, set `workerStreams.strategy.type: Recreate`; `worker-streams` then stops for a few seconds during each upgrade.

If you run the workers with explicit selectors, add the two new loops: `sessions` to one `AGENTA_WORKER_STREAMS` list and `channels-inbox` to one `AGENTA_WORKER_QUEUES` list. An empty selector already runs every loop.

On Enterprise Edition, the default roles include the new permissions `view_channels`, `edit_channels` and `run_channels`. If you replace the role catalog with [`AGENTA_ACCESS_ROLES`](https://agenta.ai/docs/self-host/access-control/dynamic-access-controls.md), add them to your roles, or members without them get `403` on Channels.

### API behavior changes

- **An app-only reference to an archived app returns `410`.** An invoke that names an archived application by its id alone, with no variant or revision reference and no inline configuration, now fails with status `410` and a `status.type` ending in `#v0:references:archived`. Before, it ran. Unarchive the application, or point the caller at a live one. Invokes that name a variant or revision, or carry an inline configuration, still run on an archived application, as before; see [#7110](https://github.com/Agenta-AI/agenta/issues/7110).
- **Answering an interaction needs an `Idempotency-Key` header.** `POST /api/sessions/interactions/{interaction_id}/respond` returns `422` without the header and `202` with a continuation body on success. See [Invoke an agent](https://agenta.ai/docs/reference/agents/manage-sessions.md#interactions).
- **Posting to the Agenta channel needs the `run_channels` permission.** On Enterprise Edition, an API key whose owner has the viewer or annotator role can no longer post to the Agenta channel of an agent.

## Upgrading to 0.119.0

This section applies if your projects use MCP servers, or if you plan to add one. Skip it otherwise, and follow the standard upgrade process below.

### What changed

Before 0.119.0, an agent's sandbox called an MCP server directly. Since 0.119.0, every MCP call an agent makes goes to the api container, which relays it to the server. The server's credential stays on your deployment instead of travelling into the sandbox. `AGENTA_MCP_GATEWAY_ENABLED` controls the relay and defaults to `true`.

Because the api container now makes the call, the relay's own outbound guard decides which MCP servers an agent can reach. That guard is a separate setting from the one that governs webhooks.

### Add the new settings to your env file

An upgrade reuses your existing `.env` file, which has none of the new lines, so your deployment runs on the code defaults. Those defaults refuse an MCP server that is on a private network or answers over plain HTTP. The env templates shipped with 0.119.0 set them permissively instead, so a fresh install and an upgraded install behave differently until you add the lines yourself.

If an MCP server in one of your projects is on `http://` or on a private address, add this to your env file:

```bash
# Let the relay call MCP servers on plain HTTP and on private addresses.
# Code default: false. The 0.119.x env templates ship true.
AGENTA_GATEWAYS_INSECURE_EGRESS_ALLOWED=true
```

On a deployment where people you do not trust can create MCP connections, leave `AGENTA_GATEWAYS_INSECURE_EGRESS_ALLOWED` at `false` and name the servers you want reachable with `AGENTA_MCP_GATEWAY_HOST_ALLOWLIST` instead. Both postures are set out in [Use an MCP server on a private network or over plain HTTP](https://agenta.ai/docs/self-host/agents/tools-and-triggers.md#use-an-mcp-server-on-a-private-network-or-over-plain-http).

Containers read the env file at start, so recreate them after editing it:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml \
  --env-file hosting/docker-compose/oss/.env.oss.gh \
  --profile with-traefik up -d --remove-orphans
```

For Helm, set `gatewayEgress.insecureAllowed` in your values file. The chart leaves it unset, so an upgrade that touches no values file keeps the code default and the guard stays on. The chart renders the key you set into the containers that read it. See [Agenta gateways](https://agenta.ai/docs/self-host/reference/configuration.md#agenta-gateways).

Two more things change for Helm in this release. The chart now implements all five gateway keys, so a key you added under `api.extraEnv`, `services.extraEnv` or `agentRunner.extraEnv` to work around their absence now duplicates the one the chart renders. Remove the `extraEnv` copy. And the schema now rejects an unknown key under `mcpGateway`, `llmGateway`, `gatewayEgress` or `gatewayCredentials`, where 0.119.0 accepted and ignored it, so `helm upgrade` fails on a typo it used to swallow. For the same reason a real key that used to do nothing now takes effect: if you set `mcpGateway.enabled: false` against 0.119.0 and saw no change, it now turns the MCP gateway off.

### Saving an MCP server URL on 0.119.0

This applies only while you are on 0.119.0. In that version, the check that runs when someone saves a custom MCP server URL reads `AGENTA_INSECURE_EGRESS_ALLOWED`, the setting that governs webhooks, rather than the gateway setting above. The two production templates, `env.oss.gh.example` and `env.ee.gh.example`, set it to `false`, so on such a deployment a plain-HTTP or literal-private-IP URL is refused with a `400`:

```text
endpoint.data.route.base_url is invalid: URL must use https.
endpoint.data.route.base_url is invalid: URL resolves to a blocked IP range.
```

From 0.119.1, that check follows `AGENTA_GATEWAYS_INSECURE_EGRESS_ALLOWED`, the same setting the relay uses at call time. Upgrade to 0.119.1 rather than setting `AGENTA_INSECURE_EGRESS_ALLOWED=true`: that variable has no effect on MCP saves from 0.119.1, and setting it widens what webhooks, workflow hooks, custom model provider endpoints and OIDC issuer probes may reach. If you set it to `true` on 0.119.0 for this reason alone, set it back after upgrading.

A server that is already saved keeps working. This check runs only when a URL is saved.

### Before rolling back below 0.119.0

Migration `oss000000030` adds two labels, `OAUTH_PROVIDER` and `OAUTH_GRANT`, to the Postgres enum behind the `kind` column of the `secrets` table. A version before 0.119.0 does not know those labels, and listing a project's secrets reads every row, so one row of either kind makes the whole list fail with a server error. That takes down the playground's provider key list for the project, not just the MCP screens.

PostgreSQL cannot remove a value from an enum once it is added, and running the migration's own downgrade does not remove it either. A schema rollback alone does not fix this.

If any project completed an MCP OAuth connection while you were on 0.119.0 or later, delete those rows before rolling back:

```sql
DELETE FROM secrets WHERE kind IN ('OAUTH_PROVIDER','OAUTH_GRANT');
```

Through Docker Compose:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml \
  --env-file hosting/docker-compose/oss/.env.oss.gh exec -T postgres \
  psql -U username -d agenta_oss_core \
  -c "DELETE FROM secrets WHERE kind IN ('OAUTH_PROVIDER','OAUTH_GRANT');"
```

Those rows are the stored OAuth registrations and tokens for MCP connections. Deleting them ends those connections. Reconnect each affected MCP server after you upgrade again.

## Standard Upgrade Process

For most upgrades, follow these steps to update your Agenta instance:

### 1. Update the Files in Your Clone

A release can change the compose files, for example 0.121.0 added the mobile app service. In the folder where you cloned Agenta, get the newest files:

```bash
git pull
```

### 2. Pull the Latest Images

Download the newest version of all Agenta Docker images:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh pull
```

### 3. Restart Services

Restart all services with the updated images:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh --profile with-traefik up -d --remove-orphans
```

:::info
This method will cause a brief downtime while services restart. For production environments, consider the zero-downtime upgrade approach below.
:::

## Zero-Downtime Upgrade

For production environments where uptime is critical, use this approach to upgrade without service interruption.

### Prerequisites

Install [docker rollout](https://github.com/wowu/docker-rollout) for rolling updates

### Upgrade Steps

**1. Pull Latest Images**

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh pull
```

**2. Apply Database Migrations**

Before updating services, apply any database schema changes. This runs the `alembic` migration job once, from the image you just pulled:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh run --rm -e ALEMBIC_AUTO_MIGRATIONS=true alembic
```

Use the compose file and env file of your deployment. On an Enterprise install, they are `hosting/docker-compose/ee/docker-compose.gh.yml` and `hosting/docker-compose/ee/.env.ee.gh`.

**3. Rolling Update Services**

Update each service individually to maintain availability:

```bash
# Update core services one by one
docker rollout -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh api
docker rollout -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh services
docker rollout -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh web-mobile
# Background workers run as two consolidated kinds by default:
#   worker-streams = records + events + spans
#   worker-queues  = webhooks + triggers + interactions + evaluations
docker rollout -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh worker-streams
docker rollout -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh worker-queues
```

Each command will:
- Scale the service to double the current instances
- Wait for new containers to be ready
- Remove old containers once new ones are healthy

## Helm Chart Upgrade

:::warning One-time migration from pre-v0.100.3 to v0.100.3
v0.100.3 relocated the Helm chart (from `hosting/helm/agenta-oss/` to `hosting/kubernetes/helm/`), reshaped the `values.yaml` keys, and renamed many env vars. If you are upgrading **across** that boundary, follow [Migrate to v0.100.3 (Helm chart relocation + config reshape)](https://agenta.ai/docs/self-host/upgrade-and-migrate/v0.100.3-migration.md) once, then resume using this section for subsequent upgrades.
:::

If you deployed Agenta on Kubernetes using the Helm chart, the chart is a folder in your clone. Get the newest chart first, then upgrade:

```bash
git pull
helm upgrade agenta hosting/kubernetes/helm \
  --namespace agenta \
  -f hosting/kubernetes/oss/.values.oss.yaml
```

Database migrations run automatically as a post-upgrade hook. Check the migration job status:

```bash
kubectl -n agenta get jobs -l app.kubernetes.io/component=alembic
kubectl -n agenta logs job/agenta-alembic
```

To pin to a specific version, set the image tags in your `values.yaml`:

```yaml
api:
  image:
    tag: "v0.132.0"
webMobile:
  image:
    tag: "v0.132.0"
services:
  image:
    tag: "v0.132.0"
```

For full details, see the [Deploy on Kubernetes](https://agenta.ai/docs/self-host/deploy/deploy-to-kubernetes.md#upgrade) guide.

## Database Schema Migrations

### PostgreSQL major-version upgrade

Agenta's Docker Compose deployment pins PostgreSQL to major version 17. The Helm chart pins the bundled PostgreSQL image to major version 18. If your existing Docker Compose deployment was created with an older major version, do not upgrade by only changing the image tag while reusing the same Postgres data volume.

PostgreSQL data directories are tied to the major version that created them. A newer major version container cannot start against an older major version data directory. Use a backup and restore flow instead.

#### Docker Compose

These commands use the default OSS Compose files from the self-host quick start.

Check the current Postgres version:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh exec postgres \
  psql -U username -d postgres -c "SHOW server_version;"
```

Create a logical backup and confirm the file is not empty:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh exec -T postgres \
  pg_dumpall -U username > agenta-postgres-17-backup.sql
ls -lh agenta-postgres-17-backup.sql
```

Stop the stack:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh down
```

Find the existing Postgres volume, keep a copy, then remove the original so Compose can create a fresh volume for the new version:

```bash
docker volume ls | grep postgres

POSTGRES_VOLUME=<postgres-volume-name>
POSTGRES_VOLUME_BACKUP="${POSTGRES_VOLUME}-pg17-backup"

docker volume create "$POSTGRES_VOLUME_BACKUP"
docker run --rm \
  -v "$POSTGRES_VOLUME":/from:ro \
  -v "$POSTGRES_VOLUME_BACKUP":/to \
  alpine:3 sh -c 'cd /from && cp -a . /to'

docker volume rm "$POSTGRES_VOLUME"
```

Do not remove the backup volume until the upgrade is verified. Start the new Postgres version and restore the dump:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh up -d --remove-orphans postgres

cat agenta-postgres-17-backup.sql | docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh exec -T postgres \
  psql -U username -d postgres
```

Verify the restore:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh exec postgres \
  psql -U username -d postgres -c "SHOW server_version;"

docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh exec postgres \
  psql -U username -d postgres -c "\l"
```

Start the full stack. The `alembic` job runs the migrations at start. Check its log:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh --profile with-traefik up -d --remove-orphans

docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh logs alembic
```

Verify the stack:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh ps
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh logs --tail=100 api
```

Open the Agenta web UI and confirm that existing projects, prompts, traces, and evaluations are present before deleting any backup files or backup volumes.

#### Kubernetes / Helm

The Helm chart uses the Bitnami PostgreSQL subchart. These commands use the default release and namespace from the Kubernetes guide: `agenta`.

The chart pins the bundled image `bitnami/postgresql` by digest in `postgresql.image.digest`. The pinned image runs PostgreSQL 18, and it does not change on a pod restart. Before you upgrade, run the version check below. If the server reports PostgreSQL 17, do not upgrade by changing the image. Use the backup and restore flow described here. Do not change `postgresql.image` to a different major version without a dump and restore.

The digest has priority over `postgresql.image.tag`. If you set your own `postgresql.image.tag` or mirror the image in a private registry, also set `postgresql.image.digest` to your own digest, or to an empty string, or Helm ignores your tag. The `run.sh` launcher upgrades with `--reuse-values`, which keeps the values of the first install. A release that was installed before this pin keeps its old image setting until you pass `--reset-then-reuse-values` to `helm upgrade`. That flag does not replace a digest you set yourself. To check, run `helm get values agenta -n agenta`. If `postgresql.image.digest` is in the output, that value stays in use.

Check the current Postgres version:

```bash
kubectl -n agenta exec agenta-postgresql-0 -- \
  psql -U agenta -d postgres -c "SHOW server_version;"
```

Create a logical backup and save the current Helm values:

```bash
kubectl -n agenta exec agenta-postgresql-0 -- \
  pg_dumpall -U agenta > agenta-postgres-backup.sql

ls -lh agenta-postgres-backup.sql
helm -n agenta get values agenta -o yaml > agenta-values-before-pg18.yaml
kubectl -n agenta get pvc
```

Create a fresh PostgreSQL data volume for the new major version. The exact storage operation depends on your cluster: use your storage provider's snapshot/restore workflow, restore into a new release, or delete the old bundled PostgreSQL PVC only after you have verified the logical backup. For a disposable local cluster, that last option looks like this:

```bash
kubectl -n agenta scale deploy --all --replicas=0
kubectl -n agenta delete statefulset agenta-postgresql --ignore-not-found
kubectl -n agenta delete pvc data-agenta-postgresql-0
```

Upgrade the chart so bundled PostgreSQL starts with the major-18 image. If you installed with `--set` values instead of a file, pass the same required secrets and settings again.

```bash
helm upgrade agenta hosting/kubernetes/helm \
  --namespace agenta \
  -f hosting/kubernetes/oss/.values.oss.yaml
```

Wait for PostgreSQL, restore the dump, and verify the databases:

```bash
kubectl -n agenta rollout status statefulset/agenta-postgresql

cat agenta-postgres-backup.sql | kubectl -n agenta exec -i agenta-postgresql-0 -- \
  psql -U agenta -d postgres

kubectl -n agenta exec agenta-postgresql-0 -- \
  psql -U agenta -d postgres -c "SHOW server_version;"

kubectl -n agenta exec agenta-postgresql-0 -- \
  psql -U agenta -d postgres -c "\l"
```

Run the Helm upgrade again to restart Agenta workloads and run the migration hook, then watch the rollout:

```bash
helm upgrade agenta hosting/kubernetes/helm \
  --namespace agenta \
  -f hosting/kubernetes/oss/.values.oss.yaml

kubectl -n agenta get jobs
kubectl -n agenta get pods -w
```

Open the Agenta web UI and confirm that existing data is present before deleting the backup file or any old storage snapshots.

If you use an external database, upgrade that database through your provider's supported PostgreSQL major-version process, then run the Agenta upgrade.

### When Migrations Are Needed

Check the release notes to see if a version requires database migrations. Not all updates require schema changes.

### Manual Migration Process

Apply all pending migrations by running the `alembic` migration job once, from the image in your compose file:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml --env-file hosting/docker-compose/oss/.env.oss.gh run --rm -e ALEMBIC_AUTO_MIGRATIONS=true alembic
```

Use the compose file and env file of your deployment. On an Enterprise install, they are `hosting/docker-compose/ee/docker-compose.gh.yml` and `hosting/docker-compose/ee/.env.ee.gh`.

The job is the same one that runs at every start: every core and tracing migration, in order.

### Verifying Migrations

After running migrations:

1. **Check Application Health**: Access Agenta through your web browser
2. **Verify Data Integrity**: Ensure your projects, prompts, and evaluations are intact
3. **Test Core Functions**: Try creating a new prompt or running an evaluation
4. **Check Logs**: Review container logs for any error messages

### Migration Troubleshooting

If you encounter issues after migration:

1. **Check Migration Status**:

   ```bash
   docker exec <api-container-name> alembic -c alembic.ini current
   ```

2. **Review Migration History**:

   ```bash
   docker exec <api-container-name> alembic -c alembic.ini history
   ```

3. **Rollback if Necessary**:

   ```bash
   docker exec <api-container-name> alembic -c alembic.ini downgrade -1
   ```

4. **Report Issues**: Create a [GitHub issue](https://github.com/Agenta-AI/agenta/issues) with details about the problem

## Automatic Migration Configuration

:::warning
Use automatic migrations with caution in production environments. Always test migrations on staging environments first.
:::

You can configure Agenta to run migrations automatically during container startup.

### Enabling Automatic Migrations

Add this environment variable to your `.env.oss.gh` file:

```bash
ALEMBIC_AUTO_MIGRATIONS=true
```

With this setting enabled:
- Migrations run automatically when the API container starts
- No manual migration commands are needed
- Container startup may take longer while migrations run
