Skip to content

feat(github): add PR comment cutover command + cutover fixes#97

Draft
aparajon wants to merge 1 commit into
mainfrom
worktree-ready-to-complete
Draft

feat(github): add PR comment cutover command + cutover fixes#97
aparajon wants to merge 1 commit into
mainfrom
worktree-ready-to-complete

Conversation

@aparajon
Copy link
Copy Markdown
Collaborator

@aparajon aparajon commented May 13, 2026

Summary

Add cutover via PR comment command, sentinel-based crash recovery, and cutover state fixes.

Cutover via PR comment — new `schemabot cutover -e ` command. Validates apply state, resolves tern client via stored deployment, triggers cutover, posts acknowledgment comment. Error handling for missing apply ID, missing environment, and environment-based instance routing.

Sentinel-based crash recovery — when a container restarts while a task is in `waiting_for_cutover`, check whether Spirit's `_spirit_sentinel` table exists in the target database. If it does, transition to a new `recovering` state that blocks cutover until Spirit re-reaches `WaitingOnSentinelTable` from its checkpoint. Replaces the previous blanket `CanEngineOverrideTaskState` guard with evidence-based recovery. Future: block/spirit#844 will add a `resume` field to replace the sentinel check.

ReadyToComplete centralized — set in `transitionTaskState` so both atomic and sequential modes mark tasks ready when entering `waiting_for_cutover`.

Engine state normalization — `NormalizeTaskStatus` converts camelCase Spirit states to canonical snake_case. Fixes CLI and PR comment rendering.

State downgrade prevention — Progress API only overwrites task state when the task is still pending or running, using sentinel-aware reconciliation.

Cutover UX — yellow progress bars and `⏸️ Ready for cutover` (green reserved for completions). Cutover footer includes apply ID and environment. Recovering state shows `🔄 Recovering...` with last known progress bar.

Templates — all cutover PR comments rendered via `pkg/webhook/templates/cutover.go`. AGENTS.md guideline: all PR comments must use templates.

Documentation — new `docs/cutover.md` covering the cutover lifecycle, sentinel table mechanism, Spirit's rename-under-lock algorithm, force-kill behavior, and recovery state. Updated `pkg/state/README.md` with recovering state.

Copilot AI review requested due to automatic review settings May 13, 2026 15:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes progress/cutover state reporting across the Progress API and PR comment rendering, ensuring engine-reported states (including Spirit camelCase) are normalized to canonical task states and that tasks in waiting_for_cutover are counted as ready for cutover.

Changes:

  • Prevent Progress polling from overwriting storage states beyond pending/running (avoids downgrades after restart when the engine reports pending/no active migration).
  • Add ready_to_complete to TableProgress (proto + server population) and set ReadyToComplete when tasks enter waiting_for_cutover (atomic path).
  • Normalize per-table engine progress states via state.NormalizeTaskStatus instead of strings.ToUpper.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/tern/local_client.go Adjusts Progress polling state update rules; normalizes engine per-table states; returns ReadyToComplete in TableProgress.
pkg/tern/local_client_integration_test.go Adds an integration test intended to validate Progress state normalization and ReadyToComplete behavior.
pkg/tern/local_apply.go Sets Task.ReadyToComplete when atomic progress transitions to waiting_for_cutover.
pkg/proto/ternv1/tern.pb.go Regenerated Go proto to include TableProgress.ready_to_complete.
pkg/proto/tern.proto Adds ready_to_complete field to TableProgress message.
Files not reviewed (1)
  • pkg/proto/ternv1/tern.pb.go: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/tern/local_apply.go
Comment thread pkg/tern/local_client_integration_test.go Outdated
Comment thread pkg/tern/local_client_integration_test.go
Comment thread pkg/tern/local_client.go Outdated
@aparajon aparajon force-pushed the worktree-ready-to-complete branch 6 times, most recently from aea885c to 402e787 Compare May 13, 2026 16:32
@aparajon aparajon changed the title fix(github): fix cutover state display and ReadyToComplete fix(github): cutover state fixes and PR comment cutover command May 13, 2026
@aparajon aparajon force-pushed the worktree-ready-to-complete branch from 402e787 to 6bfea64 Compare May 13, 2026 16:51
@aparajon aparajon changed the title fix(github): cutover state fixes and PR comment cutover command feat(github): add PR comment cutover command + cutover fixes May 13, 2026
@aparajon aparajon force-pushed the worktree-ready-to-complete branch 9 times, most recently from 87f05b7 to d5d6d2d Compare May 13, 2026 21:52
@aparajon aparajon marked this pull request as ready for review May 13, 2026 22:07
@aparajon aparajon requested review from Kiran01bm and morgo as code owners May 13, 2026 22:07
@aparajon aparajon force-pushed the worktree-ready-to-complete branch 2 times, most recently from 8b81deb to 80970f7 Compare May 14, 2026 17:32
@aparajon aparajon force-pushed the worktree-ready-to-complete branch 2 times, most recently from 46c9090 to 09ff60c Compare May 15, 2026 15:36
@aparajon aparajon marked this pull request as draft May 15, 2026 15:45
@aparajon aparajon force-pushed the worktree-ready-to-complete branch 3 times, most recently from 5137bf5 to d91122e Compare May 16, 2026 14:42
Add PR comment cutover command (schemabot cutover <apply-id> -e <env>),
sentinel-based crash recovery for deferred cutover, and cutover comment
lifecycle improvements.

Key changes:
- Cutover command handler with environment validation
- Recovering state with sentinel table check for crash recovery
- Cutover comment UX: progress freezes, cutover comment serves as summary
- Progress tombstone differentiates from summary comment
- Cutover and recovering state rendering in CLI and PR comments
- Integration tests for sentinel recovery and cutover flows

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aparajon aparajon force-pushed the worktree-ready-to-complete branch from d91122e to 49b12d1 Compare May 16, 2026 14:52
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