Repository navigation
fix(taskproto): never upload an empty completion record when /tmp is full (#1179) - #1279
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…full (#1179) The task wrapper and terminal-flush hook wrote completion.json and .exitcode to /tmp and uploaded the files unconditionally. A task that filled /tmp left both empty, and the empty objects were uploaded, so `spawn task status` failed with "unexpected end of JSON input". Both scripts now build the record in memory (printf -v), write the local copy, read it back, and when it does not match stream the record to S3 with `aws s3 cp -`, which needs no local disk. tasklaunch.ReadCompletionAt reports an empty object as ErrEmptyCompletionRecord, naming the task's command.log.
scttfrdmn
force-pushed
the
fix/1179-empty-record
branch
from
October 23, 2026 21:58
e82afe7 to
2119f0b
Compare
Merged
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.
Fixes #1179
Problem
The task wrapper (
pkg/taskproto/wrapper.go) and the terminal-flush hook (pkg/taskproto/flush.go) wrotecompletion.jsonand.exitcodeto/tmpwithcat > file <<JSON/printf > file, then ranaws s3 cp file ...without checking the result. On a container task/tmpis also the staging tmpfs. When the task filled it, both writes left 0-byte files, and those empty files were uploaded.spawn task statusthen failed withparse completion record: unexpected end of JSON input, even though the failure was recorded incommand.log.Change
printf -v REC <format> <args>. That is a bash builtin, so it needs no fork, no heredoc temp file and no disk. The Go-quotedtask_id/run_idJSON is passed as printf arguments and never as part of the format. A new helper,writeRecordFile, emits the same three steps for each of the four record files: write the local copy, read it back and compare it with the value in memory, then upload the local copy if it matches. If it doesn't match, it prints a warning and streams the value withprintf '%s' "$REC" | aws s3 cp - <dest>. The fallback uploads the full record (the same bytes), not a cut-down one, sostate/exit_code/retry_class(andterminal_reasonfrom the hook) stay accurate. The local file is still written, so the flush hook's[ -f completion.json ]interlock works as before. The JSON fields have the same names and order as the old heredoc. The only differences are that the record has no trailing newline, and a backslash in a task id is no longer eaten by heredoc expansion.tasklaunch.ReadCompletionAt, the one reader thattask status,task run --waitand the MCP server all use, now returns a newtasklaunch.ErrEmptyCompletionRecordfor an empty or whitespace-only object. The error readscompletion record is empty at <uri> (the instance's disk was probably full when the task ended); see the task's log at s3://.../command.log. It is notErrNoCompletionRecord, so--waitreturns at once and does not keep polling.api/public-surface.txt: one addition,var ErrEmptyCompletionRecord(make api-snapshot). Nothing was removed or changed.### Fixedentry under[Unreleased].User-data budget
Measured with gzip on the test fixtures: the wrapper grew from 2139 to 2268 bytes (+129) and the flush hook from 975 to 1084 bytes (+109).
TestBareBootstrapFitsItsBudgetand the tasklaunch user-data limit tests pass.Gates, each shown failing against a compiling revert
TestWrapperUploadsAValidRecordWhenTheLocalCopyCannotBeWrittenandTestFlushHookUploadsAValidRecordWhenTheLocalCopyCannotBeWritten(pkg/taskproto/fulldisk_test.go). Each test leaves the local record files present, empty and read-only, which is the state a full disk leaves them in. It then runs the generated script under bash with a stubawsthat stores everys3 cpupload, reading stdin when the source is-. Both tests check the uploaded objects against the documented record: wrapperfailed/7/app_errorwith task_id and run_id,.exitcode=7; hookfailed/-1/ttl_expired/terminal_reason=ttl_expired,.exitcode=-1. They skip on Windows like their neighbours, and also skip as root, because root ignores the file mode.wrapper.goandflush.goreverted toorigin/main(stashed; tests compile and run): both fail withuploaded completion.json is not a record (parse completion record: unexpected end of JSON input): "", the exact error from the issue..exitcodefallback disabled (the condition replaced bytrue): both fail withuploaded .exitcode = "", want "7"/want "-1".TestReadCompletion_EmptyRecord(pkg/tasklaunch) checks that""and"\n"returnerrors.Is(ErrEmptyCompletionRecord), are notErrNoCompletionRecord, return no record, and that the error names.../command.log. With the check disabled (if false && ...): it fails with... parse completion record: unexpected end of JSON input, want errors.Is ErrEmptyCompletionRecord.Two existing structural tests matched the old heredoc text and were updated to the new form while keeping their intent.
TestGenerateWrapper_StampsRunIDnow checks that the run id is theprintf -v RECargument matching the format's"run_id": %s;TestGenerateWrapper_RunIDKeepsCompletionJSONValid, which runs the script, still parses the run id from the written record.TestFlushHookStagingFileIsNotTheInterlockFilenow matches the write to the staging path.Checks run
GOTOOLCHAIN=go1.26.10 go test -short ./...: all pass. This includes the shellcheck test on the generated scripts (shellcheck is installed locally).make lint: clean in all 10 modules.make api-snapshot: diff reviewed, one addition.go test -run Changelog .: pass.make gen-docs: not needed, no help text changed.Not in this PR
spawn task status --check-completeexit 3 (error), not 1 (failed). An empty record proves the task ended, but not whether it succeeded, so it is reported as an error with a pointer to the log.--commandbootstrap inpkg/launcher, which writes/tmp/SPAWN_COMPLETEwithcat > <<JSONEOF, has the same shape but is not part of the task record contract, so it is left alone./tmp(the issue's first suggestion) is deliberately not done, because spored shares/tmp(spawn#66).