Skip to content

fix: re-sync PrefectAutomation every reconcile for continuous self-heal#298

Merged
mitchnielsen merged 2 commits into
PrefectHQ:mainfrom
Tip-cue:fix/automation-resync-parity
Jul 9, 2026
Merged

fix: re-sync PrefectAutomation every reconcile for continuous self-heal#298
mitchnielsen merged 2 commits into
PrefectHQ:mainfrom
Tip-cue:fix/automation-resync-parity

Conversation

@ShmuelOps

Copy link
Copy Markdown
Contributor

What

PrefectAutomation persisted Status.LastSyncTime, so needsSync short-circuited on a 10-minute drift timer and never re-checked Prefect in between reconciles. A manual edit or delete of the automation in the Prefect UI/API was not reconciled back until the drift window elapsed or the operator restarted.

PrefectDeployment reconciles against Prefect on every pass (its status carries no LastSyncTime), so it self-heals out-of-band changes continuously. This aligns PrefectAutomation with that behavior: needsSync now returns true each reconcile. syncWithPrefect is idempotent (update-in-place), so re-running it every pass is safe.

Why it was observable

With the drift gate, a deleted automation showed only the Reconciling debug line every ~10s and never came back until a restart — even though the CR was Ready. After this change the controller re-checks each loop and re-applies desired state.

Relationship to #297

Complementary. #297 makes the delete case recreate (surfaces a 404 on update as a sentinel → recreate). This PR fixes the cadence so that recreate (and any drift/edit correction) happens within one requeue interval instead of only on the 10-minute drift. Together they give prompt, continuous self-heal. This PR is orthogonal to #297 (it does not touch syncWithPrefect/UpdateAutomation) and can merge independently.

Test

Adds TestAutomationNeedsSync — a unit test asserting needsSync returns true in steady state (id set, spec hash unchanged, generation observed, just synced), which was false before.

Related to #294, #297.

UpdateAutomationStatus stamped Status.LastSyncTime, so needsSync short-circuited
on a 10-minute drift timer and didn't re-check Prefect in between. A manual edit
or delete of the automation in Prefect wasn't reconciled until the drift window
elapsed or the operator restarted.

PrefectDeployment never persists LastSyncTime, so needsSync's nil check makes it
reconcile against Prefect every pass and self-heal continuously. Match that:
stop stamping LastSyncTime on PrefectAutomation (needsSync is otherwise
unchanged). syncWithPrefect is idempotent, so re-running it each pass is safe.

Tests: UpdateAutomationStatus leaves LastSyncTime nil; needsSync returns true in
steady state.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ShmuelOps ShmuelOps force-pushed the fix/automation-resync-parity branch from b305be7 to f9a2dbf Compare July 9, 2026 10:12
@ShmuelOps ShmuelOps marked this pull request as ready for review July 9, 2026 10:14

@mitchnielsen mitchnielsen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@mitchnielsen mitchnielsen merged commit 7550959 into PrefectHQ:main Jul 9, 2026
3 checks passed
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.

2 participants