Skip to content

fix(spored): act on a short task's completion before the on-complete tag was visible (#270) - #1195

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/270-short-task-completion
Oct 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/270-short-task-completion

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

spored learns on-complete from EC2 tags. Tags are eventually consistent, and spored re-read them only on tick 1 and then every 5th tick. A short task that wrote /tmp/SPAWN_COMPLETE before spawn:on-complete was readable was ignored until the next scheduled refresh. If the tick-1 refresh had already happened, the instance ran on toward its TTL.

This implements fix direction 1 in signal-driven form, rather than refreshing every tick on every instance:

  • In checkAndAct, on a tick with no scheduled refresh, refreshForEarlyCompletion checks for the completion file when no on-complete action is known. It looks at the configured path or, when the completion-file tag is invisible too, provider.DefaultCompletionFile (new constant, now also used by provider/ec2.go). If the file exists, it re-reads the tags right away, so step 1 acts on the same tick.
  • At most 5 such out-of-cadence refreshes per agent (maxEarlyCompletionRefreshes). A workload that writes the file with no on-complete configured falls back to the normal cadence instead of costing one DescribeTags call a minute forever.
  • The refresh body is factored into refreshConfigFromTags, which behaves the same as before.

Known limit: a custom --completion-file whose tag is also not yet visible is still only picked up at the next scheduled refresh. spored cannot know that path without the tag.

Gates (counted ticks and refreshes, no wall clock; each watched failing against a revert that compiles)

  • TestCompletionBeforeOnCompleteTagIsVisibleStillActsNextTick: the fake provider hides on-complete from refresh Feature request: --tag / --tags flag for custom EC2 instance tags #1 and shows it from feat: Discord chat integration (alongside Slack and Teams) #2 on. Tick 1 does nothing; the file is written; tick 2 (not a scheduled refresh tick) must terminate, with exactly 2 refreshes. Revert (call replaced with _ = refreshed): FAIL. Revert (default-path fallback disabled): FAIL.
  • TestEarlyCompletionRefreshesAreCapped: 20 ticks with the file present and the tag never visible must give exactly 5 scheduled + 5 early = 10 refreshes. Revert (cap removed): FAIL, with 20.
  • TestNoCompletionSignalKeepsTheRefreshCadence: no file means no extra refreshes.

Checks

  • make check: everything passes except check-build-tags, which fails identically on unmodified main on this machine (/private/tmp paths).
  • semgrep --config=auto --error: clean. make check-docs: clean.

pkg/provider is not in the api-snapshot set. Not validated on a real instance.

Fixes #270

@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 88.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/agent.go 87.50% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…complete is known (#270)

A short task could write its completion file before spawn:on-complete was
visible (EC2 tag eventual consistency); spored only re-read tags on tick 1
and every 5th tick, so on_complete waited up to 5 minutes or fell back to the
TTL. A completion signal with no known on-complete now triggers a tag
refresh on that tick (default path checked when completion-file is also
invisible), capped at 5 such refreshes.

Fixes #270
@scttfrdmn
scttfrdmn force-pushed the fix/270-short-task-completion branch from ed581c6 to 8cf367e Compare October 19, 2026 21:53
@scttfrdmn
scttfrdmn merged commit d1e63a7 into main Oct 19, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/270-short-task-completion branch October 19, 2026 22:12
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.

spored: short task can signal completion before on-complete tag is visible → no prompt self-terminate (TTL backstop)

1 participant