Repository navigation
fix(extend): add the safety floor, write both TTL tags, nudge spored (#54) - #63
Merged
Merged
Conversation
…54) `extend` could hand back a deadline in the past. It added the duration to the existing deadline with no floor, so extending an instance whose deadline had already passed produced a deadline still behind `now` — reported as success, then reaped on the ttl-reaper's next pass. That fails precisely when it matters most: the instance you're trying to rescue is by definition one that's overdue. As with #55, the bug existed twice. `SpawnClient.extend` and the CLI's `extend` each had their own copy of the arithmetic, and each had the same three defects. So the fix is one shared pure function, `computeExtension` (core/lifecycle.ts, next to `ttlDeadline`, the rule it has to agree with), consumed by both. Three changes: 1. **The floor.** `max(old + by, now + by)`, matching Go's cmd/extend.go:126. The two rules compose: a live instance still gets `old + by`, so stop/start still buys nothing; only an overdue one is pulled forward. Both paths say when the floor engaged — an `info` event and a `note:` line — because the user asked for one deadline and got another, and reporting bare success hides that their instance was already expired. 2. **Both TTL tags.** `spawn:ttl` is recomputed from the launch anchor alongside `spawn:ttl-deadline`. The deadline tag is authoritative for both enforcers, but Go's `extend` reads `instance.TTL` for its no-deadline fallback (cmd/extend.go:119) and spored synthesizes `anchor + config.TTL` when the deadline tag is zero (pkg/agent/agent.go:140) — two TTL tags that disagree are a trap for whichever reads the stale one. When there's no usable launch anchor the tag is omitted rather than guessed: absent reads as unknown, wrong reads as fact. 3. **The spored reload** (the issue's "optional" part 3, which turned out to be load-bearing). spored evaluates TTL against an in-memory config it refreshes from tags only every ~5 ticks (pkg/agent/agent.go:378), so between an extend and that refresh it still holds the OLD deadline and can terminate the instance the user just rescued. Go nudges it over SSH (`triggerReload`); a browser has no private key, so `EC2Provider.reloadAgent` uses `ssm:SendCommand` + AWS-RunShellScript to run the same `sudo spored reload`. Preflighted the SSM endpoint live: `access-control-allow-origin: *`, so no proxy. It's an optional `Provider` method, best-effort, and never fatal — the tag write is the durable part and has already succeeded. Absence of the capability and a failed call are treated identically: a stated gap naming the ~5-minute window and the manual command, never silence. A 200 with no CommandId counts as failure too — we can neither confirm nor look it up. The manual hint prefers `spawn:local-username` over a hardcoded ec2-user (as cmd/connect.go:135 does), since a hint that names a nonexistent account fails when followed. Both call sites now gate on `ttlDeadline(i)` rather than the raw `i.ttlDeadlineMs`, so an instance carrying only `spawn:ttl` is extendable instead of rejected. Tests: 420 → 451. Proven to catch the bug: reverting `computeExtension` to the old logic fails 11 of the new tests across all three files. The only pre-existing test ("extend pushes out the TTL deadline") passed in both directions, which is how this survived. Verified by driving the built CLI end-to-end, not just vitest — the clamped + failed-reload output and the live + successful-reload output both read correctly. Closes #54
scttfrdmn
added a commit
that referenced
this pull request
Aug 1, 2026
…us` (#56) (#64) `spawn status` answered "what did you configure" and nothing else. Go appends four notices after its remote `spored status` output (cmd/status.go:130-134); none were ported, and every one of them is pure tag reading that a browser can already do. The headline gap: spored writes `spawn:dns-status` + `spawn:dns-error` when registration fails, specifically so the failure isn't buried in the instance's journal (spawn#435) — and nothing in spawn-ts ever read them. A portal user got an FQDN that never resolves and no explanation, while the diagnostic sat in a tag DescribeInstances had already returned. New pure `src/core/notices.ts` returning structured `{ kind, level, text, detail }` rather than pre-formatted strings, so the CLI, the dashboard and the portal render one source three ways: - lifecycleProtection() — who enforces the deadline, when it falls, and the worst-case *compute* cost to it. The counterpart to accumulatedCost(), which reports only what's been spent; the ceiling is the number that tells a user whether to worry. - dnsNotice() — the failure, with spored's own reason. - sporedUpgrade() + compareSemver() — a port of libs/update's comparison, so the two tools never disagree about whether an upgrade exists. - elasticIpNotice() — an EIP on a *stopped* instance keeps billing (~$3.60/mo) precisely because nothing is using it, which is exactly when the user believes they've stopped paying. Pure; the lookup is src/aws/eip.ts. Absence is never smoothed into reassurance, per #63. Each notice has an input it can't do without, and a missing input omits the notice rather than answering optimistically: no dns-status tag does not mean "registered", and no supplied latest version does not mean "up to date". That principle forces one deliberate divergence from Go. GetInstanceElasticIP (pkg/aws/cleanup.go:219) returns nil,nil on any API error, so a missing ec2:DescribeAddresses permission is indistinguishable from a clean bill of health — in the one check whose entire job is catching an unnoticed charge. Here a failed lookup is its own warn notice naming the error. Two other honesty constraints carried over verbatim and asserted in tests: the out-of-band reaper is described as a backstop "if deployed" (it runs in the infra account and isn't visible from the launch account), and the cost figure keeps its "compute only" label since it excludes EBS and network. Wiring: EC2Provider.lookupElasticIp delegates to the shared lookup with the credentials it already holds, and the CLI falls back to it when the ShellCtx supplies no override — without that the notice would exist but never fire in the real app, since terminal.ts builds a bare ShellCtx. The dashboard renders the two notices its meters don't already cover, escaped (spawn:dns-error is whatever the DNS endpoint returned, and it lands in innerHTML). Also fixes an adjacent line found by driving the built CLI rather than trusting vitest: humanRemaining() already returns "expired", so `status` on an overdue instance read "ttl: 4h — expired left (terminates)". Not ported, and deliberately: the remote `spored status` output these notices are appended *to* (needs a shell on the box), and Go's fallback of parsing the spored version out of that output. Verified: each new guard was checked against the absent/Go-equivalent behaviour (5 mutations → 11 failures; the XSS guard → 1 more) before being kept. Driven end to end through the built CLI and through Chromium, where the notice CSS was confirmed to actually land. 451 → 503 tests; typecheck, build and build:lib all clean. Refs #56
This was referenced Jul 31, 2026
scttfrdmn
added a commit
that referenced
this pull request
Aug 1, 2026
The plugin *engine* landed in 3da2170 — src/core/plugins.ts parses the spore:plugin:* provenance tag and validates launch declarations, and src/aws/userdata.ts writes /etc/spawn/plugins.json. None of it was reachable. LaunchInput had no `plugins` field, so `spec.plugins` could not be set from SpawnClient, the CLI, or the UI, and nothing called detectPlugins(). Both halves of the issue's two-column matrix existed as dead code. This wires the surface. Declare at launch (7 of 12) - LaunchInput.plugins → LaunchSpec → user-data, verified against the real payload: [{"ref":"jupyterlab"},{"ref":"mountpoint-s3",…}]. - CLI `--plugin ref[@Version]`, repeatable, matching Go's pflag StringArray (cmd/launch_flags.go:351). - Dashboard launch form: a checkbox per declarable plugin, so the offered set IS the supported set and a rejection can't be reached from the form. The five that aren't offered are named with the reason underneath — an unexplained absence reads as an arbitrary omission, and worse, as "the browser has no plugin support". Detect (12 of 12) - `status` renders decoded provenance; `--plugins` asks explicitly. - Instance cards get a `plugins —` line with three distinct styles, so verify=none (a finding), verify=signature (clean) and verify=unknown (no data) can't be read alike. - spore-sync and tailscale render exactly like the rest. A card built on the install column alone shows nothing when five things are deployed, which is the defect the second column exists to fix. Two deliberate divergences from Go - A ref that can't be honoured aborts the launch. Go writes any ref into plugins.json and lets a push-dependent plugin park at StatusWaitingForPush on the box (pkg/pluginruntime/runtime.go:62) — a failure invisible from the launch side. Nothing is billed at the point of refusal and the fix is a one-word edit: refusing costs a retry, launching costs an instance that can't do its job. - The success line says "declared", never "installed". spored installs at boot; whether it worked is only knowable later from the tags. Parser fix, not a workaround parseArgs' flags map is single-value/last-wins, so `--plugin a --plugin b` would have installed one and dropped the other with no signal. Added ParsedArgs.lists + flagList(); flags[] stays last-wins, so every existing single-value reader is untouched. Both exported. Honesty rules carried through from #63/#56 - With no plugin tags, status says NOTHING (and the card renders no line). The tag is best-effort and is never written for launch-time declarations, so absence means "we don't know". --plugins gets describePluginState's full caveat rather than a bare "none". - An unparseable tag value still reports the plugin as deployed — the tag's existence is the evidence. 451 → 538 tests. Every new guard was proven against the absent behaviour first: five mutations (last-wins lists, silent-filter instead of refusal, absence-as-"no plugins installed", one class for every verify tier, fd.get instead of getAll, unregistered --plugins) produced 21 failures across four suites. Found by driving the built CLI, not by the suite: a bare unparseable token was joined into the same comma list as the decoded fields, so "verify=unknown, garbage-no-kv" read as though the garbage had been parsed. It now gets its own line; a forward-compatible key=value pair still goes inline, because that one IS provenance. Also drove the dashboard in real Chromium (new dev-only demo/direct/plugins.harness.html — the tags can only be written by the Go CLI or spored, so no path through the app itself reaches that state) and looked at the rendered card: the three verify tiers compute to green / yellow / grey and the picker reads legibly. Not ported, deliberately: `spawn plugin install` on a running instance (SSH tunnel to :7777 — no SSH in a browser), and the local halves of spore-sync / rclone / tailscale / github-actions-runner / globus-personal-endpoint. docs/data-movement.md already classified those; its `validateDeclarations` example now matches the shipped behaviour instead of implying a partial launch. Closes #53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #54.
extendcould hand back a deadline in the past. It added the duration to the existing deadline with no floor, so extending an instance whose deadline had already passed produced a deadline still behindnow— reported as success, then reaped on the ttl-reaper's next pass. That fails precisely when it matters most: the instance you're trying to rescue is by definition one that's overdue.The shape of the bug is the same as #55
extendexisted twice, independently —SpawnClient.extendand the CLI'sextendeach had their own copy of the arithmetic, and each had the same three defects. So the fix is one shared pure function,computeExtension(src/core/lifecycle.ts, placed next tottlDeadline, the rule it has to agree with), consumed by both.Three changes
1. The floor.
max(old + by, now + by), matching Go'scmd/extend.go:126.The two rules compose — the floor is a lower bound on the anchored sum, not a replacement for it. A live instance still gets
old + by, so stop/start still buys nothing; only an overdue one is pulled forward. Both paths say when the floor engaged (aninfoevent; anote:line), because the user asked for one deadline and got another, and reporting bare success hides that their instance was already expired.2. Both TTL tags.
spawn:ttlis recomputed from the launch anchor alongsidespawn:ttl-deadline.The deadline tag is authoritative for both enforcers, so this is nearly cosmetic — but not quite: Go's own
extendreadsinstance.TTLfor its no-deadline-tag fallback (cmd/extend.go:119), and spored synthesizesanchor + config.TTLwhen the deadline tag is zero (pkg/agent/agent.go:140). Two TTL tags that disagree are a trap for whichever reads the stale one. Where there's no usable launch anchor the tag is omitted rather than guessed — absent reads as unknown, wrong reads as fact.3. The spored reload — the issue's "optional" part 3, which turned out to be load-bearing.
spored evaluates TTL against an in-memory config it refreshes from tags only every ~5 ticks (
pkg/agent/agent.go:378, read againsta.config.TTLDeadlineat:419). So between anextendand that refresh it still holds the OLD deadline — and can terminate the instance the user just rescued. Go nudges it over SSH (triggerReload,cmd/extend.go:303); a browser has no private key, soEC2Provider.reloadAgentusesssm:SendCommand+AWS-RunShellScriptto run the samesudo spored reload.Preflighted the SSM endpoint live before building on it:
So no proxy — same property that made STS and Bedrock browser-callable.
It's an optional
Providermethod, best-effort, and never fatal: the tag write is the durable, authoritative part and has already succeeded. Per #63, absence of the capability and a failed call are treated identically — a stated gap naming the ~5-minute window and the manual command, never silence. A 200 with noCommandIdcounts as failure too, since we can neither confirm it nor look it up later. And a trueokmeans "the reload was requested", not "spored reloaded" — it doesn't poll, and an accepted SendCommand still fails on a box whose SSM Agent isn't running.The manual hint prefers
spawn:local-usernameover a hardcodedec2-user(ascmd/connect.go:135does) — a hint naming an account that doesn't exist on the box fails when it's followed.Also
Both call sites now gate on
ttlDeadline(i)rather than the rawi.ttlDeadlineMs, so an instance carrying onlyspawn:ttlis extendable instead of rejected outright.New permission requirement, documented:
ssm:SendCommand, plus the instance being SSM-managed. The live-smoke workflow doesn't exerciseextend, so its permission list is unchanged.Verification
npm run typecheck && npm test && npm run buildall clean. 451 tests, up from 420.Proven to catch the bug rather than assert the fix: reverting
computeExtensionto the old logic fails 11 of the new tests across all three files (6 inlifecycle.test.ts, 2 inclient.test.ts, 3 incommands.test.ts). The only pre-existing test — "extend pushes out the TTL deadline" — passes in both directions, which is how this survived.Also driven end-to-end against the built library rather than only through vitest. Worst case (overdue + failed reload):
and the happy path:
Docs: the extend floor and the reload rationale in
docs/lifecycle.md, cross-linked fromconcepts.md;api.md's cost-safety note also corrected, since it still described the pre-#55 guard.