Skip to content

fix(launcher): strip comments from the bootstrap's user data (#1246) - #1273

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1246-bootstrap-size
Oct 23, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1246-bootstrap-size

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1246

The spored bootstrap's static script text was 39 KB raw, and 16.5 KB of that was comments. Gzipped, the bootstrap alone was 12.8 KB of EC2's 16 KiB user-data limit. A trivial spawn task run used 14,711 bytes, leaving about 1.7 KB for a task's own command.

Change

New package internal/shellmin. Strip drops whole-line comments and blank lines and keeps every other line byte for byte. Heredoc bodies are kept whole: quoted, unquoted and <<- are tracked, and a <<< here-string is not mistaken for a heredoc. BuildLinuxBootstrap strips only spawn's own five static templates:

  • the key setup;
  • the verified spored install;
  • the Spot-replacement check;
  • the bootstrap body, stripped before the completion-file path is substituted in;
  • the Spot-replacement stop.

Caller content (command, storage, container and custom user data) is added as given.

bash -c 'echo hi' task, gzipped user data before after
bare bootstrap 12,829 B 7,253 B
whole task (spawn task run --dry-run, real AWS, us-west-2) 14,711 of 16,384 9,149 of 16,384

A task now has about 7.2 KB of headroom instead of 1.7 KB.

Gates

  • TestMinifiedTemplatesParseTheSame parses each template with mvdan.cc/sh (the shfmt parser) before and after stripping. It prints both, comment-free and minified, and requires them to be identical. So Strip must remove nothing but comments, blank lines and layout. With heredoc tracking disabled, it fails on the real bootstrap body, not just on the unit cases.
  • TestEveryStrippedTemplateIsChecked reads bootstrap.go's shellmin.Strip calls from its AST, so a template added later cannot skip that gate. A sixth call fails it.
  • TestMinifyShellKeepsData covers the edge cases: heredocs (quoted, unquoted, <<-), the here-string, and trailing comments, which are kept.
  • TestBareBootstrapFitsItsBudget sets an 8 KiB gzipped budget for the bare bootstrap, as the issue suggests. Growth past it now needs a review decision.

Test changes

Three bootstrap tests located script sections by comment text (# Decode and write SSH public key, # Create login banner). They are now anchored on code. TestBurstMembersInstallAndVerifySpored compares against the stripped install function.

mvdan.cc/sh/v3 is a test-only dependency. Runtime stripping is a line filter, and no lambda module's go.mod changes.

Checks run

  • go test -short ./...: pass.
  • make lint: clean in all 10 modules.
  • semgrep: clean.

Not yet validated on a real instance boot.

@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/shellmin/shellmin.go 0.00% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Booted live from this branch in the dev account, us-west-2, on 2026-10-23: spawn task run --wait on a t4g.nano with a 10m TTL, user data 9,175 of 16,384 bytes.

  • spored installed and running: the spawn:spored-version 0.140.0 and spawn:last-heartbeat tags were set. The verified install fails closed, so spored running means its sha256 and signature checks passed.
  • Command ran: command.log shows bootstrap-1246-ok / aarch64, exit 0, and the completion record says completed.
  • Self-terminated: on-complete terminate, at 21:09:44Z, about 3 min after the command finished.
  • Leak check: no running or stopped instances in the region, and no available volumes or ENIs.

@scttfrdmn
scttfrdmn merged commit e45e1b9 into main Oct 23, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1246-bootstrap-size branch October 23, 2026 21:11
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.

spored bootstrap is 12.5 KB gzipped, 76% of EC2's 16 KiB user-data limit; a task has ~2 KB left

1 participant