Skip to content

fix(cli): let tale deploy cross the automation protocol cutover - #4954

Merged
yannickmonney merged 13 commits into
mainfrom
fix/tag-deploy-automation-cutover
Oct 13, 2026
Merged

yannickmonney merged 13 commits into
mainfrom
fix/tag-deploy-automation-cutover

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

From v0.5.79 on, tale deploy refused every workspace still on v0.5.77 or earlier at the automation writer protocol cutover, and pointed it at managed apply, which cannot adopt a blue/green workspace either. A client hit it upgrading to v0.5.89; every self-hoster on v0.5.77 would. tale deploy now runs the cutover barrier itself, safely and resumably, and a nightly check upgrades a real workspace so a release cannot strand one again.

From v0.5.79 on, tale deploy refused every workspace still on v0.5.77 or earlier:

An existing protocol-1 database must upgrade through managed deployment apply and its automation cutover barrier before using tag deployments.

Managed apply could not take such a host either: it adopts only its own receipt or a complete single-project source-Compose runtime, and its cutover refuses the writers tale deploy runs in <id>-blue/<id>-green ("blue/green writers are outside its custody"). A client hit this upgrading to v0.5.89; every self-hoster on a v0.5.77 workspace would too. Reproduced on a real v0.5.77 workspace with the official v0.5.89 CLI (rc=3, the message above, nothing changed).

What changes

  • tale deploy runs the cutover barrier itself. cutoverLegacyAutomation gains an optional workspace scope (managed apply is byte-identical in behaviour and wording): custody of <id>, <id>-blue, <id>-green; resumed target writers in a colour project on the admitted digest of the configured registry; recovery worded as "run tale deploy again".
  • Everything that can refuse is asked first, read-only, before the deploy changes anything (planTagAutomationCutover): the v0.5.77 backend source (b4931db4) and unless-stopped, the ledger, an empty census across every organization (lock-free READ ONLY; the held census still decides), a workspace that records its live colour (a first deploy would skip the snapshot and replace the database), no --stop (it would replace the database mid-cutover) or --services, and — when new writers already exist — the recorded handoff, through a verify-only barrier call that never locks or stops. Each refusal names its next step and says nothing was changed; barrier-time refusals say the old backend was not stopped. --dry-run reports readiness.
  • Placement: after the snapshot and the sandbox roll, right before the new colour starts. Docker's event log on a real host: v0.5.77 writers died at 17:17:19, the first 0.5.89 writer was created at 17:17:20.
  • Resume: while the new colour runs (it installs 0163 before it serves or works), a rerun verifies the recorded handoff. Otherwise — no new colour yet, or one that stopped before finishing, which the deploy recreates — it takes a fresh held census over the old writers, over v0.5.77's ledger or one a first boot cut before 0163 continued (the interrupt removes that colour and migrations commit per file). A reboot or a snapshot restored in place is counted again, never waved through.
  • A resumed flip waits for its running replicas to be healthy (deploy and rollback): rerunning after a health timeout used to promote a colour that might still be migrating; an exited leftover replica is not waited on.
  • tale update --version X works: Commander's root --version claimed it, printed the CLI version and exited 0 without updating — the documented way to change release lines did nothing. Refusals and the new docs use -v, which works on every release (older CLIs keep the bug).
  • Rollback never crosses the cutover (the legacy admission is opt-in for tale deploy only) and refuses on a partly upgraded ledger.
  • Docs (EN/DE/FR upgrades page): the v0.5.77 path, what tale deploy checks and stops, API downtime, how a rerun resumes, rollback, and how to hold the barrier by hand — in a safe order — with your own Compose files or the Kubernetes manifests, where nothing holds it.

Independent review

An adversarial review of the first version found six issues, all fixed in fix(cli): keep a workspace cutover resumable and refuse it earlier and docs: hold the cutover by hand in a safe order: a dead end after a cut first boot plus a database restart; refusals that could fire after mutation and messages claiming nothing changed; a manual procedure that counted before stopping; a first deploy over an existing database skipping the snapshot; a resume health wait that an exited leftover replica could wedge; and a rollback guard that an abandoned attempt could block for good. A second pass confirmed all six and found one gap in the first fix (a database restored in place under a stopped new colour could skip the census), closed by fix(cli): count a restored database again before a workspace resumes, with tests at the barrier and the plan.

How it is held

  • CLI unit: barrier cases (colour custody, managed refusal unchanged, resume onto colour writers only, a cut first boot and a database restart taking a fresh held census, stale receipt, verify-only never locking, routed refusals, busy census, wording, registry), tag-deploy cases built on the real v0.5.77 host's facts (admitted; scope follows ROTATABLE_SERVICES/colorProject; every plan refusal routed with nothing changed; reruns after stop, cut boot + reboot, new writers), deploy-level refusal before the snapshot, rollback guards, running-only health wait, update --version routing incl. the Commander trap.
  • Backend integration (required, real Postgres): 6 new checks — readiness without the lock, neither waiting for nor blocking a write in flight, unfinished work elsewhere, ledger shapes legacy/continued from the real ledger query, and the held census accepting the continued ledger for a workspace while managed apply does not. Ran locally against a disposable tale-db: 20/20 pass.
  • Workspace upgrade workflow (nightly + manual, never in the merge gate): tools/cli/scripts/workspace-upgrade-check.ts deploys v0.5.77 (and the release before the newest) with its own CLI, signs up an owner and creates an organization, tale update -v, deploys with the CLI built from main, and requires the migrations, data and sign-in to survive, a second deploy to succeed and the rollback across the cutover to be refused.

Observed

On a real local Docker v0.5.77 workspace (project ws-a3667f):

  • official v0.5.89 CLI: refused, rc=3 (the client's error);
  • this branch's CLI (stamped 0.5.89): --dry-run reports "Would run the one-time automation writer protocol cutover…"; deploy succeeds; ledger 152 → 190 with 0163; the owner made on 0.5.77 signs in on 0.5.89 with the same user id; cutover-org listed; /api/health 0.5.89; a second deploy succeeds; tale rollback to 0.5.77 refused (rc=3) with 0.5.89 still serving.
  • tools/cli/scripts/workspace-upgrade-check.ts, end to end from v0.5.77 on a fresh workspace: passed (cutover ran, 0163 recorded, 0.5.89 serving, data survived, owner signs in, rollback refused with 0.5.89 still serving, second deploy ordinary), and its cleanup left no containers or volumes.
  • Interrupted cutover: Ctrl-C 6 s after the new colour started (the SIGINT handler removed it; the old writers were already stopped, receipt stopped); a plain tale deploy rerun started the new colour, waited for health, flipped and retired the old one.
  • From the previous release (0.5.88 → 0.5.89) through the script: passed (0.5.89 serving, data survived, owner signs in, second deploy ordinary), cleanup complete.

Not in this change

  • tale reset --all does not delete named volumes on Docker 23+ (volume prune without -a); the upgrade check removes its own.
  • The old colour's aimed chat drain answers 404 during a flip (also on a plain v0.5.77 redeploy); harmless here, the API is already stopped.
  • Making the Workspace upgrade a release-candidate receipt needs the candidate contract change (Ops review); RELEASING.md asks to check its newest run before tagging.

Suggested release-note text

  • tale deploy now upgrades a workspace from v0.5.77 across the automation writer protocol cutover, which v0.5.79–v0.5.89 refused. It checks the backend, the migration history and the automation runs before changing anything, stops the v0.5.77 backend under a held census right before the new version starts, and resumes after an interruption. Older workspaces go to v0.5.77 first (tale update -v 0.5.77, tale deploy). See Upgrades.
  • tale update --version <x.y.z> updates again; before, it printed the CLI's version and changed nothing. With an older CLI, use tale update -v <x.y.z>.

Checklist

  • bun run check parts that this change touches pass locally: CLI typecheck, lint and unit suite (3200 pass; the one failure, tests/smoke-fixture.test.ts, is Bun hiding passing titles under CLAUDECODE=1 and passes without it), platform typecheck, docs locale/structure/link checks (486), lint:links, lint:manual, knip, oxfmt.
  • bun run lint:sast passes (Opengrep) on the changed files: 205 rules, 0 findings. The upgrade check verifies TLS against the workspace's own Caddy root instead of disabling verification.
  • Translations: N/A, no UI message keys (CLI output is English).
  • Docs updated in docs/{en,de,fr}/self-hosted/operate/upgrades.md; CLI README, .github/CI.md and .github/RELEASING.md updated.
  • README.md / README.de.md / README.fr.md: N/A.

Test plan

  • bun test src/lib/deployment/automation-cutover.test.ts src/lib/deployment/tag-automation-cutover.test.ts src/lib/actions/rollback.test.ts src/utils/update-version-flag.test.ts scripts/workspace-upgrade-check.test.ts in tools/cli.
  • Backend integration (real Postgres) runs the new readiness and ledger-shape checks in automation-floor.integration.ts.
  • After merge, dispatch Workspace upgrade (gh workflow run workspace-upgrade.yml --ref main): both legs must pass on a hosted runner. Locally, bun tools/cli/scripts/workspace-upgrade-check.ts --from 0.5.77 --cli <CLI stamped 0.5.89> --workdir <dir> passed, and so did --from 0.5.88.

From v0.5.79 every `tale deploy` refused a workspace still on v0.5.77 and
sent it to managed apply, which cannot adopt a blue/green workspace and
whose cutover refuses writers in `<id>-blue`/`<id>-green`. No route was
left, and v0.5.89 met it on a real client host.

`tale deploy` now runs the same held-census barrier itself, with custody
of the deployment's own and both colour projects. Everything that can
refuse is read first, read-only and before anything changes: the v0.5.77
backend source and restart policy, the exact v0.5.77 ledger and a
lock-free census of unfinished runs in every organization. Each refusal
names its next step. The barrier stops the old writers right before the
new colour starts. A rerun resumes its own handoff, also after a first
boot was cut before 0163 committed (the colour is removed on interrupt
and migrations commit per file, so no census can pass any more). A
resumed flip, in deploy and rollback, now waits for the colour to be
healthy. Managed apply keeps its exact behaviour and wording; rollback
still never crosses the cutover.

Real-Postgres checks cover the readiness census and the ledger shapes.
Commander resolves program options anywhere on the command line, so the
root `--version` claimed `tale update --version 0.5.77`: the CLI printed
its own version, exited 0 and updated nothing. That is the documented way
to change release lines, and the way a v0.5.76 workspace must reach
v0.5.77 before the automation protocol cutover. Once `update` is the
command, its `--version` is spelled as the `-v` only `update` declares.
The upgrades page now tells an operator on v0.5.77 or earlier what the
one-time automation writer protocol cutover needs (v0.5.77 first, no
unfinished runs, a preview), what `tale deploy` checks and stops, when
the API is down, how a rerun resumes, and that rollback cannot cross it.
The commands use `-v`, which older CLIs understand.
v0.5.79 to v0.5.89 stranded every v0.5.77 workspace at the automation
writer protocol cutover while nothing ran the upgrade an operator runs.
`tools/cli/scripts/workspace-upgrade-check.ts` does: it deploys an older
release with its own CLI, signs up an owner and creates an organization,
moves the workspace with `tale update -v`, deploys with the CLI under
test, and requires the migrations, the account, the organization and a
sign-in to survive, a second deploy to succeed and, across the cutover,
the rollback to be refused.

The Workspace upgrade workflow runs it nightly and on demand from
v0.5.77 and from the release before the newest, with the CLI built from
`main` against the newest published images. It is informational, never
in the merge gate; RELEASING.md asks to check its newest run before
tagging.
A rolling update of your own Compose files or the Kubernetes manifests
starts the new backend while the v0.5.77 one still runs, so nothing holds
the barrier and unfinished runs end up on hold for good. The section now
says how to hold it: pause schedules and triggers, wait for zero
unfinished runs (the census predicate, as a query), stop the old
`backend-api` and `backend-worker`, then roll out.
Once `tale deploy` has stopped the v0.5.77 backend for the cutover, the
database may already hold part of the new release's migrations. A rollback
then started old writers beside it, and a later deploy could neither
resume the recorded handoff nor take a census. While the receipt exists
and the installed protocol is still 1, rollback now refuses and points to
`tale deploy`. A deploy test also proves the read-only plan refuses a
workspace it cannot cut over before any retag, volume, Compose or traffic
change.
Review findings on the tale deploy cutover:

- A first boot cut before 0163 plus a database restart (a host reboot)
  was a dead end: the resume needed the exact database start time. A
  workspace now takes a fresh held census over v0.5.77's ledger or one
  such a boot continued, and compares its database by container, image
  and labels when new writers already exist.
- The read-only plan now asks everything that can refuse: a workspace
  with no recorded colour (it would deploy without a snapshot), --stop
  (it would replace the database mid-cutover), --services, and, when new
  writers exist, the recorded handoff through a verify-only barrier call
  that never locks or stops. Barrier refusals no longer claim that
  nothing changed; they say the old backend was not stopped.
- Rollback refuses on a partly upgraded ledger instead of on the receipt
  alone, so an abandoned attempt no longer blocks a later rollback.
- A resumed flip waits only on running replicas; an exited leftover
  would have wedged every rerun.

The deploy test now runs without --skip-backup, so it proves the plan
refuses before the snapshot.
Stop the v0.5.77 backend first, make sure none is left, and only then
count unfinished runs: a run started between a zero count and the stop
would be held for good. Step 4 says a cutover deploy runs without --stop
or --services.
An earlier attempt's receipt alone made the plan report a resume, and the
deploy then said the old backend stays stopped while the barrier was
about to stop a backend running again. A resume now means the old
writers are already stopped or the new ones exist.
Both read "as long as no run is unfinished" where the meaning is "once
none is"; the French also mixed genders in "l'un d'eux".
Comparing only the database container, image and labels let a snapshot
restored in place under a stopped new colour pass the census-free resume,
and 0163 would then have held every run left unfinished in it. A
workspace now skips the census only while its new colour runs (it installs
0163 before it serves or works, so nothing is left to protect). A new
colour that does not run never finished migrating and is recreated by the
deploy: the old writers take a fresh held census, in the read-only plan
and again under the lock, whatever the database went through since.
@yannickmonney
yannickmonney marked this pull request as ready for review October 13, 2026 16:26
A stopped protocol-2 backend outside the colour projects, which the deploy
would not recreate, was refused only at the barrier, after the snapshot and
the sandbox roll. The read-only plan now refuses it first, and the barrier
asks before its verify-only return.
@yannickmonney
yannickmonney force-pushed the fix/tag-deploy-automation-cutover branch from f380aef to 059a6bb Compare October 13, 2026 16:29
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Closing and reopening to refresh the test merge: the first round merged with main at 711b91b, two commits before #4949 fixed main's formatting, so Format failed on a file this PR does not touch.

@yannickmonney yannickmonney reopened this Oct 13, 2026
@yannickmonney yannickmonney reopened this Oct 13, 2026
@yannickmonney
yannickmonney added this pull request to the merge queue Oct 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 13, 2026
On Windows, resolve() turns /tmp/upgrade into D:\tmp\upgrade, so the
literal expectation failed the Windows CLI build in the merge queue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant