Skip to content

fix(schedule): schedule params/record/EventBridge lifetime, and the target region (#1382, #1383) - #1399

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1382-1383-schedule-lifetime-region
Oct 28, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1382-1383-schedule-lifetime-region

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1382
Fixes #1383

What changed

#1382: schedule params and records expired while the schedule was alive. Nothing deleted what a schedule left behind.

  • No expiry at creation. pkg/staging.ensureBucket no longer puts expire-schedules (7 days on schedules/).
  • Migration. Every upload to a schedules bucket now reconciles its lifecycle (reconcileSchedulesLifecycle): Get, drop expire-schedules and DeleteOldScheduleParams, keep every other rule, then Put, or DeleteBucketLifecycle if 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.
  • Queue configs keep their own expiry. spawn launch --batch-queue writes to the same bucket and the same schedules/<id>/params.yaml layout, and the queue's instance role is scoped to that key. So its configs are now uploaded by UploadQueueConfig, tagged Component=queue, and expired after 7 days by a tag-filtered expire-queue-configs rule. That rule never matches schedule params, which are tagged Component=scheduler. The queue path adds this rule and removes nothing, so in a queue-only bucket the old expire-schedules still expires configs that older CLIs uploaded untagged. If the queue path can't reconcile, it warns and uploads anyway.
  • Cancel is the deleter. DeleteSchedule deletes 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, CreateSchedule deletes the params it was given; if the record save fails, it deletes all three.
  • Record TTL (design). An unbounded recurring schedule gets no TTL: ttl is omitempty, so the attribute is absent. A one-time or --end-after schedule gets last possible firing + 30 days: the at() time parsed in the schedule's timezone, or EndAfter, 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.
  • Run-out schedules clean up.
    • EventBridge schedules are created with ActionAfterCompletion=DELETE, so a one-time schedule deletes itself after it fires.
    • An --end-after schedule also gets EndDate = end_after + 30 days, the same instant as its record TTL.
    • scheduler-handler now calls CompleteSchedule on the launch that reaches max_executions, after a one-time launch succeeds, and on any firing that FiringAt reports as MaxExecutions or Expired. CompleteSchedule sets the record to completed with a 30-day TTL first, then deletes the EventBridge schedule and the params.
  • FiringAt consistency (fix(reaper): keep spawn-instance-* roles an enabled schedule still names (#1378) #1386). A one-time schedule is now recorded with max_executions: 1, so FiringAt reports it run out after its firing. A completed record 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 resume now works only on a paused schedule, so a completed or cancelled record can't be made to look live again.
  • Pause/resume. They built their client with an empty target ARN, and UpdateSchedule replaces the whole schedule, so both calls failed and dropped the target input. They now send the full target, including the ActionAfterCompletion and EndDate above.

#1383: --region other than us-east-1 targeted a function that doesn't exist.

  • Design. The schedule's control plane stays in us-east-1: the record, the EventBridge schedule and the target (scheduler.HandlerARN, always scheduler.TableRegion). --region only decides where the sweep's members launch. It is already carried on the record as Region, 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.
  • The handler also read the params from a 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

  • scheduler-handler role (deployment/cloudformation/scheduler-handler-role.yaml):
    • + s3:DeleteObject on spawn-schedules-*/schedules/*
    • + scheduler:DeleteSchedule on arn:aws:scheduler:${AWS::Region}:${AWS::AccountId}:schedule/default/*
    • The IAM coverage gate (TestEveryPrincipalCallIsGranted) passes, and fails with scheduler:DeleteSchedule removed.
  • New CLI-caller permissions (listed in the CHANGELOG; spore.host provisions no template for CLI callers):
    • spawn schedule create: s3:GetLifecycleConfiguration, s3:DeleteObject
    • spawn schedule cancel: s3:DeleteObject, dynamodb:GetItem
    • spawn 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.md is regenerated with make cli-iam-actions.
  • The nested-spawn role does not get the two new lifecycle calls. They are listed in nestedSpawnNotGranted, next to the existing s3:PutBucketLifecycleConfiguration.

Gates (each watched failing against a revert that compiles)

Gate Revert Result
TestNewSchedulesBucketDoesNotExpireScheduleParams re-add the 7-day expire-schedules Put in ensureBucket FAIL
TestReconcileRemovesExactlyTheRetiredRules, ...DeletesALifecycleLeftEmpty filter only expire-schedules FAIL (both)
TestQueueConfigBucketGetsItsOwnTagScopedRule, TestReconcileQueueConfigAddsItsRuleAndRemovesNothing never add the queue rule FAIL (both)
TestDeleteScheduleDeletesParamsEventBridgeScheduleAndRecord skip the params delete FAIL
TestRecurringScheduleRecordHasNoTTL, TestSaveScheduleWritesTheFiniteTTL TTL = now+90d FAIL (both)
TestFiniteScheduleTTLComesAfterItsLastFiring RecordTTL returns now+90d FAIL
TestCompleteScheduleDeletesWhatARunOutScheduleLeaves CompleteSchedule only updates the record FAIL
TestOneTimeScheduleRunsOutAndDeletesItself drop ActionAfterCompletion FAIL
TestLastRunCompletesTheSchedule (handler) lastRun returns false FAIL
TestScheduleTargetIsTheDeployedHandlerWhateverTheRegion (cmd) ARN region from scheduleRegion FAIL for us-west-2 and eu-west-1

The #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 ActionAfterCompletion and EndDate on GetSchedule (scttfrdmn/substrate#1442), so those two are asserted on the outgoing request.

Live steps (not done; no AWS calls were made)

  1. Migrate the three production buckets (infra account 966362334030). Each has only DeleteOldScheduleParams, so the whole lifecycle goes. The next spawn schedule create in each region does this automatically. To do it now, for each of us-east-1 us-west-2 eu-west-1:
    aws s3api get-bucket-lifecycle-configuration --bucket spawn-schedules-$R --region $R   # confirm the only rule is DeleteOldScheduleParams
    aws s3api delete-bucket-lifecycle --bucket spawn-schedules-$R --region $R
    aws s3api get-bucket-lifecycle-configuration --bucket spawn-schedules-$R --region $R   # expect NoSuchLifecycleConfiguration
    
    If any bucket has other rules, put the configuration back without DeleteOldScheduleParams instead of deleting it.
  2. Redeploy the scheduler-handler role stack (deployment/cloudformation/scheduler-handler-role.yaml, us-east-1). Snapshot the parameters first and diff afterwards. Simulate s3:DeleteObject on spawn-schedules-us-west-2/schedules/x/params.yaml and scheduler:DeleteSchedule on schedule/default/x (allow), plus a deny control (e.g. s3:DeleteObject on spawn-sweeps-*/x).
  3. Redeploy the function: scripts/deploy-scheduler-handler.sh (us-east-1).

Follow-ups filed

Checks

make check, make lint (0 issues, 10 modules), semgrep scan --config=auto --error ., make gen-docs + check-docs, make api-snapshot (no change) and make cli-iam-actions all pass, from /private/tmp/spawn-1382 with go1.27.3. The branch is rebased on origin/main at 021fb56.

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.57447% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/scheduler/scheduler.go 87.62% 12 Missing ⚠️
pkg/staging/staging.go 85.48% 9 Missing ⚠️
pkg/scheduler/types.go 82.60% 4 Missing ⚠️
cmd/schedule.go 40.00% 3 Missing ⚠️
cmd/launch_batchqueue.go 0.00% 1 Missing ⚠️

📢 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
scttfrdmn force-pushed the fix/1382-1383-schedule-lifetime-region branch from ba24a31 to fd584f8 Compare October 28, 2026 21:08
@scttfrdmn
scttfrdmn merged commit 1bede66 into main Oct 28, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1382-1383-schedule-lifetime-region branch October 28, 2026 21:33
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant