Skip to content

fix(cli): deploy's ifAbsent push no longer treats a 401 probe as an absent site - #246

Merged
Madraka merged 2 commits into
mainfrom
claude/deploy-token-probe
Nov 15, 2026
Merged

Madraka merged 2 commits into
mainfrom
claude/deploy-token-probe

Conversation

@Madraka

@Madraka Madraka commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #245.

Production fix for 0.10.1 (patch changeset for @cloudhal/cli, naming #245).

What happened

cloudhal.com's Workers Builds deploy (CLI 0.10.0) failed after both Workers had been uploaded:

  1. The log showed "seeded the starter site …; it is pushed only if the deployment does not have it yet".
  2. About 6 s after the admin upload: the deployment has diverged from your local copy: {"error":"conflict","message":"target already has site … with different content"}.
  3. The deploy exited 1, and post-deploy-check never ran.

A retry of the same commit succeeded.

Cause

pushSite's ifAbsent probe (GET /api/admin/sites/:id/bundle), reached from deploy/ship.ts through whileTokenPropagates, read any non-200 as "absent":

  1. The fresh CLOUDHAL_DEPLOY_TOKEN had not reached the edge yet, so the probe got 401.
  2. The CLI went on to a bootstrap PUT.
  3. By then the token worked, so the deployment answered the PUT with 409.

Fix (packages/cli/src/commands/sync.ts)

  • The probe:
    • 200 means the deployment already has the site, so it is left alone.
    • 404 (not_found) means the site is absent, so it is pushed.
    • Any other status throws checking whether the deployment has the site failed (<status>): …; nothing was pushed.
    • whileTokenPropagates retries only errors containing (401), so a 401 is retried while the token spreads and any other status fails without pushing.
  • Defence in depth: under ifAbsent (and not --replace), a bootstrap PUT answered 409 with the "error":"conflict" "already has site" body is logged as already deployed and returns { pushed: false }.
  • Unchanged: cloudhal push keeps its divergence error, and other 409s, such as open schedules, are still errors.

Tests

New file packages/cli/test/push-if-absent.test.ts, using fetch stubs:

  • Probe 401, 401, then 200: retried through whileTokenPropagates, no PUT.
  • Probe 404: one PUT.
  • Probe 500, 502 or 403: an error, no PUT, and no retry.
  • ifAbsent PUT 409 for the same site: no error, "already deployed".
  • Non-ifAbsent PUT 409: still "diverged". An ifAbsent 409 for running schedules is still an error.

Without the fix, three of the five tests fail (the 401 retry, other probe statuses, the ifAbsent 409); the 404 and non-ifAbsent 409 cases pass either way.

I ran these test files one at a time in packages/cli, and all pass:

  • push-if-absent (5)
  • deploy (6)
  • comments-cli (5)
  • deploy-workers-builds (3)
  • deploy-attach (1)
  • deploy-release (24)

tsc in packages/cli, biome and pnpm size:check are clean.

🤖 Generated with Claude Code

Closes #245

Madraka and others added 2 commits November 15, 2026 21:01
…bsent site

A Workers Builds deploy of cloudhal.com (CLI 0.10.0) failed after both Workers were uploaded.
pushSite's ifAbsent probe (GET /api/admin/sites/:id/bundle) read any non-200 as "absent". The
fresh CLOUDHAL_DEPLOY_TOKEN had not reached the edge yet, so the probe got 401, and the bootstrap
PUT that followed, once the token worked, got 409 "target already has site … with different
content". The deploy exited 1 before post-deploy-check.

- The probe: 200 keeps the deployed site, 404 pushes. Any other status throws "checking whether
  the deployment has the site failed (<status>) …; nothing was pushed". whileTokenPropagates
  retries the 401 form (it matches "(401)") and no other.
- Under ifAbsent (and not --replace), a bootstrap PUT answered 409 with the "already has site"
  conflict is logged as already deployed and returns { pushed: false }. `cloudhal push` keeps the
  divergence error, and other 409s (open schedules) stay errors.
- test/push-if-absent.test.ts (fetch stubs): probe 401, 401, 200 is retried with no PUT; 404
  pushes; 500/502/403 fail with no PUT and are not retried; ifAbsent PUT 409 is no error;
  non-ifAbsent PUT 409 still is. Three of the five fail without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
@Madraka
Madraka merged commit 3979aa8 into main Nov 15, 2026
9 checks passed
@Madraka
Madraka deleted the claude/deploy-token-probe branch November 15, 2026 18:26
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.

Workers Builds deploy fails with 409 when the new deploy token is still propagating (ifAbsent probe)

1 participant