fix(crane): require up-to-date PR checks before completion#118
Merged
Conversation
This was referenced Jun 11, 2026
8 tasks
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.
fix(crane): require up-to-date PR checks before completion
TL;DR
This tightens Crane’s completion gate so green checks count only after the PR head contains the current base branch SHA. The scheduler now verifies
base_sha...head_shathrough GitHub’s compare API before it evaluates check-runs, and the Crane workflow prompt now teaches the same gate. That closes the stale-check path that let a migration be marked complete after stricter gates landed onmain.Important
This PR is about the completion mechanism, not claiming the Go migration itself is complete.
Problem (WHY)
get_pr_head_check_gate()treated “all checks on the PR head are success” as sufficient without proving that the PR head contained the current base SHA..github/workflows/crane.mdused the weakerpr-head-checkswording, so the agent prompt and the scheduler shared the same stale-base blind spot.Why these matter: deterministic completion has to be evidence about the code that would actually be merged. A successful check set on an old PR head is not deletion-grade proof after
mainchanges underneath it.Approach (WHAT)
stale-base:<head>:<status>:base:<base>failure when GitHub reportsbehind,diverged, unknown, or any non-current comparison status.pr-head-checkstoup-to-date-pr-head-checks..github/workflows/crane.lock.ymlwith the samev0.74.4gh-aw compiler used by CI’s lock check.Implementation (HOW)
.github/workflows/scripts/crane_scheduler.py—get_pr_head_check_gate()now reads both PRhead.shaandbase.sha, calls/compare/{base_sha}...{head_sha}, and refuses to pass unless the comparison isaheadoridentical..github/workflows/crane.md— the halting condition now says completion requires an up-to-date PR head, explicitly calls out the compare API, and forbids completion from checks produced before the current base SHA was included.tests/unit/test_crane_scheduler.py— existing check-gate tests now provide a base SHA and compare response; a new regression test proves adivergedPR fails withstale-base.tests/unit/test_crane_workflow_prompt.py— prompt assertions now requireup-to-date-pr-head-checksand the “current base branch SHA” language..github/workflows/crane.lock.yml/.github/aw/actions-lock.json— regenerated with gh-awv0.74.4after editing the workflow source.Diagrams
Legend: the highlighted region is the new freshness check Crane must pass before check-runs can certify completion.
sequenceDiagram participant C as Crane scheduler participant P as GitHub PR API participant X as GitHub compare API participant R as Check-runs API C->>P: fetch PR head and base rect rgb(255, 247, 200) C->>X: compare base_sha...head_sha X-->>C: ahead or identical Note over C,X: NEW: stale, behind, diverged, or unavailable fails gate end C->>R: fetch check-runs for head_sha R-->>C: check conclusions C-->>C: complete only when all checks are successTrade-offs
None/failure behavior; rejected optimistic completion because this path controls issue labels and migration finality.v0.74.4because.github/workflows/gh-aw-lock-check.ymlpins that version; rejected newer local output because CI would mark it stale.Benefits
crane-completedjust because old head checks passed.Validation
/tmp/gh-aw-v0.74.4/darwin-arm64 --version && /tmp/gh-aw-v0.74.4/darwin-arm64 compile --no-check-update:uv run pytest tests/unit/test_crane_scheduler.py tests/unit/test_crane_workflow_prompt.py -q:uv run --extra dev ruff check src/ tests/ && uv run --extra dev ruff format --check src/ tests/ && uv run --extra dev python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ && bash scripts/lint-auth-signals.sh:uv run python -m py_compile .github/workflows/scripts/crane_scheduler.py:git diff --check:npx --yes -p @mermaid-js/mermaid-cli mmdc -i /tmp/apm-mermaid-check/diag1.mmd -o /tmp/apm-mermaid-check/diag1.svg --quiet:Scenario Evidence
tests/unit/test_crane_scheduler.py::test_pr_head_gate_fails_when_pr_head_does_not_contain_current_basetests/unit/test_crane_scheduler.py::test_pr_head_gate_passes_only_when_all_checks_succeedtests/unit/test_crane_workflow_prompt.py::test_crane_completion_is_two_phase_and_pr_head_gatedHow to test
uv run pytest tests/unit/test_crane_scheduler.py tests/unit/test_crane_workflow_prompt.py -qand observe18 passed.v0.74.4compiler withcompile --no-check-updateand observe.github/workflows/crane.mdcompiles with zero errors..apm/instructions/linting.instructions.mdand observe ruff, format, duplication, and auth-signal checks pass.test_pr_head_gate_fails_when_pr_head_does_not_contain_current_baseand confirm adivergedcompare response returnsstale-base.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com