Repository navigation
fix: task env reaches containers; task run --wait fails on a failed task (#1059, #1143) - #1176
Merged
Merged
Conversation
…ask (#1059, #1143) TaskSpec env was exported in the host wrapper shell and never passed to docker run. Pass each key as -e 'KEY=VALUE' with the literal, single-quoted value: a bare -e KEY loses the value through sudo's env_reset, and a "$KEY" reference picks up wrapper variables reassigned after the export. task run --wait exited with the record's exit_code alone, so a failed task whose command exited 0 (output_delivery_error) exited 0. Exit 1 for any state other than completed, matching task status --check-complete. Fixes #1059 Fixes #1143
scttfrdmn
force-pushed
the
fix/1059-1143-task-wrapper
branch
from
October 19, 2026 05:09
6fd6388 to
7aa97d4
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#1059: TaskSpec
envnow reaches a container task.pkg/taskproto/wrapper.goexportedenvin the host wrapper shell, butdocker runnever received it.writeContainerRunnow adds one-e 'KEY=VALUE'argv word per key, in sorted order, before the image. The value is the literal one from the spec, single-quoted withshQuote.-e KEY(the issue's first suggestion):sudoresets the environment by default, so docker would never see the exported value.--preserve-env=listdepends on the sudoers policy.-e "KEY=$KEY": a key such asSTAGE_RCorrcnames a wrapper variable that is reassigned after the export. The container would get the wrapper's value, not the spec's.--env-filecan't carry a multi-line value.Validateto[A-Za-z_][A-Za-z0-9_]*(taskspec.go,validEnvKey).docker runcommand line, so they show in the process list while the task runs. They were already written in clear text in the wrapper script on disk. The CHANGELOG entry says so.#1143:
task run --waitnow exits non-zero on a failed task.On
OUT_RC != 0, the wrapper writesstate=failed,retry_class=output_delivery_errorand the command'sexit_code, which is 0.--waitlooked only atexit_code, so it exited 0.waitExitCode(rec)returns the task's exit code when non-zero, otherwise 1 for any state other thancompleted.task status --check-complete, which exits 1 forState == failed || ExitCode != 0.--waitflag help now says so.Gates (each watched failing against a revert that compiles)
pkg/taskproto/wrapper_env_test.goTestContainerTaskEnvReachesTheContainer:', a$, a backtick and", plus the keySTAGE_RC.exportlines, thenSTAGE_RC=0, then the extractedsudo docker run …under bash.sudoclears the environment (env -i), like env_reset. The stand-indockerresolves-ethe way docker does:KEY=VALUEas given, a bareKEYfrom its own env.Reverts tried:
-eat all-e KEY-e "KEY=$KEY"STAGE_RCarrives as 0)-e KEY=VALUEThe other two gates:
TestContainerTaskEnvFlagsPrecedeTheImage: every-emust come before the image, otherwise it is container argv. The revert that moves the flags after the image fails here and only here.TestHostTaskEnvIsStillExported: anchored^export KEY='VALUE'$for every key. Removing the export fails it.cmd/task_wait_exit_test.goTestTaskRunWaitFailsOnAFailedTask:RetryClassandTaskStateconstant by parsingpkg/taskproto/*.gowithgo/parser. It fails if discovery finds none, and fails if it missesoutput_delivery_error.state=failed, exit_code=0must give 1. For each state other thancompleted,exit_code=0must give 1. An empty state must give 1.if false && rec.State != …. It fails:state=failed retry_class=output_delivery_error exit_code=0: --wait exits 0, want 1.TestTaskRunWaitKeepsTheTaskExitCode: completed/0 gives 0, and a non-zero task exit code is passed through.Real docker, run locally, not committed:
alpine:latestrunningprintenv PLAIN WITH_SPACE TRICKY STAGE_RC. A stand-insudo(env -i) was used.it's $HOME \id` "q"andthe-spec-value`. rc=0.-eflags stripped (main's behaviour) printed nothing, rc=1.Not verified
sudoon AL2023 was not exercised. The-e KEY=VALUEform doesn't depend on sudo's env handling.task status --check-completeexits 0 forstate=cancelled, exit_code=0, because it checks onlyfailed.--waitnow treats every state other thancompletedas failure. Left unchanged here.Checks
make check: fmt, vet (all GOOS), hermetic short tests, nested and tidy all pass.GOOS=linux staticcheck ./...is clean. On darwin, SA4023 inpkg/agent/sys_other.gois known noise.check-build-tagsoutput is identical to unmodifiedorigin/mainon this machine, so it's local-only.semgrep scan --config=auto --error .is clean.Fixes #1059
Fixes #1143