Skip to content

feat(taskproto)!: script generators take WrapperOptions and return an error (#764) - #765

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/764-wrapper-options
Oct 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/764-wrapper-options

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #764.

The decision

Four options were on the table. This takes the third, and the reasoning for
rejecting the others is the useful part.

Rejected — leave it positional. The hazard is live, not theoretical. See
below.

Rejected — a struct, and nothing else. This is what #764 literally asked for,
and on its own it makes the failure more likely. A new positional parameter at
least forces a compile error at every call site, so somebody has to look. An
omitted struct field is silence.

Rejected — move GPU detection into taskproto. Tempting, because
spore-host-mcp had to reimplement spawn's rule
(spec.Resources.GPUs > 0 || aws.DetectGPUInstance(sizedType)). But
DetectGPUInstance lives in pkg/aws, and pkg/taskproto currently has zero
dependency on pkg/aws or the AWS SDK
— its only spawn-internal import is
pkg/ecrref. That is a valuable property for the wire-contract package six
workflow adapters use just to parse a CompletionRecord, and not worth spending
to deduplicate one boolean.

Taken — a struct, plus validation that makes the dangerous zero value loud.

Why validation, not just a struct

spore-host-mcp's own regression test records what actually happened after the
v0.111.1 signature change — the quickest way to make the package build again was:

GenerateWrapper(spec, bucket, region, false, "")

That compiles, passes every test, and emits an empty run_id while dropping
--gpus all. It is #608 and #606 reintroduced by a padding edit, in the MCP
path only, discovered days later. The old doc comment already warned that ""
reads downstream as "unattributable" — which is the evidence that documenting it
was not enough.

So WrapperOptions carries Validate, and the generators return
ErrMissingRunID / ErrMissingResultsPrefix instead of a script.

Two non-obvious calls

Region is deliberately not required. It is used only for the ECR login of a
private-registry image, so a host-command task legitimately has none. Validating
it would make the check fire on correct input, and a check that cries wolf is one
people route around — which is how the original bug survived a documented
warning. Pinned by a test.

RunID is not defaulted, even though empty is always wrong. Minting one
inside the library looks like the obvious safe fix and is actually the dangerous
one: cmd/task.go uses the same id in five places — clearing the previous
attempt's record, the flush script, displayed output, and
pollCompletion(..., runID, ...) for --wait verification. An id minted
privately in here would be invisible to exactly the code that has to match it,
defeating #608's verification rather than protecting it.

No positional shim

There is one external caller (spore-host-mcp/launch.go:237, already on the
current signature); GeneratePooledJobScript and GenerateFlushScript have
none. A deprecated positional form would preserve the exact hazard being removed
in exchange for almost nothing. Hard cutover.

Verification

The #763 API gate's first real use, and it reported exactly what it exists to
report:

REMOVED or CHANGED — breaks a consumer, so the release bumps MINOR, not PATCH:
  - func GenerateFlushScript(spec *TaskSpec, resultsPrefix, region, runID string) string
  - func GeneratePooledJobScript(spec *TaskSpec, resultsPrefix, region string, gpu bool, runID string) string
  - func GenerateWrapper(spec *TaskSpec, resultsPrefix, region string, gpu bool, runID string) string

New tests cover what is new: all three generators reject an empty RunID and an
empty ResultsPrefix, an empty Region is accepted, the options reach the
emitted script, and the flush hook's output is byte-identical with GPU true vs
false.

Both confirmed to fail on revert, with compiling edits — a build failure is
not a passing gate:

revert caught
drop the RunID check from Validate all three generators reported
drop the Validate call from GenerateWrapper only caught — the partial regression a single shared check would hide

Locally: format, vet ./..., -short ./..., all 12 nested modules, changelog
gate, docs-drift gate, semgrep --config=auto --error — clean.

Downstream — your call, not done here

This needs a MINOR release to be consumable, and then a coordinated
spore-host-mcp update. Neither is in this PR: tagging is yours to approve, and
mcp is a separate repo.

Migration is mechanical:

// before
GenerateWrapper(spec, prefix, region, gpu, runID)
// after
GenerateWrapper(spec, taskproto.WrapperOptions{
    ResultsPrefix: prefix, Region: region, RunID: runID, GPU: gpu,
})

Also still outstanding from #679's measurement, unrelated to this change:
lagotto is pinned to spawn v0.111.1 — the broken patch release itself — and
calque to v0.100.0.

…n an error

BREAKING for pkg/taskproto. #764, split from #679.

GenerateWrapper, GeneratePooledJobScript and GenerateFlushScript shared
four positional parameters, two of which were added in separate releases:

  v0.111.0  GenerateWrapper(spec, resultsBucket, region string) string
  v0.111.1  ... gpu bool) string                  <- PATCH. broke mcp
  v0.112.0  ... gpu bool, runID string) string    <- MINOR, compliant

Both additions are per-launch decisions with no safe default, so neither
could be defaulted away. The problem is that both have a zero value that
compiles and reads as deliberate. spore-host-mcp's own regression test
records what actually happened: the quickest way to make the package build
again was

  GenerateWrapper(spec, bucket, region, false, "")

which compiles, passes every test, and emits an empty run_id while dropping
--gpus all. That is #608 and #606 reintroduced by a padding edit, in the
MCP path only, found days later.

## Why a struct alone is not the fix

An options struct makes that failure MORE likely, not less. A new positional
parameter at least forces a compile error at every call site, so somebody
has to look; an omitted struct field is silence.

So the struct ships with Validate, and the generators return
ErrMissingRunID / ErrMissingResultsPrefix instead of a script. That trades a
compile error for a loud runtime error at the point of misuse, rather than
an unattributable S3 record discovered weeks later. The old doc comment
already warned that "" emits an unattributable run_id — which is the
evidence that documenting it was not enough.

Region is deliberately NOT required. It is used only for the ECR login of a
private-registry image, so a host-command task legitimately has none, and a
check that fires on correct input is one people route around.

RunID is NOT defaulted here either, though an empty value is always wrong.
The caller needs the same id for the work it does around the launch —
clearing the previous attempt's record, and verifying run_id when polling
for completion (cmd/task.go uses it in five places). An id minted privately
inside the library would be invisible to exactly the code that has to match
it, defeating #608's verification rather than protecting it.

GenerateFlushScript takes the same options so the three stay in step and the
next per-launch input is non-breaking for all of them. It ignores GPU; it
does not run the container. Asserted, not assumed.

## No positional shim

Deliberate. A deprecated positional form would preserve the exact hazard
being removed, and there is ONE external caller (spore-host-mcp/launch.go).
Hard cutover, MINOR bump, coordinated mcp update.

## Verification

- The #763 API gate reports all three signatures under "REMOVED or CHANGED",
  which is its first real use and the behaviour it exists for. Snapshot
  regenerated.
- New tests cover what is new: all three generators reject an empty RunID
  and an empty ResultsPrefix, an empty Region is ACCEPTED (pinning the
  non-requirement), the options reach the emitted script, and the flush
  hook's output is byte-identical with GPU true vs false.
- Both confirmed to fail on revert, with compiling edits: dropping the
  RunID check from Validate, and dropping the Validate call from
  GenerateWrapper alone — the partial regression a single shared check
  would otherwise hide.

Not changed: pkg/taskpool and cmd/task.go mint their run ids exactly as
before. cmd/task.go now builds ONE options value for both the wrapper and
the flush hook, so they cannot disagree about the prefix or the run id.
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.78947% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/task.go 0.00% 11 Missing ⚠️
pkg/taskpool/exec.go 75.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 21c7647 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/764-wrapper-options branch October 8, 2026 21:42
scttfrdmn added a commit that referenced this pull request Oct 8, 2026
Promotes [Unreleased] to [0.126.0] and adds the compare link.

MINOR, not PATCH, because this release contains a breaking change to a
package other repos compile against: pkg/taskproto's three script
generators now take a WrapperOptions struct and return an error (#765/#764).
Pre-1.0 the project's rule is that a breaking change bumps MINOR.

Also in this release: the cross-repo API surface gate that will report the
next such change before it ships (#763/#679), `spawn logs` (#761), the
spored console log tail it reads (#759), the MPI peer-SSH readiness poll
(#758), and the remaining sleep-audit fixes plus the creation-stamp/orphan
reaper work (#752, #755, #756, #757, #762).

Release guard passed: both binaries report 0.126.0 for tag v0.126.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pkg/taskproto: GenerateWrapper should take an options struct (split from #679)

1 participant