carlos / platform Public

Release staging rolls back a healthy build when another supervisor restarts the unit at the same time ("systemd restarted it (new invocation)") Issue open

Claimed by claude~paul@keymail.dev 3 weeks ago

On Tito production (IE box, carlos v0.28.15), a release was rolled back as "did not come up" when it had come up fine. Another supervisor on the box restarted the same unit at the same moment as the staging pass's own restart. The staging pass saw a systemd invocation it didn't start and treated that as a failure.

What happened (2026-10-27, UTC)

titogo merge 2bf0a40 was promoted to edge at 22:02:27.

  • 22:02:41: carlos-stage moved connect, demo, go, vicky, tunnel and the shared platform.ie.go.tito.io binary 4d678aa → 2bf0a40.
  • 22:02:42: titogo's own control daemon saw /opt/carlos/live/yste-demo-canary.go.tito.io change and restarted titogo-canary@yste-demo-canary.go.tito.io, as the staging pass was restarting it too. The staging pass logged:

`` yste-demo-canary.go.tito.io: update to 2bf0a40 failed: titogo-canary@yste-demo-canary.go.tito.io.service did not come up: systemd restarted it (new invocation) — rolled the symlink back ` The unit's own journal shows the instance starting cleanly (serve: instance on unix:/run/titogo/yste-demo-canary.go.tito.io.sock ...`).

  • 22:02:43: every other host skipped 2bf0a40 ("failed on another host this pass"), except about 40 hibernating hosts, which had already been repointed to 2bf0a40.
  • 22:02:55: the next pass refused 2bf0a40 for connect, platform.ie, tunnel and yste-demo-canary: `` refused: 2bf0a40 did not come up on this box at 2026-10-27T22:02:40Z (systemd restarted it (new invocation) — ...); retry with: carlos promote --retry 2bf0a40 edge ``
  • 22:03–22:08: the shared binary went back to 4d678aa, and titogo's control daemon restarted the always-on fleet onto it.

The result: the box was split for an hour. Hibernating hosts woke on 2bf0a40 and always-on hosts stayed on 4d678aa. The deploy's "Serving check" waited about 15 minutes and failed. It cleared only when the next merge (a621578) staged cleanly at 23:03.

The "Supervising process N which is not our child" line in the evidence comes from the unit's PrivatePIDs=yes and isn't the cause.

What I think is wrong

The staging pass's "did it come up" check treats any new systemd invocation it didn't start as a crash-restart. Here the extra invocation was a deliberate restart by another process, and the new build was healthy. One clash rolled back the whole release for the box, and the refusal is sticky until someone runs carlos promote --retry.

What would help

  • Base "came up" on whether the new build actually serves, not on the invocation count. For example, the unit is active, running the new target, and its socket answers. If something else restarts the unit onto the same new build, that should count as a pass.
  • Or wait out a concurrent restart: if the invocation changes, keep checking for the remaining time before declaring failure.
  • Say who restarted it. The failure message reads like a crash. Reporting "restarted by something other than this pass" would have pointed straight at the clash.
  • Downstream: titogo CI's deploy check says "the server box has stopped picking up releases" whenever edge holds a build the box isn't serving. That sent us looking in the wrong place. If the box could report "refused 2bf0a40 (see stage log)" somewhere a deploy check can read, the check could say that instead.

titogo is also fixing its side: its control daemon shouldn't restart units on a symlink change while CARLOS is staging them (tracked at Tito as PRO-6381). The CARLOS check should still survive a restart it didn't make, because any operator service could cause one.

A fix is ready for review on stage-foreign-restart-452. It is not merged and not released; that is Paul's call. Tito production stays on v0.28.15.

What was wrong. settleUnit (internal/host/unitsettle.go) is the "did it come up" check behind every named-unit restart: stage/adopt, the rollback restart, and the legacy and root restart requests. It fixed on the first new invocation it saw and failed on any later one, as "systemd restarted it (new invocation)". titogo-controld's restart at the same second was exactly that.

What changed. The fix is in the check itself; nothing is specific to titogo.

  • A later invocation with NRestarts 0 is now treated as a restart by something else. A crash-restart by systemd's Restart= bumps that counter and still fails at once. For the NRestarts-0 case, the check moves onto the new invocation and keeps the same proof until the original deadline: active, MainPID's exe in the new version's directory, then the Ready probe (socket or HTTP). With no probe, the Hold starts again in the new invocation. A restart onto the same healthy new build now passes.
  • inactive/dead counts as an operator stop only with no pending Job. Another caller's restart passes through that state with its start job queued. Before, that read as "stopped, not judged" and the new build went unchecked.
  • It still fails on a failed unit, a crash loop, the old build at the deadline, or a build that never answers.
  • The message says when the restart wasn't a crash. Failures after a foreign restart now add "during the check it was also restarted N time(s) by something other than this pass, not by systemd's Restart=".

How it was tested.

  • The #452 sequence was written first as a test and failed with the production message ("did not come up: systemd restarted it (new invocation)").
  • New settleUnit cases cover: a foreign restart onto the new build (passes), the Hold restarting, onto the old build (fails, with the note), never ready (fails, with the note), a crash loop after a foreign restart including the RestartSec wait (fails at once), the stop half of a foreign restart followed by healthy and by failed, and the exe check not carried across invocations.
  • go test ./internal/host/ -run 'TestSettle|TestParseShow|TestNamedRestart|TestRollbackRestart|Restart' passes. The census tests (./internal/provision -run 'Census|Plan14') pass.
  • amadan CI on the tip 68da4b7f6e8ce525edc907f33dd016532adab4e4: passed. - The run before it, on 00a7dee6, failed two tests in other packages: TestLargeManifestReleaseThenKeep (activator) and TestDBForwardThroughTheBackhaulHop (root). Both pass on local re-run (×5, ×3), so they look like flakes. - A local full make test hit only environment failures that CI does not have (VCS stamping inside a linked worktree, a privileged-mount test). go build ./... and go vet ./... are clean.

Review. Astra (gpt-6-astra) ran three rounds; findings are under docs/superpowers/reviews/CODEX-FINDINGS-stage-foreign-restart-452-r*.md.

  • Round 1 found two blockers, both fixed: the stop half above, and a /proc permission skip leaking into the next invocation.
  • Round 2 found the census overlay missing (now proposed) and one P3.
  • Round 3: READY, census approved and recorded on #280.

Left open.

  • Follow-up P3 (branch task 905): a foreign restart whose invocations never reach active isn't counted in the message. The verdict is still right.
  • This branch does not cover the downstream point in the issue: letting the box publish "refused 2bf0a40" somewhere titogo's deploy check can read. That is a separate change if wanted.
  • The fix relies on systemd's NRestarts semantics (a manual start resets it; Restart= increments it before the new invocation). The existing check already relied on them, and Astra checked them against systemd v257's source.