fix(infrastructure): retry region infra deploy on transient Cosmos RequestTimeout (ARO-30635) #8330
Pipeline controller notification
This PR uses the pipeline controller for second-stage tests. Selection and triggering follow the repository configuration.
Use /test ? to list jobs and /pipeline help for commands.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: <a href="https://github.com/Azure/ARO-HCP/pull/8330#" title="Author self-approved">moisescassidy</a>
Once this PR has been reviewed and has the lgtm label, please assign stevekuznetsov for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":["stevekuznetsov"]} -->
Hi @moisescassidy. Thanks for your PR.
I'm waiting for a Azure member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.
Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test label.
I understand the commands that are listed here.
<details>
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
</details>
Blocking: the captures retain prohibited service URLs, and this fixture also exposes a production Cosmos backend address and topology diagnostics. Sanitize this fixture and line 1 of aro30635-stack-badrequest-rulescount.txt and aro30635-stack-conflict-409-nonterminal.txt, using reserved example hosts and removing backend diagnostics without changing the retry tokens or error nesting. Rewrite the introducing commits so the original captures do not remain in history.
Blocking: the PR description's Operational contract discusses an internal Microsoft rollout system and its retry rendering. Please have that disclosure reviewed and replace it with a neutral statement about the separate production rollout dependency. If the same information is in commit messages, replace those commits rather than leaving it in history.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Captured fixtures expose prohibited service URLs and production backend diagnostics that require sanitization and history cleanup, while internal rollout details in the PR description need disclosure review.
<details open>
<summary><strong>2 open issues</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
Extends the regional infrastructure pipeline’s existing retries to recover from transient Cosmos DB provisioning timeouts (ARO-30635), building on #7976 with regression coverage.
Changes:
| File | Description |
| ---- | ----------- |
| dev-infrastructure/region-pipeline.yaml | Adds two timeout retry tokens and explains deployment resubmission. |
| tooling/templatize/pkg/pipeline/region_infra_retry_test.go | Checks retry configuration and fixture-based error classification. |
| tooling/templatize/pkg/pipeline/testdata/aro30635-cosmos-requesttimeout.txt | Supplies the nested Cosmos timeout positive case. |
| tooling/templatize/pkg/pipeline/testdata/aro30635-stack-badrequest-rulescount.txt | Supplies a validation-failure negative case. |
| tooling/templatize/pkg/pipeline/testdata/aro30635-stack-conflict-409-nonterminal.txt | Supplies a deployment-stack conflict negative case. |
</details>
<sub>Review effort: Balanced</sub>
Fixed. All three fixtures are now synthetic mirrors of the captured errors, and the introducing commit was amended and force-pushed, so the original captures are not in the branch history.
What changed in the fixtures:
management.azure.com → management.example.com; the Cosmos backend address → rntbd://cosmos-backend.example.com:11010 (reserved example hosts)systemHistory, transport request timeline, replica health statuses) is elided entirely, keeping the same escape level and the diagnostic's cut-off tail so the rendering shape is unchangedWhat is preserved exactly is what the retry decision depends on: the azcore rendering (failed to run ARM step: failed to poll deployment: …, RESPONSE 200, ERROR CODE: DeploymentFailed), the nesting chain DeploymentFailed → Conflict{ResourceDeploymentFailure → DeploymentFailed(rp-cosmos-account) → ResourceDeploymentFailure → RequestTimeout}, and the token text itself. The tests still pass and golangci-lint is clean on the package.
Fixed. The operational-contract bullet no longer names the rollout system or links its documentation; it now states neutrally that production rollout is a separate process outside this PR and points at the repository documentation. The PR description is updated in place.
For the record: the specifics that were there are already public in this repository — CLAUDE.md and the CI-integration doc under docs/ci/ both describe the rollout system and the pipelines repo it flows through — so nothing non-public was disclosed. Flagging it for review was still correct per the review policy, and the description is cleaner without it.
The commit messages never contained this information, so no history change was needed for this finding (the force-push in the other thread is for the fixture sanitization only).
The PR description's operational contract promises up to ~34 minutes for four timeout failures, but RunPipeline wraps the entire retry loop in a 30-minute step deadline (run.go:730–740), and ARM steps cannot override it (stepContextTimeout). With 6.5-minute failures and 2-minute waits, the fourth attempt starts at 25.5 minutes and is cancelled before its expected completion at 32 minutes; the 8-hour job timeout does not extend this deadline. Please correct the operational contract to describe the shared 30-minute cap, or explicitly address the step deadline if four full attempts are required.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
The operational contract promises four timeout attempts over roughly 34 minutes, but a shared 30-minute step deadline cancels the fourth attempt early and is not extended by the job timeout.
<details open>
<summary><strong>3 open issues</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
Confirmed — good catch, and verified in the code before changing anything: defaultStepContextTimeout = 30 time.Minute (run.go:56) is applied by the consumer loop around the whole executeNode call (run.go:739-741), so it bounds the entire retry sequence — attempts and* waits — not each attempt; and stepContextTimeout (run.go:975) only honors a Timeout override on Istio-upgrade and ARMStack-delete steps, so a plain ARM step like infra cannot raise it. The arithmetic in the operational contract was wrong exactly as you describe: at ~6.5 min per timeout attempt with 2-minute waits, attempts complete at 6.5 / 15 / 23.5 minutes, the fourth starts at 25.5 and is cut at the 30-minute deadline (and with the slowest observed ~8-minute attempts, it never starts).
Resolved by correcting the contract rather than the mechanism: the PR description and the commit message now state that the sequence shares the 30-minute step deadline — three complete attempts for the slow RequestTimeout class, worst case ~30 minutes — and that a deadline-cut final attempt surfaces the step-timeout error while each attempt's own error is still logged.
Why not address the deadline itself:
AROSLSRE-1708 widening) and also serve the fast-failing InternalServerError class, where all four attempts run in ~8 minutes, well inside the deadline. Lowering maximumRetryCount to make the slow class fit would take a real attempt away from the class that can use it; shortening durationBetweenRetries would halve the propagation window that class relies on.Retrying step + RequestTimeout followed by a completed provision) will produce real attempt-outcome data; if it ever shows recoveries clustering on late attempts, that is the point to revisit the budget or the deadline.The corrected description and commit (amended, so the wrong arithmetic is not left in history) are force-pushed.
<!-- ccr-overview-v2 -->
🟢 Approval recommended
No active review issues were identified for the targeted Cosmos DB timeout retry change.
No open issues 🎉
<details>
<summary><strong>3 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
/assign @geoberle
/ok-to-test
Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-parallel
/test e2e-parallel-inplace-upgrade
have you verified these errors are recoverable?
not all resources on azure can be retried once they failed during deployment, e.g. postgres, eventgrid
in that is the case for cosmosdb, a retry does not solve the problem but increases the time we spend on an unresolvable issue instead of failing fast
tests like these are not necessary. the retry contract for errors is the list in pipeline.yaml and that mechanism is well tested already
moisescassidy
Summary
The
regional/infrastep in the region pipeline deploysregion.bicep, which provisions the RP's Cosmos DB account through therp-cosmos-accountmodule. Occasionally Azure's Cosmos control plane gives up creating the account server-side (~6.5 minutes in) and ARM reports the deployment as terminally failed. That failure arrives as an HTTP 200 whose body saysstatus: Failedwith a nestedRequestTimeoutcode — so no transport-level retry policy can act on it, and re-polling returns the same terminal result. The only recovery is re-submitting the deployment, which the step-levelautomatedRetryloop already does; its token list just didn't match this error, so the whole e2e provision went red.This adds
"RequestTimeout"and"exceeded maximum alloted time"to theinfrastep'serrorContainsAny, and locks the tokens to real captured error text with tests.Why now: 16 failed provisions across three DEV CI jobs between 2026-10-29 and 2026-11-12 (
e2e-parallel×12,healthcheck-provision-canadacentral×3,healthcheck-provision-centralus×1). None retried — no token matched. There has been no occurrence since 2026-11-12 (the trigger is transient Cosmos control-plane behavior, clustered on a few canadacentral backends), so this is insurance against recurrence rather than an active fire: landing it costs two YAML lines, not landing it costs a full red provision every time the Azure issue returns.Changes
dev-infrastructure/region-pipeline.yaml(CI/CD pipeline configuration — called out explicitly per PR standards): two newerrorContainsAnytokens onregional/infra, plus a comment explaining why.maximumRetryCount: 4anddurationBetweenRetries: 2mare untouched.tooling/templatize/pkg/pipeline/region_infra_retry_test.go+testdata/:TestRegionInfraAutomatedRetryConfigloads the realregion-pipeline.yaml, finds theregional/infrastep, and asserts the retry config (4 attempts, 2m, both tokens present).TestShouldRetryErrorRegionInfraARO30635runs real error strings captured from CI through the realshouldRetryErroragainst that real step config: the CosmosRequestTimeoutfrom build 2118429933473632256 → retries; a stackBadRequestvalidation failure and a stack 409 non-terminal-state conflict (both from real runs) → no retry. Fixtures are synthetic mirrors of the captured errors — every identifier and host replaced with synthetic or reserved-example values, preserving the nesting, codes and casing the retry decision depends on. If ARM rewords the error or a refactor drops the tokens, these tests fail instead of the retry silently disappearing.Operational contract
InternalServerErrorclass still gets all four attempts, well inside the deadline. If the deadline cuts the final attempt, the step's terminal error is the step timeout rather than the underlying ARM error — each attempt's own error is still logged before it. The job timeout is 8h.strings.Contains); the fixtures pin the exact casing ARM emits.Security
Reviewed from a security perspective — no findings. Properties worth recording:
errorContainsAnytokens are inert string literals:shouldRetryErrorcompares each token against ARM-returned error text with a case-sensitivestrings.Containsand uses the result only as a boolean retry decision. Tokens are never compiled to regex, interpolated, or executed, so matched error text cannot alter pipeline behavior beyond the retry itself.synthetic-*resource names,2026-01-01timestamps, and reservedexample.comhosts everywhere (including therntbd://backend address). No credentials, real identifiers, or internal endpoints; only the nesting, codes and casing the retry decision depends on are preserved.redactSubscriptionError) before logging, exactly as final failures already do.Non-goals
RequestTimeoutsources more narrowly: the token is intentionally broad, bounded by the 4-attempt budget.Verification
go test ./...intooling/templatize— full module passes, including the new tests.make verify-yamlfmt,make verify-bicep-fixtures,make validate-config-pipelines— pass.golangci-lintontooling/templatize/pkg/pipeline— 0 issues.executeNodeloop with the real error text (attempt 0 fails → 2-minute wait → fresh deployment attempt succeeds); see ARO-30635.Links
main(post-ARMStack-revert) with the tests added. Please close it in favor of this PR.Suggested reviewers: @geoberle, @stevekuznetsov (OWNERS for both
dev-infrastructure/andtooling/templatize/).🤖 Generated with Claude Code