Skip to content

fix(nativeupdate): fall back to the previous release when current is damaged - #1895

Merged
frahlg merged 2 commits into
masterfrom
f4-launcher-falls-back-to-previous
Oct 27, 2026
Merged

frahlg merged 2 commits into
masterfrom
f4-launcher-falls-back-to-previous

Conversation

@frahlg

@frahlg frahlg commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Item F4 of the stable plan.

Problem

Manager.Select always ends with ReleaseDir(state.Current) (slots.go:182-187). If one file in the current release goes missing, for example web/index.html after SD card damage, every start fails with release v0.132.0 is incomplete. The launcher exits, systemd restarts it every 5 s, and Core never runs. Probation cannot help: it acts only within one hour of a commit, and its rollback check also requires a healthy current release. ftw-launcher rollback fails for the same reason. The only fix today is to edit /opt/ftw/slots.json by hand.

Repro: current v0.132.0, previous v0.131.0, both on schema 7, 48 h after commit. Delete releases/v0.132.0/web/index.html. On master, five starts in a row fail and the slots stay unchanged.

ADR 0007 decision 3 already says the launcher should select previous offline under the same schema rule. The code did not.

Change

When the current release fails its check and no trial is starting, Select now runs the previous release once as a trial. It does so only when:

  • the previous release passes ReleaseDir;
  • the previous release has not already failed (Previous != LastFailed), so a fallback that dies is not retried;
  • the receipts of both releases are readable and name the same state schema.

If the current receipt is the damaged file, the schema is unknown, so the launcher does not fall back. The trial commits like any other trial, after Core is ready. rollbackCandidateLocked and PrepareRollback are unchanged. The launcher logs a warning naming both releases when it falls back.

Select sets LastFailed to the damaged current release only when nothing is marked yet. A release that already failed, such as a trial that just crashed, stays marked, so the update check does not offer it again. A fallback trial that dies still marks the previous release through the trial branch, so it runs only once.

launch() used to refuse a trial from its second Select. With a pending update that failed to exec while current was damaged, the fallback never ran, and the next start marked it failed (Codex P2). launch() now execs that trial with one attempt. If the exec fails, it records the failure with FailTrial and returns the error.

Rollout

The fallback runs in ftw-launcher. ftw update replaces only releases/<tag>, not /opt/ftw/ftw-launcher (ADR 0007 decision 14; docs/native-beta.md "Launcher and command updates"). A box gets this only after an installer refresh from a release that contains it. The changeset says so, and the release notes should ask for the refresh.

Tests

  • slots_damaged_current_test.go: the audit repro TestSelectFallsBackWhenCurrentReleaseIsDamaged (fails on master, passes here), one-time fallback, no fallback without a current receipt, no fallback across schemas, and TestSelectFallbackKeepsTheCrashedTrialMarked.
  • cmd/ftw-launcher/main_test.go: TestTrialExecFailureWithDamagedCurrentRunsPrevious and TestFallbackExecFailureIsRecordedAndNotRetried. These three new tests fail without the second commit.
  • cd go && go test -race -count=1 ./internal/nativeupdate/... ./cmd/ftw-launcher/... ./internal/selfupdate/... ./internal/ftwcli/...: ok
  • go test ./cmd/ftw -run 'Native|Trial|Fallback', go vet ./... and go build ./...: ok

Risk

Low. The new path runs only when Select would otherwise return an error, so a healthy box behaves as before. It never crosses a state schema. After a successful fallback, Prune refuses to run while the damaged release is still Previous, and logs a warning. The next update clears this.

🤖 Generated with Claude Code

…damaged

Select always ended on Current, so a release with a missing file failed
every start. When Current fails its release check, the previous release
is healthy and both receipts name the same state schema, run Previous
once as a trial and record Current as LastFailed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T13:33:02.267050Z 69eb361 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 69eb361da6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +196 to +197
tag, trial = previous, true
path, readErr = m.ReleaseDir(tag)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow the launcher to execute the newly selected fallback trial

If a pending update fails to exec and the current release is also damaged, this path selects the healthy previous release as a trial, but launch in go/cmd/ftw-launcher/main.go:121–126 explicitly rejects a trial returned by its second Select() call. The launcher exits with fallback selected another trial without executing the previous release. On the next service start, Select() marks that unexecuted trial as failed, permanently suppressing the only healthy fallback. Update the launcher to accept this recovery transition, and cover the pending-update exec-failure scenario with a launcher integration test.

Useful? React with 👍 / 👎.

When a pending update failed to exec while current was damaged, the
launcher's second Select returned the previous release as a trial, and
launch() refused it. The next start then marked that unrun release as
failed, so the box stayed in its restart loop. launch() now execs the
fallback as a trial with one attempt and records a failure with
FailTrial.

The fallback no longer overwrites a LastFailed that is already set, such
as a trial that just crashed. Updates would otherwise offer that release
again. A fallback that dies still marks the previous release, so it runs
only once.

Log a warning when the launcher falls back, and say in the changeset
that boxes need an installer refresh of ftw-launcher to get this.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@frahlg
frahlg merged commit d35748e into master Oct 27, 2026
22 checks passed
@frahlg
frahlg deleted the f4-launcher-falls-back-to-previous branch November 11, 2026 09:16
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