Skip to content

Scale to zero: land #3 on main - #5

Merged
michaelaguiar merged 8 commits into
mainfrom
scale-to-zero
Oct 13, 2026
Merged

michaelaguiar merged 8 commits into
mainfrom
scale-to-zero

Conversation

@michaelaguiar

Copy link
Copy Markdown
Member

PR #3 merged into its stacked base share-cloudflare-tunnel 25 seconds after #2 had merged that branch into main, so it never reached main.

This PR carries the same head that #3 merged (5668786). The code is identical to what was reviewed there; see #3 for the description, the five review rounds and the testing notes. It merges cleanly into main, and the diff is only #3's changes.

- Global services gain alios_idle (image tagged with the CLI version,
  ALIOS_IDLE_TIMEOUT passed through, Docker socket mounted, internal
  network only).
- The base Caddyfile defines an alios_wake snippet that sends 502/503/504
  upstream failures to the waker; project, HTTP-only and share vhosts
  import it in place of the old "Project unavailable" response.
- `alios idle [on|off|<duration>]` stores a per-project setting in the
  alios.project.idle label (recreating the container like `alios env`).
- `exec`, `shell`, the implicit command fallthrough and `share` start a
  sleeping project instead of failing; `list` and `status` show a stopped
  project as sleeping while alios_idle runs; `stop` says a visit restarts
  it.
- `doctor` checks alios_idle, ALIOS_IDLE_TIMEOUT, vhosts that predate the
  snippet, and busy-warning lines from the last 24h; `global start` and
  `restart` point out vhosts that still need `alios cert repair`.
- scripts/release.sh builds and pushes the multi-arch alios-idle image.
- docs/IDLE.md, README and CLAUDE.md describe it.

Verified in sandboxes on the real Docker daemon, without touching the
live stack: the watcher stopped a 1m-timeout container on schedule, and
a request through Caddy with the generated snippet woke a stopped
project in ~280ms and was redirected back to the same URL. Caddy 2.10
adapts the generated Caddyfile with the snippet routing only 502/503/504.
- POST/PUT bodies: the first proxy hop consumes the body, so forwarding
  the request to the waker failed and Caddy returned an empty 502. The
  snippet now asks the waker with a bodiless GET; the browser resends the
  original method and body after the 307. Verified through Caddy 2.10
  with 100 KB and chunked POSTs.
- `alios cert repair` wrote vhosts importing alios_wake without the base
  Caddyfile that defines it, so Caddy crash-looped until `global start`.
  Repair now writes the base config first (services.WriteBaseConfig).
- alios_idle was a compose service in GlobalServices, so an unpullable
  image aborted `global start` and took every project down. It now runs
  on its own, best-effort, with a warning when it can't start.
- `alios pause` stopped projects while the waker still ran, so a request
  mid-pause could start one again. Pause stops alios_idle first and still
  resumes it.
- An `alios shell` opened as the container started was folded into the
  process baseline and never counted, so the shell was killed after the
  timeout. Exec'd processes are now identified directly (not descended
  from the container's main PID) instead of against a baseline.
- Open redirect: a path starting "//" made the waker's Location
  protocol-relative (https://<share>//evil.com). Leading slashes are
  collapsed.
- ALIOS_IDLE_TIMEOUT from whichever shell started services silently reset
  the service's timeout. It's now only changed when the variable is set,
  stored on the container, and status/idle/doctor report the running
  value.
- A container started moments ago by anything (not just the waker) gets a
  retry instead of "not responding"; a request that arrives while the
  container is being stopped starts it again once the stop finishes
  rather than waiting out the timeout; Docker API calls time out after
  30s; a failed sample no longer restarts a project's idle timer; the
  stale-vhost hint counts only project vhost files.
- startIdle removed the running alios_idle before pulling the image for
  the new CLI version, so a failed pull (offline, not yet published) left
  no waker and every sleeping project served an empty 502. It now pulls
  first and keeps the previous service on failure.
- alios_idle is listed in `alios status` / `global status` again (it left
  GlobalServices), so a stopped or crashed one is visible. Doctor's
  services section skips it; its own section covers it.
- An open but idle `alios shell` counted as "busy without traffic" and
  produced busy warnings after 2h. Only CPU use without traffic counts
  now (regression test fails without the fix).
- Docs/comments no longer describe the removed process baseline.
A project the watcher stops for being idle is asleep and wakes on the
next visit. One stopped by hand now stays stopped: otherwise a polling
browser tab, an HMR reconnect or a webhook undoes the stop a second
later with no explanation.

- The vhost records which: `alios stop` swaps `import alios_wake <name>`
  for `import alios_stopped <name>`, a new snippet answering 503 "<name>
  is stopped. Run 'alios start'..." (checked through Caddy 2.10).
  `alios start` rewrites the vhost back; restart, pause/resume leave it.
- `cert repair` keeps stopped projects stopped.
- `exec`, `shell` and `share` start an asleep project but refuse a
  stopped one; `list`/`status` show sleeping vs stopped; doctor reports
  a stopped project as info, and neither it nor the global-start hint
  mistakes a stopped vhost for one that predates scale to zero.
- The swap matches whole lines (unit-tested), so stopping "sho" can't
  touch "shop"'s vhost.
- P1: the vhost was marked stopped only after the container was down, so
  a polling tab hit the waker mid-stop and it started the project again.
  The marker is now written (and Caddy reloaded) before the stop.
- rebuild, php and image start the container but left the marker, so a
  running project showed as stopped and wouldn't wake after its next
  idle stop. They clear it now.
- A vhost importing a snippet the running base Caddyfile lacks (stack
  started by an older alios) made the reload fail and left a file that
  crash-loops Caddy on its next start. stop/start/rebuild/php/image now
  write the current base Caddyfile first, and SetProjectStopped puts the
  vhost back if Caddy rejects it.
- `cert remove` (updateVhostToHTTP) keeps a stop.
- exec/shell/share refuse only a project stopped by hand; if alios_idle
  is down or the vhosts can't be read they wake it as before.
- `alios list` reads the stop markers only when a project is down and
  alios_idle runs, and on a read error calls nothing asleep.
- The stop message no longer promises "stays stopped" after a failed
  mark; docs list which commands clear and keep the marker.
@michaelaguiar
michaelaguiar merged commit 429d57f into main Oct 13, 2026
@michaelaguiar
michaelaguiar deleted the scale-to-zero branch October 13, 2026 20:56
@linear-code

linear-code Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
ALI-836 Rename alios-cli to Ingot and ship 2.0.0 with scale to zero

Record of the work finished 2026-10-13 and 2026-10-14. Nothing is left to do here; the follow-ups are linked.

What shipped

Migration on Mike's desktop

  • Moved over: all 13 projects, the CA (already trusted), and the MySQL 8.0 data.
  • Hostnames updated:
    • aguiarshomecrumb MAIL_HOST=ingot_mail
    • alios DB_HOST=ingot_mysql
    • chandlerpediatrics, via ingot env set DB_HOST=ingot_mysql
  • Cleanup: all alios containers, volumes, the network and the binary are removed. ~/.bashrc now has alias php='ingot exec php'.

Verified live

  • 12 projects stopped on schedule.
  • The alios project stayed up because it was getting real traffic.
  • Waking a stopped project takes about 270 ms: michaelaguiar.dev, glowhouse.

Not tested

  • Docker Desktop (macOS/Windows)
  • Rootless Docker

Review in Linear

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