Skip to content

fix(pool): workers terminate when drained; idempotent drain; --cost-limit (#1146, #1183) - #1192

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/1146-1183-pool-lifecycle
Oct 20, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/1146-1183-pool-lifecycle

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Pool workers now terminate when they run out of work, pool drain is idempotent, and pool create takes a per-worker --cost-limit. Owner decision on #1146: idle or drained workers terminate (not stop).

Fixes #1146
Fixes #1183

Depends on #1200 (rebased onto fix/1150-1151-app-service-lifecycle). Until #1200 merges, this PR's diff also shows its commit. #1200 adds spored's idle-terminate action (LaunchConfig.TerminateOnIdle) and sets it for pool workers in poolWorkerBaseConfig. This PR builds on that rather than adding a second mechanism.

What changed

Gates (each watched failing against a revert that compiles)

Gate Revert Result
TestWorker_QueueDeletedDrainsAtOnce: one ReceiveMessage, zero retries, nil return if false && IsQueueGone(cerr) FAIL
TestWorker_ClaimErrorsHonourTheIdleDeadline: counting sleep advances a fake clock if false && now().After(idleDeadline) FAIL
TestDrainRun_Idempotent: second drain (true, nil) after exactly 1 GetQueueUrl if false && IsQueueGone(err) FAIL
TestPoolWorkerCleanExitWritesTheCompletionRecord (runs the script with a stub spored) + TestPoolWorkerScriptWritesTheFileSporedWatches (anchored ^\s*cat > "<CompletionFile>" <<JSONEOF$, tied to the launch config's CompletionFile) redirect the clean-exit cat to /dev/null both FAIL
TestPoolCostLimitReachesTheWorkerLaunchConfig (set through the real flag) drop CostLimit: FAIL

Also: #1200's TestIdleTerminateClaimsAreTrue now sees pool create --idle-timeout's new help ("Workers terminate after..."), so spawn pool create is added to its idleTerminateProofs. The claim is true: TerminateOnIdle is set.

TestPoolWorkerThatGivesUpWritesAFailedRecord runs the script with a failing stub spored and a no-op sleep on PATH. It is Linux-only, like the existing script tests.

Checks

  • make check: every step passed except check-build-tags, which fails on the /private/tmp worktree path for untouched test/e2e files (known on main).
  • make check-docs: clean. semgrep --config=auto --error: clean. go test -race on the touched packages: pass.

Not verified

Not run on AWS. The spored pool-worker queue-gone-at-open path has no unit test: it sits behind provider/IMDS construction.

@scttfrdmn scttfrdmn added this to the v0.136.0 milestone Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.19355% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/pool.go 81.25% 6 Missing ⚠️
pkg/taskpool/pool.go 60.00% 5 Missing and 1 partial ⚠️
cmd/spored/pool_worker.go 0.00% 3 Missing ⚠️
pkg/taskpool/worker.go 91.66% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…le; truthful idle wording

spawn app launch sets an 8h TTL when --ttl is not given and refuses an
empty one (#1150). spawn service and pool workers set the new
LaunchConfig.TerminateOnIdle (spawn:terminate-on-idle), so spored
terminates them when idle instead of stopping them (#1151, refs #1146).
Help and notices that said idle terminates on stop paths are corrected,
and a gate walks the command tree for idle-terminate claims (#1132).
…-cost-limit

Pool workers now write the completion record on a clean drain (and a failed
one when they exhaust restarts), so on_complete=terminate fires. Worker.Run
drains at once when its queue is deleted and honours its idle deadline on the
claim-error path. Builds on #1200's TerminateOnIdle for spored's own idle
action. pool drain reports 'already drained' and exits 0 on a missing queue.
pool create gains a per-worker --cost-limit.

Fixes #1146
Fixes #1183
@scttfrdmn
scttfrdmn force-pushed the fix/1146-1183-pool-lifecycle branch from d4e2118 to c1726f2 Compare October 20, 2026 00:25
@scttfrdmn
scttfrdmn merged commit 0c92a15 into main Oct 20, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1146-1183-pool-lifecycle branch October 20, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant