Skip to content

Fix LRO operation-status source selection - #1071

Open
Heath Stewart (heaths) wants to merge 4 commits into
Azure:mainfrom
heaths:copilot/lro-status-1070
Open

Heath Stewart (heaths) wants to merge 4 commits into
Azure:mainfrom
heaths:copilot/lro-status-1070

Conversation

@heaths

@heaths Heath Stewart (heaths) commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Read only the applicable operation-status field instead of deserializing intermediate responses as the public monitor model. Ignore unrelated initial resource lifecycle statuses, including terminal-looking names.

Match canonical success/failure/cancellation explicitly and use wildcard progress for everything else. Preserve existing public APIs, final retrieval, raw responses, and Resource Manager behavior.

Add AppConfig-shaped regressions with distinct status enums, including provisioning as both a lifecycle value and an unknown nonterminal monitor value. Preserve pre-existing tests.

Remove the custom-terminal machinery and SDK hook dependency from this fix. Azure/azure-sdk-for-rust#5665 and Azure/azure-rest-api-specs#48456 are unnecessary and withdrawn; raw intermediate-response documentation is separate.

Fixes #1070

Fixes #1068

Fixes Azure#1070

Fixes Azure#1068

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e94dcdb4-aef1-4344-8e22-d1af639cee19
Preserve existing APIs and terminal handling, default all other operation statuses to progress, and cover AppConfig-shaped lifecycle responses without custom annotations or SDK hooks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e94dcdb4-aef1-4344-8e22-d1af639cee19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

LRO initialization can apply monitor decoding to unrelated resource responses and accept empty required monitor bodies, causing incorrect polling termination or masking malformed responses.

2 open issues
What changed in this PR

Updates the TypeSpec Rust emitter to distinguish operation-monitor statuses from resource lifecycle statuses, addressing #1068 and #1070 without changing public poller APIs or Resource Manager handling.

Changes:

  • Adds metadata-driven status selection and private, status-only JSON decoders.
  • Handles canonical terminal statuses explicitly and continues polling for unknown values.
  • Adds App Configuration-shaped regressions and regenerates affected Rust clients.
File Description
packages/​typespec-rust/​test/​tsp/​lro-status/​main.tsp Defines distinct resource and monitor status fixtures.
packages/​typespec-rust/​test/​tcgcadapter.test.ts Tests status-source metadata and decoder generation.
packages/​typespec-rust/​test/​spector/​azure/​core/​lro/​standard/​src/​generated/​clients/​standard_client.rs Regenerates standard LRO polling logic.
packages/​typespec-rust/​test/​spector/​azure/​core/​lro/​rpc/​src/​generated/​clients/​rpc_client.rs Regenerates RPC polling logic.
packages/​typespec-rust/​test/​other/​lro/​tests/​status.rs Tests unknown values and case-insensitive terminal conversion.
packages/​typespec-rust/​test/​other/​lro/​src/​generated/​clients/​ni_client.rs Regenerates existing LRO clients.
packages/​typespec-rust/​test/​other/​lro/​Cargo.toml Adds the JSON decoder dependency.
packages/​typespec-rust/​test/​other/​lro_status/​tests/​status_flow.rs Tests lifecycle isolation, raw responses, terminal handling, and final retrieval.
packages/​typespec-rust/​test/​other/​lro_status/​src/​lib.rs Exports the new regression crate.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​models/​models.rs Adds resource and monitor models.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​models/​models_impl.rs Implements monitor status and output contracts.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​models/​mod.rs Exports generated model modules.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​models/​method_options.rs Adds client method options.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​models/​header_traits.rs Adds typed operation-location header access.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​models/​enums.rs Defines separate lifecycle and operation enums.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​models/​enums_serde.rs Adds status enum serialization.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​models/​enums_impl.rs Adds enum conversions preserving unknown values.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​mod.rs Exposes generated clients and models.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​clients/​mod.rs Exports fixture clients.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​clients/​lro_status_test_snapshots_client.rs Implements generated resource and monitor polling flows.
packages/​typespec-rust/​test/​other/​lro_status/​src/​generated/​clients/​lro_status_test_client.rs Adds fixture client initialization.
packages/​typespec-rust/​test/​other/​lro_status/​Cargo.toml Declares regression crate dependencies.
packages/​typespec-rust/​test/​other/​fakes/​src/​generated/​clients/​fakes_client.rs Regenerates fake-client polling logic.
packages/​typespec-rust/​test/​Cargo.toml Registers the regression crate.
packages/​typespec-rust/​test/​Cargo.lock Records new crate dependencies.
packages/​typespec-rust/​src/​tcgcadapter/​adapter.ts Derives operation-status sources from TCGC metadata.
packages/​typespec-rust/​src/​codemodel/​client.ts Represents status paths and field optionality.
packages/​typespec-rust/​src/​codegen/​clients.ts Emits minimal decoders and explicit terminal handling.
packages/​typespec-rust/​CHANGELOG.md Documents the polling fixes.
packages/​typespec-rust/​.scripts/​tspcompile.js Registers fixture generation.

Review effort: Balanced

@xirzec Jeff Fisher (xirzec) 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.

A couple thoughts from copilot, but I think Joel caught most of it

Select initial monitor responses by HTTP status without interpreting resource lifecycle fields. Reuse generated monitor decoding and preserve existing missing/null status behavior.

Add AppConfig-shaped and mixed-response regressions, avoid phase-variable collisions, and remove decoder-only dependencies.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e94dcdb4-aef1-4344-8e22-d1af639cee19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Header-variable shadowing and misclassified initial responses can break generated clients, while status decoding still validates unrelated fields and treats missing or null required status as progress.

4 open issues
2 resolved since last review

Review effort: Balanced

Comment on lines +1976 to +1987
const monitorCondition = initialMonitorStatusCodes.map(code => `status == azure_core::http::StatusCode::from(${code})`).join(' || ');
body += `${indent.get()}let poller_status = if !${initialVar}${monitorCondition ? ` || ${monitorCondition}` : ''} {\n`;
body += `${indent.push().get()}let res: ${helpers.getTypeDeclaration(helpers.unwrapType(method.returns.type))} = body.json()?;\n`;
body += `${indent.get()}res.status()\n`;
body += `${indent.pop().get()}} else {\n`;
indent.push();
const pollingHeader = pollingStepHeaderName
? ` || headers.get_optional_string(&HeaderName::from_static("${pollingStepHeaderName}")).is_some()`
: '';
body += `${indent.get()}if status == azure_core::http::StatusCode::Accepted${pollingHeader} { PollerStatus::InProgress } else { PollerStatus::Succeeded }\n`;
body += `${indent.pop().get()}};\n`;
statusExpression = 'poller_status';
Comment on lines +2564 to +2565
if (path && serializedPath(path) !== serializedPath(pollingPath)) {
throw new AdapterError('UnsupportedTsp', `LRO ${method.name} has an initial monitor incompatible with its polling model`);
Comment on lines +1978 to +1979
body += `${indent.push().get()}let res: ${helpers.getTypeDeclaration(helpers.unwrapType(method.returns.type))} = body.json()?;\n`;
body += `${indent.get()}res.status()\n`;
Comment on lines +207 to +208
async fn missing_or_null_monitor_status_uses_existing_progress_semantics() {
for missing in ["{}", r#"{"status":null}"#] {
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.

Fix LRO operation-status source selection and nonterminal fallback LRO poller misinterprets initial resource status as operation status

4 participants