Skip to content

feat: configure persistent swap by default on new devboxes - #25

Open
banjo wants to merge 2 commits into
mainfrom
feat/default-swap
Open

banjo wants to merge 2 commits into
mainfrom
feat/default-swap

Conversation

@banjo

@banjo banjo commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

What

Configure 2 GiB swap by default during first-boot cloud-init, before Docker/mise setup and application work. This protects small devboxes from short-lived build/browser memory spikes without relying on an agent remembering a manual swap command.

  • swap_size_mib = 2048 by default; configurable non-negative integer, 0 skips setup.
  • Reuse any active swap rather than allocating another file.
  • Otherwise create a fully allocated /var/lib/devbox/swapfile with 0600 permissions, activate it, read back activation and persist one /etc/fstab entry.
  • Reactivate inactive managed swap without reformatting/resizing; refuse unsafe or non-swap files.
  • Require space for the allocation plus a 1 GiB disk reserve; report syscall/allocation errors visibly.
  • Update README, example config and the versioned devbox skill. Swap is spike protection, not an excuse for unlimited concurrency or a substitute for RAM.

The setting applies when provisioning (including from a snapshot), not to an already running server. Changing it does not resize existing swap, and zero never removes/disables existing swap.

Verification — all remote

  • uv run --frozen pytest -q: 289 passed.
  • New helper/config/rendering/CLI tests cover custom/disabled values, repeats, preservation, low disk, permissions, failures, unsafe files and fstab behavior.
  • Review follow-ups: halt bootstrap immediately on helper failure; clean up only a newly-created file after failed mkswap so retries work; reject noauto fstab entries rather than claiming reboot persistence.
  • Real cloud-init shellify() verification: forced helper failure exits 37 and skips the next command.
  • Regression sensitivity: old cloud-init template fails all three new rendering cases; restored change passes the full suite.
  • uv build --wheel: pass; verified both helper modules and the cloud-init YAML are included.
  • Rendered cloud-init passes cloud-init schema on Ubuntu 24.04.
  • Live helper reuse of the existing host swap leaves its swap table and /etc/fstab unchanged.
  • Real Linux allocation/activation/repeat/inactive-reactivation/fstab activation exercised with an isolated 64 MiB test file, then cleaned up. Test-only inventory filtering hid unrelated host swap so the allocation branch could be exercised without disabling it.

Not tested: new Hetzner VM provisioning, actual reboot or provider snapshot round-trip. No extra server was created and the existing Draw preview/server was not rebooted. No controller-host test/build execution.

See verification details.

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