Skip to content

Make --on-idle hibernate and --on-complete hibernate configure hibernation (#949) - #961

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/949
Oct 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/949

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #949

Stacked on #951 (base fix/922). Review and merge #951 first.

What was wrong

EC2 hibernates only an instance launched with HibernationOptions.Configured=true and an encrypted root, and only --hibernate set those. --on-idle hibernate, --hibernate-on-idle and --on-complete hibernate all launched an instance whose hibernate fell back to a plain stop in EC2Provider.Hibernate, so RAM was lost. After #922, a persistent Spot request for one of these launches was interrupted by stop as well.

Fix: imply, don't refuse

Implying hibernation is cheap here. config.Hibernate already carries the whole configuration: HibernationOptions, the encrypted root, and the hibernate interruption behaviour on a persistent Spot request. The CLI pre-flight already refused types that can't hibernate when --on-idle hibernate was given.

  • pkg/aws: added LaunchConfig.HibernationRequested(). Launch normalizes Hibernate from it before it builds tags, block devices and Spot options. This is where the invariant lives, so SDK callers (lagotto, spore-host-mcp, sweeps) get the fix too.
  • CLI: buildLaunchConfig sets Hibernate too, so the pre-flight, the dry-run plan and --estimate-only all see it. The pre-flight now covers --on-complete hibernate as well, and its refusal names the flag that asked for hibernation.
  • Root size: with no --volume-size, a hibernation launch's root is sized from the type's real memory (DescribeInstanceTypes via the existing InstanceMemoryMiB) plus 10 GiB. The per-family table gave every m7i 16 GiB of RAM, so an m7i.4xlarge (64 GiB) got a 26 GiB root. When the lookup fails it falls back to that table. An explicit --volume-size is kept as given.
  • spawn status: reads EC2's HibernationOptions.Configured (new field InstanceInfo.HibernationConfigured). For an --on-idle hibernate instance launched before this fix, it now says the idle timeout will stop it and RAM is not kept.
  • Public API, additions only (snapshot updated): LaunchConfig.HibernationRequested() and InstanceInfo.HibernationConfigured.

Tests (each seen to fail against a revert that compiles)

  • pkg/aws TestLaunch_HibernateLifecycleConfiguresHibernation goes through the real Client.Launch against a wire-level fake. It checks HibernationOptions.Configured and the encrypted root for each lifecycle.
  • pkg/aws TestLaunch_HibernationRootSizedFromRealMemory and TestHibernationRootGiB.
  • pkg/aws TestLaunch_SpotRequestShapeForEachLifecycle: the --spot launches one-time Spot requests, which EC2 cannot stop — idle-stop, on-idle/on-complete stop, hibernate and 'spawn stop' can never work for --spot #922 row that expected on-idle hibernate → interruption stop was asserting the bug, so it now expects hibernate. A new on-complete hibernate row is added.
  • cmd TestBuildLaunchConfig_HibernateLifecycleImpliesHibernation, TestHibernationRequestedBy, and TestIdleActionDescription with a new not-configured row.

Reverts tried: HibernationRequested returning only lc.Hibernate, the CLI implication disabled with if false &&, the RAM-size assignment replaced with _ = gib, and the status branch disabled with if false &&. Every one made its tests fail.

make check: everything passes except the known Docker-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker. make check-nested: all 9 nested modules clean.

Caveats

  • An SDK caller that sets HibernateOnIdle or OnComplete: "hibernate" on a type or AMI that can't hibernate now gets an EC2 RunInstances error, where before the launch succeeded and later stopped instead of hibernating. Only the CLI runs the friendly pre-flight.
  • --spot --on-idle hibernate with no idle timeout now makes a persistent request, because hibernation is configured.
  • AMI support for hibernation is not pre-checked. EC2 rejects an unsupported AMI at RunInstances.
  • Not tested against live AWS (cost rules).

…ation (#949)

EC2 hibernates only an instance launched with HibernationOptions.Configured
and an encrypted root, and only --hibernate set that. --on-idle hibernate,
--hibernate-on-idle and --on-complete hibernate therefore launched instances
whose hibernate fell back to a plain stop, and a persistent Spot request was
interrupted by stop.

pkg/aws Launch now implies Hibernate from LaunchConfig.HibernationRequested(),
before tags, block devices and Spot options are built, so SDK callers get it
too. The CLI sets it in buildLaunchConfig so the hibernation pre-flight (now
also covering --on-complete hibernate), dry-run and estimate see it. With no
--volume-size the hibernation root is sized from the type's real memory
(DescribeInstanceTypes) + 10 GiB. spawn status reads EC2's
HibernationOptions.Configured (new InstanceInfo.HibernationConfigured) and says
a not-configured instance will be stopped, not hibernated.

(#949)
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_preflight.go 75.00% 2 Missing and 1 partial ⚠️
cmd/launch_single.go 0.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit da89df4 into main Oct 17, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/949 branch October 17, 2026 01:51
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.

--on-idle hibernate / --on-complete hibernate without --hibernate never configure hibernation, so 'hibernate' silently becomes stop

1 participant