Repository navigation
Description
Context
Found while diagnosing a real calque incident (spore-host/calque#141/#142/#143): calque's internal/exec/orchestrate.go's WaitForSummary polls S3 for a summary.json warmd writes on completion, with a caller-supplied fixed timeout — if the file doesn't appear in that window, calque declares the run a failure, even when the instance may still be legitimately working (this happened live: a real vLLM run was still executing at 40 minutes with no way to distinguish "almost done" from "stuck," other than the caller's own guess at what a reasonable deadline should be).
Scott's question, which this issue tracks: why isn't calque using spawn's/spored's OWN completion-detection capability instead of reinventing a poll-with-deadline loop? Investigated spawn's actual code to answer this precisely.
What spawn already has
pkg/agent/agent.go's Agent.checkCompletion (agent.go:1345-1387) is a real, working on-instance sentinel mechanism: it watches for config.CompletionFile (a local file path) to appear, then acts per config.OnComplete (terminate/stop/hibernate/exit), after a grace period, and fires a.notifier.Notify(ctx, "completion", "") (agent.go:1362) before doing so.
pkg/agent/notifier.go's Notifier.Notify (notifier.go:93) is the ONLY completion-event hook — and it's hardcoded to a Slack webhook endpoint (spore-bot), not a caller-registerable callback. There's no way for an external caller (calque, or any other consumer) to register their own webhook/SQS/EventBridge target and be notified when a launched instance's completion sentinel fires.
spawn task run --wait's own pollCompletion (cmd/task.go:489-508) — the one caller-facing "wait for completion" primitive spawn itself exposes — has the EXACT SAME shape as calque's WaitForSummary: poll S3 (tasks/<taskID>/completion.json) on a fixed interval, and if time.Now().After(deadline) (task.go:500), give up. The one meaningful difference: spawn's timeout message says "poll later with spawn task status" (task.go:501) rather than declaring outright failure — a materially better UX than calque's hard-fail, but the underlying design gap (a caller must pre-guess a wall-clock number with no way to distinguish "still working" from "stuck") is identical.
The actual gap
Two things are missing, and both matter for calque's (and presumably other consumers') fleet/batch use cases where per-job runtime is genuinely unpredictable ahead of time:
- No caller-registerable completion callback.
Notifier.Notify's Slack-only design (notifier.go) can't be pointed at anything else. A caller wanting to "block until this instance's work is done" has no choice but to implement their own polling loop against whatever artifact the workload itself writes (S3, in calque's case) — spawn's own sentinel mechanism never surfaces to them at all. - No liveness/progress signal a polling caller can check to distinguish "legitimately still running" from "stuck." Nothing (an EC2 tag updated periodically, a CloudWatch metric, anything) tells a caller "the instance is alive and making progress" independent of the final completion artifact. Without this, any caller's polling loop is forced to pick ONE number and treat exceeding it as failure — exactly the ambiguity that caused calque's real incident.
Ask
Two independent, incrementally useful asks — either alone would help calque's case:
- Generalize
Notifier/checkCompletion's completion event so a caller can register their own target (webhook URL, SQS queue ARN, etc.) at launch time, not just the hardcoded Slack notify. This would let calque subscribe to spawn's OWN completion signal instead of maintaining a parallel S3-polling mechanism that's completely unaware of spawn's sentinel machinery. - A periodic liveness/progress signal (e.g. an EC2 tag, mirroring how
spawn:compute-secondsor similar tags already track cost-relevant state) that a polling caller can check to tell "still alive and working" from "hung" — letting a caller poll indefinitely (or with a much longer backstop) instead of pre-committing to one wall-clock number.
Also worth noting (not part of this ask, context only)
calque's own bootstrap script (internal/exec/bootstrap.go, spore-host/calque) doesn't even write spawn's CompletionFile sentinel today — it invented its own separate S3-summary-polling mechanism from scratch, unaware of OnComplete's existence. That's a calque-side gap worth fixing once (1) above exists, tracked separately in the calque repo, not blocking this issue.
Why filing here, not on calque
Confirmed via code reading that this capability gap is structural to spawn/spored, not something calque's own retry/polling logic could paper over correctly — task run --wait's own implementation hits the identical flaw, meaning any spawn consumer with unpredictable per-job runtime (not just calque) would benefit from a real fix here.
Activity
feat(agent): completion webhook + always-on heartbeat tag (#497) (#498)
scttfrdmn commentedon Aug 11, 2026
Confirmed fixed in v0.100.0 — verified both pieces directly in source:
pkg/agent/agent.go'semitCompletionWebhookPOSTs tocfg.CompletionWebhookURLbefore the grace-period sleep/lifecycle action, exactly as the changelog describes.pkg/agent/agent.go's throttled (1/min)writeHeartbeatTagstampsspawn:last-heartbeaton every monitor tick, unconditionally.calque has adopted the heartbeat tag (spore-host/calque#141-adjacent fix, commit
7e9775e):internal/exec.WaitForSummaryLivenessnow checksspawn:last-heartbeatalongside its existing S3 artifact poll, failing fast withErrInstanceStaleif the tag goes stale, instead of dead-waiting a guessed deadline. Wired into every real-AWS single-instance path (calque real, fleet shards, spawn-fanout shards,calque smoke).Didn't wire up
--completion-webhook-urlyet — calque's CLI runs locally with no reachable public endpoint for spored to POST to, so there's nothing useful to point it at today. Revisiting if/when calque runs as a hosted service or gets a real receiver endpoint. Bumped calque's spawn dependency to v0.100.0 in the same session (commit111bb63).Thanks for the quick turnaround on this.
feat(reaper): report when spored has stopped checking in (#682)
feat(reaper): report when spored has stopped checking in (#682) (#729)