Skip to content

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

Closed

Description

@scttfrdmn

Summary

getObject resolves a seedable task-completion when no real object exists at
tasks/<task_id>/completion.json (#360), but headObject has no equivalent
hook — it returns NoSuchKey for the same key. So HEAD and GET disagree about
whether the object exists, which real S3 never does.

The practical consequence is that aws s3 cp cannot read a synthesized
completion record at all
, because the CLI HEADs before it GETs. That is the
exact command spawn prints for users:

Completion:   s3://spawn-results-<acct>-<region>/tasks/<id>/completion.json
  aws s3 cp s3://spawn-results-<acct>-<region>/tasks/<id>/completion.json -

Reproduction (v0.83.0, substrate server)

$ export AWS_ENDPOINT_URL=http://localhost:4566 AWS_ACCESS_KEY_ID=test \
         AWS_SECRET_ACCESS_KEY=test AWS_DEFAULT_REGION=us-east-1
$ B=spawn-results-123456789012-us-east-1
$ aws s3 mb s3://$B

# GET synthesizes the nominal completion — correct, as designed:
$ aws s3api get-object --bucket $B --key tasks/t1/completion.json /dev/stdout
{"task_id":"t1","exit_code":0,"state":"completed","started_at":"…","ended_at":"…"}

# HEAD on the very same key says it does not exist:
$ aws s3api head-object --bucket $B --key tasks/t1/completion.json
An error occurred (404) when calling the HeadObject operation: Not Found

# …so the documented user-facing command fails, never reaching the GET:
$ aws s3 cp s3://$B/tasks/t1/completion.json -
download failed: … An error occurred (404) when calling the HeadObject operation: Not Found

Holds identically for an explicitly seeded record:

$ curl -s -X POST localhost:4566/v1/spawn/task-completion -H 'Content-Type: application/json' \
    -d '{"task_id":"s1","exit_code":7,"state":"failed","started_at":"…","ended_at":"…"}'
{"ok":true,"taskId":"s1"}
$ aws s3api head-object --bucket $B --key tasks/s1/completion.json
An error occurred (404) when calling the HeadObject operation: Not Found

A really staged object at the same key HEADs fine — confirming the gap is
specific to the synthesis path, not to HEAD generally.

Cause

emulator/s3_plugin.go — getObject (~line 617) calls the resolver when
data == nil:

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

headObject (~line 692) has no counterpart:

if data == nil {
    return s3ErrorResponse("NoSuchKey", …, http.StatusNotFound), nil
}

Why it matters

This is the failure shape v0.80.0–v0.83.0 have been systematically closing, with
the polarity flipped: instead of substrate reporting success where AWS fails, it
reports absence where its own GET reports presence, so a consumer's
"is it done yet?" probe is wrong in the direction that looks like still running
— a poll loop that never terminates rather than a visible error.

Two consumer patterns hit it:

  1. aws s3 cp / aws s3 sync — HEAD-then-GET. Cannot read the record at all.
  2. SDK HeadObject existence polling — a common way to wait for a completion
    marker without paying for the body. spore-host's own
    pipeline.CheckCompletionMarker polls a marker this way.

spore-host's engine-composition tests (miniwdl / airflow / snakemake) happen to
be unaffected, because spawn's fetchCompletion goes straight to
GetObject and treats NoSuchKey as "not finished". They pass for a reason
that is one refactor away from not holding.

Suggested fix

Give headObject the same resolver call, discarding the body — the resolver
already returns a fully-populated S3Object, so objectResponseHeaders(&obj)
should produce a consistent Content-Length/ETag/Content-Type with no new
synthesis logic:

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

Worth confirming the clock/consistency gating (resolveTaskCompletion's
not-yet-complete case) behaves the same on HEAD as GET, so a HEAD before the
simulated completion time is a 404 exactly as the GET is.

Out of scope, deliberately

ListObjectsV2 also omits synthesized completions, and I'd argue that one is
correct as-is and should not be "fixed": HEAD is keyed — the caller names the
task, so the resolver can answer — whereas a list is unkeyed and substrate
cannot enumerate the set of task IDs a consumer might ask about. Noting it so the
asymmetry is a recorded decision rather than an oversight.

Environment

Activity

  1. added
    type: bug
    area: s3
    on Aug 1, 2026
  2. added this to the v0.85.0 milestone on Aug 1, 2026
  3. added
    priority: high
    on Aug 1, 2026
  4. scttfrdmn commented on Aug 1, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed and merged in #460.

    Reproduced exactly as filed before touching anything, which is worth recording because
    the two responses are so far apart:

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

    The suggested fix was right, including the versionID == "" guard. headObject now
    calls the same resolver and discards the body; because the resolver already returns a
    fully-populated S3Object, objectResponseHeaders produces a Content-Length, ETag,
    Content-Type and Last-Modified identical to what GET reports, with no new synthesis
    logic. The delete-marker branch moved into the else where it belongs — a synthesized
    record cannot be a delete marker.

    On the clock gate

    You flagged this as worth confirming rather than assuming. Confirmed, and asserted
    directly: a HEAD before the seeded ended_at is a 404, exactly as the GET is. That
    case is in the table as clock-gated, not yet complete, and it matters more than the
    positive cases — a HEAD that answered 200 early would report a task complete that GET
    still reports as absent, which is the same disagreement with the sign flipped.

    The test shape

    Every case runs through both verbs together and asserts they agree, rather than
    asserting each verb separately. That is deliberate: a suite where every test exercises
    one verb could never have caught this, which is exactly how it survived. On a 200 the
    headers are compared field by field, including Content-Length against the actual byte
    count GET returns — that is what aws s3 cp sizes its download from, so a HEAD
    promising a different length would be its own wrong answer.

    Also covered: ranges on a synthesized record (satisfiable and unsatisfiable),
    conditionals (If-None-Match → 304, non-matching If-Match → 412 — the cheap
    "has it changed?" poll), non-matching keys still 404, and an explicit versionId not
    resolving on either verb.

    Mutation-tested three ways: reverting the fix fails four tests, dropping the versionID
    guard fails the versioned case, and moving the delete-marker branch back out fails the
    existing TestS3_GetHeadObject_DeleteMarker.

    ListObjectsV2 — agreed, and now recorded

    Your reasoning is right and I've written it into docs/services.md as a decision rather
    than leaving it implicit: 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 — a list that invented entries would be a
    wrong answer, not a more complete one.

    While there: the task-completion resolver turned out to be undocumented entirely —
    the key shape, the seeding endpoints, and the clock gate appeared nowhere in docs/. That
    gap is closed too, in a new ### Task-completion records section.

    The point about spore-host's tests

    Worth restating, because it's the most useful line in the report: those engine-composition
    tests pass only because fetchCompletion happens to go straight to GetObject. They were
    one refactor away from not holding, and nothing in the suite would have said so. That
    pipeline.CheckCompletionMarker polls a marker via HEAD is the concrete case — that path
    was broken this whole time.

    The "version":"dev" note

    Correct diagnosis, and left out of scope on purpose rather than silently: it's #402's
    immutable-tag caveat applying to go install builds, since the -X ldflag is only set by
    the release build. Not a regression, and not something this PR should have quietly
    touched.

    Targeted at v0.85.0.

  5. added a commit that references this issue on Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: s3priority: hightype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions