Skip to content

feat(cleanup,reaper): delete orphaned schedule params (#1398) - #1414

Merged
scttfrdmn merged 4 commits into
mainfrom
fix/1398-schedule-orphan-sweeper
Oct 29, 2026
Merged

scttfrdmn merged 4 commits into
mainfrom
fix/1398-schedule-orphan-sweeper

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1398

Since #1382, schedule params (spawn-schedules-<region>/schedules/<id>/params.yaml) have no expiry. Three paths leave them orphaned once the record's TTL deletes the record. This adds the named deleter: one rule in pkg/schedulesweep, used by the TTL reaper (REAPER_SCHEDULE_PARAMS) and by spawn cleanup --schedule-params. It follows the #1301 / #1351 / #1378 pattern.

Deletion rule (all must hold)

  • The bucket is spawn-schedules-<region> or spawn-schedules-<this account>-<region>, found with ListBuckets(Prefix). Every call names the account as ExpectedBucketOwner, and each bucket is read in its own region.
  • The key is exactly schedules/<id>/params.yaml.
  • No record in spawn-schedules has that schedule_id or names that bucket/key. The table is read with a full consistent Scan, done after the objects are listed. Records are read by instancerole.ScanSchedules, now shared with the Reaper InstanceRoles would delete a spawn-instance-* role that an enabled schedule still names #1378 role sweep.
  • The object is at least scheduler.RecordTTLMargin (30 d) old.
  • It is a schedule's params, not a queue config. It must be tagged Component=scheduler with ScheduleID=<id> and have no QueueID tag, and <id> must match sched-YYYYMMDD-HHMMSS (the form GenerateScheduleID gives).
    • The key layout can't tell a queue config from params: UploadQueueConfig writes the same key.
    • Current queue configs are Component=queue&QueueID=....
    • Pre-v0.148.0 queue configs were tagged exactly like params (Component=scheduler&ScheduleID=queue-...). Only the id form tells them apart.
    • If the tags can't be read, or there are none, the object is kept.

Fail closed: if any Scan page fails or any record can't be decoded, the sweep deletes nothing anywhere. The reaper counts this in schedule_params_unreadable, and also in Errors unless the cause is AccessDenied. The CLI refuses.

Reaper switch

off|report|reap, default report, with REAPER_DRY_RUN overriding. It is set by:

  • the template parameter ScheduleParams
  • the make variable SCHEDULE_PARAMS
  • spawn reaper deploy --schedule-params
  • pkg/reaperconfig (Settable and the census)

The value survives a deploy that doesn't name it (TestScheduleParamsSurvivesAMakeDeploy). The sweep runs once per run, on the function's own credentials.

IAM

Source: pkg/reaperiam.ScheduleParamsSweepStatements, copied into the SAM template (unconditional, beside the #1378 read) and into ScanSelfPolicyDocument (spawn reaper deploy):

  • s3:ListAllMyBuckets on * (ListBuckets has no resource ARN and returns names only)
  • s3:ListBucket on arn:aws:s3:::spawn-schedules-*, with StringLike s3:prefix = schedules/*
  • s3:GetObjectTagging and s3:DeleteObject on arn:aws:s3:::spawn-schedules-*/schedules/*

The member role (ttl-reaper-cross-account-role.yaml) is unchanged: schedules live in the reaper's own (infra) account, where spawn schedule create writes them with LoadInfraAWSConfig. TestScheduleReadIsOnTheReapersOwnRoleOnly enforces this. internal/iamcoverage can now claim call sites by package, so pkg/schedulesweep's calls are checked against the function role.

CLI (make cli-iam-actions): spawn cleanup now also needs s3:ListAllMyBuckets and s3:GetObjectTagging, both already needed by other commands. They are used only for --schedule-params, in the infra account.

Deploy steps

  1. Merge, then redeploy the reaper from lambda/ttl-reaper: make deploy (no SCHEDULE_PARAMS). The stack gets ScheduleParams=report and the new grants. Snapshot the stack parameters before the deploy and diff them after; expect zero drift apart from the new parameter.
  2. Check the run summary (schedule_params_*) and the WOULD delete schedule params lines.
  3. Leave the switch at report until reviewed. Arm it later with make deploy SCHEDULE_PARAMS=reap.

No member-role redeploy is needed.

Checks

make check, make lint (0 issues), semgrep scan --config=auto --error ., make check-docs and make api-snapshot (no change) all pass. Each gate was watched failing against a revert that compiles; see the agent report.

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.21519% with 169 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...hedulesweep/schedulesweeptest/schedulesweeptest.go 0.00% 122 Missing ⚠️
pkg/schedulesweep/schedulesweep.go 82.82% 28 Missing ⚠️
cmd/cleanup.go 75.36% 17 Missing ⚠️
pkg/instancerole/schedules.go 91.30% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

…1398)

pkg/schedulesweep decides when a schedules/<id>/params.yaml in a
spawn-schedules-* bucket is orphaned: no record names it (consistent
full scan, after the listing), older than RecordTTLMargin, tagged as a
schedule's params (not a queue config, current or pre-#1399), in a
bucket named for the account. Fails closed on an unreadable table.
instancerole.ScanSchedules is now shared by the role sweep and this one.
#1398)

Off/report/reap, unset = report, threaded through the template
(ScheduleParams), the Makefile (SCHEDULE_PARAMS) and spawn reaper deploy
--schedule-params, with the preservation gate. Runs once per run on the
reaper's own credentials. IAM in pkg/reaperiam.ScheduleParamsSweepStatements
and the SAM template: s3:ListAllMyBuckets, s3:ListBucket on
spawn-schedules-* conditioned on s3:prefix schedules/*, and
s3:GetObjectTagging + s3:DeleteObject on spawn-schedules-*/schedules/*.
The same pkg/schedulesweep rule from a workstation, on spawn's infra
account credentials, dry-run aware. iamcoverage now claims call sites by
package, so the sweep's s3:ListBucket/DeleteObject are held to the
reaper's own role, not the member role. Docs, README, CHANGELOG.
@scttfrdmn
scttfrdmn force-pushed the fix/1398-schedule-orphan-sweeper branch from 4cf4ab3 to 657a42c Compare October 29, 2026 05:41
@scttfrdmn
scttfrdmn merged commit 2dddb5b into main Oct 29, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1398-schedule-orphan-sweeper branch October 29, 2026 05:59
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.

Schedule params orphaned after the record TTL in three edge cases (failed one-time firing, paused past end-after, cadence > 30 days)

1 participant