Skip to content

fix(migrate-apim): say what a stopped phase still leaves reachable - #74

Merged
Facundo Santiago (santiagxf) merged 2 commits into
mainfrom
fix/stopped-phase-names-what-is-reachable
Dec 3, 2026
Merged

Facundo Santiago (santiagxf) merged 2 commits into
mainfrom
fix/stopped-phase-names-what-is-reachable

Conversation

@santiagxf

@santiagxf Facundo Santiago (santiagxf) commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Addresses finding 8 of #62. The issue stays open — see Scope below.

The problem

$ migrate-apim apply --plan plan.json --phase providers --execute
Phase providers -- EXECUTING
  failed           item:modelProvider/foundry-ai-endpoint
                   foundry-ai-endpoint: ERROR: (ValidationError) ...

Stopped in providers. The source APIM is untouched; the gateway is partially built.

$ migrate-apim apply --plan plan.json --next-phase --execute
Phase providers -- EXECUTING
  failed           item:modelProvider/foundry-ai-endpoint
...

Stopped in providers. The source APIM is untouched; the gateway is partially built.

--next-phase is what the tool prints after every successful phase, and it now returns providers on every run, for as long as the cause stands. That answer is correct — the phase is incomplete, and re-running it is how a fix gets confirmed — and it is indistinguishable from the tool having run out of moves.

models, aliases, toolServers, policies and keys can still be run by naming each with --phase. Nothing says so. The operator in the lab run that found this worked it out and finished the migration by hand, one phase at a time.

Proposed solution

Say it, rather than add a flag. #62 floated --skip; everything missing here is already derivable from state the tool keeps, so a flag would buy one sentence at the price of a second way to half-run a migration. next_phase() is unchanged, with a test pinning that a stopped phase is still what it returns.

summary.render_stopped prints under the existing stop line — which a re-run prints again, so the operator is told on the first stop and on every repeat:

Stopped in providers. The source APIM is untouched; the gateway is partially built.
--next-phase returns providers until it completes: a stopped phase is re-run to confirm a
fix, not passed over. --phase can still name the phases after it that have steps: models,
aliases, toolServers, policies. Each may name an object providers was to create, so whether
it can run before this is settled depends on whether that object is already there.

It names what is reachable and stops short of advising it: whether models runs with no provider is a claim about the gateway that nothing in the plan answers, so the last sentence hands that question back. It prints nothing when no later phase has steps. README.md gains the same sample under Phases.

Scope

Findings 1-7 and 9 of #62 are already fixed on main and untouched here. Two residuals keep the issue open:

  • The provider read-back shape has never been checked against a live 1.0.0b34 gateway — tests/test_apply.py says so in its own docstring. That needs a real deployment.
  • The catalog is still pinned at aigateway-1.0.0b31.json.

No Azure resources were provisioned and no az was run against a live subscription.

Verification

  • python -m pytest -q -> 1049 passed, 1 skipped (1043 before; 6 new)
  • python -m migrate_apim compile --strict -> 0 errors, 0 warnings, exit 0

New TestAStoppedPhaseSaysWhatIsStillReachable covers the invariant that --next-phase still returns the stopped phase, that the hint names every later phase that has steps and skips one already verified, that it carries the dependency caveat, that a stop in the last phase with steps prints nothing, and an end-to-end CLI run against an az that refuses every write — asserting the hint appears under the stop line and again on the next --next-phase --execute.

🤖 Generated with Claude Code

`--next-phase` returns the first phase that has steps and is not complete, and
completeness is derived from the journal rather than stored -- so a phase that
stopped on a stuck step is never complete and comes back on every run, for as
long as the cause stands. That is the right answer and stays one: re-running
the phase is how a fix is confirmed, and passing over a stop would turn a stop
into a shrug. What was missing is that nothing said so, and the repeat read as
the tool being out of moves. Lab 17 worked the rest of its migration out by
naming every later phase to `--phase` by hand (issue #62, finding 8).

So the stop now names what is reachable and stops there. Under "Stopped in
providers", where a re-run prints it again:

  --next-phase returns providers until it completes: a stopped phase is re-run
  to confirm a fix, not passed over. --phase can still name the phases after it
  that have steps: models, aliases, toolServers, policies. Each may name an
  object providers was to create, so whether it can run before this is settled
  depends on whether that object is already there.

That `--phase` can name `models` is a fact about this tool; that `models` would
succeed with no provider registered is a claim about the gateway, which nothing
in the plan answers, so the sentence stops short of making it. Nothing prints
when no later phase has steps, because then the repeat is the whole truth.

No new state and no new flag: the later phases come from `phases_remaining`,
the same derivation the checklist already reads.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@paulyuk Paul Yuknewicz (paulyuk) left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Facundo Santiago (@santiagxf), I found one edge case in the new stop hint. If someone explicitly runs a later phase with --phase and it fails, --next-phase still points to the earliest unfinished phase. That can be an earlier phase, not the one that just failed. The current hint says otherwise.

Impact: the CLI can point operators at the wrong phase to retry, which makes it harder to understand what is still blocked and what the next command will do. This patch makes the hint match the CLI behavior and adds two regression tests for the case. The combined suite passes on Python 3.10 and 3.13 with #73 included (1,061 tests each).

diff --git a/tools/migrate-apim/README.md b/tools/migrate-apim/README.md
index 3545e13..9a81b59 100644
--- a/tools/migrate-apim/README.md
+++ b/tools/migrate-apim/README.md
@@ -1030,7 +1030,7 @@ later phase to `--phase` by hand. The stop now says where else `--phase` can go:

Stopped in providers. The source APIM is untouched; the gateway is partially built.
--next-phase returns providers until it completes: a stopped phase is re-run to confirm a
-fix, not passed over. --phase can still name the phases after it that have steps: models,
+fix, not passed over. --phase can still name the phases after providers that have steps: models,
aliases, toolServers, policies. Each may name an object providers was to create, so whether
it can run before this is settled depends on whether that object is already there.

@@ -1039,6 +1039,8 @@ It stops at what is reachable and recommends none of it. That `--phase` can name
about this tool; that `models` would succeed while the provider it registers against does not exist
is a claim about the gateway, which nothing in the plan answers. Nothing is printed when no later
phase has steps, because then the repeat is the whole truth.
+If you explicitly run a later phase, `--next-phase` still returns the earliest unfinished phase,
+not necessarily the one that just stopped.

### What the last two phases apply

diff --git a/tools/migrate-apim/migrate_apim/summary.py b/tools/migrate-apim/migrate_apim/summary.py
index 30a39c1..4acdbf2 100644
--- a/tools/migrate-apim/migrate_apim/summary.py
+++ b/tools/migrate-apim/migrate_apim/summary.py
@@ -855,7 +855,8 @@ def render_stopped(journal: dict[str, Any], steps: list[Any], phase: str) -> lis
    `Executor.next_phase` returns the first phase that has steps and is not
    complete, and completeness is derived from the journal rather than stored.
    A phase that stopped on a stuck step is never complete, so `--next-phase`
-    hands that same phase back on every run, for as long as the cause stands.
+    keeps returning the earliest unfinished phase for as long as its cause
+    stands, even if an explicit `--phase` run just stopped in a later phase.
    That is the right answer and has to stay one -- re-running the phase is how
    a fix is confirmed, and passing over a stop would turn a stop into a shrug.
    What was missing is that nothing said so, so the repeat read as the tool
@@ -871,7 +872,8 @@ def render_stopped(journal: dict[str, Any], steps: list[Any], phase: str) -> lis
    """
    from .apply import PHASES

-    later = [name for name in phases_remaining(journal, steps)
+    remaining = phases_remaining(journal, steps)
+    later = [name for name in remaining
             if PHASES.index(name) > PHASES.index(phase)]
    if not later:
        return []
@@ -880,8 +882,8 @@ def render_stopped(journal: dict[str, Any], steps: list[Any], phase: str) -> lis
    # cannot be written down. `_wrap` is the one that leaves `--next-phase`
    # whole -- the default breaks it at the hyphen into a flag nobody can type.
    return _wrap(
-        f"--next-phase returns {phase} until it completes: a stopped phase is re-run to "
-        f"confirm a fix, not passed over. --phase can still name the phases after it that "
+        f"--next-phase returns {remaining[0]} until it completes: a stopped phase is re-run to "
+        f"confirm a fix, not passed over. --phase can still name the phases after {phase} that "
        f"have steps: {', '.join(later)}. Each may name an object {phase} was to create, so "
        "whether it can run before this is settled depends on whether that object is already "
        "there.",
diff --git a/tools/migrate-apim/tests/test_apply.py b/tools/migrate-apim/tests/test_apply.py
index 3a7ef9a..10f8aaa 100644
--- a/tools/migrate-apim/tests/test_apply.py
+++ b/tools/migrate-apim/tests/test_apply.py
@@ -1210,6 +1210,21 @@ class TestAStoppedPhaseSaysWhatIsStillReachable:
        # different answer.
        assert executor.next_phase() == "gateway"

+    @pytest.mark.parametrize("earlier_status", [None, "failed"])
+    def test_an_explicit_later_stop_names_the_actual_next_phase(
+        self, settled, inventory, earlier_status
+    ):
+        statuses = {"providers": "failed"}
+        if earlier_status:
+            statuses["gateway"] = earlier_status
+        journal = self._journal(settled, statuses)
+        executor = Executor(settled, inventory, journal, execute=False)
+        assert executor.next_phase() == "gateway"
+        text = " ".join(summary.render_stopped(journal, steps_for(settled), "providers"))
+        assert "--next-phase returns gateway until it completes" in text, text
+        assert "--next-phase returns providers" not in text, text
+        assert "models" in text, text
+
    def test_it_names_the_later_phases_that_still_have_steps(self, settled):
        journal = self._journal(settled, {"gateway": "failed"})
        steps = steps_for(settled)

@paulyuk Paul Yuknewicz (paulyuk) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can take but suggested bug fix first in comments

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified with the stopped-phase guidance update.

No open issues 🎉

What changed in this PR

Addresses issue #62’s stopped-phase guidance without changing phase selection or adding a skip flag.

Changes:

  • Explains why --next-phase returns the earliest unfinished phase.
  • Lists later unfinished phases accessible through --phase, with a dependency caveat.
  • Documents the guidance and tests repeated stops, explicit phase selection, and completed-phase filtering.
File Description
tools/​migrate-apim/​tests/​test_apply.py Tests phase-selection invariants and stopped-phase guidance.
tools/​migrate-apim/​README.md Explains stop behavior and shows example guidance.
tools/​migrate-apim/​migrate_apim/​summary.py Renders later-phase options and dependency caveats.
tools/​migrate-apim/​migrate_apim/​cli.py Prints guidance beneath the existing stop message.

Review effort: Balanced

@paulyuk Paul Yuknewicz (paulyuk) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clearer

@santiagxf
Facundo Santiago (santiagxf) merged commit ee5667c into main Dec 3, 2026
5 checks passed
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.

3 participants