microsoft/aspire · error · InvalidOperationException

The Microsoft Foundry model catalog returned the same…

Error message

The Microsoft Foundry model catalog returned the same continuation token twice. Refusing to overwrite the generated model descriptors with a partial catalog. Response: {GetResponseSnippet(pageResponse)}

What it means

While paging the Foundry catalog, GetAllModelsAsync tracks the previous continuation token and throws if the service returns the identical token twice, which would loop forever and produce a partial catalog. The guard exists so generated descriptors are never overwritten from an incomplete page walk.

Solutions

  1. Retry the tool run after some time — repeated identical tokens from a degraded service are often transient.
  2. Inspect the response snippet to see the token values and confirm the server is not advancing pagination.
  3. Check whether a proxy/cache is serving stale pages; bypass caching or add no-cache headers in ModelClient.
  4. Verify the requested API version supports continuation tokens as the tool sends them; adjust paging parameters if the contract changed.
Defensive patterns

Strategy: retry

Try / catch

try
{
    await RunGenModelAsync();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("same continuation token twice"))
{
    // service-side paging stall: back off and retry the whole run
}

Prevention

When it happens

Trigger: The Foundry catalog's next-page continuation token does not advance — consecutive pages return the same token — inside the do/while pagination loop of GetAllModelsAsync.

Common situations: Foundry service bug or degraded state where the next-page link is stale; cached/proxied responses replaying the same page; API version mismatch causing the server to ignore paging parameters; index larger than the server can page correctly.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/23446f4f83a7b7a5. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Foundry/tools/GenModel.cs:783

            foreach (var model in pageModels)
            {
                allModels.Add(model);
            }

            Console.WriteLine($"Fetched page with {pageModels.Count} models. Total so far: {allModels.Count}");

            // Check if there's a continuation token for the next page
            previousToken = continuationToken;
            continuationToken = apiResponse?.IndexEntitiesResponse?.ContinuationToken;

            if (!string.IsNullOrEmpty(continuationToken))
            {
                Console.WriteLine($"Found continuation token for next page: {continuationToken.Substring(0, Math.Min(50, continuationToken.Length))}...");

                // Check for infinite loop (same token repeated)
                if (continuationToken == previousToken)
                {
                    throw new InvalidOperationException($"The Microsoft Foundry model catalog returned the same continuation token twice. Refusing to overwrite the generated model descriptors with a partial catalog. Response: {GetResponseSnippet(pageResponse)}");
                }
            }

        } while (!string.IsNullOrEmpty(continuationToken));

        Console.WriteLine($"\n=== Pagination Complete ===");
        Console.WriteLine($"Total pages fetched: {pageCount}");
        Console.WriteLine($"Total models collected: {allModels.Count}");

        RunFixups(allModels);

        // Return the consolidated response using our model
        return new ConsolidatedResponse
        {
            TotalCount = allModels.Count,
            PagesCombined = "All pages fetched",
            Entities = allModels
        };

View on GitHub (pinned to 25830f84bd)