Repository navigation
Description
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 servestale 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.
/eventsreceived 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 withconnection timed outand it reset the connection. A browserEventSourcesees 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.
dbandproxyfall behind. They stayed on v0.5.101; only--stopupdates 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/readyandGET /api/auth/get-sessionsigned in. AlsoPOST /api/auth/update-userevery second, and one/eventsstream, reopened 250 ms after any end or error. The repeat flips addedGET /api/health/readyon 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 unsignedPOST sandbox:8003/v1/sessions(401 while the spawner serves, 503drainingwhile it drains, no answer while it is down). docker eventsfor 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/healthand/api/health/readyhung 15 s. The last of these used a new client connection, so the hang lies between the proxy and the old colour. The/eventsstream'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
499after 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/eventsstream's last heartbeat arrived at 32.3 s. At 319.7 s the proxy loggedread: connection timed outon 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
- A version-changing deploy snapshots before any mutation unless
--skip-backup(deploy.ts:534-565). - Each run of volumes is archived inside one
withVolumeContainersPaused(create-snapshot.ts:122-149), one group after another (:268-274). Captured:db-data,knowledge-db-data,config-data,object-store-data,caddy-data,caddy-config,llm-gateway-data(backup/constants.ts:43-53). config-datais mounted by the backend tier (create-backend-services.ts:75-78), the web tier (create-platform-service.ts:23) and the spawner (create-sandbox-service.ts:142), so its archive pauses the whole live colour. The proxy's two volumes pause the proxy (create-proxy-service.ts:14).- One archive may take up to 30 minutes, the blob store's up to 4 hours, and "the snapshot side pauses the volume's containers for the duration either way" (
backup/constants.ts:88-103). The docs say the same (backups-and-restore.md:59).
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 oninFlight === 0(:135-149). - The spawner answers
{ draining, sessions, sessionIds }and noinFlight(control-routes.ts:101-112, documented incontrol-cli.ts:13-14). It has answeredsessionssince at leastb569e177e(2026-09-03); the one-shot lane the CLI's comments describe was retired inf646cb60b(2026-09-06). The CLI's tests still feed{"inFlight":0}(drain-sandbox.test.ts:92). - While draining, the spawner answers every
POST /v1/sessionswith 503draining(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,sandboxandsandbox-egressroll in place on every default deploy (compose/types.ts:153-171) through onedocker compose up -dof 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
retireColordrains 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_TOKENin its environment it answers 404 (control/routes.ts:18-25,:41-45). The CLI sends$TALE_CONTROL_TOKENexpanded inside the container (control-call.ts:165). Onmain, 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-ownerandtale deploy --override-all(/reseed).tale migratefailed 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
- The intended order is written down in
color-lifecycle.ts:16-36. Both colours carry theplatformandbackend-apialiases (create-platform-service.ts:52-56,create-backend-services.ts:189-205). retireColorkeeps the old web tier healthy because "Caddy health-checks that hostname as ONE upstream — a 503 from the old colour marks the whole site down" (color-lifecycle.ts:308-311). It sleepsDRAIN_TIMEOUT(:317-318), then disconnects the colour, which "severs live connections on those networks" (:320-327), frominternalandtale-sandbox-net(:113-117), and only then stops it (:332-333).dbandobject-storeare reachable only oninternal(create-db-service.ts:57,create-object-storage-service.ts:48).- The proxy: the SPA lane has an active health check and
lb_try_duration 5s(Caddyfile:311-343)./api/healthand the/api/*fallback have neither (:201-211), and no injected backend lane,/eventsincluded, has a retry, health check or timeout (docker-entrypoint.sh:283-380). The error handler describes the window it covers: "During a deployment there is a brief window when the old platform loses its DB connection and the new one is not ready yet" (Caddyfile:360-369). - The web client leaves an opened
/eventsstream to the browser's native reconnect and does not watch the 15 s heartbeats (use-backend-hints.ts:64-72,sse.ts:17). - The backend's Docker health check is liveness (
/ping), not readiness (/ready) (create-backend-services.ts:178-188,backend/app.ts:219-279). The backend listens only after its migrations (backend/main.ts:113-121).
7. The stop-gated tier
db,object-storeandproxyare left running unless the deploy is a first one, they are stopped, or--stopis given (compose/types.ts:144-152,select-services.ts:30-50).--stop"recreates those containers, so accept a brief downtime" (cli-install.md:124). Stop-gatingdbis what ended the deploy-window Postgres restarts of Bug: self-hosted demo05.tale.dev worker jobs and live API requests crash on deploy-window Postgres restarts (GlitchTip #1,2,3,5,6,7,9,10) #3273 (feat(cli): run the application tier as a colour replica set #3277).- These images are versioned with every release (
tale-db,tale-proxy). Since 2026-09-01, 23 commits onmaintouchedservices/proxyand 17 touchedservices/db. A workspace that never runs--stopkeeps the proxy and database image of the release it was first deployed with.
8. Managed rollouts have no colours
applyRuntimeends with onedocker compose up -d --no-build --pull neverover the deployment's single project (runtime-apply.ts:1377-1400). Everytale-*service's image is chosen by the source revision (runtime-prepare.ts:334-405, andVERSION: sha-<revision>inruntime-env.ts:251). A rollout to a new revision therefore recreatesdb,knowledge-db,proxyand 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). Thecreate-migrationskill 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
Caddyfile:18-21: "Only one platform instance can be healthy at a time (DB constraint)".deploy.ts:263-269saysbackend-apiandbackend-worker"roll in-place"; they are colour-rolled (compose/types.ts:99-103).drain-sandbox.ts:98-104andsession_client.ts:1188-1189describe one-shot executions and a sandbox colour flip; both are gone.
Constraints any change has to respect
- Migrations are forward-only and run at boot while the previous image still serves (repo contract,
create-migrationskill). 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: Recreatefor 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_basebackupor 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_TOKENin every deployment path (tale init, existing workspaces throughensureEnv, 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-storeandproxyapart 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
- What counts as downtime: failed requests only, or also requests that hang, refused chat sends, silent event streams and stopped sandbox sessions?
- Does the stop-gated tier have to roll without an outage too, or is
--stopan accepted maintenance step? - Does the managed (
--bundle) path have to meet the same bar astale deploy? - May the pre-deploy snapshot cost availability, or must recovery points be taken online?
- Must a running sandbox session survive an upgrade, or is a stop with its workspace kept acceptable?
- One host only, or is a multi-host (high-availability) setup in scope?
- What budget should CI enforce: zero failed reads, a latency ceiling during the hand-over, a reconnect time for streams?
- Should the missing control token, which also breaks
tale migrate,tale auth reset-ownerand--override-all, be fixed on its own first?
Related
- feat(deployment): Implement zero-downtime blue-green deployment #44 (closed): the original zero-downtime blue-green feature.
- Bug: self-hosted demo05.tale.dev worker jobs and live API requests crash on deploy-window Postgres restarts (GlitchTip #1,2,3,5,6,7,9,10) #3273 (open), Bug: 0.5.x demo worker jobs crash with raw PostgresError during deploy-window Postgres restarts — 7 GlitchTip groups in the un-swept demo05 project, one per task type (24 events, 08-31) #3266 (closed): Postgres restarts during deploys. Stop-gating
db(feat(cli): run the application tier as a colour replica set #3277) fixed the cause; classifying transient errors is still open there. - Decision: how should built-in skills reach organizations that already exist? #4964 (open): what
tale migrateprovisions; it assumes the control door answers. - bug(cli):
tale restore --stopneither refuses nor stops a colour replica that is restarting #4980, bug(cli):tale reset --allremoves no volumes on Docker Engine 23 and later #4981 (closed): colour replicas and volumes inrestore --stopandreset --all. - Docs to update with any change:
upgrades.md,cli-install.md,backups-and-restore.md,kubernetes.md, and theirdeandfrversions.
Activity
yannickmonney commentedon Nov 14, 2026
Decision
A routine
tale deployis 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, anddocker network disconnectis no longer part of it. The switch is a stop-gated, content-labelled singleton, so a routine flip never recreates it.Answers
--stopstays acceptable, but routine releases must not need it. The images are versioned by content, and the CLI warns when they fall behind.compose up -d.pg_dump, SQLite's online backup, unpaused copies of blobs and file volumes taken after the dump). Restore keeps reading the legacy format.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
TALE_CONTROL_TOKENin every path (S, main)Cross-issue amendments (decisions taken together with #4870, #4942):