Skip to content

Improvement: make the blue/green deployment truly zero-downtime #5409

Open

Description

@yannickmonney

Summary

tale deploy rolls the application tier (platform, backend-api, backend-worker) as a blue/green colour, but a routine upgrade still interrupts people in several places, and the hand-over between the colours is not seamless either. The docs say so themselves: "A blue-green rollout overlaps application replicas, but snapshots, drain periods, and stateful-service replacements can interrupt work" (upgrades.md:6), and they ask operators to agree on a maintenance window (:15).

The goal of this issue is an upgrade nobody notices, so that the maintenance window is no longer needed. It records what a measured local upgrade showed, every place where a routine deploy interrupts work, the constraints a change has to respect, options and the questions that decide the scope. It does not choose a design.

A local upgrade from v0.5.101 to v0.5.102 with tale deploy, and two repeat flips, with probes running throughout, showed:

  • Sandbox sessions refused for 307.8 s. The deploy's sandbox drain waits for a field the spawner stopped sending, so it always runs to its 5-minute deadline. While it waits, every new session is refused, and the backend gives up on such a create after about 2 s. The spawner reported {"draining":true,"sessions":0,"sessionIds":[]} the whole time.
  • The colour drain is skipped. The backend's control door answered 404 in all three flips, because no deployment path sets TALE_CONTROL_TOKEN; the CLI logged "Backend drain unavailable — proceeding". The same door serves tale migrate, which failed the same way on the same workspace.
  • The switch moves no traffic; the cut does. In the 30 s between "Switching traffic" and the cut, all 147–148 answers per web-lane probe still came from the old colour, in every flip. On the API lane, 0 to 56 of 144–149 answers per probe came from the new colour.
  • Requests hang at the cut, for minutes. When the old colour left the network, requests the proxy sent over its pooled connections to that colour got no answer, and new requests kept landing on such connections for up to 22 s after the cut. Each one hung until its client gave up: 15 s with a 15 s timeout, 291 s with a 15-minute one. The proxy was still waiting every time and logged 499. This happened to 4 requests in the upgrade and 3 and 9 in the repeat flips, including one on a brand-new client connection.
  • The live event stream goes silent for minutes. /events received nothing after the cut: no heartbeat (sent every 15 s), no end, no error. It stayed silent for 287.4 s, until the proxy's upstream read failed with connection timed out and it reset the connection. A browser EventSource sees nothing wrong until then, so a tab gets no live updates for those minutes.
  • The snapshot freezes the stack. API reads and writes stalled for 2.0–2.8 s while a 13.5 MB database was archived. Each data volume's users are paused for the length of their archive, the blob store's included, so the stall grows with the data.
  • db and proxy fall behind. They stayed on v0.5.101; only --stop updates them, and it recreates them in place.

Code anchors are on main at 3d802f94f (2026-11-06), the line v0.5.102 ships from. On the feature line (feature-train at 813be1ff4), the edge is Traefik instead of Caddy (6c9eba1), and the stop-gated tier adds its docker-api. Its colour routers still point at the shared aliases, so the cutover stays DNS-driven (traefik-labels.ts:14-18). The snapshot (which adds the edge's proxy-data), both drains, the control door, the session create's drain retry (5 × 400 ms) and the colour lifecycle work the same way there. The measurements were not repeated on the Traefik edge.

What the local upgrade showed

Setup. macOS with Docker Desktop (engine 29.6.1, VM with 12 CPUs and 7.75 GiB). A fresh workspace from scripts/install-cli.sh with VERSION=0.5.101, then tale init and tale deploy, one owner and one organization. Then tale update -v 0.5.102 and tale --yes --ci deploy. One replica per role, no model provider, no chat or automation traffic. The data was tiny (13.5 MB database, 7 KB of blobs), so every size-dependent number below is a lower bound. Two same-version flips followed with the same probes, to study the cut.

Probes.

  • Through the proxy, every 200 ms with a 15 s client timeout: GET /, GET /api/health, GET /api/health/ready and GET /api/auth/get-session signed in. Also POST /api/auth/update-user every second, and one /events stream, reopened 250 ms after any end or error. The repeat flips added GET /api/health/ready on a new client connection for every request, recorded the arrival of every stream chunk, and the last flip added five probes with a 15-minute timeout (three on /api/health/ready, two on /api/health).
  • On the internal network, every 250 ms with a new connection each time: platform:3000/api/health, backend-api:3005/ping, llm-gateway:8080/health, object-store:9000/minio/health/live, and an unsigned POST sandbox:8003/v1/sessions (401 while the spawner serves, 503 draining while it drains, no answer while it is down).
  • docker events for pause, stop, start and network changes.

Upgrade timeline (seconds from the deploy's first log line):

t (s) Step What the probes saw
0–55 Image pulls nothing
55.0–148.6 Snapshot of 6 volumes (18.9 MB). Paused: db 55.2–58.0; blue-platform, blue-backend-api, blue-backend-worker and sandbox 63.3–63.8; object-store 94.3–94.6; proxy 105.1–105.6; sandbox-llm-gateway 136.8–138.0. The rest of the phase waits for each paused container to report healthy again. /api/health/ready, the session read and the write took 2.0–2.8 s during the database's pause
150.1–451.7 Sandbox drain; the CLI ends it with "Sandbox still has unknown execution(s) after 300s — recreating anyway" every session create answered 503 draining (1,166 attempts)
451.9–458.2 sandbox, sandbox-egress and sandbox-llm-gateway recreated in place sessions: no answer for 6.3 s (23 attempts); gateway: no answer for 0.8 s
464.7–471.4 Green colour started and healthy nothing
471.5 Traffic "switched"; the colour drain answered 404 and was skipped nothing
471.6–501.9 DRAIN_TIMEOUT (30 s); both colours are up every answer still came from the old colour: 148 of 148 on /api/health, 149 of 149 on /api/health/ready
501.7–501.9 Blue disconnected from internal and tale-sandbox-net one request each on /, /api/health and /api/health/ready hung 15 s; a write sent at ~523.7 s hung 15 s
502.0–532.1 Blue stopped and removed the /events stream opened before the deploy never ended or failed; the proxy noticed it only when the probe hung up at 546.5 s
532.4 "Deployment complete! Version 0.5.102 is now live" db and proxy still run 0.5.101

Repeat flips (same version, no snapshot, no sandbox recreate).

  • Green to blue: the drain answered 404 again. At the cut (42.1–42.4 s), one request each on /, /api/health and /api/health/ready hung 15 s. The last of these used a new client connection, so the hang lies between the proxy and the old colour. The /events stream's last heartbeat arrived at 29.4 s, 12.8 s before the cut. Nothing followed: no heartbeat, end or error in the 133.9 s until the probe stopped.
  • Blue to green, observed for 6 minutes afterwards: the drain answered 404 again. The four long-timeout requests in flight at the cut (41.3 s) hung until the client gave up 291 s later, and the proxy logged them as 499 after 291.0–291.2 s. Requests with the 15 s timeout hung when sent at 41.0, 41.2, 56.4 and 61.5 s. The /events stream's last heartbeat arrived at 32.3 s. At 319.7 s the proxy logged read: connection timed out on its upstream connection and reset the client's, and the stream reopened at 320.0 s.

The internal probes, which open a new connection every time, saw no failure on platform or backend-api in any run. Fresh connections reach the new colour; only connections that already existed toward the old colour fail.

Not examined: production-size data; more than one replica per role; real chat, agent, automation or model traffic; tale deploy --stop; the managed (--bundle) path (code only); Kubernetes; Linux hosts (Docker Desktop's VM network may differ from a Linux host's in how a vanished peer shows up); how a browser EventSource and the app's own requests behave on the hung connections (the probes are Bun fetch); what makes the proxy give up after about 4.7 minutes (connection timed out on the upstream read points at TCP keepalive).

Where a routine tale deploy interrupts work today

# Step What happens Who notices
1 Pre-deploy snapshot (every version change) Each data volume is archived with tar while every running container that mounts it is paused: db, the whole live colour and sandbox (for config-data), object-store, proxy, sandbox-llm-gateway Every request to a paused service waits for its archive; the blob store's pause grows with everything ever uploaded
2 Sandbox spawner Drained, then recreated in place. The drain waits for a field the spawner stopped sending, so it runs to its 5-minute deadline, and a draining spawner refuses every new session Agent turns and code runs that need a new sandbox session fail
3 Model gateway Recreated in place: a new model call fails until the new container answers, and a stream still running after 90 s is cut Chat turns, agent turns, the model endpoints
4 Colour drain Meant to stop new chat turns on the old colour and wait for its work, but skipped on every CLI deployment (control door 404). Where it does run, a turn that reaches the draining colour gets a 503 refusal In-flight turns and automation steps of the old colour, or chat sends during the drain
5 Colour cut docker network disconnect takes the old colour off internal and tale-sandbox-net. Its connections are left half-open, and it loses db and object-store, which live only on internal Requests on pooled proxy connections hang and open event streams go silent, for minutes; the old colour's in-flight work cannot write
6 Proxy routing Caddy sees one upstream per alias; the backend lanes have no retry, health check or timeout A request that reaches a replica that is going away hangs or fails
7 db, object-store, proxy Left on their old image unless --stop, which recreates them in place Everyone during --stop; otherwise these services fall behind the release
8 Managed (--bundle) rollouts One docker compose up -d over a single project: every service whose image changed is recreated in place, db and proxy included Every managed deployment, on every rollout
9 Mixed versions The new colour migrates the shared database while the old colour still serves; nothing proves the previous release works on the new schema Data and API errors during the overlap
10 Proof No check measures availability during an upgrade Regressions go unseen

What the repo says today

1. The snapshot pauses the stack

2. The sandbox drain always runs to its deadline

  • The deploy drains the spawner before recreating it whenever its version changes (deploy.ts:582-611) and polls for up to 5 minutes (drain-sandbox.ts:67-72).
  • The poll accepts a status only when it carries a numeric inFlight, and treats anything else as unknown (:83-96). It returns early only on inFlight === 0 (:135-149).
  • The spawner answers { draining, sessions, sessionIds } and no inFlight (control-routes.ts:101-112, documented in control-cli.ts:13-14). It has answered sessions since at least b569e177e (2026-09-03); the one-shot lane the CLI's comments describe was retired in f646cb60b (2026-09-06). The CLI's tests still feed {"inFlight":0} (drain-sandbox.test.ts:92).
  • While draining, the spawner answers every POST /v1/sessions with 503 draining (server.ts:733-748). The backend asks again at most 5 times, 400 ms apart (session_client.ts:1114-1120, :1188-1203). Its comment still expects "the targeted colour is mid-flip", but the sandbox tier has no colours (compose/types.ts:117-122).

3. The always-roll tier is replaced in place

  • sandbox-llm-gateway, sandbox and sandbox-egress roll in place on every default deploy (compose/types.ts:153-171) through one docker compose up -d of the stateful compose (deploy.ts:613-650). Every release publishes new images, so a version change always recreates them.
  • What the gateway does meanwhile: upgrades.md:62.

4. The colour drain never runs on a CLI deployment

  • retireColor drains the old API through the backend's control door before the cut (color-lifecycle.ts:313-315). When the door refuses, the drain logs a warning and returns (drain-backend.ts:138-150).
  • The door is fail-closed: without TALE_CONTROL_TOKEN in its environment it answers 404 (control/routes.ts:18-25, :41-45). The CLI sends $TALE_CONTROL_TOKEN expanded inside the container (control-call.ts:165). On main, the name appears only in the door, that call, comments, tests and a bundle check. No env generator, Compose file, managed runtime environment or doc sets it; the green replica of the measured workspace had none.
  • The same door serves tale migrate (/provision), tale auth reset-owner and tale deploy --override-all (/reseed). tale migrate failed on the measured workspace with "the control door refused … 404".
  • When the drain does run, a turn that reaches the draining colour gets HTTP 503 status: 'refused', "The backend is restarting for an upgrade — send again in a moment." (chat/routes.ts:1449-1461). The drain waits up to 3 minutes (drain-backend.ts:40-44). The CLI's module comment says the UI does not retry such a refusal (:9-10); how each client surface presents it was not examined.

5–6. The cut and the proxy

7. The stop-gated tier

8. Managed rollouts have no colours

  • applyRuntime ends with one docker compose up -d --no-build --pull never over the deployment's single project (runtime-apply.ts:1377-1400). Every tale-* service's image is chosen by the source revision (runtime-prepare.ts:334-405, and VERSION: sha-<revision> in runtime-env.ts:251). A rollout to a new revision therefore recreates db, knowledge-db, proxy and the application in place. The docs call it "a state-preserving stack rollout … the workspace blue-green behavior described above is a separate path" (cli-install.md:313).

9. Mixed versions

  • "Both versions can serve during the overlap, so releases must remain compatible with the previous application version while migrations run" (upgrades.md:56). The create-migration skill asks every migration to be safe mid-roll, but no check boots the previous release against the new schema.

10. Proof

  • The nightly upgrade check proves data survival, sign-in, migrations and the rollback refusal (workspace-upgrade-check.ts:1-20). It does not watch availability while the deploy runs.

Comments that describe an older design

Constraints any change has to respect

  • Migrations are forward-only and run at boot while the previous image still serves (repo contract, create-migration skill). The snapshot is their recovery point: dropping it moves that duty elsewhere rather than removing it.
  • The automation writer fence and the hand-over of runs between colours (upgrades.md:60).
  • The control door stays fail-closed: a fix provisions the token or another authenticated channel, never an open door.
  • The spawner is a singleton by construction: it holds docker.sock, the session directory and the gateway volume (compose/types.ts:117-122). The gateway keeps its state in SQLite in one volume.
  • One Docker host. Only the proxy publishes 80/443, and two proxies cannot bind them at once. The Kubernetes guide runs the proxy, the object store and the gateway with strategy: Recreate for the same kind of reason (kubernetes.md:37-44, :419).
  • Two colours need twice the application tier's memory during the overlap (upgrades.md:15).
  • Self-hosters on their own Compose files or Kubernetes do not get the CLI's mechanics (kubernetes.md:805-807).

Options

Grouped by row. None is preferred, and several combine.

Snapshot (1)

  • A. Take the database's recovery point online (pg_dump, pg_basebackup or a Postgres-level snapshot), and copy blobs without pausing the store. Blobs are written once, so a copy taken after the database dump is consistent with it.
  • B. Keep paused archives only for the small volumes, and protect the blob store separately (store-side versioning or replication).
  • C. Use a filesystem or volume-driver snapshot where the host offers one, and fall back to today's archive.
  • D. Skip the snapshot when the target adds no database or store migration; the CLI can read both before it changes anything.

Sandbox and gateway (2, 3)

  • E. Make the drain read what the spawner reports, and decide what it should wait for now that one-shot executions are gone. Let a session create wait out a drain and a restart instead of about 2 s.
  • F. Start the new spawner or gateway beside the old one and hand over. This needs a plan for docker.sock, the session directory and the gateway's SQLite store.
  • G. Version these images on their own, so a release that does not change them does not recreate them.

Drain, cut and proxy (4–6)

  • H. Provision TALE_CONTROL_TOKEN in every deployment path (tale init, existing workspaces through ensureEnv, the managed runtime environment), or reach the door through an in-container signer that needs no shared token, as the spawner's control client does. Make a skipped drain fail the deploy, or at least the acceptance check.
  • I. Switch traffic at the proxy (per-colour upstreams changed through Caddy's admin API or a reload) instead of shared aliases plus docker network disconnect. The old colour would then take no new request before its drain, and the proxy would stop using its connections before the colour goes away.
  • J. Have the old colour close its connections itself: end keep-alive connections and event streams with a reconnect hint while draining, and stop its processes while still attached, so the proxy sees the connections close instead of a silent peer.
  • K. Give the backend lanes per-replica health, timeouts and retries (lb_try_duration, passive health, transport timeouts), retrying only what is safe to repeat.
  • L. Let clients ride the hand-over: retry a drain refusal (the send is "safe to repeat", chat/routes.ts:1449-1450), and reopen an event stream whose heartbeats stop.

Stop-gated tier and managed rollouts (7, 8)

  • M. Version db, object-store and proxy apart from the application, so routine releases never need --stop.
  • N. Hold database connections through a planned restart (a connection pooler that can pause and resume), or switch over to a replica.
  • O. Reload the proxy's configuration in place when only its configuration changes.
  • P. Give the managed rollout the same colour mechanics as the workspace path, or a start-first replacement for the application services.

Mixed versions and proof (9, 10)

  • Q. A CI job that runs the previous release's smoke tests against the new release's migrated database.
  • R. Run availability probes like the ones above during the nightly upgrade check, and fail on any refused, failed or hung request or silent stream outside an agreed budget.

Questions

  1. What counts as downtime: failed requests only, or also requests that hang, refused chat sends, silent event streams and stopped sandbox sessions?
  2. Does the stop-gated tier have to roll without an outage too, or is --stop an accepted maintenance step?
  3. Does the managed (--bundle) path have to meet the same bar as tale deploy?
  4. May the pre-deploy snapshot cost availability, or must recovery points be taken online?
  5. Must a running sandbox session survive an upgrade, or is a stop with its workspace kept acceptable?
  6. One host only, or is a multi-host (high-availability) setup in scope?
  7. What budget should CI enforce: zero failed reads, a latency ceiling during the hand-over, a reconnect time for streams?
  8. Should the missing control token, which also breaks tale migrate, tale auth reset-owner and --override-all, be fixed on its own first?

Related

Activity

  1. added
    needs discussion
    improvement
    on Nov 6, 2026
  2. yannickmonney commented on Nov 14, 2026

    @yannickmonney
    ContributorAuthor

    Decision

    A routine tale deploy is zero-downtime when no request fails or hangs, no drain refusal reaches the user, no event stream goes silent, and no sandbox create or model call fails. The target is one Docker or Incus host. The Docker runtime uses the traffic switch the Incus runtime already has (Caddyfile.switch, admission probes, withdrawal by marker). The cut becomes withdraw, then drain, then a graceful stop, and docker network disconnect is no longer part of it. The switch is a stop-gated, content-labelled singleton, so a routine flip never recreates it.

    Answers

    1. What counts as downtime: all of it. Failed requests, hung requests (more than 5 s over normal), refusals the user sees, streams silent for more than 30 s, failed sandbox creates, and model calls that fail across a gateway restart.
    2. Stop-gated tier (db, object-store, edge, switch): an announced --stop stays acceptable, but routine releases must not need it. The images are versioned by content, and the CLI warns when they fall behind.
    3. Managed path: same bar. It uses the shared colour lifecycle and the switch instead of one compose up -d.
    4. Snapshot: must be online and pause nothing (pg_dump, SQLite's online backup, unpaused copies of blobs and file volumes taken after the dump). Restore keeps reading the legacy format.
    5. Sandbox sessions: a stop with the workspace kept is acceptable if the backend resumes the session on its next call. Creates wait out the drain and restart, with a deadline of about 90 s, and the spawner drain is bounded at 60 s. Model calls wait out a gateway restart; streams in flight keep the 90 s grace.
    6. Scope: one host. Multi-host high availability is out of scope.
    7. Budget: 0 failed requests; 0 requests more than 5 s over normal; 0 refusals reaching the user; no stream gap over 30 s and a reconnect within 5 s; 0 failed sandbox creates (each within 90 s); 0 failed model calls across a gateway restart; 0 pauses during the snapshot. Enforced by the nightly upgrade check on Docker, and on Incus where its lab check runs.
    8. Control token: yes, it is fixed first and on its own. It is provisioned like SANDBOX_TOKEN, and the door stays fail-closed. After the fix, a refused door fails the deploy, except for a one-time warning when the old colour predates the token.

    Rationale

    The sandbox drain's field mismatch is already fixed on main (#5429). The Incus runtime already has a hand-over that stops new requests before the drain and never reloads config. Running the same switch on Docker removes the half-open disconnect behind the multi-minute hangs and silent streams, without adding a second mechanism. Because every request crosses the switch, it is stop-gated like the edge, so routine releases never recreate it. An existing workspace moves onto it during an ordinary deploy, within the budget. Online recovery points keep the forward-only migration safety net without a stall that grows with the data. Content labels stop needless restarts of the singletons, and when one does change, its callers wait out the restart instead of failing. The docs drop the maintenance window only once every budget row is enforced.

    Implementation units

    1. fix(cli): provision TALE_CONTROL_TOKEN in every path (S, main)
    2. fix(platform): sandbox creates and model calls ride a spawner or gateway restart; 60 s drain bound (M, main)
    3. feat(platform): resume a session after the spawner is replaced (M, main; after 2)
    4. feat(cli): stop-gated traffic switch and marker withdrawal on Docker, including the move of existing workspaces onto it (L, main; after 1)
    5. fix(proxy): timeouts, passive health and idempotent-only retries on the switch and the edge's backend lanes (S, main)
    6. fix(platform): close streams on withdrawal with a retry hint; client heartbeat watchdog; auto-retry of drain refusals (M, main)
    7. feat(cli): recreate stateful, always-roll and switch services only when their image content changes (M, main)
    8. feat(cli): online database recovery points (M, main)
    9. feat(cli): unpaused copies of blobs and file volumes; audit config-data writers (M, main; after 8)
    10. feat(cli): managed rollouts through the colour lifecycle (L, main; after 4 and 7)
    11. ci: previous release's smoke tests against the migrated schema (M, main)
    12. test(cli): availability budget in the nightly upgrade check, each row enforced as its fix lands (M, main)
    13. docs: drop the maintenance window for routine upgrades, en/de/fr (S, main; after 12 and every fix unit)
    14. chore: carry the units onto feature-train, with the Traefik edge pointing at the switch (M, feature-train; after 4, 5 and 7)

    Cross-issue amendments (decisions taken together with #4870, #4942):

  3. added
    agent-ready
    and removed
    needs discussion
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyimprovement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions