Skip to content

fix(s3): resolve task completions on HeadObject so HEAD matches GET (#457) - #460

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/457-headobject-task-completion
Aug 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/457-headobject-task-completion

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #457.

The defect

getObject consults resolveTaskCompletion when no real object is staged at
tasks/<task_id>/completion.json (#360). headObject had no equivalent hook, so the
two verbs disagreed about whether the key exists — something real S3 never does.

Reproduced before fixing:

GET  /results/tasks/t1/completion.json  → 200, 120-byte body, ETag, Content-Type
HEAD /results/tasks/t1/completion.json  → 404 NoSuchKey

aws s3 cp could not read a synthesized record at all. The CLI HEADs before it
GETs, fails on the 404, and never reaches the working GET — and that is the exact
command spawn prints for users.

An SDK HeadObject poll broke in the worse direction. Absence reads as still
running
, so a wait loop spins forever rather than failing visibly. That is the
inverse of the polarity this batch has mostly been closing: not success where AWS
fails, but absence where substrate's own GET reports presence.

The fix

headObject calls the same resolver, discarding the body:

if data == nil {
    var handled bool
    if versionID == "" {
        obj, _, handled = p.resolveTaskCompletion(ctx, key)
    }
    if !handled {
        return s3ErrorResponse("NoSuchKey", …, http.StatusNotFound), nil
    }
} else { … }

The resolver returns a fully-populated S3Object, so Content-Length, ETag,
Content-Type and Last-Modified match what GET reports with no new synthesis
logic. The versionID == "" guard and the real-object-wins precedence mirror
getObject, and the delete-marker branch moves into the else where it belongs — a
synthesized record cannot be a delete marker.

The clock gate applies identically, which the issue specifically asked to have
confirmed: a HEAD before the simulated ended_at is still the 404 that a poll loop
depends on to keep polling. Asserted directly, not assumed.

Tests

Tests assert HEAD and GET together rather than either in isolation, since the
defect was precisely one verb's view of the resolver drifting from the other's — a
test exercising one verb could never have caught it.

TestSpawn_TaskCompletion_HeadMatchesGet runs the resolver's whole behavior matrix
through both verbs: nominal success, a seeded failure, the clock-gated
not-yet-complete case, and a real staged object. Each asserts the two status codes
agree, and on a 200 that every header a HEAD exists to report matches what GET
returns — including Content-Length against the actual byte count, which is what
aws s3 cp sizes its download from.

Plus HEAD-specific coverage: ranges (satisfiable and unsatisfiable), conditionals
(If-None-Match → 304, non-matching If-Match → 412, which is what makes a cheap
"has it changed?" poll work), non-matching keys still 404, and an explicit
versionId not resolving.

Mutation-tested:

Mutation Result
Revert the fix entirely 4 tests fail
Drop the versionID == "" guard the versioned case fails
Move delete-marker handling out of the else existing TestS3_GetHeadObject_DeleteMarker fails

Docs

The task-completion resolver was undocumented entirely — no mention of the key
shape, the seeding endpoints, or the clock gate anywhere in docs/. Added a
### Task-completion records section covering all of it, plus the HEAD/GET agreement
contract.

It also records the reporter's point about ListObjectsV2: not enumerating
synthesized records is correct and deliberate, not an oversight. A keyed read
works because the caller names the task, so the resolver has something to answer
about; a list is unkeyed and substrate cannot enumerate the set of task IDs a
consumer might ask about, so a list that invented entries would be a wrong answer
rather than a more complete one.

Not addressed here

The issue's closing note that go installed builds report "version":"dev" on
/health is real but separate — it's #402's immutable-tag caveat applying to
go install, since the -X ldflag is only set by the release build. Left out of
scope deliberately rather than silently.

Verification

gofmt -l · go build ./... · go vet ./... · golangci-lint run ./... (0 issues) ·
make test (race) · make docs-reference-check docs-versions — all clean.

…457)

getObject consults resolveTaskCompletion when no real object is staged at
tasks/<task_id>/completion.json (#360). headObject had no equivalent hook, so
HEAD returned NoSuchKey for a key GET served with a 200 and a full body. Real S3
never contradicts itself about whether an object exists.

Reproduced before fixing: GET → 200 with a 120-byte body and an ETag, HEAD → 404
on the identical key.

The practical failure is that `aws s3 cp` cannot read a synthesized record at
all. The CLI HEADs before it GETs, so it fails on the 404 and never reaches the
working GET — and that is the exact command spawn prints for users. An SDK
HeadObject existence poll breaks in the worse direction: absence reads as "still
running", so a wait loop spins forever instead of failing visibly.

headObject now calls the same resolver, discarding the body. The resolver returns
a fully-populated S3Object, so Content-Length, ETag, Content-Type and
Last-Modified match what GET reports with no new synthesis logic, and the
ended_at clock gate applies identically — a HEAD before the simulated completion
time is still the 404 a poll loop depends on. The versionID == "" guard and the
real-object-wins precedence mirror getObject: a synthesized record has no version
history, so answering for a named version would invent one.

Tests assert HEAD and GET together rather than either alone, since the defect was
precisely one verb's view of the resolver drifting from the other's. The matrix
covers nominal success, a seeded failure, the clock gate, and a real staged
object, plus HEAD-specific coverage for ranges, conditionals, non-matching keys,
and an explicit versionId.

Mutation-tested: reverting the fix fails four tests; dropping the versionID guard
fails the versioned case; moving delete-marker handling out of the else fails the
existing TestS3_GetHeadObject_DeleteMarker.

Documents the task-completion resolver in docs/services.md for the first time,
including the reporter's point that ListObjectsV2 not enumerating synthesized
records is correct and deliberate — a keyed read works because the caller names
the task, while a list is unkeyed and substrate cannot enumerate the task IDs a
consumer might ask about.
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/s3_plugin.go 81.81% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit fda3580 into main Aug 1, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/457-headobject-task-completion branch August 2, 2026 22:02
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.

S3: HeadObject does not resolve a synthesized task-completion, so HEAD and GET disagree (breaks aws s3 cp)

1 participant