Repository navigation
feat: the lazy CLI last mile, report mode (libs#78) - #1670
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
scttfrdmn
marked this pull request as ready for review
November 20, 2026 19:04
scttfrdmn
force-pushed
the
feat/lastmile-report
branch
from
November 20, 2026 19:11
1763ebe to
fd567cc
Compare
After a command succeeds, the root command's post-run hook runs libs/lastmile (v0.55.0) for spawn: it reports a stale teardown lease (with its plan re-checked by pkg/teardown's report-only deleter), the self-hosted reaper's teardown residue (the spawn-reaper-teardown-invoke role and each region's spawn-reaper-teardown schedule group, #1668) once no spawn lifecycle item is left, and an empty spore-host-lifecycle table. Report only and never in the way: nothing on stdout, nothing at all without --verbose (then debug: lines on stderr), the exit status is untouched, the hook stops waiting after the 30 s budget, between 6-hourly checks it makes no AWS call, and a cut-off check waits an hour. The account comes from the command's own GetCallerIdentity, observed passively through an inert pkg/config seam that only cmd.Execute sets. The lifecycle client refuses every write and the Deleter every delete. Skipped after completion, help, version, footprint, teardown, doctor, cleanup, every reaper subcommand and hidden plumbing commands, and in the infra account; SPORE_LASTMILE=off turns it off. FullVisibility is false: the account-idle verdict is package main of lambda/ttl-reaper and not reusable from cmd. The decision (an activity reader AND readable infra-account tables) is encoded and tested both ways. The wiring is in cmd/lastmile.go; the AWS-touching pieces are in the new pkg/lastmilespawn (cmd may not import SDK services, #326/#327). libs is bumped to v0.55.0 in the root, ttl-reaper and sweep-orchestrator modules. Part of spore-host/libs#78.
…lock) A 1 ns budget can still read as positive under Windows' coarse clock, so lastmile.Run ran. A negative budget is past its deadline everywhere. Part of spore-host/libs#78.
scttfrdmn
force-pushed
the
feat/lastmile-report
branch
from
November 20, 2026 19:57
fd567cc to
2e06e13
Compare
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.
Part of spore-host/libs#78 (leave-no-trace, spore-host/spore-host#752). This is the spawn half: it wires
lastmilefrom libs v0.55.0 into the spawn CLI, in report mode, following lagotto#337's design. (v0.54.0 was tagged before libs#84 merged and has nolastmile.) The root module and both nested modules that use libs (lambda/ttl-reaper,lambda/sweep-orchestrator, indirect) are on v0.55.0.Hook point
rootCmd.PersistentPostRunE = lastMileHook(cmd/root.go,cmd/lastmile.go).cobra.EnableTraverseRunHooks, so a group with its own post-run neither hides it nor runs it twice (tested).completion(and__complete),help,version,footprint,teardown,doctor,cleanup, everyreapersubcommand, and every hidden top-level command (gen-docs,bootstrap-body,awscli-pin,spored-signing-key; discovered fromHidden, not listed). Gated onlastmile.ModeFromEnv():SPORE_LASTMILE=offskips it.--verbose,debug:lines on stderr: theResult.Summary()line, each would-action and each note.cmd.Executeinstalls a passive middleware (lastmilespawn.AccountObserver) through a new, inert seam,spawnconfig.SetCLIAPIOptions. The caller's-account loaders (pkg/aws.NewClientWithRegion,LoadComputeAWSConfig, andLoadInfraAWSConfigonly when infra is the caller's own profile) append it to every config. It records the account from the command's ownGetCallerIdentityresponses, the--accountguard's included, and records nothing if two calls name different accounts (a compute profile in another account). A command that made no STS call skips the last mile. The seam is empty in every other program, so nothing is recorded inside lagotto, calque or spore-host-mcp.footprintspawn.InfraAccountIDis skipped.lastMileMaybeDuereads~/.spore-host/lifecycle.json(version 1) first. Anything it can't read counts as due, andlastmile.Runthen makes the exact decision.Why there's a new
pkg/lastmilespawncmd/aws_imports_test.go(#326/#327) allows cmd no new direct AWS SDK service imports. So the AWS-touching pieces live inpkg/lastmilespawn: the account observer, the read-only lifecycle wrapper, the residue and its re-check, the report-only deleter and the infra probe. None of them runs by itself. The wiring (the hook, the skip list, the seams, the rate-limit pre-check, the options and the visibility decision) is all incmd/lastmile.go, so it can't run inside another program's process.pkg/lastmilespawnandpkg/configare not in the public-surface table, andapi/public-surface.txtis unchanged.Options
Tooltags.ToolSpawnAccountRegionsGetEnabledRegions,ec2:DescribeRegions), listed fromus-east-1when no region is configuredLifecyclelastmilespawn.NewLifecycleReader, withControlRegion = lifecyclemark.ControlRegion(us-east-1, where spawn's creators and the reaper write the global scope). Its DynamoDB clients refuse every write (ReadOnlyLifecycle), as defence in depth under report mode. After one IAM refusal they stop asking.Footprintpkg/aws.AccountFootprint(account, regions)(spawn footprint --all-regions -o json), read at most once per run (a mutex, notsync.Once: see the iamcoverage note)Deleterlastmilespawn.ReportOnlyDeleter. The residue is re-checked byResidueChecker; everything else bypkg/teardown.NewReportOnly, the deleter the reaper's account-idle sweep plans with.Deletealways returnsErrReportOnly.Patternsfootprintspawn.Patternsplus the residue's two exact names (lastmilespawn.Patterns)Residuespawn-reaper-teardown-invoke(global), plus thespawn-reaper-teardownschedule group in every region, per #1668. Each groupDependsOnthe role. All are taggedspore-host:managed-by=spawnand none carriesspore-host:role=service.FullVisibilityfalse, andActivityis nil (below)How the residue is re-checked. The re-check is targeted and never loads the footprint (the "no spawn item anywhere" case is common: see IAM below):
iam:GetRolesaysNoSuchEntity;spawn-ttl-reaper-selfscan-role, exists, because the jobs that remove that role run as this one (a reaper still deployed, or a self-removal that hasn't finished);scheduler:GetScheduleGroupsays not found, and in use whileListSchedulesfinds a job in it. That job also keeps the role (DependsOn).pkg/teardownhas no deleter for either one:spawn reaper teardownremoves them. That's why their names are in the last mile'sPatternsonly, never infootprintspawn.Patterns. When libs#79 turns on reap, someone must wire the reaperdeploy deletes deliberately.The
spore-host-lifecycletables are not inResidue. They belong to the suite, and lastmile reports each empty one itself, to go throughCloseTableIfEmpty.The
FullVisibilitydecision: falselastMileVisibilitysetsFullVisibilityonly when both of these hold:LoadInfraAWSConfigsucceeds, and a one-itemScanof each ofspawn-sweep-orchestration,spawn-pipeline-orchestrationandspawn-schedulesworks (lastmilespawn.InfraSignalsReadable, the same three tables as the reaper's sweep; a missing table counts as readable, as it does there).Production has no reader, so
FullVisibilityis false,Activityis nil, and the infra tables are not even read. The reasons:accountVerdictand its signal readers are packagemainoflambda/ttl-reaper, a separate module. They also importcalque/pkg/calquefootprintfor calque's activity, which spawn's root module doesn't depend on (calque imports spawn).Observe. Without the reaper's sweep, no scope is ever recorded idle, soFullVisibilitycould only ever say "Observe would start the grace now".Moving the verdict into a
pkg/that the reaper and the CLI share is the precondition for setting it, with libs#79. The decision and the probe are tested both ways with fakes.IAM
Nothing is provisioned and no policy changes. All the last mile's calls are reads, and a refused read is silent at default verbosity: one
debug: lastmile: not permitted, skipped: ...line under--verbose, never a warning. After the first refusal by IAM, the lifecycle, IAM and Scheduler readers each stop asking, so an identity without the grants costs one denied request per run per service, not one per region.What a run can call, once per 6 h per account:
ec2:DescribeRegions;dynamodb:GetItem,ScanandDescribeTableonspore-host-lifecycle;iam:GetRole(×2), and per regionscheduler:GetScheduleGroup, plusListTagsForResourceandListScheduleswhere the group exists;Users today mostly can't read the lease table (spawn#1666), so for them the run ends at the first denied
GetItem.docs/reference/cli-iam-actions.mdis regenerated. The inventory walk now includes the root's persistent post-run, so the last mile's calls appear under "Outside any command", and the page says what it is. That list includes delete and write actions: they're the static over-approximation offootprint.Executeand the deleter call graph (the same setspawn teardownlists), and the last mile never makes them. VTA also merges everyfootprint.Deleterthat reachesfootprint.Execute, sospawn teardownnow lists three Scheduler reads (GetScheduleGroup,ListSchedules,ListTagsForResource). Those are reads, andteardownnever makes them.Tests
cmd/lastmile_test.go,pkg/lastmilespawn/*_test.go,pkg/config/cli_api_options_test.go,pkg/aws/client_region_test.go. All are hermetic, with no AWS access:lifecycletest, fakes and a refusing HTTP client.When it runs
reapersubcommand and every hidden top-level command.help,completion bashand__completerun end to end.listruns it.SPORE_LASTMILE=off/OFF/Offskip it before any call. Unset,report,reapand unknown values all run as report, with zero writes and emptyDid.Never in the way
Run, the region listing or the footprint panic, and whenRunreturns warnings and would-actions. This holds with and without--verbose. It's captured through both the command's writers and the process's fds.--verbose, every line starts withdebug: lastmile.Runthat ignores its context, and a lifecycle table that never answers, both return within budget + slack.Behaviour
DependsOn, norole=service,FullVisibilityfalse andActivitynil.Deleter.Deleteand aMarkActivethrough the client are both refused.FullVisibilitydecision, both ways: no reader gives false, and the infra probe is not called. Reader plus unreadable infra gives false. Reader plus readable infra gives true, and lastmile asks the reader.--verbose, one denied request across 4 regions.lastMileMaybeDuecases.Runstep that fails skips with one debug line. A footprint failure means no would-delete.Executeinstalls it.pkg/lastmilespawn(100% statements): the observer (conflict, a doubled middleware, failures); the latch (refusals only, not throttles); every write refused before it reaches the table; the residue checker's every branch and its per-service latches; the deleter's routing; the infra probe.Revert checks. Each was applied with a script, built, seen to fail, and reverted:
fmt.Println);cmd.OutOrStdout();recover;FullVisibilityforced true;DependsOn;Executenot installing the observer;NewClientWithRegionnot appending it;Gates
make checkfrom a space-free copy at the physical path/private/tmp/lm-spawn-check: gofmt, vet, every GOOS, staticcheck, golangci-lint (0 issues in all 10 modules), hermetic short tests (./cmd,./internal/iamcoverage, which includesTestEveryCreatorMarksTheLeaseand the principal grants, and./pkg/lastmilespawn), nested modules, tidy and build tags: all passed.The last-mile tests pass with
-race.make cli-iam-actionsregenerated and current.make gen-docs: no diff. The last mile skips the hiddengen-docs.make api-snapshot: no diff.TestPublicAPISurfacepasses; no public package changed its exported surface.The changelog test passes:
Addedhas the last mile,Changedhas the libs bump.The Tier 0 coverage table is unchanged: no command was added or altered. The hook is a root post-run, and the gate compares the command list.
semgrep scan --config=auto --erroron every changed file: clean, with nonosemgrepadded.Patch coverage of the new and changed code (deduplicated statement blocks):
cmd/lastmile.go97.6% (the 3 lines not hit are the lifecycle-client error branch, which can't fire with a ControlRegion set);pkg/lastmilespawn100%;pkg/config/cli_api_options.go100%. Overall 99.0% (298/301). The one other changed line not covered is theSetCLIAPIOptionscall inExecute, which callsos.Exit; a source gate covers it.CI: every check is green, including
codecov/patch, Test (Windows) and E2E Tier 0 (Substrate). The first Windows run failed.no budget leftused a 1 ns budget, and on Windows' coarse clock that can still read as positive. The second commit makes the budget negative, which is already past its deadline everywhere.For libs#79
pkg/teardowncan't delete the invoke role or the schedule group. Wirepkg/reaperdeploy's deletes, and replaceReportOnlyLifecycleandReportOnlyDeleterdeliberately; the tests pin both.FullVisibilityneeds the reaper's verdict in a sharedpkg/. Until then the CLI can't judge spawn idle.lastmiledue-check, and lastmile's own backoff after a cut-off scope.