Repository navigation
fix(schedule): schedule params/record/EventBridge lifetime, and the target region (#1382, #1383) - #1399
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
- No expiry on schedule params: new schedules buckets get no lifecycle; every upload removes expire-schedules / DeleteOldScheduleParams and keeps other rules. Batch queue configs get their own tag-scoped 7-day rule. - Record TTL: none for unbounded recurring schedules; one-time and end-after schedules expire 30 days after their last possible firing. - spawn schedule cancel deletes params, EventBridge schedule and record, idempotently. EventBridge schedules self-delete on completion; scheduler-handler completes run-out schedules. - The schedule target is always the us-east-1 scheduler-handler; --region only chooses where members launch. The handler reads params in the bucket's region. Fixes #1382 Fixes #1383
scttfrdmn
force-pushed
the
fix/1382-1383-schedule-lifetime-region
branch
from
October 28, 2026 21:08
ba24a31 to
fd584f8
Compare
scttfrdmn
added a commit
that referenced
this pull request
Oct 29, 2026
…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.
scttfrdmn
added a commit
that referenced
this pull request
Oct 29, 2026
* feat(schedulesweep): verifying sweeper for orphaned schedule params (#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. * feat(reaper): REAPER_SCHEDULE_PARAMS sweep of orphaned schedule params (#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/*. * feat(cleanup): spawn cleanup --schedule-params (#1398) 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. * test(iamcoverage): say what the site claim does and does not check (#1398)
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.
Fixes #1382
Fixes #1383
What changed
#1382: schedule params and records expired while the schedule was alive. Nothing deleted what a schedule left behind.
pkg/staging.ensureBucketno longer putsexpire-schedules(7 days onschedules/).reconcileSchedulesLifecycle): Get, dropexpire-schedulesandDeleteOldScheduleParams, keep every other rule, then Put, orDeleteBucketLifecycleif nothing is left. A bucket that needs no change is not written. For a schedule, a lifecycle the CLI can't read or write fails the create; otherwise the params could expire under the schedule.spawn launch --batch-queuewrites to the same bucket and the sameschedules/<id>/params.yamllayout, and the queue's instance role is scoped to that key. So its configs are now uploaded byUploadQueueConfig, taggedComponent=queue, and expired after 7 days by a tag-filteredexpire-queue-configsrule. That rule never matches schedule params, which are taggedComponent=scheduler. The queue path adds this rule and removes nothing, so in a queue-only bucket the oldexpire-schedulesstill expires configs that older CLIs uploaded untagged. If the queue path can't reconcile, it warns and uploads anyway.DeleteScheduledeletes the params object, then the EventBridge schedule, then the record. The record goes last because it is the index to the other two. It is idempotent: a missing key, bucket, EventBridge schedule or record is not an error. If the EventBridge create fails,CreateScheduledeletes the params it was given; if the record save fails, it deletes all three.ttlisomitempty, so the attribute is absent. A one-time or--end-afterschedule gets last possible firing + 30 days: theat()time parsed in the schedule's timezone, orEndAfter, whichever is later. I chose dropping the TTL over refreshing it on each firing because a refresh only happens when the schedule fires. A paused schedule, or one whose cadence is longer than the window, would still lose its record while its EventBridge schedule and params stayed. A--max-executions-only schedule has no TTL at creation: the limit counts successful runs, which may never happen. The handler sets a TTL when it completes the schedule.ActionAfterCompletion=DELETE, so a one-time schedule deletes itself after it fires.--end-afterschedule also getsEndDate=end_after+ 30 days, the same instant as its record TTL.CompleteScheduleon the launch that reachesmax_executions, after a one-time launch succeeds, and on any firing thatFiringAtreports as MaxExecutions or Expired.CompleteSchedulesets the record tocompletedwith a 30-day TTL first, then deletes the EventBridge schedule and the params.FiringAtconsistency (fix(reaper): keep spawn-instance-* roles an enabled schedule still names (#1378) #1386). A one-time schedule is now recorded withmax_executions: 1, soFiringAtreports it run out after its firing. Acompletedrecord reads as FiringNotActive. Because the record is marked completed before its params are deleted, the reaper's role sweep (Reaper InstanceRoles would delete a spawn-instance-* role that an enabled schedule still names #1378) never sees an active schedule with missing params.spawn schedule resumenow works only on a paused schedule, so a completed or cancelled record can't be made to look live again.UpdateSchedulereplaces the whole schedule, so both calls failed and dropped the target input. They now send the full target, including theActionAfterCompletionandEndDateabove.#1383:
--regionother than us-east-1 targeted a function that doesn't exist.scheduler.HandlerARN, alwaysscheduler.TableRegion).--regiononly decides where the sweep's members launch. It is already carried on the record asRegion, and the orchestrator already uses it. This is the small change: one ARN, and no new deployments or tables. Refusing other regions would have removed a feature that works once the target is right.spawn-schedules-<region>bucket using a client in its own region, and S3 answers that with a 301. It now uses a client in the bucket's region.IAM
deployment/cloudformation/scheduler-handler-role.yaml):+ s3:DeleteObjectonspawn-schedules-*/schedules/*+ scheduler:DeleteScheduleonarn:aws:scheduler:${AWS::Region}:${AWS::AccountId}:schedule/default/*TestEveryPrincipalCallIsGranted) passes, and fails withscheduler:DeleteScheduleremoved.spawn schedule create:s3:GetLifecycleConfiguration,s3:DeleteObjectspawn schedule cancel:s3:DeleteObject,dynamodb:GetItemspawn launch --batch-queue:s3:GetLifecycleConfiguration. Without it the upload still happens with a warning; the config just doesn't expire.docs/reference/cli-iam-actions.mdis regenerated withmake cli-iam-actions.nestedSpawnNotGranted, next to the existings3:PutBucketLifecycleConfiguration.Gates (each watched failing against a revert that compiles)
TestNewSchedulesBucketDoesNotExpireScheduleParamsexpire-schedulesPut inensureBucketTestReconcileRemovesExactlyTheRetiredRules,...DeletesALifecycleLeftEmptyexpire-schedulesTestQueueConfigBucketGetsItsOwnTagScopedRule,TestReconcileQueueConfigAddsItsRuleAndRemovesNothingTestDeleteScheduleDeletesParamsEventBridgeScheduleAndRecordTestRecurringScheduleRecordHasNoTTL,TestSaveScheduleWritesTheFiniteTTLTTL = now+90dTestFiniteScheduleTTLComesAfterItsLastFiringRecordTTLreturns now+90dTestCompleteScheduleDeletesWhatARunOutScheduleLeavesCompleteScheduleonly updates the recordTestOneTimeScheduleRunsOutAndDeletesItselfActionAfterCompletionTestLastRunCompletesTheSchedule(handler)lastRunreturns falseTestScheduleTargetIsTheDeployedHandlerWhateverTheRegion(cmd)scheduleRegionThe #1383 gate reads the deploy region from
scripts/deploy-scheduler-handler.sh(REGION="${SPAWN_LAMBDA_REGION:-...}") and asserts that the created schedule's target ARN, read back from EventBridge, is in that region.Substrate drops
ActionAfterCompletionandEndDateonGetSchedule(scttfrdmn/substrate#1442), so those two are asserted on the outgoing request.Live steps (not done; no AWS calls were made)
DeleteOldScheduleParams, so the whole lifecycle goes. The nextspawn schedule createin each region does this automatically. To do it now, for each ofus-east-1 us-west-2 eu-west-1:DeleteOldScheduleParamsinstead of deleting it.deployment/cloudformation/scheduler-handler-role.yaml, us-east-1). Snapshot the parameters first and diff afterwards. Simulates3:DeleteObjectonspawn-schedules-us-west-2/schedules/x/params.yamlandscheduler:DeleteScheduleonschedule/default/x(allow), plus a deny control (e.g.s3:DeleteObjectonspawn-sweeps-*/x).scripts/deploy-scheduler-handler.sh(us-east-1).Follow-ups filed
--end-afterschedule paused past its end; cadence longer than 30 days). A verifying sweeper is proposed.Checks
make check,make lint(0 issues, 10 modules),semgrep scan --config=auto --error .,make gen-docs+check-docs,make api-snapshot(no change) andmake cli-iam-actionsall pass, from/private/tmp/spawn-1382with go1.27.3. The branch is rebased on origin/main at 021fb56.