Skip to content

fix(crane): ignore stale completion for active migrations#101

Merged
mrjf merged 2 commits into
mainfrom
codex/fix-crane-stale-completion
Jun 2, 2026
Merged

fix(crane): ignore stale completion for active migrations#101
mrjf merged 2 commits into
mainfrom
codex/fix-crane-stale-completion

Conversation

@mrjf
Copy link
Copy Markdown
Contributor

@mrjf mrjf commented Jun 2, 2026

fix(crane): ignore stale completion for active migrations

TL;DR

This fixes Crane re-treating an active migration as completed just because repo-memory still says Completed: true. If an issue still has crane-migration, the scheduler now selects it and marks the stale state explicitly; the agent prompt then requires fresh verification before completion can be claimed again.

Problem (WHY)

  • Issue Crane Migration: Python to Go -- Full APM CLI Rewrite #78 was re-finalized from stale repo-memory after the parity framework changed the completion contract.
  • The scheduler treated Completed: true as authoritative before checking that the issue was still an active crane-migration.
  • The agent prompt also needed to say that stored best_metric / Completed: true cannot finish a migration without a current accepted verification result.

Approach (WHAT)

Area Change
Scheduler Add is_completed_state() and make completion skip issue-aware.
Runtime JSON Add stale_completed_state so the agent can see active issues with stale completed memory.
Prompt Require fresh verification before re-completing a reactivated migration.
Tests Cover scheduler skip behavior and prompt guardrails.
Changelog Record the workflow fix under Unreleased.

Implementation (HOW)

.github/workflows/scripts/crane_scheduler.py still skips completed migrations by default, but passes issue_active=True for issue-based migrations discovered through the crane-migration label. Those migrations are added to stale_completed_state instead of being skipped.

.github/workflows/crane.md documents that stale_completed_state means the active issue label wins over stale repo-memory. The prompt now tells agents to clear stale completion markers before the halting check and to only complete from the current accepted iteration's score.

tests/unit/test_crane_scheduler.py covers inactive completion skip, active issue override, paused migrations still skipping, and string completed-state recognition. tests/unit/test_crane_workflow_prompt.py locks the prompt wording that prevents finishing from stored state alone.

CHANGELOG.md records the fix under Unreleased for #101.

Diagram

This shows how an active migration issue now overrides stale completed memory until fresh verification runs.

flowchart LR
    A["Issue has crane-migration"] --> B["Repo-memory says Completed=true"]
    B --> C["Scheduler emits stale_completed_state"]
    C --> D["Agent runs current verification"]
    D --> E{"Fresh accepted score reaches target?"}
    E -->|Yes| F["Mark completed"]
    E -->|No| G["Keep migration active"]
Loading

Trade-offs

  • The override only applies to issue-based migrations with an active crane-migration label; completed file-based migrations still skip.
  • A paused migration still skips even if the issue is active, preserving the manual hold semantics.
  • The lockfile was checked with gh aw compile; it did not produce a crane.lock.yml diff for these prompt/script changes.

Benefits

  1. Prevents stale repo-memory from silently removing active migration work.
  2. Gives the agent an explicit runtime signal when completion state has been reactivated.
  3. Adds regression tests around the exact failure mode from Crane Migration: Python to Go -- Full APM CLI Rewrite #78.

Validation

UV_CACHE_DIR=/private/tmp/apm-uv-cache /Users/mrjf/.local/bin/uv run pytest tests/unit/test_crane_scheduler.py tests/unit/test_crane_workflow_prompt.py -q
.......                                                                  [100%]
7 passed in 0.34s

UV_CACHE_DIR=/private/tmp/apm-uv-cache /Users/mrjf/.local/bin/uv run ruff check tests/unit/test_crane_scheduler.py tests/unit/test_crane_workflow_prompt.py
All checks passed!

git diff --check

/opt/homebrew/bin/gh aw compile
✓ .github/workflows/crane.md (122.4 KB)
✓ Compiled 1 workflow(s): 0 error(s), 0 warning(s)

Scenario Evidence

Scenario Test
Completed inactive migrations still skip tests/unit/test_crane_scheduler.py::test_completed_state_skips_inactive_migration
Active crane-migration issue overrides stale completed state tests/unit/test_crane_scheduler.py::test_active_issue_overrides_stale_completed_state
Manual pause still wins tests/unit/test_crane_scheduler.py::test_active_issue_does_not_override_pause
Prompt forbids completion from stored state alone tests/unit/test_crane_workflow_prompt.py::test_crane_prompt_blocks_stale_completed_state_from_finishing

How to test

  • Apply crane-migration to an issue whose repo-memory state says Completed: true.
  • Run Crane and confirm /tmp/gh-aw/crane.json includes the migration in stale_completed_state.
  • Confirm the agent runs verification and does not remove crane-migration unless the current accepted iteration reaches the target.

@mrjf mrjf merged commit de7e3bb into main Jun 2, 2026
14 checks passed
@mrjf mrjf deleted the codex/fix-crane-stale-completion branch June 2, 2026 17:07
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.

1 participant