Repository navigation
Description
A task's whole life is currently two timestamps. generateWrapper sets STARTED_AT at the top (pkg/taskproto/wrapper.go:89) and ENDED_AT after the user command (:165), and those are the only two — they're what completion.json carries (:213–214). Everything in between is one number: stage-in, the dnf install docker, the image pull, the user command, stage-out.
That's fine until you want to know where the time went, and then it's a wall.
The measurement that made this concrete
cookbook-relion-postprocess-r1 (spawn 0.103.1, m8g.large, quay.io/aarchbio/relion):
command window (started_at → ended_at) |
94s |
the science (relion_postprocess, self-reported) |
25s |
| everything else | ~69s, unattributable |
I know from the inputs that the ~69s is stage-in of 975 MiB, a 62 MB / 11-package Docker install on the stock AL2023 AMI, and a 0.40 GiB image pull. I can't tell you how that ~69s divides among the three, and that's the split that decides what's worth fixing — a pre-baked AMI attacks one term, a shared filesystem (#570) attacks another, and image size attacks the third. Choosing between them on a guess is exactly the kind of thing this project is trying not to do.
It also matters for short tasks generally, which is most of them: on a 94s window the platform's fixed setup was most of the bill, and the interesting question is never "how long did the task take" but "which part."
Patch
Attached below; built, gofmt-clean, and go test ./pkg/taskproto/... passes against ec968ec (0.103.1) — including the executable TestGenerateWrapper_StagedFileOwnedByInvokingUID_RealFilesystem and ..._ChownFixesCrossUIDStickyUnlink_Docker. I also generated wrappers for a container spec and a host spec, bash -n'd both, and ran the host one with stubbed aws/sudo:
spawn: [2026-09-04T16:30:55Z] wrapper start
spawn: [2026-09-04T16:30:55Z] stage-in start
spawn: [2026-09-04T16:30:55Z] stage-in done rc=0
spawn: [2026-09-04T16:30:55Z] command start
hi
spawn: [2026-09-04T16:30:55Z] command exit rc=0
One spawn_phase() helper, then markers at each real boundary. On the container path that's wrapper start → stage-in start → stage-in done rc=N → docker install start → docker install done → image pull start → image pull done; command start → command exit rc=N → stage-out start → stage-out done rc=N. The host path gets the same minus the Docker ones.
Three choices worth stating rather than leaving to be inferred:
- Plain text on stdout, not a second structured artifact.
command.logis already captured to S3 (wrapper.go:202) and nothing parses it — I checked everycommand.logreference in the tree;cmd/service.go:145's readiness grep is the service path, not this wrapper — so added lines break no consumer. Aphases[]array incompletion.jsonwould be nicer to graph and is a bigger change with a wire-format implication; this is the version that costs onedateper phase and can go in now. Happy to do the structured version instead if you'd rather have that. rc=is carried on the "done" markers. Makesstage-in done rc=1visible in the log at the moment it happens, which is a small independent win given A task whose command fails writes no completion record at all, so the box rides to TTL instead of self-terminating #566's "no completion record at all" failure mode — the phase markers show how far the wrapper actually got, which is currently only inferable from console output.- Nothing is added between
ENDED_ATand the completion write. The classification/record tail stays untouched, so no failure path changes shape.
diff --git a/pkg/taskproto/wrapper.go b/pkg/taskproto/wrapper.go
index 8c3dbd8..d5d886c 100644
--- a/pkg/taskproto/wrapper.go
+++ b/pkg/taskproto/wrapper.go
@@ -86,7 +86,18 @@ func generateWrapper(spec *TaskSpec, resultsBucket, region string, signalComplet
p("TASK_ID=%s\n", shQuote(taskID))
p("RESULTS_PREFIX=%s\n", shQuote(resultsPrefix))
- p("STARTED_AT=\"$(date -u +%%Y-%%m-%%dT%%H:%%M:%%SZ)\"\n\n")
+ p("STARTED_AT=\"$(date -u +%%Y-%%m-%%dT%%H:%%M:%%SZ)\"\n")
+ // Phase markers. completion.json carries only started_at/ended_at, so the
+ // whole interval between them — stage-in, the Docker install, the image pull,
+ // the user command, stage-out — is one opaque number. Measured on a real task
+ // (cookbook-relion-postprocess-r1): a 94s window of which the user command was
+ // 25s, with no way to attribute the other ~69s. These lines make command.log
+ // self-timing at the cost of one `date` per phase. Deliberately plain text on
+ // stdout rather than a second structured artifact: nothing parses command.log
+ // (cmd/service.go's readiness grep is the service path, not this wrapper), and
+ // a log a human can read is the thing that was missing.
+ p("spawn_phase() { echo \"spawn: [$(date -u +%%Y-%%m-%%dT%%H:%%M:%%SZ)] $*\"; }\n")
+ p("spawn_phase 'wrapper start'\n\n")
// ---- env ----
if len(spec.Env) > 0 {
@@ -99,6 +110,7 @@ func generateWrapper(spec *TaskSpec, resultsBucket, region string, signalComplet
// ---- stage-in ----
p("# ---- stage-in ----\n")
+ p("spawn_phase 'stage-in start'\n")
p("STAGE_RC=0\n")
// mkdir -p every directory containerMountDirs will bind-mount (spawn#564):
// input Destination parents AND output Source parents, from the SAME set
@@ -145,6 +157,7 @@ func generateWrapper(spec *TaskSpec, resultsBucket, region string, signalComplet
p(" sudo chown%s \"$(id -u):$(id -g)\" %s 2>/dev/null || true\n", recursiveChownFlag(m.Source), shQuote(m.Destination))
p("fi\n")
}
+ p("spawn_phase \"stage-in done rc=$STAGE_RC\"\n")
p("\n")
// ---- run user command ----
@@ -155,8 +168,10 @@ func generateWrapper(spec *TaskSpec, resultsBucket, region string, signalComplet
writeContainerRun(p, spec, region)
} else {
// Host path: run argv in a subshell (no shell re-parse of a joined string).
+ p(" spawn_phase 'command start'\n")
p(" ( %s )\n", quoteArgv(spec.Command))
p(" rc=$?\n")
+ p(" spawn_phase \"command exit rc=$rc\"\n")
}
p("else\n")
p(" echo 'spawn: stage-in failed; skipping user command' >&2\n")
@@ -169,9 +184,11 @@ func generateWrapper(spec *TaskSpec, resultsBucket, region string, signalComplet
p("OUT_RC=0\n")
if len(spec.Outputs) > 0 {
p("if [ \"$STAGE_RC\" -eq 0 ]; then\n")
+ p(" spawn_phase 'stage-out start'\n")
for _, m := range spec.Outputs {
p(" aws s3 cp%s %s %s || OUT_RC=$?\n", recursiveFlag(m.Source), shQuote(m.Source), shQuote(m.Destination))
}
+ p(" spawn_phase \"stage-out done rc=$OUT_RC\"\n")
p("fi\n")
}
p("\n")
@@ -266,6 +283,7 @@ func writeContainerRun(p func(string, ...interface{}), spec *TaskSpec, region st
// then make sure the daemon is up before we pull. Failures are fatal to the
// container run — abort early with a non-zero rc so the completion record
// classifies it, rather than hanging on a `docker` call to a dead daemon.
+ p(" spawn_phase 'docker install start'\n")
p(" if ! command -v docker >/dev/null 2>&1; then\n")
p(" echo 'spawn: installing docker...'\n")
p(" sudo dnf install -y docker\n")
@@ -273,6 +291,7 @@ func writeContainerRun(p func(string, ...interface{}), spec *TaskSpec, region st
p(" sudo systemctl enable --now docker\n")
// Wait for the socket (service start is async); bounded so we never hang.
p(" for _i in $(seq 1 30); do sudo docker info >/dev/null 2>&1 && break; sleep 2; done\n")
+ p(" spawn_phase 'docker install done'\n")
// Private-ECR images need a docker login with the instance-role creds; public
// images pull anonymously. ecrImageAccount!="" ⇒ private ECR ref.
@@ -306,9 +325,12 @@ func writeContainerRun(p func(string, ...interface{}), spec *TaskSpec, region st
for _, d := range containerMountDirs(spec) {
fmt.Fprintf(&mounts, "-v %s:%s ", shQuote(d), shQuote(d))
}
+ p(" spawn_phase 'image pull start'\n")
p(" sudo docker pull %s\n", shQuote(image))
+ p(" spawn_phase 'image pull done; command start'\n")
p(" sudo docker run --rm --user \"$(id -u):$(id -g)\" %s%s%s %s\n", gpuFlag, mounts.String(), shQuote(image), quoteArgv(spec.Command))
p(" rc=$?\n")
+ p(" spawn_phase \"command exit rc=$rc\"\n")
}
// containerMountDirs returns the distinct host directories to bind-mount into theNo new test is included, because the existing wrapper_test.go asserts on generated-script content and I'd rather add assertions in the shape you prefer than guess. If you want them: one per phase marker present in the container path, one for the host path, and one that the helper is defined before its first use.
Related: #570 (a container task can't see a mounted EFS) — same root motivation, since stage-in is one of the three terms this would let anyone actually measure.
Activity
feat(taskproto): add phase-timestamp markers to the wrapper log (#571) (