Skip to content

Persist where a store was written instead of re-deriving it - #851

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/804-persist-resolved-bucket
Oct 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/804-persist-resolved-bucket

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #804. Correctness audit 2026-10.

Two subsystems, one defect: the writer resolved a location at runtime and the reader
rebuilt the name from a convention
, so the two agreed only by coincidence.

1. Scheduled executions read a bucket they had never written to

resolveSchedulesBucket handles the shared bucket name being taken by another account:

preferred := fmt.Sprintf("spawn-schedules-%s", region)
fallback  := fmt.Sprintf("spawn-schedules-%s-%s", c.accountID, region)

It returns the one it used. cmd/schedule.go threw it away:

_, s3Key, size, sha256, err := stagingClient.UploadScheduleParams(...)

ScheduleRecord had no bucket field, and the handler rebuilt the name from the region:

bucket := fmt.Sprintf(schedulesBucketTmpl, region)

So in any account that took the fallback path, every scheduled sweep failed on a
missing object.

The record now carries s3_params_bucket and the handler prefers it. The template remains
the fallback for records written before the field existed, which is right for those: an
account on the fallback path would already have been failing, so a pre-existing record is
necessarily on the shared name.

2. spawn queue results looked in the wrong bucket

// This should match what was specified in the queue config
bucket := fmt.Sprintf("spawn-results-%s", downloadRegion)

It never loaded the config. The writer uploads to the queue JSON's result_s3_bucket.
It worked for the wizard default and the bundled examples — and not for
pkg/queue/templates/*.json's {{S3_BUCKET}}, for any other bucket a user names, or for
the integration fixtures.

Nothing persists queue state server-side (the config is a local JSON supplied at launch),
so the reader can only be told or guess. It now takes --config (reading
result_s3_bucket and result_s3_prefix) or --bucket, and announces the guess when
given neither:

⚠️  No --bucket or --config given, so guessing spawn-results-us-east-1 from the region.
   That is only correct if the queue was launched with the wizard default. If the
   listing below is empty, the results are probably in the bucket your queue config
   named — pass --config <queue.json> or --bucket.

The announcement is the load-bearing part: guessing wrong produces an empty listing,
which is indistinguishable from the queue having produced nothing. A --config that
declares no bucket is an error rather than a silent fall back to the guess.

Three notes on the gates, because two were wrong first

The ordering assertion I started with was checking style, not mechanism. It compared
source positions to require that downloadParams consult the recorded bucket before the
region template. A revert that computed the template first and then overrode it passed —
and correctly, because computing-then-overriding is equally valid. The decision is now a
pure paramsBucket(recorded, region) with a behavioural table test beside it in the
handler's own module, and the note replacing the assertion explains why. That is rule 6
for the fourth time in this audit
— gating a correlate rather than the mechanism.

Two matchers were satisfied by a prefix. dynamodbav:"s3_params_bucket is a prefix of
dynamodbav:"s3_params_bucket_unused", so a revert renaming the field slipped past them.
Rule 3 applies to a gate's own matcher as much as to the code it guards.

Five compiling reverts, all now caught: the CLI discarding the bucket, the record field
renamed, the recorded bucket ignored, the queue flags removed, and the guess no longer
announcing itself.

Not addressed here

The issue's third suggestion — reconciling the two results-bucket naming schemes
(spawn-results-<region> here vs pkg/taskproto.DefaultResultsBucket's
spawn-results-<account>-<region>) — is a naming decision with a migration attached, not a
bug fix, so it stays open for #811's company rather than being guessed at.

Verification

make check (all nested modules), make check-docs, changelog gate, semgrep 0 findings,
make api-snapshot no drift, Tier 0 e2e with -count=1, go mod tidy clean in
lambda/scheduler-handler.

Two subsystems shared one defect: the writer resolved a location at
runtime and the reader rebuilt the name from a convention, so the two
agreed only by coincidence.

resolveSchedulesBucket prefers the shared spawn-schedules-<region> and
falls back to an account-scoped spawn-schedules-<account>-<region> when
the shared name is taken by another account — and it RETURNS which one
it used. cmd/schedule.go discarded that, ScheduleRecord had no bucket
field, and the scheduler-handler rebuilt the name from the region alone.
So in any account that took the fallback path, every scheduled sweep
failed on a missing object. The record carries s3_params_bucket now and
the handler prefers it, falling back to the region template only for
records written before the field existed — right for those, since an
account on the fallback path would already have been failing.

`spawn queue results` derived spawn-results-<region> directly beneath a
comment saying it "should match what was specified in the queue config",
which it never loaded, while the writer uploads to the queue JSON's
result_s3_bucket. It worked for the wizard default and the bundled
examples, and not for pkg/queue/templates/*.json's {{S3_BUCKET}}, any
other bucket a user names, or the integration fixtures. Nothing persists
queue state server-side, so the reader can only be told or guess: it
takes --config or --bucket now, and ANNOUNCES the guess when given
neither, because guessing wrong produces an empty listing that looks
exactly like the queue having produced nothing. A --config declaring no
bucket is an error rather than a silent fall back.

Three notes on the gates, since two of them were wrong first.

The ordering assertion I started with compared source positions to
require that downloadParams consult the recorded bucket before the
region template. A revert computing the template first and then
overriding it PASSED — correctly, because computing-then-overriding is
equally valid. It was checking style, not mechanism. The decision is a
pure paramsBucket(recorded, region) now, with a behavioural table test
beside it, and the note replacing the assertion says why. Rule 6, fourth
time in this audit.

And `dynamodbav:"s3_params_bucket` is a PREFIX of
`dynamodbav:"s3_params_bucket_unused"`, so a revert renaming the field
slipped past two matchers. Rule 3 applies to a gate's own matcher as
much as to the code it guards.

Closes #804
@scttfrdmn scttfrdmn added this to the Correctness audit 2026-10 milestone Oct 11, 2026
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/queue.go 84.84% 4 Missing and 1 partial ⚠️
cmd/schedule.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 83603f2 into main Oct 11, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/804-persist-resolved-bucket branch October 11, 2026 22:38
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.

Write side resolves an S3 location, read side guesses it: scheduled params and queue results can read the wrong bucket (or none)

1 participant