You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/workflows/crane.md
+37-13Lines changed: 37 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -180,7 +180,7 @@ The pre-step fetches open issues with the `crane-migration` label via the GitHub
180
180
When a migration is issue-based, `/tmp/gh-aw/crane.json` includes:
181
181
-**`selected_issue`**: The issue number (e.g., `42`) if the selected migration came from an issue, or `null` if it came from a file.
182
182
-**`issue_migrations`**: A mapping of migration name -> issue number for all issue-based migrations found.
183
-
-**`stale_completed_state`**: Issue-based migrations whose issue still has`crane-migration` even though repo-memory says `Completed: true`.
183
+
-**`stale_completed_state`**: Issue-based migrations whose completion state is not trustworthy. This includes active issues that still have`crane-migration` even though repo-memory says `Completed: true`, and completed-label issues whose current PR-head completion gate did not pass.
184
184
185
185
### Reading Migrations
186
186
@@ -194,7 +194,7 @@ The pre-step has already determined which migration to run. Read `/tmp/gh-aw/cra
194
194
-**`selected_strategy`**: The `strategy` value from the migration's frontmatter -- one of `"in-place"`, `"greenfield"`, or `"auto"`. If `"auto"`, the agent must pick on the first iteration and write the chosen strategy back into the state file's Machine State table.
195
195
-**`state_file_size_bytes`** / **`state_file_max_bytes`**: For rolling-compaction decisions (see [Update Rules](#update-rules)).
196
196
-**`issue_migrations`**: A mapping of migration name -> issue number for all discovered issue-based migrations.
197
-
-**`stale_completed_state`**: A list of active issue-based migrations where repo-memory still says `Completed: true`; treat this as stale memory, not as permission to finish.
197
+
-**`stale_completed_state`**: A list of issue-based migrations where repo-memory still says `Completed: true`, but the issue label state or PR-head completion gate says the migration is not safely complete; treat this as stale memory, not as permission to finish.
198
198
-**`deferred`**: Other migrations that were due but will be handled in future runs.
199
199
-**`unconfigured`**: Migrations that still have the sentinel or placeholder content.
200
200
-**`skipped`**: Migrations not due yet based on their per-migration schedule, or completed/paused.
@@ -209,7 +209,8 @@ If `selected` is not null:
209
209
3. Read the current state of all source and target paths.
210
210
4. Read the state file `{selected}.md` from the repo-memory folder. This contains the Machine State table, the Migration Plan, lessons, blockers, and iteration history.
211
211
5. If `selected_issue` is not null, also read the issue comments for any human steering input.
212
-
6. If `selected` appears in `stale_completed_state`, ignore any pre-existing `Completed: true`, `Completed Reason`, or target-satisfying `best_metric` as a completion signal. First run the current verification contract and only re-complete after a fresh accepted iteration satisfies the current halting condition.
212
+
6. If `selected` appears in `stale_completed_state`, ignore any pre-existing `Completed: true`, `Completed Reason`, target-satisfying `best_metric`, or `crane-completed` label as a completion signal. Restore the issue to active migration state by ensuring `crane-migration` is present and `crane-completed` is absent unless the deterministic completion gate passes later in this run. First run the current verification contract and only enter the completion-candidate path after a fresh accepted iteration satisfies the target metric.
213
+
7. Before making code changes, inspect the state file's `Completion Candidate` field. If it is `true`, run the deterministic completion gate in [Halting Condition](#halting-condition). Only finalize completion if the current PR head checks pass. If the gate is failing, fix the failing PR checks instead of starting unrelated migration work. If the gate is pending or unavailable, leave the issue active and update `Completion Gate Status`.
213
214
214
215
## Multiple Migrations
215
216
@@ -549,7 +550,7 @@ If `status == "failure"`, **fix and retry -- do not revert, do not accept**:
549
550
- Update **[docs] Lessons Learned** if this iteration revealed something new (e.g. a bridging trick, a parity surprise, a perf trap).
550
551
- Update **[scope] Future Work** if this iteration opened new threads.
551
552
5.**Update the migration issue**: edit the status comment and post a per-iteration comment using the same shared accepted iteration summary.
552
-
6.**Check halting condition** (see [Halting Condition](#halting-condition)): if `target-metric` is set, compare the new `best_metric` from this accepted iteration against it. For `higher` direction: completed when `best_metric >= target-metric`. Never mark completed from stored `best_metric` alone or a pre-existing `Completed: true`; completion requires the current accepted iteration's fresh verification result. When the target is met, mark the migration as completed.
553
+
6.**Check halting condition** (see [Halting Condition](#halting-condition)): if `target-metric` is set, compare the new `best_metric` from this accepted iteration against it. For `higher` direction, the target is reached when `best_metric >= target-metric`. Reaching the target metric does **not** complete the migration in this run. It creates a completion candidate: set `Completion Candidate: true`, set `Completion Gate: pr-head-checks`, set `Completion Gate Status: pending`, keep `Completed: false`, keep `Completed Reason: --`, and leave the `crane-migration` label on the issue. Completion is finalized only by a later run after the pushed PR head's deterministic checks are observed green.
553
554
554
555
**If the score did not improve**:
555
556
1. Discard the code changes (do not commit them to the long-running branch).
@@ -652,29 +653,46 @@ After **every iteration** (accepted, rejected, or error), post a **new comment**
652
653
- For issue-based migrations, the source issue body IS the migration definition -- do not modify it (the user owns it).
653
654
- For file-based migrations, the migration issue body is informational and may be lightly updated, but the migration file (`migration.md`) remains the source of truth.
654
655
- The `crane-migration` label must remain on the issue for the migration to be discovered. When a migration completes, the label is removed and replaced with `crane-completed`.
655
-
- If an issue has `crane-migration` but repo-memory says `Completed: true`, the active label wins. Treat the completed state as stale until the current verification contract passes in a fresh accepted iteration.
656
+
- If an issue has `crane-migration` but repo-memory says `Completed: true`, the active label wins. Treat the completed state as stale until the current verification contract passes in a fresh accepted iteration and the deterministic completion gate passes on the pushed PR head.
657
+
- If an issue has `crane-completed` but the scheduler selected it in `stale_completed_state`, the completed label is stale. Restore `crane-migration`, remove `crane-completed`, and work the migration until the deterministic completion gate passes.
656
658
- Closing the migration issue stops the migration from being discovered. Do NOT close the migration issue when the PR is merged -- the branch continues to accumulate future iterations until the target metric is reached.
657
659
- Migration issues are labeled `[crane-migration, automation, crane]`.
658
660
659
661
## Halting Condition
660
662
661
-
Migrations are usually **goal-oriented** -- you want to finish. Set `target-metric: 1.0` in the frontmatter and Crane stops the migration when the health score reaches 1.0 (which, with the recommended `correctness x progress` convention, means "fully migrated and verified").
663
+
Migrations are usually **goal-oriented** -- you want to finish. Set `target-metric: 1.0` in the frontmatter to nominate a migration for completion once the health score reaches 1.0 (which, with the recommended `correctness x progress` convention, means "fully migrated and verified"). The metric is necessary but not sufficient: final completion always requires a deterministic PR-head completion gate.
662
664
663
665
### How It Works
664
666
665
667
1. Parse the `target-metric` value from the migration's YAML frontmatter (if present).
666
668
2. After each **accepted** iteration, compare the new `best_metric` from that iteration against the `target-metric`.
667
-
3. For `higher` direction (default): completed when `best_metric >= target-metric`.
668
-
4. For `lower` direction: completed when `best_metric <= target-metric`.
669
-
5. When completed:
669
+
3. For `higher` direction (default): the target is reached when `best_metric >= target-metric`.
670
+
4. For `lower` direction: the target is reached when `best_metric <= target-metric`.
671
+
5. When the target is reached, create a completion candidate instead of completing immediately:
672
+
- Set `Completion Candidate: true`.
673
+
- Set `Completion Gate: pr-head-checks`.
674
+
- Set `Completion Gate Status: pending`.
675
+
- Keep `Completed: false` and `Completed Reason: --`.
676
+
- For issue-based migrations, keep the `crane-migration` label and do not add `crane-completed`.
677
+
- Update the status comment to Active with a note that the migration is waiting on deterministic PR-head checks.
678
+
6. On the next run while `Completion Candidate: true`, run the deterministic completion gate before making code changes:
679
+
- Resolve the migration PR from `existing_pr` or the state file's `PR` field.
680
+
- Query the PR's current head SHA via the GitHub API.
681
+
- Query check-runs/check-suites for that exact PR head SHA, or use `gh pr checks "$PR" --json name,conclusion,state,startedAt,completedAt`.
682
+
- The gate passes only if every check for the current PR head is terminal success. Treat missing checks, pending checks, queued checks, failing checks, cancelled checks, timed-out checks, stale checks, and action-required checks as not passing.
683
+
- If the gate is pending or missing, leave `Completion Candidate: true`, keep `Completed: false`, ensure `crane-migration` is present, ensure `crane-completed` is absent, set `Completion Gate Status: pending:<sha or reason>`, and end without completing.
684
+
- If the gate fails, leave `Completion Candidate: true`, keep `Completed: false`, ensure `crane-migration` is present, ensure `crane-completed` is absent, set `Completion Gate Status: failing:<signature>`, and fix the failing PR checks.
685
+
7. Only when the deterministic completion gate passes:
670
686
- Set `Completed: true` in the Machine State table.
671
-
- Set `Completed Reason` to a human-readable message (e.g., `target metric 1.0 reached with value 1.0`).
687
+
- Set `Completed Reason` to a human-readable message that includes both the target metric and PR-head check evidence (e.g., `target metric 1.0 reached; PR #123 head abc1234 checks passed`).
688
+
- Set `Completion Candidate: false`.
689
+
- Set `Completion Gate Status: passed:<sha>`.
672
690
-**For issue-based migrations**: remove the `crane-migration` label, add the `crane-completed` label.
673
691
- Update the status comment to [+] Completed.
674
692
- Post a celebratory per-iteration comment: `[+] **Migration complete!** {source} -> {target} finished after {N} iterations.`
675
693
- The migration will not be selected for future runs.
676
694
677
-
Do not enter this path from repo-memory alone. A stored `Completed: true`, old `Completed Reason`, or historical `best_metric`is only evidence about a previous run; the current run must produce and accept a verification score that satisfies the current migration definition.
695
+
Do not enter final completion from repo-memory alone. A stored `Completed: true`, old `Completed Reason`, historical `best_metric`, or same-run sandbox score is only evidence about a previous or local run. Final completion requires deterministic evidence from the current PR head after safe outputs have pushed the branch and GitHub Actions has reported the head checks.
678
696
679
697
### Open-Ended Migrations
680
698
@@ -724,6 +742,9 @@ When creating or updating a migration's state file, use this structure:
724
742
| Pause Reason | -- |
725
743
| Completed | false |
726
744
| Completed Reason | -- |
745
+
| Completion Candidate | false |
746
+
| Completion Gate | pr-head-checks |
747
+
| Completion Gate Status | -- |
727
748
| Consecutive Errors | 0 |
728
749
| Recent Statuses | -- |
729
750
@@ -820,8 +841,11 @@ All iterations in reverse chronological order (newest first).
820
841
| Issue |`#number` or `--`| Single migration issue |
821
842
| Paused |`true` or `false`| Whether the migration is paused |
822
843
| Pause Reason | text or `--`|`manual`, `consecutive errors`, `ci-fix-exhausted: <sig>`, `stuck in CI fix loop: <sig>`, `ci-timeout`|
823
-
| Completed |`true` or `false`| Whether the target metric has been reached |
824
-
| Completed Reason | text or `--`| e.g., `target metric 1.0 reached with value 1.0`|
844
+
| Completed |`true` or `false`| Whether the deterministic completion gate has passed and the migration is final |
845
+
| Completed Reason | text or `--`| e.g., `target metric 1.0 reached; PR #123 head abc1234 checks passed`|
846
+
| Completion Candidate |`true` or `false`| Whether the target metric has been reached and the migration is waiting for deterministic PR-head checks |
847
+
| Completion Gate | text | Deterministic gate required for final completion. Default: `pr-head-checks`|
848
+
| Completion Gate Status | text or `--`| Latest gate result, such as `pending:<sha>`, `failing:<signature>`, or `passed:<sha>`|
0 commit comments