Skip to content

fix(taskproto): lost outputs and failing commands both lose their completion record (#561, #566) - #567

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/561-566-task-completion-record-silence
Sep 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/561-566-task-completion-record-silence

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Two ends of the same underlying defect: the task-completion wrapper
(pkg/taskproto/wrapper.go) computes failure information and then the
durable completion record doesn't reflect it, in different ways for
different failure modes.

#561 — a failed output upload was reported as success

OUT_RC (the stage-out aws s3 cp exit code) was assigned in the
stage-out loop and never read anywhere else — confirmed by grep in the
issue report. A declared output that failed to upload left the
completion record at state: completed, exit_code: 0,
retry_class: "" even though the artifact never reached its S3
destination.

Fix: classification now has a third branch consulting OUT_RC,
checked only after STAGE_RC and rc are both confirmed clean (so a
stage-in or command failure still takes priority). It gets its own
retry class, RetryOutputDeliveryError ("output_delivery_error"),
distinct from staging_error/app_error: the compute already
succeeded, so a retry only needs to redeliver the output. Marked
Retryable() == true since output-delivery failures are more often
transient (S3 hiccup) than an intrinsic defect.

#566 — a task whose command failed wrote NO completion record at all

Root cause CONFIRMED via reproduction, not just inspection. The
wrapper's own comment says "we do NOT set -e", and that's true of the
wrapper's own text — but pkg/launcher/bootstrap.go's
/tmp/spawn-command.sh preamble is a literal #!/bin/bash\nset -e\n...,
and the wrapper text is written onto the TAIL of that same file and
executed as ONE bash invocation, not sourced or exec'd separately. A
shell option set early in a script stays in effect for the rest of
that script, so the wrapper silently inherited -e from the preamble
it gets embedded into.

Under that inherited -e, a failing user command — host subshell or
docker run, it doesn't matter which — aborted the entire script
at the point of failure, before rc=$? was ever captured. Stage-out,
classification, and the completion-record write
(completion.json/.exitcode/SPAWN_COMPLETE) never ran. That is
exactly the reported symptom: a failed task producing nothing under
s3://.../tasks/<id>/, spawn task status reporting running
indefinitely, and the box riding out its full TTL instead of
self-terminating on failure.

Reproduced locally by concatenating the generated wrapper after
bootstrap.go's exact set -e preamble and running the combined script
under real bash with a stand-in docker that exits non-zero:
completion.json/.exitcode/SPAWN_COMPLETE were never written
until the fix was applied. Confirmed on both the containerized
(docker run) and host (bare subshell) command paths.

Fix: the wrapper now explicitly set +es its own preamble
(set +e -u -o pipefail) instead of relying on the embedding caller's
shell state — correct regardless of whatever script it gets appended
to.

Why together

Same root shape, opposite symptoms: #561 turns a failure into a false
success; #566 turns a failure into silence. Fixing them together gave
one coherent read of the wrapper's control flow (stage-in → command →
stage-out → classify → write) instead of two patches that might miss
each other's edge cases.

Tests

make check clean. make check-docs clean (no drift; only a plain
prose doc — docs/workflow-adapter-protocol-rfc.md — was touched, not
generated flag/help text). All lambda/*/go.mod nested modules build
clean, no go mod tidy needed. No stray autoscale-orchestrator
binary in the diff.

Process note on #566

This is a confirmed root-cause fix, not a defensive/hardening
guess: the exact mechanism (inherited -e across a script
concatenation) was pinned down and reproduced in isolation before
being fixed, and the fix's SurvivesEmbeddingAfterSetE test
reconstructs the real embedding path (pkg/launcher/bootstrap.go's
literal preamble + this wrapper) rather than a synthetic stand-in.

…pletion record (#561, #566)

Two ends of the same defect class: the wrapper computes failure
information and then the record doesn't reflect it.

#561: OUT_RC (the stage-out `aws s3 cp` exit code) was assigned in the
stage-out loop and never read anywhere else. A declared output that
failed to upload left the completion record at state=completed,
exit_code=0, retry_class="" even though the artifact never reached its
destination. Classification now has a third branch consulting OUT_RC,
gated behind STAGE_RC and rc both being clean, with its own retry
class (RetryOutputDeliveryError="output_delivery_error") since compute
already succeeded and only delivery needs retrying.

#566: confirmed root cause via reproduction, not just inspection. The
wrapper's own comment says "we do NOT set -e", but pkg/launcher/
bootstrap.go concatenates this generated script onto the tail of
/tmp/spawn-command.sh, whose own preamble is a literal `set -e` — the
two run as ONE bash invocation, not two, so the wrapper silently
inherited -e despite its comment. A failing user command (host
subshell or `docker run`) then aborted the whole script at that line,
before `rc=$?` was ever captured, so stage-out/classification/the
completion-record write never ran — exactly the reported symptom of a
failed task producing no completion.json/.exitcode/SPAWN_COMPLETE and
riding out its full TTL instead of self-terminating. Fixed by making
the wrapper explicitly `set +e` its own preamble instead of relying on
the embedding caller's shell state.

Both fixes verified with exec-based tests (real bash, stand-in aws/
docker/sudo on PATH) that fail without the fix and pass with it, in
addition to text-assertion tests on the generated script.
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant