Skip to content

fix(agent): let upgrade run on a machine with no recovery partition - #4821

Merged
mudler merged 1 commit into
kairos-io:masterfrom
ci-forks:fix/4820-upgrade-no-recovery
Sep 29, 2026
Merged

mudler merged 1 commit into
kairos-io:masterfrom
ci-forks:fix/4820-upgrade-no-recovery

Conversation

@ci-robbot

Copy link
Copy Markdown
Collaborator

Fixes #4820

kairos-agent upgrade panicked with a nil pointer dereference on any machine without a COS_RECOVERY partition.

NewUpgradeSpec leaves Partitions.Recovery nil when neither the ghw partition list nor the device-mapper lookup finds it, and UpgradeSpec.Sanitize requires it only for a --recovery upgrade. Run then mounted it unconditionally, and MountRWPartition discards the "nil partition" error IsMounted returns, so the nil reached MountPartition and was dereferenced.

A system upgrade never writes to the recovery partition. Partitions.Recovery is read exactly once in upgrade.go, inside the RecoveryUpgrade() branch that picks the final image file. Every other optional partition in the same file already skips when absent: OEM and persistent in upgradeHook, persistent in recordState, EFI in refreshESP. This makes recovery behave the same way.

Test

New spec in agent/pkg/action/upgrade_test.go, in the existing "Booting from COS_ACTIVE" context: set spec.Partitions.Recovery = nil and upgrade from a docker source, asserting the active image is replaced and the old one is backed up to passive.

Checked by mutation: with the fix reverted the spec fails with runtime error: invalid memory address or nil pointer dereference; with it, 1 Passed. The whole agent/pkg/action suite is green.

AI disclosure

Written by an AI agent. No human read the code before this pull request was opened.

NewUpgradeSpec leaves Partitions.Recovery nil when the machine has no
COS_RECOVERY, and Sanitize only requires it for a recovery upgrade. Run
mounted it unconditionally, so a plain upgrade on such a machine panicked
with a nil pointer dereference inside MountPartition instead of upgrading.

A system upgrade never writes to the recovery partition: it is read only
in the RecoveryUpgrade branch that picks the final image file. Skip the
mount when it is absent, the way OEM, persistent and EFI are already
skipped in this file.

Fixes kairos-io#4820

Signed-off-by: Ettore Di Giacinto <mudler@kairos.io>
@itxaka-agent

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

Picking this up for review โ€” checking the nil-partition fix against the upgrade code paths it touches and the accompanying test.

@itxaka-agent itxaka-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override any
action taken here.

Round 0: approve. The nil-recovery-partition panic in #4820 is real โ€” MountRWPartition discards the "nil partition" error IsMounted returns, so the nil reaches MountPartition's dereference. The fix matches how OEM, persistent, and EFI are already skipped when absent elsewhere in this file, and the flipped test panics on master and passes with the fix.

Two things worth a maintainer's glance before merge, not blockers: the commit's Signed-off-by (Ettore Di Giacinto) doesn't match the PR account (ci-robbot), and the PR body has no AI-use disclosure per the repo's AGENTS.md.

@itxaka-agent

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override any
action taken here.

Audit summary โ€” round 0: approve. Full review: #4821 (review)

@mudler
mudler merged commit f81d543 into kairos-io:master Sep 29, 2026
1 of 2 checks passed

This branch was previously deployed

1 inactive deployment
fork-pr-builds โ€” 24a632fb Deployed Sep 20, 2026 by ci-robbot via authorize #663
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.

kairos-agent upgrade panics on a machine with no recovery partition, which NewUpgradeSpec and Sanitize both treat as optional

3 participants