Repository navigation
feat(task): real 'spawn task run' — launch + S3 staging + durable completion record (spawn#386) - #404
Merged
Merged
Conversation
…pletion record (spawn#386) Increment 2 of the task-execution protocol: task run --spec now launches (not just --dry-run). It sizes the cheapest fitting instance (reusing the existing truffle sizer), ensures the per-account results bucket, and launches an ephemeral instance via launcher.Provision running a generated bash wrapper that stages inputs, runs the command, stages outputs, and writes a durable completion record to s3://spawn-results-<acct>-<region>/tasks/<task_id>/ — completion.json (authoritative), .exitcode (legacy signal), command.log. The wrapper (pkg/taskproto/wrapper.go) IS the reference impl — no bootstrap or spored change. It deliberately avoids 'set -e' (which would abort before the completion record) and single-quotes all argv/env/paths. New taskproto types: LaunchResult, CompletionRecord, RetryClass + ClassifyLaunchError (app_error, staging_error, capacity wired; spot/health/ttl/controller-lost stubbed). A scoped IAM instance profile grants exactly the input/output/results buckets the task touches (no wildcard), via a new IAMRoleConfig.InlinePolicyJSON field. Spot falls back to on-demand once on a capacity error when configured. Container execution is deferred (rejected clearly). Refs #386
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…into interface{}
Semgrep's go-unsafe-deserialization-interface rule flags json.Unmarshal into an
interface{}. The intent here is only to assert the string-built policy is valid
JSON, so json.Valid is both correct and rule-clean.
SearchInstanceTypes does not return on-demand pricing (that's a separate call), so every candidate had OnDemandPrice=0. The sizer ranks on price, so 'cheapest' collapsed to the alphabetical name tie-break — which picked the LARGEST matching type (a 2-vCPU/2-GiB request sized to c7i.12xlarge, 48 vCPU). Caught by the increment-2 smoke test. truffleFinder.FindCandidates now looks up each candidate's on-demand price via tc.OnDemandPrice (AWS pricing API with a static libs/pricing fallback). A lookup miss leaves price 0, which the sizer sorts last, so a priced option always wins and we never silently pick a huge box because pricing was briefly unavailable. Refs #386
CreateOrGetInstanceProfile built a trust policy with an empty Service principal
when the caller passed no TrustServices, which IAM rejects with
MalformedPolicyDocument ('statement with no principals'). An instance profile is
always assumed by the EC2 service, so default to ec2 when unset. This is a latent
bug on any headless CreateOrGetInstanceProfile caller (lagotto included); caught
by the increment-2 smoke test when 'spawn task run' created a scoped profile.
Also set TrustServices explicitly at the task-run call site for clarity.
Refs #386
This was referenced Jul 19, 2026
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
First of two stacked PRs for spawn#386 increment 2. Makes
spawn task runactually launch (previously--dry-runonly).task run --spec <file>:spawn-results-<account>-<region>exists,launcher.Provision(keyless/SSM, auto AMI+IAM+user-data) running a generated bash wrapper,The wrapper (
pkg/taskproto/wrapper.go) is the reference implAssigned to
LaunchConfig.JobArrayCommand, embedded by Provision — zero changes tobootstrap.goor spored. It: stages inputs (aws s3 cp) → runs the argv command capturingrc=$?→ stages outputs (even on failure) → writes the durable record tos3://.../tasks/<task_id>/(completion.json,.exitcode, best-effortcommand.log) → signals/tmp/SPAWN_COMPLETEsoon_complete: terminatefires →exit $rc.Design points (commented in the generated script):
set -e— it would abort before stage-out/record on a failing command.rc=$?is captured explicitly.shQuote, the safe single-quote form — notstrconv.Quote). Env keys validated as shell identifiers inValidate().New taskproto types
LaunchResult,CompletionRecord(JSON shape authoritative for cross-lang adapters; timestamps kept as strings),RetryClass+ClassifyLaunchError. Wired:app_error,staging_error,capacity. Defined-but-stubbed:spot_interruption,instance_health,ttl_expired,controller_lost.pkg/awschangeIAMRoleConfig.InlinePolicyJSON— attach a scoped inline policy from a string (mirrors the existingPolicyFilepath), folded intohashPoliciesso different bucket sets get different cached roles.Deferred
spec.container) — rejected clearly; host command path ships fully.spawn task status+--waitpoller — PR B (stacked on this).Testing
pkg/taskproto: wrapper structure/quoting/ordering golden-ish assertions (incl. no-set -e, metachar args), CompletionRecord round-trip + parse-the-wrapper-shape,Retryable()/ClassifyLaunchErrortables, env-key validation.cmd:taskLaunchConfigmapping,s3Bucket(s),taskStagingPolicy(scoped, valid JSON, no wildcard, input≠write).pkg/aws:InlinePolicyJSONrole-name determinism.TestFlagConventions/TestTier0pass; docs-gen regenerated; Semgrep clean on new files. No billable EC2 — all unit-level. A real end-to-end launch is gated for a later approved run.Refs #386