Skip to content

Simulate spore.host task completion: write completion.json/.exitcode to emulated S3 after a spawn-launched instance goes running #360

Closed

Description

@scttfrdmn

Summary

Add a seedable task-completion outcome for spore.host spawn task run — a programmable per-task {exit_code, state} that the emulator serves as the task's completion record, on the simulated clock. This is the same shape as #345's proposed SSM programmable-response hook and the existing capacity-error/seeded-result mechanism — not workload execution, so it stays inside Substrate's scope boundary.

Framing (corrected — thanks to reading docs/scope.md)

My first draft asked Substrate to "write completion.json to S3 after the instance runs," which fights the scope boundary (that's simulating a workload side-effect). The scope doc already describes the right model:

"[a workload input is] captured as recorded intent with a seedable success/failure/completion signal ... a command invocation going Pending → InProgress → Success"

So the completion record is a seedable outcome, exactly like a seeded SSM GetCommandInvocation (#345) or a seeded CapacityError — the caller seeds {exit_code, state} per task; Substrate serves it deterministically over the simulated clock. No user-data execution, no scope violation.

Context / why

The spore.host workflow adapters (nf-spawn, miniwdl-spawn, cwl-spawn, snakemake-executor-plugin-spawn, airflow-spawn, pegasus-spawn) run each task via spawn task run, which launches an ephemeral EC2 instance; the task writes a durable completion record to s3://<results-bucket>/tasks/<task_id>/completion.json (+ .exitcode), and the adapter polls it. We want these adapters' engine-composition tests to run in CI against Substrate (AWS_ENDPOINT_URL → emulator) — real engine + real spawn task run + real aws s3 staging, all against the emulated S3/EC2 APIs (verified spawn task run honors AWS_ENDPOINT_URL). The only missing piece is the completion signal, which today never appears because Substrate (correctly) doesn't run the instance's workload.

Ask (pick whichever fits Substrate's seeding model — team decides)

A programmable-response hook for the spore task lifecycle, e.g.:

  • Seed by task id / instance tag: register {exit_code:int, state:"completed"|"failed", started_at, ended_at} for a spawn:task-id (a tag spawn task run already sets), served as the completion.json object when the S3 GET arrives — mirroring how SSM: SendCommand should (optionally) execute the shell command, not always return empty Success #345 proposes per-(instance, command) SSM canned results.
  • Default nominal path: absent a seed, return exit_code:0 / completed (the nominal success path, per the seeding philosophy) so the happy path needs no seeding at all.
  • Clock-aware: a poll observes "not yet present / still running" then "completed" over the simulated clock, so the adapters' real poll loops are exercised.

Record schema (from spawn/pkg/taskproto/completion.go):

{"task_id":"<id>","exit_code":0,"state":"completed","started_at":"<rfc3339>","ended_at":"<rfc3339>"}

Payoff

  • All six spore.host workflow adapters get faithful, hermetic, no-AWS engine-composition CI (real spawn + real staging; only the completion outcome seeded).
  • spawn's own Tier-0 can then assert task run → completion → exit-code end-to-end against Substrate (today Tier-0 covers launch/list/terminate, not task completion).
  • Natural companion to SSM: SendCommand should (optionally) execute the shell command, not always return empty Success #345 (both are "seedable result for a recorded-intent workload," same design question).

Interim

Until this lands, the adapter CI tests hand-seed the record with a one-line aws s3 cp of a completion.json into the emulated bucket (works against today's Substrate); they drop that line once the seeding hook exists.

Filed per the spore.host workflow: substrate changes are requested via issue, not PR'd from consumer repos. Corrected framing after studying docs/scope.md + the #345 precedent. Found while scoping real-engine-in-CI regression guards for the workflow adapters (spore-host#397).

Activity

  1. scttfrdmn commented on Jul 26, 2026

    @scttfrdmn
    OwnerAuthor

    Accepted — this is in-scope and well-framed. Thanks for course-correcting against docs/scope.md; the seedable-completion-signal model is exactly right, and it lands as a direct sibling of #345 (seeded GetCommandInvocation, shipped in v0.74.0) and the SageMaker/Bedrock/Athena seed pattern. No workload execution — just a seedable, clock-aware completion observation.

    Design (proposed)

    S3-GET intercept, not materialize-on-seed. The adapters do a real aws s3 GET of tasks/<task_id>/completion.json against the emulated S3 (you confirmed spawn task run honors AWS_ENDPOINT_URL), so keeping the S3 API observation authentic is the priority. A seeded completion resolves inside getObject, gated on the simulated clock in one place, rather than pre-writing a real object.

    • Seed endpoint (control plane): POST /v1/spawn/task-completion with {"task_id","exit_code","state","started_at","ended_at"}, plus DELETE /v1/spawn/task-completion?taskId=... (or clear-all), following the /v1/ssm/command-invocation convention.
    • Clock-aware transition: a GET of tasks/<task_id>/completion.json (and the .exitcode companion) checks the seed store first. Before the seed's ended_at (on the simulated clock via TimeController) → 404 NoSuchKey (i.e. "still running"); at/after ended_at → synthesize the record body. This exercises the adapters' real poll loops (not-present → completed) deterministically.
    • Default nominal path: absent a seed, behaviour is unchanged — a real object at that key is served as today, and the interim aws s3 cp staging keeps working. Note: the "no seed → exit 0/completed" default only makes sense scoped to keys matching the task-completion pattern; a bare unseeded GET of a non-existent key must still 404. I'll scope any synthesized default to the tasks/*/completion.json key shape so we don't turn every 404 into a fake success.

    One thing to confirm before I implement

    From spawn/pkg/taskproto/completion.go, please pin:

    1. Exact JSON field casing for completion.json (issue shows task_id/exit_code/state/started_at/ended_at snake_case — confirm that's the wire form).
    2. The .exitcode companion object — plain-text body (just the integer?), and is it polled independently or only completion.json?
    3. state value set — "completed"/"failed" only, or others?

    Once those are pinned I'll implement against emulator/s3_plugin.go getObject + a new emulator/spawn_control.go, mirroring ssm_control.go. Targeting the next minor (v0.75.0).

  2. added this to the v0.75.0 milestone on Jul 26, 2026
  3. scttfrdmn commented on Jul 26, 2026

    @scttfrdmn
    OwnerAuthor

    Great — the S3-GET-intercept design (resolve inside getObject, clock-gated, scoped to the tasks/*/completion.json key shape so a bare 404 stays a 404) is exactly right. Pinning your three questions from spawn/pkg/taskproto/completion.go + cmd/task.go:

    1. completion.json wire form — snake_case, confirmed

    Marshalled from taskproto.CompletionRecord:

    type CompletionRecord struct {
        TaskID       string     `json:"task_id"`
        ExitCode     int        `json:"exit_code"`
        State        TaskState  `json:"state"`                 // "completed" | "failed"
        StartedAt    string     `json:"started_at"`            // RFC3339
        EndedAt      string     `json:"ended_at"`              // RFC3339
        CostEstimate float64    `json:"cost_estimate,omitempty"`
        Logs         []string   `json:"logs,omitempty"`
        RetryClass   RetryClass `json:"retry_class,omitempty"`
    }

    So the minimal synthesized body is exactly the five fields the issue listed; cost_estimate/logs/retry_class are omitempty and the consumer tolerates their absence — you can omit them.

    2. .exitcode companion — the CLI does NOT read it; you can skip it

    This is the useful simplifier. The wrapper writes .exitcode as a plain-integer body (printf '%s' "$rc" → e.g. 0) alongside completion.json, but it's a legacy/external signal — I grepped the whole CLI (cmd/, pkg/taskproto, pkg/aws) and nothing reads .exitcode. spawn task status — both --check-complete and -o json — resolves solely through fetchCompletion(), which GETs tasks/<task_id>/completion.json only (NoSuchKey ⇒ "still running"). So:

    • For the adapters' poll loops to work, you only need to synthesize completion.json.
    • Synthesizing .exitcode (plain integer text at tasks/<id>/.exitcode) is optional — nice for fidelity/external consumers, not required by any spawn CLI path.

    3. state value set

    The TaskState enum is submitted | launching | running | completed | failed | cancelled, but a completion record only ever carries a terminal value: "completed" (exit 0) or "failed" (nonzero/cancelled). So for the seed, state ∈ {completed, failed} is the complete set — default seed exit_code:0 / state:"completed".

    Net for your implementation

    • Intercept getObject on the tasks/*/completion.json key shape.
    • Before seed's ended_at (simulated clock) → NoSuchKey; at/after → synthesize the 5-field JSON above.
    • No seed + matching key → nominal exit_code:0 / completed; non-matching key → normal 404 (as you said).
    • .exitcode synthesis: optional.

    Seed endpoint POST /v1/spawn/task-completion {task_id, exit_code, state, started_at, ended_at} mirroring /v1/ssm/command-invocation is perfect. That fully unblocks the adapters' engine-composition CI (real spawn + real aws s3 staging vs. Substrate; only the completion outcome seeded). Thanks — will migrate the adapters off the interim aws s3 cp seed to this once v0.75.0 ships.

  4. scttfrdmn commented on Jul 26, 2026

    @scttfrdmn
    OwnerAuthor

    Landed on `main` in #361 (commit 18a7919). Ships in v0.75.0.

    Implemented exactly as agreed:

    • `POST /v1/spawn/task-completion` `{task_id, exit_code, state, started_at, ended_at}`; `DELETE /v1/spawn/task-completion?taskId=...` (one) / no query (all).
    • GET `tasks/<task_id>/completion.json` → clock-gated: before `ended_at` (simulated clock) it is `NoSuchKey` ("still running"), at/after it serves the record. Your adapters' real poll loops work unchanged.
    • No seed + matching key → nominal `exit_code:0 / completed`; a real staged object at the key (your interim `aws s3 cp`) always wins; any non-`tasks/*/completion.json` key stays a normal 404.
    • Only `completion.json` is synthesized (`.exitcode` unread by the CLI, per your note); `state ∈ {completed, failed}`.

    You can migrate the adapters off the interim `aws s3 cp` seed to `POST /v1/spawn/task-completion` once v0.75.0 tags. Ill comment here when the release goes out.

  5. added a commit that references this issue on Jul 26, 2026
  6. scttfrdmn commented on Jul 26, 2026

    @scttfrdmn
    OwnerAuthor

    Released in v0.75.0 — https://github.com/scttfrdmn/substrate/releases/tag/v0.75.0 (`go get github.com/scttfrdmn/[email protected]`). You can now migrate the adapters off the interim `aws s3 cp` seed to `POST /v1/spawn/task-completion`.

  7. added
    type: feature
    and removed on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions