Skip to content

Fix Graph batch request contracts for public delegation - #1590

Open
ashwinikarke wants to merge 11 commits into
devfrom
fix/graph-batch-request-contracts
Open

ashwinikarke wants to merge 11 commits into
devfrom
fix/graph-batch-request-contracts

Conversation

@ashwinikarke

@ashwinikarke ashwinikarke commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix request handling in the private Invoke-ZtGraphBatchRequest helper,
addressing the prerequisite issues raised in the review of #1584.

This PR updates the private helper only. Public delegation and parameter
forwarding remain part of #1584. The API-version fix is handled separately in #1591. This PR does not add
private GraphBaseUri support.

Changes

  • Support OutputType, mapping PSCustomObject to the SDK's PSObject representation.
  • Correct collection output, matched results, and NoPaging behavior.
  • Preserve zero and string request IDs and reject case-insensitive duplicates.
  • Validate response IDs and statuses before emitting results.
  • Fail incomplete or malformed batches without partial output or resubmission.
  • Use URL-bearing request descriptors as malformed-response error targets.
  • Restore outer retries for GET/HEAD-only batches using Invoke-ZtRetry.
  • Isolate intermediate retry errors from caller error variables after successful recovery.
  • Avoid replaying batches containing writes after outer failures.
  • Normalize and validate dependsOn IDs; require dependency-bearing workloads to fit within one batch.
  • Remove satisfied dependency references from retry descriptors without replaying successful prerequisites.

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

Dependency handling breaks for zero-valued IDs and when batch splitting separates dependent requests.

2 open findings
What changed in this PR

Updates the private Graph batching helper to enforce request/response contracts and configurable routing.

Changes:

  • Adds Graph URI, API version, batch size, and output controls.
  • Improves paging, IDs, response validation, and retry behavior.
  • Adds comprehensive contract tests.
File Description
src/​powershell/​private/​graph/​Invoke-ZtGraphBatchRequest.ps1 Implements corrected batching contracts and retry handling.
code-tests/​commands/​Invoke-ZtGraphBatchRequest.Tests.ps1 Tests routing, output, validation, paging, IDs, and retries.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/powershell/private/graph/Invoke-ZtGraphBatchRequest.ps1
Comment thread src/powershell/private/graph/Invoke-ZtGraphBatchRequest.ps1 Outdated

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

A dependent 424 response is discarded when its prerequisite is throttled, preventing the dependent request from being retried.

1 open finding
2 resolved since last review

🧠 Review effort: Balanced

Comment thread src/powershell/private/graph/Invoke-ZtGraphBatchRequest.ps1

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

The advertised caller-selected BatchSize remains unimplemented because batching is hard-coded to 20.

2 open findings

🧠 Review effort: Balanced

Comment thread src/powershell/private/graph/Invoke-ZtGraphBatchRequest.ps1
@ashwinikarke
ashwinikarke marked this pull request as ready for review October 14, 2026 06:13
@ashwinikarke ashwinikarke added the ready for review PR is ready for review and merging label Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ashwinikarke Please, address my feedback.

Comment thread src/powershell/private/graph/Invoke-ZtGraphBatchRequest.ps1
Comment thread src/powershell/private/graph/Invoke-ZtGraphBatchRequest.ps1
Copilot AI balanced review requested due to automatic review settings October 15, 2026 04:46

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.

🔵 Needs a closer look

Interacting retry, timeout, paging, and dependency behavior requires runtime validation and final human review.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 07:44

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

Unresolved ID-handling defects can bypass completeness validation or create invalid dependencies, and explicit-ID validation scales quadratically.

1 open finding
Previously missed (2)

In code that hasn't changed since last review

Medium severity Explicit ID validation scales quadratically

src/​powershell/​private/​graph/​Invoke-ZtGraphBatchRequest.ps1:456

This enumerates every previously created task's ID for each explicit ID, making request preparation quadratic before transport starts. The public caller assigns explicit IDs to every request (public/Invoke-ZtGraphRequest.ps1:287–293), so 10,000 requests cause roughly 50 million prior IDs to be enumerated, with repeated array allocation. Track seen explicit IDs in a case-insensitive hashtable instead; generated IDs already avoid explicit IDs through ReservedIDs.

Medium severity Generated numeric IDs collide with explicit string IDs

src/​powershell/​private/​graph/​Invoke-ZtGraphBatchRequest.ps1:462

Generated request IDs remain integers, so these membership checks can compare explicit string IDs numerically. For example, -Request @('users', @{ id = '01'; url = 'groups' }) rejects '01' as a duplicate of generated ID '1', although they are distinct correlation IDs. Dependency validation also accepts '01' as a reference to generated ID '1', leaving a dangling dependency in the submitted batch. Store generated request IDs as strings and add regression tests for both cases.

🧠 Review effort: Balanced

Comment thread src/powershell/private/graph/Invoke-ZtGraphBatchRequest.ps1 Outdated
Copilot AI balanced review requested due to automatic review settings October 15, 2026 07:58

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.

🔵 Needs a closer look

Mixed numeric and string task IDs can incorrectly reject distinct correlation IDs.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Store generated task IDs as strings for consistent ID comparisons

src/​powershell/​private/​graph/​Invoke-ZtGraphBatchRequest.ps1:462

Generated task IDs remain integers, so this containment check can compare IDs numerically. For example, -Request @('users', @{ id = '01'; url = 'groups' }) rejects '01' as a duplicate of generated ID 1, although the correlation strings '1' and '01' are distinct. Store generated task IDs as strings so duplicate and dependency checks consistently use string equality, and add a regression test for this mixed-ID workload.

🧠 Review effort: Balanced

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review PR is ready for review and merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants