fix(rollback): plan rollback from selected apply - #119
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates rollback planning to be based on the requested apply’s captured pre-apply schema, routes rollback planning through the normal Plan flow so local and gRPC clients share behavior, and extends Tern plan responses to include the captured “original schema” for later rollback planning and remote plan storage.
Changes:
- Add
original_schematoSchemaChangein the Tern proto and propagate it through LocalClientPlanresponses and SchemaBot plan storage. - Replace the prior client-level
RollbackPlanflow with service-level rollback planning (ExecuteRollbackPlanForApply) that calls the standardPlanpath and stores the resulting plan. - Update webhook/API rollback handlers and tests to use apply-scoped rollback planning.
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/webhook/rollback.go | Rollback plan generation now uses the requested apply; rollback-confirm re-plans via the service. |
| pkg/tern/local_control.go | Removes LocalClient RollbackPlan implementation (no longer needed). |
| pkg/tern/local_client.go | Attaches stored OriginalSchema to plan response schema changes. |
| pkg/tern/local_client_integration_test.go | Asserts OriginalSchema is present in Plan responses. |
| pkg/tern/grpc_client.go | Removes unsupported RollbackPlan method. |
| pkg/tern/client.go | Removes RollbackPlan from the tern.Client interface. |
| pkg/proto/tern.proto | Adds original_schema field to SchemaChange. |
| pkg/proto/ternv1/tern.pb.go | Regenerated protobuf bindings for original_schema. |
| pkg/proto/ternv1/tern_grpc.pb.go | Regenerated gRPC bindings (version bump). |
| pkg/api/rollback_plan_integration_test.go | Integration test ensuring rollback uses the requested apply’s original schema and stores rollback plan original schema. |
| pkg/api/proto_helpers.go | Persists SchemaChange.OriginalSchema into stored plan namespaces. |
| pkg/api/plan_handlers.go | Introduces ExecuteRollbackPlanForApply, factors out storePlanResponse, adds latest-completed-apply lookup. |
| pkg/api/handlers_test.go | Enhances mock Tern client to capture/return Plan requests/responses. |
| pkg/api/control_handlers.go | Rollback plan endpoint now plans from the requested apply (apply-scoped). |
Files not reviewed (2)
- pkg/proto/ternv1/tern.pb.go: Language not supported
- pkg/proto/ternv1/tern_grpc.pb.go: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aparajon
force-pushed
the
armand/rollback-fixes
branch
from
May 18, 2026 19:39
152eb57 to
8c18ebb
Compare
aparajon
force-pushed
the
armand/rollback-fixes
branch
from
May 18, 2026 19:55
8c18ebb to
ddca597
Compare
This comment was marked as resolved.
This comment was marked as resolved.
aparajon
force-pushed
the
armand/rollback-fixes
branch
from
May 21, 2026 21:09
ddca597 to
04bb632
Compare
aparajon
marked this pull request as ready for review
May 21, 2026 21:16
aparajon
force-pushed
the
armand/rollback-fixes
branch
3 times, most recently
from
May 26, 2026 20:30
3310e73 to
19b123d
Compare
aparajon
force-pushed
the
armand/rollback-fixes
branch
8 times, most recently
from
June 7, 2026 16:08
d2be34c to
f249984
Compare
aparajon
marked this pull request as draft
June 7, 2026 16:24
aparajon
force-pushed
the
armand/rollback-fixes
branch
from
June 8, 2026 15:12
f249984 to
47ce802
Compare
aparajon
force-pushed
the
armand/rollback-fixes
branch
4 times, most recently
from
June 16, 2026 14:50
88a0f9a to
a38f423
Compare
Rollback now plans from the exact completed apply being rolled back instead of whichever completed apply happens to be latest for the PR/database. It stores whether original schema capture succeeded separately from the schema map so create-table rollbacks can target an empty original schema, while older plans without capture still fail closed. The confirmation path also keeps rollback locks distinct from normal apply locks, routes observers through the stored rollback deployment, makes rollback-confirm database-explicit, and rejects unsupported planning-time defer-cutover flags. Vitess VSchema rollback remains fail-closed until original VSchema capture is supported. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019eb380-ca81-749e-94a2-cb4982ed90dd
aparajon
force-pushed
the
armand/rollback-fixes
branch
from
June 16, 2026 18:14
a38f423 to
cda34f9
Compare
aparajon
marked this pull request as ready for review
June 16, 2026 19:07
morgo
approved these changes
Jun 16, 2026
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.
Summary
Rollback is now planned from the apply the operator selected, after validating that it is the current completed schema change for the PR/database/type/environment.
schemabot rollback <apply-id>rebuilds declarative schema files from that source plan's capturedoriginal_files, and stores a new rollback plan for review.The PR comment flow now pins that reviewed rollback plan to the database lock, and
rollback-confirmconsumes the lock-pinned plan instead of re-planning. That keeps rollback deterministic when newer plans exist or concurrent comment deliveries occur, while still rejecting stale apply IDs instead of rolling back an older schema change.The rollback path is now engine-agnostic over captured files: MySQL table files and Vitess artifacts such as
vschema.jsonare both carried throughoriginal_files. Unsafe cases still fail closed: older applies without captured original files are rejected, rollback plans cannot be consumed byapply-confirm, and confirmation validates the pinned plan still matches the target database, type, and environment.Generated with Amp