Skip to content

Pooled task execution: worker pool for wide fan-out (#70 Phase 1) - #456

Merged
scttfrdmn merged 5 commits into
mainfrom
feat/70-pooled-workers
Jul 31, 2026
Merged

scttfrdmn merged 5 commits into
mainfrom
feat/70-pooled-workers

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Phase 1 of the pooled-execution work for nf-spawn#70 (design: spawn#454). Runs a wide fan-out as a pool of fungible worker instances draining a shared queue instead of one ephemeral instance per task — fixing both the dispatch bottleneck and the per-task instance-boot tax (Little's Law) that cap concurrency today.

History note (please read)

The two foundational packages — pkg/taskcohort and pkg/taskpool/{queue,worker} — were accidentally swept onto main by the squash-merge of PR #455 (ttl-reaper), which bundled files from my in-flight branch. That code is correct and already on main; it's just mislabeled under an unrelated commit. Per the "land it forward, no history rewrite" decision, this PR adds only the remaining pool work on top (executer, spec store, submitter, CLI, worker command). Net result on main is the same complete feature; the only artifact is #455's message understating its diff.

What this PR adds

  • pkg/taskpool (rest): ScriptExecer (runs each job via the taskproto stage/run/complete protocol), DirWorkspace (clean per-task workspace — the Server-side TTL reaper: out-of-band backstop so a spore can never outlive its deadline (even if spored is dead) #70 isolation-on-reuse gotcha), SpecStore (S3 spec staging/fetch), Pool (submitter: create queue → stage+enqueue → drain).
  • pkg/taskproto: GeneratePooledJobScript — the spawn task run wrapper minus the /tmp/SPAWN_COMPLETE self-terminate signal, so a worker survives to run the next task. A test asserts it's byte-identical to the wrapper except that block. Also ParseSpec([]byte).
  • CLI: spawn pool create|submit|status|drain (submitter) + spored pool-worker (the on-instance pull loop). create provisions workers as a PartialCohort (best-effort/eventual — ask N, accept --min-viable) via pkg/taskcohort.

Semantics

  • Best-effort + eventual: fewer workers ⇒ lower parallelism, never failure (interactive demos never hang).
  • At-least-once via SQS visibility-timeout: a worker that dies before ack redelivers the task — the task-level echo of cohort's reaped-worker replacement.
  • Scale to zero: workers self-terminate on idle-timeout; tag-based reaper (spawn:pool-run-id / spawn:role=pool-worker) backstops a missed drain.
  • Zero cohort core changes — confirmed; NewPartialCohort + the taskcohort seam express every pool semantic.

Testing (no paid AWS)

  • pkg/taskcohort: 4 tests drive cohort's real reconciler (all-up, best-effort-degrades, per-entity AZ fallback, classifier).
  • pkg/taskpool: worker-loop unit tests (fake SQS + injected clock, green under -race); queue + full submit→pull→run→drain end-to-end tests against real Substrate SQS + S3.
  • Tier-0 command-coverage gate updated (pool classified); spored CLI test updated. go build ./... clean.

The spawn pool CLI launch path itself needs real EC2 (Tier 2/3) — that live validation is Phase 2 (nf-spawn integration + the real N=108 run).

Refs nf-spawn#70. Design: docs/pooled-task-execution-design.md (spawn#454).

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.80973% with 332 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/pool.go 6.84% 204 Missing ⚠️
cmd/spored/pool_worker.go 22.22% 62 Missing and 1 partial ⚠️
pkg/taskpool/pool.go 40.00% 20 Missing and 4 partials ⚠️
pkg/taskpool/exec.go 69.01% 15 Missing and 7 partials ⚠️
pkg/taskpool/spec_store.go 58.69% 13 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn force-pushed the feat/70-pooled-workers branch from afe6c7f to a624b12 Compare July 31, 2026 02:41
@scttfrdmn
scttfrdmn merged commit faa258a into main Jul 31, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/70-pooled-workers branch July 31, 2026 02:42
scttfrdmn added a commit that referenced this pull request Jul 31, 2026
The spawn pool command (#456) was added without regenerating docs-gen/;
the missing untracked docs-gen/pool.md put the tree in a dirty state that
failed GoReleaser's git-state check on the v0.96.0 tag. Regenerated via
make gen-docs.
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.

1 participant