Skip to content

feat(task): results_prefix — put a task's durable records where you want them - #658

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/646-results-prefix
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/646-results-prefix

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #646.

The asymmetry

outputs[].destination was always fully caller-controlled — per object, to any bucket, with the launch role's inline policy built from whatever the spec names. But completion.json, .exitcode and command.log always landed at s3://spawn-results-<account>-<region>/tasks/<task_id>/: resultsBucket was computed from the account and region with no flag or env var. So a consumer wanting its own layout read two places — its own prefix for results, and the fixed spawn path for the terminal signal.

results_prefix on the TaskSpec collapses that to one. Omitting it is byte-identical to before, which matters because six workflow adapters poll the default path literally.

Three things beyond the issue

1. spawn task status needed a flag, or this would have broken it. It's given a task id, not a spec, so it cannot infer a results_prefix the spec set — setting one would have made task status look in the wrong place. --results-prefix fixes that; without it status stays on spawn's default, where every existing task's records are.

2. spawn must not create a bucket you named. It creates its own default bucket before launch so a first-ever task can't hit NoSuchBucket. For a caller-supplied bucket, a missing one is now an error: creating it would mean a typo leaves a stray bucket behind and the run still reports success — the opposite of what someone pointing at their own storage expects. IsDefaultResultsBucket gates that, and its test pins the near-misses (right account/wrong region, right region/wrong account).

3. The prefix is resolved once, by the caller. Previously the wrapper, the flush hook (#632) and the policy each derived it from a bucket name — which is how a future override reaches one and misses another, the same shape as #625's grant gap. All three now take the resolved prefix, and the pooled worker resolves it identically.

SplitS3URI rejects anything that isn't s3://bucket/... rather than treating a typo'd scheme as a bucket name.

On the argument against

I filed this with a counterargument — that a fixed, well-known location has real virtue, since completion.json is the one object guaranteed to appear even when the workload never gets far enough to write a result, and since #632 it's written when a lifecycle limit kills the task mid-command too. That still holds. The resolution is that the default is unchanged, so anyone who wants the guarantee of an unambiguous path keeps it by doing nothing; the override is for a consumer that has already decided it owns the layout.

Verification

Full suite, go vet, gofmt, and make check-docs (the new flag regenerated docs-gen/) all pass. The 47 existing test call sites keep naming a bucket, via three test-local shims that translate to the prefix the old signature would have derived — the assertions read better that way and the shims document the change.

…ant them

outputs[].destination was always fully caller-controlled: per object, to any
bucket, with the launch role's inline policy built from whatever the spec names
(cmd/task.go taskStagingPolicy). But completion.json, .exitcode and command.log
always landed at s3://spawn-results-<account>-<region>/tasks/<task_id>/ with no
override — resultsBucket was computed from the account and region and there was
no flag or env var for it. So a consumer wanting its own layout read TWO places:
its own prefix for results, and the fixed spawn path for the terminal signal.

results_prefix on the TaskSpec collapses that to one. Omitting it is
byte-identical to before, which matters because six workflow adapters poll the
default path literally.

Three things worth noting beyond the issue:

1. `spawn task status` needed a flag. It is given a task id, not a spec, so it
   cannot infer a results_prefix the spec set — setting one would have broken
   `task status` outright. --results-prefix fixes that; without it status stays
   on spawn's default.

2. spawn must NOT create a bucket the caller named. It creates its own default
   bucket before launch so a first-ever task cannot hit NoSuchBucket, but a
   caller-supplied bucket that does not exist is now an error: creating it would
   mean a typo leaves a stray bucket behind and the run still reports success,
   which is the opposite of what someone pointing at their own storage expects.
   IsDefaultResultsBucket gates that, and its test pins the near-misses (right
   account wrong region, right region wrong account).

3. The prefix is resolved ONCE, by the caller, and passed to the wrapper, the
   flush hook (#632) and the policy. Previously each derived it from a bucket
   name, which is how a future override reaches one and misses another — the
   same shape as #625's grant gap. GenerateWrapper/GeneratePooledJobScript/
   GenerateFlushScript now take the resolved prefix; the pooled worker resolves
   it the same way.

SplitS3URI rejects anything that is not s3://bucket/... rather than treating a
typo'd scheme as a bucket name.

The 47 test call sites keep naming a bucket, via three test-local shims that
translate to the prefix the old signature would have derived — the assertions
read better that way and the shims document the change.

Full suite, vet, gofmt and check-docs pass.

Fixes #646
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.52174% with 30 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/task.go 36.58% 24 Missing and 2 partials ⚠️
cmd/spored/pool_worker.go 0.00% 2 Missing ⚠️
pkg/taskproto/resultsprefix.go 88.88% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 528e038 into main Oct 4, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/646-results-prefix branch October 4, 2026 02:32
scttfrdmn added a commit that referenced this pull request Oct 5, 2026
…#717)

task status reported every finished task as "running" and --wait polled to TTL
and exited 1 on tasks that had succeeded in seconds.

EffectiveResultsPrefix already ends in the task id. completionKey appended it
again. So the wrapper wrote — and spawn PRINTED —

  tasks/<task_id>/completion.json

while the reader fetched

  tasks/<task_id>/<task_id>/completion.json

which 404s, and the read path correctly reads a 404 as "no record yet". Verified
against the reporter's own bucket: head-object on the first key returns 337 bytes,
on the second a 404. All three of their affected tasks now read `completed`,
exit 0, with matching run_id.

Present since v0.117.0, not v0.121.0 as reported: both halves — the prefix gaining
the task id and these builders appending it — arrived in the same commit (#658), so
neither looked wrong on its own. That also explains why records written by older
spawn versions were unreadable: the reader changed, not the writer.

The second defect the report could not see: clearStaleCompletion uses the same
builders, so the pre-launch clear had been deleting keys that do not exist. Deleting
an absent key is a no-op success in S3, so it reported success and removed nothing —
#608's stale-record guard has been inert since v0.117.0. Fixing only the read would
have resurrected that bug, where a previous attempt's record answers this run.

The task id is no longer a parameter to any of these builders, and
clearStaleCompletion lost its vestigial taskID too. That parameter was the actual
hazard: two plausible things to pass, no compiler or vet complaint for passing the
wrong one. An existing test caught my first attempt leaving it in place, which is
the best argument for removing it rather than documenting it.

The gate is a ROUND-TRIP: the key the reader computes must equal the URI the writer
prints, across the default bucket, a custom results_prefix, a bare bucket, and a
trailing slash. Asserting completionKey returns some expected string would not have
caught this, because the builder was self-consistent — only comparing it against the
writer's own path reveals the disagreement. Confirmed to fail against the shipped
behaviour, printing both URIs side by side.

Also updated TestClearStaleCompletion_DeletesBothKeys, which passed a bare "tasks"
prefix and so encoded a calling convention no caller used — the ambiguity that
produced this bug in the first place.
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.

task run: the completion record's location is not settable, so a consumer must read two places

1 participant