fix(tern): cancel never overwrites a terminal apply; task-state writes propagate errors#650
Draft
aparajon wants to merge 2 commits into
Draft
fix(tern): cancel never overwrites a terminal apply; task-state writes propagate errors#650aparajon wants to merge 2 commits into
aparajon wants to merge 2 commits into
Conversation
…s propagate errors Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens SchemaBot’s local tern drive state persistence so stored apply/task rows remain authoritative under races and storage write failures, preventing late control actions (cancel) or in-memory-only transitions from producing an incorrect merge gate/operator view.
Changes:
- Prevent
Cancelfrom overwriting a terminal apply outcome by guardingmarkApplyCancelledwithcancelPreservesApplyOutcome. - Propagate task-state persistence errors (instead of logging-and-continuing) across stop/cancel, sequential drive, grouped drive progress sync, and resume preparation paths.
- Add/extend tests to cover cancel-after-terminal-outcome behavior and fail-closed behavior when task writes fail.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/tern/local_control.go | Stop/cancel now fail closed if task terminal-state persistence fails; adds cancelPreservesApplyOutcome and guards cancel state overwrites. |
| pkg/tern/local_control_test.go | Adds coverage for cancel preserving final apply outcomes and for stop/cancel/drive behavior when task writes fail. |
| pkg/tern/local_control_resume.go | Makes resume preparation and certain resume transitions fail/abort on task write errors instead of proceeding with diverged in-memory state. |
| pkg/tern/local_client_test.go | Updates tests to handle new error-returning resume helpers. |
| pkg/tern/local_client_integration_test.go | Updates integration test to handle new error-returning resume helper. |
| pkg/tern/local_apply.go | transitionTaskState now returns errors; stale-task conflict resolution stops “unblocking” if it can’t persist the resolution. |
| pkg/tern/local_apply_sequential.go | Sequential drive now aborts on failed task terminal-state writes (and returns actions from task failure helpers). |
| pkg/tern/local_apply_grouped.go | Grouped drive now exits on failed progress sync writes; markTasksRunning now returns an error and is handled. |
| pkg/tern/local_apply_failure.go | Best-effort finalizers now log definitive messages when task write persistence fails. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ruthful on write failure A grouped apply whose engine already accepted the work no longer records a failed outcome when the running task-state write fails; the current owner exits so recovery re-drives the in-flight engine work from stored state, matching the sequential drive's taskAbort policy. transitionTaskState now restores the in-memory State/UpdatedAt it mutated when the storage write is refused, so callers that log or branch on task state after a failed write see the stored state. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this matters
A cancel racing an apply's completion could rewrite a fully-applied schema change as cancelled — restamping
completed_atand telling the merge gate and operators that a deployed change never ran. Separately, task-state writes that failed were logged and swallowed, letting the drive proceed with in-memory state diverging from the stored rows that crash recovery re-drives from.What it does
markApplyCancelledrefuses to overwrite an apply that already recorded a final outcome (completed, failed, reverted). The policy is a named predicate,cancelPreservesApplyOutcome.transitionTaskStateandmarkTasksRunningnow return write errors instead of logging and continuing; every caller handles the failure explicitly.taskAbort/ propagated error) instead of finalizing from task rows storage never accepted.failApplyWithTasks, pending-task cancellation) and per-tick progress writes log a definitive message and continue — each iteration is independent or rewritten by the next poll.Before / after
🤖 Generated with Claude Code