Skip to content

fix(task): stop appending the task id to the results key twice (#715) - #717

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/715-completion-key-doubled-taskid
Oct 5, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/715-completion-key-doubled-taskid

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #715.

Your diagnosis was exactly right — read path, not write path — and the cause is one character of path too many.

The bug

EffectiveResultsPrefix already ends in the task id. completionKey appended it again:

writer wrote / spawn printed:  tasks/<task_id>/completion.json
reader fetched:                tasks/<task_id>/<task_id>/completion.json

The second 404s, and the read path correctly treats a 404 as "no record yet" — so a finished task reads as running forever. Confirmed against your bucket:

$ aws s3api head-object --bucket spawn-results-942542972736-us-west-2 \
    --key tasks/cookbook-polish-align-r2/completion.json --query ContentLength
337
$ aws s3api head-object --bucket spawn-results-942542972736-us-west-2 \
    --key tasks/cookbook-polish-align-r2/cookbook-polish-align-r2/completion.json
An error occurred (404) when calling the HeadObject operation: Not Found

All three of your affected tasks now read correctly:

$ spawn task status cookbook-polish-align-r2 --region us-west-2
Task:       cookbook-polish-align-r2
Run ID:     643c4c73-0b67-46fe-92f8-aae906a0c366
State:      completed
Exit code:  0

One correction: it is not a 0.121.0 regression

It has been broken since v0.117.0. Both halves — EffectiveResultsPrefix gaining the task id, and these builders appending it — arrived in the same commit, 528e038 (#658). Neither looked wrong on its own, and no test referenced the key builders at all.

That also explains the detail you flagged as evidence of a regression: records written by older spawn versions are unreadable now because the reader changed, not the writer. Your note that --wait worked in earlier sessions is consistent — those were pre-0.117.0.

A second defect, which your report could not have shown

clearStaleCompletion uses the same builders. So the pre-launch clear has been deleting keys that do not exist — and since deleting an absent key is a no-op success in S3, it reported success and removed nothing. #608's stale-record guard has been inert since v0.117.0.

Fixing only the read path would have resurrected #608: a previous attempt's record sitting at the shared key answering the current run. That is the "stale-record-on-same-task_id-reuse quirk" in your notes, and it would have come back the moment reads started working again. Both are fixed together.

Why the parameter is gone rather than documented

The task id is no longer a parameter to completionKey, exitCodeKey, staleResultKeys or clearStaleCompletion. That parameter was the hazard itself: two plausible things to pass (tasks or tasks/<id>), with no compiler or go vet complaint for choosing wrong.

Worth admitting how I know: my first attempt left the vestigial taskID on clearStaleCompletion, and an existing test caught it — it started deleting tasks/completion.json, dropping the id entirely. Which is a better argument for deleting the parameter than any comment I could write.

That same test, TestClearStaleCompletion_DeletesBothKeys, was passing a bare "tasks" prefix — encoding a calling convention no production caller used. It is updated to match reality.

The gate is a round-trip

The writer never builds a key; it formats the resolved prefix directly:

fmt.Fprintf(out, "Completion:   %s/completion.json\n", resultsPrefix)

So the printed URI is the contract. The new test derives the key both ways and asserts they name the same object, across the default bucket, a custom results_prefix, a bare s3://bucket, and a trailing slash.

A test asserting completionKey() returns some expected string would not have caught this — the builder was perfectly self-consistent. Only comparing it against the writer's own path reveals the disagreement. Verified to fail against the shipped behaviour, printing both URIs side by side.

On your workaround

Polling the output bucket for the declared outputs rather than trusting the record is strictly better and I would keep doing it. It checks artifacts instead of a status field, which is the same reasoning behind this project's "exit 0 is not evidence" rule — and it is what let you catch this at all. The fix makes --wait usable again; it does not make it more trustworthy than checking the outputs.

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.
@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/task.go 81.25% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 02ea69e into main Oct 5, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/715-completion-key-doubled-taskid branch October 5, 2026 16:33
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