Skip to content

[Internal] Direct package: Adds msdata/direct update from master#5612

Merged
kirankumarkolli merged 845 commits intomsdata/directfrom
users/sync/update_msdata_direct_02_10_2026
Feb 11, 2026
Merged

[Internal] Direct package: Adds msdata/direct update from master#5612
kirankumarkolli merged 845 commits intomsdata/directfrom
users/sync/update_msdata_direct_02_10_2026

Conversation

@yash2710
Copy link
Copy Markdown
Contributor

Description

Refactors msdata/direct branch with changes from V3 master branch and msdata direct master branch

msft-tsharp and others added 30 commits March 25, 2025 17:44
## Description

In order to detect and prevent certain usages of exceptions within the
codebase, analyzers have been added to show messages related to
potentially incorrect usage.

Added `Microsoft.Codex.Analyzers` v1.0.5 nuget package
Added .globalconfig file as a baseline configuration

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)

## Closing issues

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
…ns for AsyncCache and AsyncCacheNonblocking (#5069)

# Pull Request Template

## Description

This PR addresses the issue of shared exception objects in the
AsyncCache class, which was causing significant performance degradation
and memory bloat recently for open AI .
 
The fix involves creating shallow copies of known offenders and
rethrowing the rest. This approach ensures that each AsyncCache.GetAsync
call receives its own exception instance, preventing the dangerous
growth of the exception object's StackTrace and reducing GC overhead.


All ICloneable implemenations of exceptions will benefit from this.


https://learn.microsoft.com/en-us/dotnet/api/system.icloneable?view=net-9.0

Key changes:
- Added support to post-process the exception in above mentioned two
cache classes that creates a shallow copy of specific exception types to
prevent stack trace proliferation and rethrows them, while propagating
all other exceptions unchanged.
- Added support for any exception that is ICloneable supported ,
TimeoutException and TaskCanceledException in this drop
- Improved exception handling to avoid shared exception objects across
threads.

**Feature is enabled by default. To turn it off, set
EnableAsyncCacheExceptionNoSharing CosmosClientOptions to false**

Proof of testing:

**Repro Steps**
To reproduce the issue, I followed these high-level steps:

- Create a Cosmos client with the necessary settings to preempt gateway
calls for address refresh to fail with a specific exception.

- Create a TaskCompletionSource that waits until all the threads are
created.

- Initiate calls to createItem that will eventually block, with one of
them erroring out with the pre-set exception.

- Observe the exception storm as the same exception trace is copied over
to all the threads.

**After the fix**

- Tested with TimeoutException (2K Threads) and TaskCanceledException
(10K threads) using TaskCompletionSource with up to 10,000 threads
without issues on the devbox.

- Implemented the fix in AsyncNonBlockingCache by creating shallow
copies of known offenders and rethrowing the rest.

- Re-ran the setup and observed a significant reduction in the number of
stack trace frames.

TaskCancelledExcpetion with 10K threads ( Even the file size is giving
away how bad the stack trace profileration problem was )



[TaskCancExceptionWithFix.log](https://github.com/user-attachments/files/19302320/TaskCancExceptionWithFix.log)

Filesize: 10 KB
  Standard Output: 
With cache fix and 10K threads 4923736 bytes allocated in (Gen0:0 1:0
2:0) Frames=2


[TaskCancExceptionWithoutFix.log](https://github.com/user-attachments/files/19302321/TaskCancExceptionWithoutFix.log)

Filesize: 1,168KB
Standard Output: 
Without cache fix and 10K threads 5612888 bytes allocated in (Gen0:0 1:0
2:0) Frames=2


TImeoutException  with 2K threads


[TimeoutExceptionWithFix.log](https://github.com/user-attachments/files/19302478/TimeoutExceptionWithFix.log)

[TimeoutExceptionWithoutFix.log](https://github.com/user-attachments/files/19302479/TimeoutExceptionWithoutFix.log)
 

## Type of change

Please delete options that are not relevant.

- [] Bug fix (non-breaking change which fixes an issue)
- [] New feature (non-breaking change which adds functionality)
- [] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [] This change requires a documentation update

## Closing issues

To automatically close an issue: closes #IssueNumber

---------

Co-authored-by: Debdatta Kunda <dkunda@microsoft.com>
Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
…ass with IsSupported as well (#5089)

# Pull Request Template

Second fix for
#5029

## Description

This adds an additional guard in the other ([previously
missed](https://github.com/search?q=repo%3AAzure%2Fazure-cosmos-dotnet-v3%20ServicePointAccessor&type=code))
location where service point is used

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)
- [] New feature (non-breaking change which adds functionality)
- [] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [] This change requires a documentation update

## Closing issues

To automatically close an issue: closes #5029

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
…ride When a Requested Cancellation Token Expires (#5063)

# Pull Request Template

## Description

**Background:**

During one of the backend drills, it was identified that when the
following quorum loss condition is met, and the user provides a
cancellation token, SDK honors the token, however doesn't apply the
partition level fail over for the offending partition:

- Quorum loss injected with the quorum replicas (3 out of 4 replicas are
down).
- The primary replica is specifically down.
- A cancellation token with 5 seconds of timeout value is provided.

**Observation:**

- SDK doesn't apply the partition level override and the subsequent
write requests fails on the current faulty region/ partition.

**Fix:**

This PR is fixing the above behavior to apply partition level override,
when a cancellation token gets expired. In order to avoid false
positives, the cancellation token based failovers are currently based on
certain thresholds, which could be overridden by setting the following
environment variables:
`AZURE_COSMOS_PPCB_CONSECUTIVE_FAILURE_COUNT_FOR_READS` and
`AZURE_COSMOS_PPCB_CONSECUTIVE_FAILURE_COUNT_FOR_WRITES`.

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #5060
# Pull Request Template

## Description

This PR adds the RANK construct to the SQL DOM to support ORDER BY RANK
in the SQL query language as well as scoring expressions in OrderBys

## Type of change

Please delete options that are not relevant.

- [] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [] This change requires a documentation update

## Closing issues

To automatically close an issue: closes #IssueNumber

---------

Co-authored-by: Minh Le <leminh@microsoft.com>
…ct. (#5091)

# Pull Request Template

## Description

Integrating exception handling analyzers rules with Cosmos project.
These rules will enhance stability, prevent performance pitfalls, and
ensure better logging practices. Also, suppressing the rules in certain
places where logging full stack trace is necessary. This PR covers
primarily DocumentClient and Telemetry files.

Performance tests in master branch:
| Method | Type | EnableBinaryResponseOnPointOperations | Mean (µs) |
Error (µs) | StdDev (µs) | P90 (µs) | P95 (µs) | P100 (µs) | Op/s | Gen0
| Allocated |

|------------------------------------------------------------------|--------|---------------------------------------|----------|-----------|------------|----------|----------|----------|---------|--------|-----------|
| CreateItem | Stream | False | 298.62 | 3.44 | 3.22 | 302.51 | 303.68 |
305.26 | 3,348.72 | 1.4648 | 26793 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | Stream
| False | 293.50 | 3.65 | 3.42 | 298.33 | 299.08 | 299.83 | 3,407.17 |
1.4648 | 26794 B |
| DeleteItemExists | Stream | False | 300.57 | 4.27 | 3.79 | 305.14 |
307.27 | 310.32 | 3,326.97 | 1.4648 | 26810 B |
| DeleteItemNotExists | Stream | False | 320.20 | 4.38 | 4.09 | 324.52 |
325.98 | 327.49 | 3,123.06 | 2.4414 | 40025 B |
| ReadFeed | Stream | False | 357.41 | 6.62 | 6.51 | 366.23 | 368.86 |
369.54 | 2,797.91 | 1.9531 | 36963 B |
| ReadItemExists | Stream | False | 321.23 | 3.58 | 2.99 | 323.75 |
325.50 | 327.79 | 3,113.08 | 1.4648 | 28089 B |
| ReadItemNotExists | Stream | False | 341.28 | 5.72 | 5.35 | 347.59 |
348.10 | 349.03 | 2,930.18 | 2.4414 | 41293 B |
| UpdateItem | Stream | False | 297.01 | 3.59 | 3.19 | 300.65 | 301.38 |
302.28 | 3,366.87 | 1.4648 | 27002 B |
| UpsertItem | Stream | False | 300.65 | 5.63 | 5.26 | 305.01 | 307.38 |
312.73 | 3,326.08 | 1.4648 | 27006 B |
| QuerySinglePartitionOnePage | Stream | False | 2564.54 | 14.57 | 12.17
| 2578.23 | 2581.78 | 2586.88 | 389.93 | 58.5938| 996767 B |
| QuerySinglePartitionMultiplePages | Stream | False | 15267.89 | 47.63
| 42.22 | 15326.44 | 15338.37 | 15341.00 | 65.50 | 343.75 | 5880526 B |
| CreateItem | Stream | True | 298.07 | 2.73 | 2.42 | 301.19 | 301.91 |
302.77 | 3,354.93 | 1.4648 | 27766 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | Stream
| True | 309.31 | 3.34 | 2.96 | 313.80 | 314.34 | 314.34 | 3,232.97 |
1.4648 | 29648 B |
| DeleteItemExists | Stream | True | 306.23 | 2.56 | 2.27 | 308.96 |
309.65 | 310.26 | 3,265.52 | 1.4648 | 27246 B |
| DeleteItemNotExists | Stream | True | 337.83 | 5.73 | 5.63 | 345.83 |
348.08 | 349.93 | 2,960.05 | 1.9531 | 35828 B |
| ReadFeed | Stream | True | 355.30 | 6.49 | 6.07 | 362.33 | 363.57 |
365.40 | 2,814.52 | 1.9531 | 36971 B |
| ReadItemExists | Stream | True | 327.99 | 6.21 | 6.37 | 334.79 |
338.23 | 339.62 | 3,048.85 | 1.4648 | 28529 B |
| ReadItemNotExists | Stream | True | 354.90 | 3.51 | 3.11 | 358.33 |
359.42 | 361.20 | 2,817.66 | 1.9531 | 37092 B |
| UpdateItem | Stream | True | 307.85 | 4.42 | 3.91 | 311.92 | 312.19 |
312.66 | 3,248.34 | 1.4648 | 27979 B |
| UpsertItem | Stream | True | 310.13 | 6.17 | 9.05 | 323.30 | 323.92 |
324.70 | 3,224.41 | 1.4648 | 28569 B |
| QuerySinglePartitionOnePage | Stream | True | 2547.10 | 13.13 | 10.25
| 2553.99 | 2562.13 | 2571.72 | 392.60 | 58.5938| 996763 B |
| QuerySinglePartitionMultiplePages | Stream | True | 15271.09 | 89.96 |
75.12 | 15334.47 | 15338.17 | 15343.42 | 65.48 | 343.75 | 5880719 B |
| CreateItem | OfT | False | 323.48 | 2.48 | 2.07 | 326.06 | 326.34 |
326.47 | 3,091.37 | 1.9531 | 38537 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
False | 0.01 | 0.00 | 0.00 | 0.01 | 0.01 | 0.01 | 73,066,308.61 | - | -
|
| DeleteItemExists | OfT | False | 319.05 | 2.17 | 1.81 | 320.29 |
321.89 | 322.44 | 3,134.28 | 1.9531 | 34554 B |
| DeleteItemNotExists | OfT | False | 391.12 | 3.54 | 3.31 | 395.50 |
396.20 | 397.32 | 2,556.78 | 2.4414 | 43436 B |
| ReadFeed | OfT | False | 2029.51 | 7.11 | 6.66 | 2039.60 | 2042.04 |
2042.66 | 492.73 | 31.25 | 538238 B |
| ReadItemExists | OfT | False | 346.53 | 5.90 | 5.52 | 352.76 | 352.88
| 354.15 | 2,885.73 | 1.9531 | 35811 B |
| ReadItemNotExists | OfT | False | 405.45 | 3.66 | 3.25 | 409.30 |
409.57 | 409.94 | 2,466.38 | 1.9531 | 44705 B |
| UpdateItem | OfT | False | 333.98 | 6.46 | 6.64 | 343.40 | 345.68 |
346.49 | 2,994.15 | 1.9531 | 38745 B |
| UpsertItem | OfT | False | 336.87 | 6.55 | 7.54 | 347.87 | 351.73 |
352.27 | 2,968.51 | 1.9531 | 41297 B |
| QuerySinglePartitionOnePage | OfT | False | 4853.18 | 93.51 | 134.12 |
4984.12 | 5078.05 | 5153.95 | 206.05 | 101.56 | 2184586 B |
| QuerySinglePartitionMultiplePages | OfT | False | 29185.41 | 417.55 |
390.58 | 29575.65 | 29584.94 | 29591.58 | 34.26 | 593.75 | 13006177 B|
| CreateItem | OfT | False | 343.09 | 2.56 | 2.00 | 345.05 | 345.95 |
347.00 | 2,914.70 | 1.9531 | 34781 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
False | 0.01 | 0.00 | 0.00 | 0.01 | 0.01 | 0.01 | 71,558,237.41 | - | -
|
| DeleteItemExists | OfT | False | 327.41 | 4.76 | 4.22 | 331.34 |
333.39 | 335.29 | 3,054.24 | 1.4648 | 30067 B |
| DeleteItemNotExists | OfT | False | 395.30 | 4.27 | 3.99 | 400.34 |
401.55 | 402.10 | 2,529.75 | 1.9531 | 39050 B |
| ReadFeed | OfT | False | 2026.36 | 9.99 | 9.35 | 2037.72 | 2038.93 |
2040.85 | 493.50 | 31.25 | 538229 B |
| ReadItemExists | OfT | False | 350.31 | 5.96 | 5.28 | 356.28 | 357.49
| 358.94 | 2,854.61 | 1.9531 | 31354 B |
| ReadItemNotExists | OfT | False | 409.55 | 5.46 | 5.10 | 416.43 |
417.63 | 419.87 | 2,441.68 | 1.9531 | 40324 B |
| UpdateItem | OfT | False | 347.23 | 4.33 | 4.05 | 350.79 | 352.32 |
355.43 | 2,879.90 | 1.9531 | 35012 B |
| UpsertItem | OfT | False | 354.04 | 4.29 | 4.01 | 359.55 | 359.84 |
360.31 | 2,824.53 | 1.9531 | 34997 B |
| QuerySinglePartitionOnePage | OfT | False | 4833.96 | 67.22 | 59.59 |
4887.08 | 4909.85 | 4946.76 | 206.87 | 101.56 | 2184671 B |
| QuerySinglePartitionMultiplePages | OfT | False | 29571.21 | 525.13 |
491.21 | 29334.47 | 29338.17 | 29343.42 | 65.48 | 593.75 | 13006177 B |




Performance Tests after the change:
| Method | Type | EnableBinaryResponseOnPointOperations | Mean (µs) |
Error (µs) | StdDev (µs) | P90 (µs) | P95 (µs) | P100 (µs) | Op/s | Gen0
| Allocated |

|------------------------------------------------------------------|--------|---------------------------------------|----------|-----------|------------|----------|----------|----------|-----------------|--------|------------|
| CreateItem | Stream | False | 305.47 | 6.01 | 6.43 | 315.16 | 315.90 |
317.74 | 3,273.60 | 1.4648 | 26794 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | Stream
| False | 292.63 | 1.55 | 1.29 | 294.24 | 294.62 | 294.94 | 3,417.31 |
1.4648 | 26793 B |
| DeleteItemExists | Stream | False | 301.75 | 3.40 | 3.01 | 305.77 |
306.77 | 308.51 | 3,314.00 | 1.4648 | 26827 B |
| DeleteItemNotExists | Stream | False | 321.53 | 5.30 | 4.96 | 327.87 |
328.66 | 329.84 | 3,110.16 | 2.4414 | 40038 B |
| ReadFeed | Stream | False | 354.59 | 3.88 | 3.63 | 358.94 | 360.12 |
360.50 | 2,820.16 | 1.9531 | 36978 B |
| ReadItemExists | Stream | False | 319.79 | 3.04 | 2.54 | 323.22 |
324.29 | 325.10 | 3,127.04 | 1.4648 | 28080 B |
| ReadItemNotExists | Stream | False | 340.28 | 5.37 | 5.02 | 345.94 |
346.43 | 346.75 | 2,938.71 | 2.4414 | 41295 B |
| UpdateItem | Stream | False | 295.47 | 3.20 | 2.84 | 298.46 | 299.41 |
301.13 | 3,384.39 | 1.4648 | 27002 B |
| UpsertItem | Stream | False | 298.47 | 4.36 | 3.87 | 302.32 | 303.41 |
305.06 | 3,350.45 | 1.4648 | 27002 B |
| QuerySinglePartitionOnePage | Stream | False | 2512.89 | 13.89 | 12.99
| 2525.53 | 2528.71 | 2535.11 | 397.95 | 58.5938| 996766 B |
| QuerySinglePartitionMultiplePages | Stream | False | 15480.71 | 47.08
| 44.03 | 15522.17 | 15534.46 | 15552.77 | 64.60 | 343.75 | 5880820 B |
| CreateItem | Stream | True | 298.14 | 1.95 | 1.73 | 300.25 | 300.89 |
301.38 | 3,354.10 | 1.4648 | 27754 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | Stream
| True | 306.86 | 2.51 | 2.22 | 309.80 | 310.31 | 310.85 | 3,258.82 |
1.4648 | 29625 B |
| DeleteItemExists | Stream | True | 303.48 | 2.17 | 1.92 | 305.49 |
305.90 | 306.43 | 3,295.13 | 1.4648 | 27250 B |
| DeleteItemNotExists | Stream | True | 335.40 | 4.51 | 4.22 | 338.92 |
341.18 | 345.82 | 2,981.50 | 1.9531 | 35839 B |
| ReadFeed | Stream | True | 413.71 | 16.33 | 48.14 | 468.34 | 490.55 |
554.75 | 2,417.14 | 1.9531 | 37467 B |
| ReadItemExists | Stream | True | 327.74 | 6.54 | 5.80 | 334.66 |
337.14 | 340.58 | 3,051.21 | 1.4648 | 28529 B |
| ReadItemNotExists | Stream | True | 355.90 | 4.03 | 3.58 | 359.56 |
361.23 | 363.69 | 2,809.75 | 1.9531 | 37093 B |
| UpdateItem | Stream | True | 306.29 | 5.59 | 7.27 | 315.91 | 318.38 |
325.81 | 3,264.85 | 1.4648 | 28646 B |
| UpsertItem | Stream | True | 306.33 | 4.31 | 3.60 | 310.21 | 312.14 |
314.57 | 3,264.47 | 1.4648 | 27981 B |
| QuerySinglePartitionOnePage | Stream | True | 2515.12 | 11.21 | 9.94 |
2524.59 | 2529.21 | 2537.47 | 397.59 | 58.5938| 996766 B |
| QuerySinglePartitionMultiplePages | Stream | True | 15397.03 | 152.24
| 134.96 | 15495.62 | 15532.86 | 15601.85 | 64.95 | 343.75 | 5880663 B |
| CreateItem | OfT | False | 324.88 | 2.15 | 1.68 | 325.97 | 326.74 |
327.67 | 3,078.11 | 1.9531| 38537 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
False | 0.01 | 0.00 | 0.00 | 0.01 | 0.01 | 0.01 | 72,548,143.66 | - | -
|
| DeleteItemExists | OfT | False | 321.54 | 4.33 | 3.84 | 325.91 |
326.31 | 326.55 | 3,110.02 | 1.9531| 34533 B |
| DeleteItemNotExists | OfT | False | 393.26 | 6.70 | 6.27 | 402.53 |
403.30 | 404.96 | 2,542.83 | 2.4414| 43429 B |
| ReadFeed | OfT | False | 2139.60 | 31.19 | 32.03 | 2166.32 | 2189.26 |
2242.76 | 467.38 | 31.25 | 538217 B |
| ReadItemExists | OfT | False | 346.27 | 4.45 | 3.94 | 351.42 | 352.45
| 353.44 | 2,887.95 | 1.9531| 35794 B |
| ReadItemNotExists | OfT | False | 412.37 | 4.98 | 4.41 | 418.29 |
418.86 | 419.20 | 2,425.01 | 1.9531| 44703 B |
| UpdateItem | OfT | False | 339.21 | 5.01 | 4.69 | 344.19 | 345.27 |
347.15 | 2,948.06 | 1.9531| 38753 B |
| UpsertItem | OfT | False | 338.96 | 6.56 | 8.06 | 349.28 | 350.84 |
352.47 | 2,950.16 | 1.9531| 41305 B |
| QuerySinglePartitionOnePage | OfT | False | 4835.19 | 62.24 | 58.22 |
4893.65 | 4900.18 | 4903.42 | 206.82 | 109.38| 2184730 B |
| QuerySinglePartitionMultiplePages | OfT | False | 29545.34 | 558.40 |
597.49 | 29888.00 | 30022.06 | 30592.09 | 33.85 | 562.50| 13006169 B |
| CreateItem | OfT | True | 345.25 | 5.60 | 5.24 | 352.00 | 354.29 |
354.73 | 2,896.48 | 1.9531| 34809 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
True | 0.01 | 0.00 | 0.00 | 0.01 | 0.01 | 0.01 | 71,222,536.20 | - | - |
| DeleteItemExists | OfT | True | 326.70 | 4.45 | 3.72 | 330.56 | 330.73
| 330.84 | 3,060.89 | 1.4648| 30067 B |
| DeleteItemNotExists | OfT | True | 391.82 | 4.45 | 4.16 | 396.14 |
397.58 | 400.23 | 2,552.16 | 1.9531| 39050 B |
| ReadFeed | OfT | True | 2108.14 | 5.97 | 4.99 | 2112.07 | 2114.55 |
2117.97 | 474.35 | 31.25 | 538231 B |
| ReadItemExists | OfT | True | 351.85 | 6.05 | 5.66 | 356.63 | 359.29 |
365.25 | 2,842.09 | 1.9531| 31351 B |
| ReadItemNotExists | OfT | True | 413.03 | 6.76 | 5.99 | 421.71 |
422.77 | 424.03 | 2,421.14 | 1.9531| 40340 B |
| UpdateItem | OfT | True | 352.24 | 6.81 | 7.00 | 362.11 | 363.40 |
365.63 | 2,838.96 | 1.9531| 35013 B |
| UpsertItem | OfT | True | 352.68 | 5.39 | 4.78 | 357.94 | 360.66 |
363.94 | 2,835.40 | 1.9531| 34997 B |
| QuerySinglePartitionOnePage | OfT | True | 4892.02 | 70.59 | 66.03 |
4953.62 | 4980.92 | 5008.40 | 204.41 | 101.56| 2184656 B |
| QuerySinglePartitionMultiplePages | OfT | True | 29880.67 | 546.15 |
510.87 | 30275.86 | 30369.45 | 30698.68 | 33.47 | 593.75| 13006303 B |
| CreateItem | OfT | False | 331.30 | 6.20 | 5.80 | 340.74 | 342.71 |
343.13 | 3,018.39 | 1.9531| 38533 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
False | 0.01 | 0.00 | 0.00 | 0.01 | 0.01 | 0.01 | 71,418,122.29 | - | -
|
| DeleteItemExists | OfT | False | 324.07 | 4.39 | 4.10 | 328.72 |
330.62 | 333.79 | 3,085.75 | 1.9531| 34532 B |
| DeleteItemNotExists | OfT | False | 392.66 | 4.18 | 3.71 | 397.59 |
398.67 | 399.38 | 2,546.74 | 2.4414| 43439 B |
| ReadFeed | OfT | False | 2077.43 | 7.10 | 6.29 | 2083.17 | 2086.36 |
2091.79 | 481.36 | 31.25 | 538248 B |
| ReadItemExists | OfT | False | 347.83 | 4.68 | 3.91 | 352.45 | 352.84
| 352.99 | 2,874.98 | 1.9531| 31352 B |
| ReadItemNotExists | OfT | False | 415.00 | 6.68 | 6.25 | 424.94 |
426.69 | 427.71 | 2,409.63 | 1.9531| 40323 B |
| UpdateItem | OfT | False | 348.77 | 4.88 | 4.33 | 353.87 | 355.35 |
356.48 | 2,867.18 | 1.9531| 34254 B |
| UpsertItem | OfT | False | 349.78 | 3.86 | 3.42 | 352.97 | 353.56 |
354.62 | 2,858.97 | 1.9531| 34254 B |
| QuerySinglePartitionOnePage | OfT | False | 4747.35 | 94.22 | 100.82 |
4847.31 | 4855.14 | 4892.31 | 210.64 | 101.56| 2184665 B |
| QuerySinglePartitionMultiplePages | OfT | False | 29366.81 | 582.58 |
670.90 | 29876.16 | 29907.80 | 30056.13 | 34.05 | 562.50| 13006844 B |


## Type of change

Please delete options that are not relevant.

- [X] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #IssueNumber

---------

Co-authored-by: Travis Sharp <94011425+msft-tsharp@users.noreply.github.com>
Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
…asses. (#5099)

# Pull Request Template

## Description

Integrating exception handling analyzers rules with Cosmos project.
These rules will enhance stability, prevent performance pitfalls, and
ensure better logging practices. Also, suppressing the rules in certain
places where logging full stack trace is necessary. This PR covers
primarily Exception related classes.

Performance tests in master branch:
| Method | Type | EnableBinaryResponseOnPointOperations | Mean (µs) |
Error (µs) | StdDev (µs) | P90 (µs) | P95 (µs) | P100 (µs) | Op/s | Gen0
| Allocated |

|------------------------------------------------------------------|--------|---------------------------------------|----------|-----------|------------|----------|----------|----------|---------|--------|-----------|
| CreateItem | Stream | False | 298.62 | 3.44 | 3.22 | 302.51 | 303.68 |
305.26 | 3,348.72 | 1.4648 | 26793 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | Stream
| False | 293.50 | 3.65 | 3.42 | 298.33 | 299.08 | 299.83 | 3,407.17 |
1.4648 | 26794 B |
| DeleteItemExists | Stream | False | 300.57 | 4.27 | 3.79 | 305.14 |
307.27 | 310.32 | 3,326.97 | 1.4648 | 26810 B |
| DeleteItemNotExists | Stream | False | 320.20 | 4.38 | 4.09 | 324.52 |
325.98 | 327.49 | 3,123.06 | 2.4414 | 40025 B |
| ReadFeed | Stream | False | 357.41 | 6.62 | 6.51 | 366.23 | 368.86 |
369.54 | 2,797.91 | 1.9531 | 36963 B |
| ReadItemExists | Stream | False | 321.23 | 3.58 | 2.99 | 323.75 |
325.50 | 327.79 | 3,113.08 | 1.4648 | 28089 B |
| ReadItemNotExists | Stream | False | 341.28 | 5.72 | 5.35 | 347.59 |
348.10 | 349.03 | 2,930.18 | 2.4414 | 41293 B |
| UpdateItem | Stream | False | 297.01 | 3.59 | 3.19 | 300.65 | 301.38 |
302.28 | 3,366.87 | 1.4648 | 27002 B |
| UpsertItem | Stream | False | 300.65 | 5.63 | 5.26 | 305.01 | 307.38 |
312.73 | 3,326.08 | 1.4648 | 27006 B |
| QuerySinglePartitionOnePage | Stream | False | 2564.54 | 14.57 | 12.17
| 2578.23 | 2581.78 | 2586.88 | 389.93 | 58.5938| 996767 B |
| QuerySinglePartitionMultiplePages | Stream | False | 15267.89 | 47.63
| 42.22 | 15326.44 | 15338.37 | 15341.00 | 65.50 | 343.75 | 5880526 B |
| CreateItem | Stream | True | 298.07 | 2.73 | 2.42 | 301.19 | 301.91 |
302.77 | 3,354.93 | 1.4648 | 27766 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | Stream
| True | 309.31 | 3.34 | 2.96 | 313.80 | 314.34 | 314.34 | 3,232.97 |
1.4648 | 29648 B |
| DeleteItemExists | Stream | True | 306.23 | 2.56 | 2.27 | 308.96 |
309.65 | 310.26 | 3,265.52 | 1.4648 | 27246 B |
| DeleteItemNotExists | Stream | True | 337.83 | 5.73 | 5.63 | 345.83 |
348.08 | 349.93 | 2,960.05 | 1.9531 | 35828 B |
| ReadFeed | Stream | True | 355.30 | 6.49 | 6.07 | 362.33 | 363.57 |
365.40 | 2,814.52 | 1.9531 | 36971 B |
| ReadItemExists | Stream | True | 327.99 | 6.21 | 6.37 | 334.79 |
338.23 | 339.62 | 3,048.85 | 1.4648 | 28529 B |
| ReadItemNotExists | Stream | True | 354.90 | 3.51 | 3.11 | 358.33 |
359.42 | 361.20 | 2,817.66 | 1.9531 | 37092 B |
| UpdateItem | Stream | True | 307.85 | 4.42 | 3.91 | 311.92 | 312.19 |
312.66 | 3,248.34 | 1.4648 | 27979 B |
| UpsertItem | Stream | True | 310.13 | 6.17 | 9.05 | 323.30 | 323.92 |
324.70 | 3,224.41 | 1.4648 | 28569 B |
| QuerySinglePartitionOnePage | Stream | True | 2547.10 | 13.13 | 10.25
| 2553.99 | 2562.13 | 2571.72 | 392.60 | 58.5938| 996763 B |
| QuerySinglePartitionMultiplePages | Stream | True | 15271.09 | 89.96 |
75.12 | 15334.47 | 15338.17 | 15343.42 | 65.48 | 343.75 | 5880719 B |
| CreateItem | OfT | False | 323.48 | 2.48 | 2.07 | 326.06 | 326.34 |
326.47 | 3,091.37 | 1.9531 | 38537 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
False | 0.01 | 0.00 | 0.00 | 0.01 | 0.01 | 0.01 | 73,066,308.61 | - | -
|
| DeleteItemExists | OfT | False | 319.05 | 2.17 | 1.81 | 320.29 |
321.89 | 322.44 | 3,134.28 | 1.9531 | 34554 B |
| DeleteItemNotExists | OfT | False | 391.12 | 3.54 | 3.31 | 395.50 |
396.20 | 397.32 | 2,556.78 | 2.4414 | 43436 B |
| ReadFeed | OfT | False | 2029.51 | 7.11 | 6.66 | 2039.60 | 2042.04 |
2042.66 | 492.73 | 31.25 | 538238 B |
| ReadItemExists | OfT | False | 346.53 | 5.90 | 5.52 | 352.76 | 352.88
| 354.15 | 2,885.73 | 1.9531 | 35811 B |
| ReadItemNotExists | OfT | False | 405.45 | 3.66 | 3.25 | 409.30 |
409.57 | 409.94 | 2,466.38 | 1.9531 | 44705 B |
| UpdateItem | OfT | False | 333.98 | 6.46 | 6.64 | 343.40 | 345.68 |
346.49 | 2,994.15 | 1.9531 | 38745 B |
| UpsertItem | OfT | False | 336.87 | 6.55 | 7.54 | 347.87 | 351.73 |
352.27 | 2,968.51 | 1.9531 | 41297 B |
| QuerySinglePartitionOnePage | OfT | False | 4853.18 | 93.51 | 134.12 |
4984.12 | 5078.05 | 5153.95 | 206.05 | 101.56 | 2184586 B |
| QuerySinglePartitionMultiplePages | OfT | False | 29185.41 | 417.55 |
390.58 | 29575.65 | 29584.94 | 29591.58 | 34.26 | 593.75 | 13006177 B|
| CreateItem | OfT | False | 343.09 | 2.56 | 2.00 | 345.05 | 345.95 |
347.00 | 2,914.70 | 1.9531 | 34781 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
False | 0.01 | 0.00 | 0.00 | 0.01 | 0.01 | 0.01 | 71,558,237.41 | - | -
|
| DeleteItemExists | OfT | False | 327.41 | 4.76 | 4.22 | 331.34 |
333.39 | 335.29 | 3,054.24 | 1.4648 | 30067 B |
| DeleteItemNotExists | OfT | False | 395.30 | 4.27 | 3.99 | 400.34 |
401.55 | 402.10 | 2,529.75 | 1.9531 | 39050 B |
| ReadFeed | OfT | False | 2026.36 | 9.99 | 9.35 | 2037.72 | 2038.93 |
2040.85 | 493.50 | 31.25 | 538229 B |
| ReadItemExists | OfT | False | 350.31 | 5.96 | 5.28 | 356.28 | 357.49
| 358.94 | 2,854.61 | 1.9531 | 31354 B |
| ReadItemNotExists | OfT | False | 409.55 | 5.46 | 5.10 | 416.43 |
417.63 | 419.87 | 2,441.68 | 1.9531 | 40324 B |
| UpdateItem | OfT | False | 347.23 | 4.33 | 4.05 | 350.79 | 352.32 |
355.43 | 2,879.90 | 1.9531 | 35012 B |
| UpsertItem | OfT | False | 354.04 | 4.29 | 4.01 | 359.55 | 359.84 |
360.31 | 2,824.53 | 1.9531 | 34997 B |
| QuerySinglePartitionOnePage | OfT | False | 4833.96 | 67.22 | 59.59 |
4887.08 | 4909.85 | 4946.76 | 206.87 | 101.56 | 2184671 B |
| QuerySinglePartitionMultiplePages | OfT | False | 29571.21 | 525.13 |
491.21 | 29334.47 | 29338.17 | 29343.42 | 65.48 | 593.75 | 13006177 B |



Performance test result after change:
| Method | Type | EnableBinaryResponseOnPointOperations | Mean (µs) |
Error (µs) | StdDev (µs) | P90 (µs) | P95 (µs) | P100 (µs) | Op/s | Gen0
| Allocated |
|--------------------------------------------------------------|-------
|---------------------------------------|----------|-----------|------------|---------|---------|----------|----------|--------|----------|
| CreateItem | Stream | False | 309.95 | 5.63 | 5.78 | 316.18 | 318.85 |
324.13 | 3,226.29 | 1.4648 | 26828 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | Stream
| False | 297.41 | 5.89 | 6.05 | 303.29 | 305.38 | 312.85 | 3,362.38 |
1.4648 | 26785 B |
| DeleteItemExists | Stream | False | 304.97 | 5.83 | 5.72 | 311.76 |
313.26 | 316.19 | 3,279.06 | 1.4648 | 26819 B |
| DeleteItemNotExists | Stream | False | 322.46 | 5.78 | 5.41 | 329.92 |
330.20 | 330.51 | 3,101.18 | 2.4414 | 40026 B |
| ReadFeed | Stream | False | 358.19 | 7.04 | 8.38 | 366.07 | 370.52 |
375.58 | 2,791.81 | 1.9531 | 39854 B |
| ReadItemExists | Stream | False | 323.67 | 3.36 | 2.62 | 326.31 |
326.62 | 326.90 | 3,089.60 | 1.4648 | 28083 B |
| ReadItemNotExists | Stream | False | 340.32 | 5.56 | 4.93 | 346.16 |
347.27 | 349.04 | 2,938.40 | 2.4414 | 41303 B |
| UpdateItem | Stream | False | 296.51 | 4.05 | 3.16 | 299.90 | 300.13 |
300.22 | 3,372.52 | 1.4648 | 27034 B |
| UpsertItem | Stream | False | 298.76 | 3.93 | 3.49 | 302.42 | 302.75 |
303.10 | 3,347.11 | 1.4648 | 26994 B |
| QuerySinglePartitionOnePage | Stream | False | 2502.77 | 10.76 | 10.07
| 2514.51 | 2518.60 | 2520.50 | 399.56 | 58.5938| 996775 B |
| QuerySinglePartitionMultiplePages | Stream | False | 16028.76 | 90.31
| 84.48 | 16076.09| 16147.29| 16156.73 | 62.39 | 343.75 | 5880642 B|
| CreateItem | Stream | True | 298.84 | 3.51 | 3.11 | 302.63 | 303.81 |
305.58 | 3,346.31 | 1.4648 | 27778 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | Stream
| True | 308.80 | 2.81 | 2.49 | 312.65 | 313.72 | 313.93 | 3,238.29 |
1.4648 | 29641 B |
| DeleteItemExists | Stream | True | 307.42 | 5.97 | 5.59 | 315.43 |
317.64 | 318.78 | 3,252.92 | 1.4648 | 27266 B |
| DeleteItemNotExists | Stream | True | 339.64 | 5.49 | 5.14 | 346.17 |
348.57 | 351.29 | 2,944.27 | 1.9531 | 35845 B |
| ReadFeed | Stream | True | 354.00 | 6.26 | 5.86 | 362.97 | 364.14 |
364.97 | 2,824.86 | 1.9531 | 36954 B |
| ReadItemExists | Stream | True | 329.20 | 5.00 | 4.43 | 333.45 |
334.50 | 336.40 | 3,037.68 | 1.4648 | 28538 B |
| ReadItemNotExists | Stream | True | 354.45 | 4.31 | 4.03 | 359.28 |
360.34 | 362.09 | 2,821.29 | 1.9531 | 37099 B |
| UpdateItem | Stream | True | 302.92 | 5.01 | 5.36 | 309.54 | 312.33 |
317.00 | 3,301.23 | 1.4648 | 27986 B |
| UpsertItem | Stream | True | 305.08 | 5.71 | 5.06 | 313.40 | 315.42 |
315.72 | 3,277.86 | 1.4648 | 27970 B |
| QuerySinglePartitionOnePage | Stream | True | 2500.07 | 17.19 | 16.08
| 2519.20 | 2522.95 | 2526.71 | 399.99 | 58.5938| 996764 B |
| QuerySinglePartitionMultiplePages | Stream | True | 15252.42 | 66.76 |
62.45 | 15317.89| 15328.21| 15339.60 | 65.56 | 343.75 | 5888955 B|
| CreateItem | OfT | False | 330.92 | 5.60 | 4.97 | 335.58 | 336.14 |
337.14 | 3,021.92 | 1.9531 | 38522 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
False | 0.01 | 0.06 | 0.06 | 0.01 | 0.01 | 0.01 | 69,687,125.02 | - | -
|
| DeleteItemExists | OfT | False | 325.49 | 3.88 | 3.44 | 328.22 |
329.50 | 331.26 | 3,072.26 | 1.9531 | 34524 B |
| DeleteItemNotExists | OfT | False | 393.82 | 7.73 | 7.23 | 404.79 |
407.05 | 407.49 | 2,539.26 | 2.4414 | 43428 B |
| ReadFeed | OfT | False | 2109.14 | 14.32 | 12.70 | 2122.85 | 2131.02 |
2138.43 | 474.13 | 31.25 | 538238 B |
| ReadItemExists | OfT | False | 351.33 | 6.72 | 6.60 | 358.20 | 361.21
| 362.63 | 2,846.32 | 1.9531 | 35805 B |
| ReadItemNotExists | OfT | False | 414.06 | 6.13 | 5.44 | 420.64 |
422.08 | 423.30 | 2,415.14 | 1.9531 | 44689 B |
| UpdateItem | OfT | False | 336.19 | 5.90 | 5.51 | 342.73 | 344.05 |
345.11 | 2,974.48 | 1.9531 | 38745 B |
| UpsertItem | OfT | False | 343.39 | 6.34 | 10.76 | 351.61 | 359.75 |
371.80 | 2,912.15 | 1.9531 | 38888 B |
| QuerySinglePartitionOnePage | OfT | False | 4786.99 | 95.60 | 110.09 |
4906.45 | 4940.55 | 5009.70 | 208.90 | 109.38 | 2184618 B|
| QuerySinglePartitionMultiplePages | OfT | False | 29570.06 | 565.43 |
528.91 | 29902.47| 30022.06| 30592.09 | 33.82 | 562.50 | 13006347 B|
| CreateItem | OfT | True | 343.29 | 4.66 | 4.13 | 348.67 | 350.42 |
351.73 | 2,913.00 | 1.9531 | 34793 B |
| CreateStreamItem_EnableBinaryResponseOnPointOperations_False | OfT |
True | 0.01 | 0.07 | 0.07 | 0.01 | 0.01 | 0.01 | 71,447,042.70| - | - |
| DeleteItemExists | OfT | True | 327.13 | 2.83 | 2.50 | 330.40 | 331.12
| 331.70 | 3,056.91 | 1.4648 | 30080 B |
| DeleteItemNotExists | OfT | True | 392.30 | 3.11 | 2.75 | 395.59 |
396.99 | 400.23 | 2,549.04 | 1.9531 | 39082 B |
| ReadFeed | OfT | True | 2074.32 | 15.91 | 13.29 | 2089.53 | 2097.96 |
2117.97 | 482.09 | 31.25 | 538230 B |
| ReadItemExists | OfT | True | 349.51 | 5.00 | 4.68 | 355.12 | 356.71 |
357.96 | 2,861.14 | 1.9531 | 31366 B |
| ReadItemNotExists | OfT | True | 412.53 | 3.25 | 2.71 | 415.29 |
415.47 | 415.64 | 2,424.07 | 1.9531 | 40332 B |
| UpdateItem | OfT | True | 358.54 | 7.09 | 7.58 | 367.16 | 367.90 |
371.43 | 2,789.06 | 1.9531 | 35019 B |
| UpsertItem | OfT | True | 352.48 | 6.11 | 5.71 | 359.58 | 361.67 |
362.15 | 2,837.03 | 1.9531 | 35001 B |
| QuerySinglePartitionOnePage | OfT | True | 4762.18 | 88.68 | 82.95 |
4853.23 | 4894.10 | 4952.79 | 209.99 | 101.56 | 2184647 B|
| QuerySinglePartitionMultiplePages | OfT | True | 29420.01 | 533.89 |
571.26 | 29971.62| 30290.42| 30610.08 | 33.99 | 562.50 | 13006198 B|


## Type of change

Please delete options that are not relevant.

- [X] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #IssueNumber

---------

Co-authored-by: Travis Sharp <94011425+msft-tsharp@users.noreply.github.com>
Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
# Pull Request Template

## Description

This PR introduces the partition level failover (PPAF + PPCB) for
Gateway Mode. The changes are mainly done in the `GatewayStoreModel`
which leverages the `GlobalPartitionEndpointManager` to apply the
partition level override.

Since the gateway mode data plane requests are retried through the
`ClientRetryPolicy`, the inbuild logic for the `Direct` mode suffices
the need for triggering the partition level fail over on certain error
codes.

As a part of the changes, we also introduced a new timeout policy
`HttpTimeoutPolicyForPartitionFailover` to fail fast the gateway
requests.

## Type of change

Please delete options that are not relevant.

- [x] New feature (non-breaking change which adds functionality)

## Closing issues

To automatically close an issue: closes #4982
## Description

### Changes in Metric and Unit Names

| Metric Name (Old) | Metric Name (New) | Otel Official Link|

|-------------------------------------|--------------------------------------|---------|
| `db.client.response.row_count` | `db.client.response.returned_rows` |
https://opentelemetry.io/docs/specs/semconv/database/cosmosdb/#metric-dbclientresponsereturned_rows
|

| Metric Name | Old Unit | New Unit | Otel Official Link|

|--------------------------------------|-----------|----------------|-----------------|
| `db.client.response.returned_rows` | `#` | `{item}` |
https://opentelemetry.io/docs/specs/semconv/database/database-metrics/#metric-dbclientresponsereturned_rows
|
| `azure.cosmosdb.client.active_instance.count` | `#` | `{instance}` |
https://opentelemetry.io/docs/specs/semconv/database/cosmosdb/#metric-azurecosmosdbclientactive_instancecount
|
| `db.client.response.request_unit` | `# RU` | `{request_unit}` |
https://opentelemetry.io/docs/specs/semconv/database/cosmosdb/#metric-azurecosmosdbclientoperationrequest_charge
|

Since, this feature is under preview, Hence, not following versioning
for this.

## Type of change
- [] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #5066
)

## Description

Adds support for reading and writing user string encoded binary data in
JsonReader, JsonWriter, and JsonNavigator.

Note: This is being introduced to support an internal scenario. For now,
user string encoded data will NOT be sent over the wire to the client.

## Type of change
- [x] New feature (non-breaking change which adds functionality)
…me (#5105)

## Description

Renames internal interface.

## Type of change

Please delete options that are not relevant.

- [] Bug fix (non-breaking change which fixes an issue)
- [] New feature (non-breaking change which adds functionality)
- [] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [] This change requires a documentation update
…layed incorrectly in diagnostics. (#5106)

# Pull Request Template

## Description

This pull request includes several changes to the
`Microsoft.Azure.Cosmos` project, focusing on improving the handling and
testing of sub-status codes in the tracing functionality. The most
significant changes include the addition of a new method to map
sub-status codes to more descriptive strings, updates to unit tests to
validate these changes.

### Improvements to sub-status code handling:

*
[`Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceJsonWriter.cs`](diffhunk://#diff-2d305bb945ccb69fdb9eb3404e3d1016302f0bc22a5d32c879513834ed9e9c0fL397-R397):
Added the `GetSubStatusCodeString` method to map sub-status codes to
more descriptive strings based on the status code. Updated the
`Visit(StoreResult storeResult)` method to use this new mapping method.
[[1]](diffhunk://#diff-2d305bb945ccb69fdb9eb3404e3d1016302f0bc22a5d32c879513834ed9e9c0fL397-R397)
[[2]](diffhunk://#diff-2d305bb945ccb69fdb9eb3404e3d1016302f0bc22a5d32c879513834ed9e9c0fR455-R564)

## Type of change

Please delete options that are not relevant.

- [] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #5104
…uest. (#5109)

# Pull Request Template

## Description

Adding ResourceId as the proxy expects the ResourceId in the RNTBD
headers otherwise the requests will start to fail.
By seting request.ResourceId = containerRid, TransportSerialization.cs
will automatically add the ResourceID header.

## Type of change

Please delete options that are not relevant.
- [x] New feature (non-breaking change which adds functionality)

## Closing issues

To automatically close an issue: closes #5107
… properties after retrieval from Gateway. (#5088)

# Pull Request Template

## Description

The goal of this task is to fetch the thin proxy endpoint from gateway,
so that from the .NET sdk side, we could remove the dependency on the
hard coded thin proxy endpoint.

Updating the AccountProperties class to capture the thin proxy endpoint
from thinClientWritableLocations property.
Have tested the change end to end against thinclient stag endpoint.

Currently the GW-SDK contract with thinclient enabled is like this but
once thinclient is live the endpoint value will be retrieved via
readableLocations and writableLocations.

```
{
	"_self": "",
	"id": "sumanttest4-westeurope",
	"_rid": "sumanttest4-westeurope.sql.cosmos.windows-int.net",
	"media": "//media/",
	"addresses": "//addresses/",
	"_dbs": "//dbs/",
	"writableLocations": [
		{
			"name": "West Europe",
			"databaseAccountEndpoint": "https://sumanttest4-westeurope.documents-test.windows-int.net:443/"
		}
	],
	"readableLocations": [
		{
			"name": "West Europe",
			"databaseAccountEndpoint": "https://sumanttest4-westeurope.documents-test.windows-int.net:443/"
		}
	],
	"enableMultipleWriteLocations": false,
	"continuousBackupEnabled": false,
	"enableNRegionSynchronousCommit": false,
	"userReplicationPolicy": {
		"asyncReplication": false,
		"minReplicaSetSize": 2,
		"maxReplicasetSize": 4
	},
	"userConsistencyPolicy": {
		"defaultConsistencyLevel": "Session"
	},
	"systemReplicationPolicy": {
		"minReplicaSetSize": 3,
		"maxReplicasetSize": 4
	},
	"readPolicy": {
		"primaryReadCoefficient": 1,
		"secondaryReadCoefficient": 1
	},
	"queryEngineConfiguration": "{\"allowNewKeywords\":true,\"maxJoinsPerSqlQuery\":10,\"maxQueryRequestTimeoutFraction\":0.9,\"maxSqlQueryInputLength\":524288,\"maxUdfRefPerSqlQuery\":10,\"queryMaxInMemorySortDocumentCount\":-1000,\"spatialMaxGeometryPointCount\":256,\"sqlAllowNonFiniteNumbers\":false,\"sqlDisableOptimizationFlags\":0,\"sqlQueryILDisableOptimizationFlags\":0,\"clientDisableOptimisticDirectExecution\":false,\"queryEnableFullText\":false,\"enableSpatialIndexing\":true,\"maxInExpressionItemsCount\":2147483647,\"maxLogicalAndPerSqlQuery\":2147483647,\"maxLogicalOrPerSqlQuery\":2147483647,\"maxSpatialQueryCells\":2147483647,\"sqlAllowAggregateFunctions\":true,\"sqlAllowGroupByClause\":true,\"sqlAllowLike\":true,\"sqlAllowSubQuery\":true,\"sqlAllowScalarSubQuery\":true,\"sqlAllowTop\":true}",
	"**thinClientWritableLocations**": [
		{
			"name": "West Europe",
			"databaseAccountEndpoint": "https://sumanttest4-westeurope.documents-test.windows-int.net:10650/"
		}
	],
	"**thinClientReadableLocations**": [
		{
			"name": "West Europe",
			"databaseAccountEndpoint": "https://sumanttest4-westeurope.documents-test.windows-int.net:10650/"
		}
	]
}

```

## Type of change

Please delete options that are not relevant.

- [x] New feature (non-breaking change which adds functionality)

## Closing issues

To automatically close an issue: closes #4999

---------

Co-authored-by: Debdatta Kunda <dkunda@microsoft.com>
Co-authored-by: Debdatta Kunda <87335885+kundadebdatta@users.noreply.github.com>
…5101)

# Pull Request Template

## Description

This change also includes a change to the IChaosInterceptor interface
which adds `CancellationToken` support to the HTTP methods.

- Direct Package Changes: Moves to EN20250120 release branch
- Fixed the Connection state completion status to fix
AggressiveTimeoutDetection
- Optimize query plan for hybrid search
- Session Consistency: Adds SessionTokenMismatchRetryPolicy optimization
through customer supplied region switch hints
- Enabling thoughput actions behind a feature flag for 
Fabric Accounts
- [Fabric] Return proper error when failed to get permi
ssion from RG.

## Type of change

Please delete options that are not relevant.

- [] New feature (non-breaking change which adds functionality)

## Closing issues

To automatically close an issue: closes #IssueNumber

---------

Co-authored-by: Neil Deshpande (from Dev Box) <ndeshpan@microsoft.com>
Co-authored-by: neildsh <35383880+neildsh@users.noreply.github.com>
Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
…mode check. (#5115)

# Pull Request Template

## Description
Fixing two issues found during testing:

- Fixing the issue of getting thinclient readable and writeable
locations through `ParseThinClientLocationsFromAdditionalProperties`.
Need this call at `GlobalEndpointManager`.
`InitializeAccountPropertiesAndStartBackgroundRefresh()` stage as well
otherwise the returned endpoint returned is a stale value.

- Fixing the thinclient mode check so that if thinclient flag is enabled
then thinclient mode is be used during gateway mode and direct mode.

## Type of change

Please delete options that are not relevant.

- [X] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #5116
…uery plan optimization (#5120)

## Description
This change adds a configuration whose value will be read from the
environment variable
`AZURE_COSMOS_HYBRID_SEARCH_QUERYPLAN_OPTIMIZATION_DISABLED`. If this
evaluates to true, then the optimization for skipping the order by
rewrite for hybrid search is disabled.

The environment variable is read, and the value is propagated as an
internally visible query request option. This is plumbed down in the
query plan APIs where it is either used to populate the supported query
features header in case of a gateway or it is used as a flag passed into
ServiceInterop.

## Type of change
- [x] New feature (non-breaking change which adds functionality)
…retried with a client cold start with only query requests (#5108)

# Pull Request Template

## Description

### Context 

Currently, there is a bug in the SDK where upon a cold start of the SDK
and rare edge cases involving online/offline-ing regions, where only
query requests are made, the SDK will not retry certain status code
responses from metadata requests causing the entire request to fail. The
correct behavior would be for the SDK to do cross region retries on
these metadata requests.

This pulls request includes several updates to enhance error handling
and retry logic in the Cosmos DB SDK. The changes mainly focus on
extending support for additional server error types and improving retry
policies for various scenarios.

### Improvements to retry logic:

*
[`ClientRetryPolicy.cs`](diffhunk://#diff-2b056512ca285b1d95e025e31f60345059fa92d958becc38f90a6fb54ce1bbb4R331-R341):
Enhanced retry logic to handle `InternalServerError` ,
`DatabaseAccountNotFound`, and `LeaseNotFound` status codes.
*
[`MetadataRequestThrottleRetryPolicy.cs`](diffhunk://#diff-a5ed5985909c3dcb6e4ce186cdd662d590dac5297ea14e68560c7d1eca307be4L26-R28):
Refactored retry policy to handle additional status codes and renamed
methods and constants to reflect the broader scope of endpoint
unavailability.

### FaultInjection enhancements to error handling testing:

*
[`FaultInjectionRuleBuilder.cs`](diffhunk://#diff-d827164a4a6a0d8737e6598f8132c915ef48a1fc01daaa6422706f770dada5d5L152-R156):
Added support for additional server error types such as
`DatabaseAccountNotFound`, `ServiceUnavailable`, `InternalServerError`,
and `LeaseNotFound` in the for metadata requests.
*
[`FaultInjectionServerErrorType.cs`](diffhunk://#diff-0c89faa9a48c428a7a98662d995474e34295618ac60e677ad9762fd048f33601L75-R82):
Updated the `FaultInjectionServerErrorType` enum to include
`LeaseNotFound` and corrected the status code for
`DatabaseAccountNotFound`.
*
[`FaultInjectionServerErrorResultInternal.cs`](diffhunk://#diff-1ae8256c6d505a8f3b0a350978a0cc9a08f6234f7328f28f1db14302ee691d72L473-R473):
Added handling for `LeaseNotFound` and updated the status code for
`DatabaseAccountNotFound` in the `GetInjectedServerError` method.
* 
### Testing updates:

*
[`CosmosItemIntegrationTests.cs`](diffhunk://#diff-16d429adf686a32936696d2014afab3fc8faf91f10c880850fb8b30f8b96bb33R153-R214):
Added a new test method
`MetadataEndpointUnavailableCrossRegionalRetryTest` to validate the
retry logic for various server error types.
*
[`ClientRetryPolicyTests.cs`](diffhunk://#diff-d3fdfdc5d4f4d8af2c2cc463d928285680e7695861422ef2e3330d1a956807e1L167-R176):
Extended existing tests to cover additional status codes and substatus
codes.

## Type of change

Please delete options that are not relevant.

- [] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #4710

---------

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
…5124)

# Pull Request Template

## Description

Hotfix will include crucial bugfix:
#5108

## Type of change

Please delete options that are not relevant.

## Closing issues

To automatically close an issue: closes #IssueNumber
…est and Response Stream Conversation (#5123)

# Pull Request Template

## Description

Create a new internal cosmos client options: `EnableStreamPassThrough`
to enable or disable the request/ response stream conversation. When
enabled, the request and/or response stream would not be converted to
the desired target serialization type and would act just like a
pass-through. The default value for this parameter is `False`.

**Usage:**

```
      CosmosClientOptions clientOptions = new CosmosClientOptions()
      {
          EnableStreamPassThrough = true,
      };

      CosmosClient cosmosClient = new (
          endpoint,
          authKey,
          clientOptions);
```

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)

## Closing issues

To automatically close an issue: closes #5122
…#5134)

# Pull Request Template

## Description

This PR adds visibility to the rest of the new query oracle namespace
(job executor and unit test

## Type of change

Please delete options that are not relevant.

- [] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [] This change requires a documentation update

## Closing issues

To automatically close an issue: closes #IssueNumber

Co-authored-by: Minh Le <leminh@microsoft.com>
#5127)

Adding support for accepting unknownRntbd headers from backend.

- [] Bug fix (non-breaking change which fixes an issue)

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
Co-authored-by: Debdatta Kunda <87335885+kundadebdatta@users.noreply.github.com>
…n through customer supplied region switch hints (#5128)

This PR will allow application developers to configure hints through a
SessionRetryOptions instance which will signal to the SDK whether to pin
retries on the local region or move quicker to a remote region when
READ_SESSION_NOT_AVAILABLE errors are thrown.
[] New feature (non-breaking change which adds functionality)

---------

Co-authored-by: Fabian Meiswinkel <fabianm@microsoft.com>
… in AddressEnumerator (#5126)

Due to a race condition between modifying and reading a shared variable
FailedEndpoints which is instantiated in the
DocumentServiceRequestContext class. multiple threads seems to be
accessing it at the same time - one adding to it in the
AddToFailedEndpoints() method in the DocumentServiceRequestContext and
the other in the AddressEnumerator where it is trying to read an item in
the GetEffectiveStatus() method which is called with in
MoveFailedReplicasToTheEnd() and it results in an
IndexOutOfRangeException . We need to move to a thread safe data
structure.

[] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes
#5046

---------

Co-authored-by: Debdatta Kunda <87335885+kundadebdatta@users.noreply.github.com>
…uest. (#5119)

# Pull Request Template

## Description

Update the logic for retrieving and setting RNTBD headers resourceId and
collectionRid for proxy request. With the current implementation the
request ends up throwing a 400 Bad Request error.

## Type of change

Please delete options that are not relevant.

- [X] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #5118

---------

Co-authored-by: Debdatta Kunda <87335885+kundadebdatta@users.noreply.github.com>
# Pull Request Template

## Description

During some of the internal binary encoding opt-in customer workload
validation, it was identified that when the cosmos .net SDK is
initialized with binary encoding, and a date time field is persisted
into a database, the value is getting converted and stored as in non-ISO
format.

Cosmos Client Creation:

```
        Environment.SetEnvironmentVariable(ConfigurationManager.BinaryEncodingEnabled, "True");
        string databaseName = "binary-encoding-db";
        string containerName = "binary-encoding-container";
        CosmosClientOptions clientOptions = new()
        {
            ConnectionMode = ConnectionMode.Direct,
            RequestTimeout = TimeSpan.FromSeconds(5000),
        };

        CosmosClient client = new CosmosClient(connectionString,
            clientOptions);

        ItemResponse<ToDoActivity> itemResponse = await container.CreateItemAsync(item);
```

Sample Data Saved in Container, when binary encoding is **Disabled** in
the SDK:


![Image](https://github.com/user-attachments/assets/4e2e17cf-80fa-48d3-9e3a-3a2c7497ee2e)

Sample Data Saved in Container, when binary encoding is **Enabled** in
the SDK:


![Image](https://github.com/user-attachments/assets/e662e8af-821a-48a4-9744-c094fa801e48)

This PR is fixing the above parsing gap. It appears that when a stream
is sent to the backend in `Text` format, the backend does some
formatting on the incoming stream, that converts `DateTime` fields into
`ISO 8601` format and stores it.


![image](https://github.com/user-attachments/assets/7638d0de-ad83-4920-b431-3de405a7a04f)

Per my analysis, when binary encoding is enabled, and the stream sent to
backend is in Binary format, the backend doesn't do any extra formatting
on the binary stream, and stores the stream as is. Therefore, [the
round-trip ("O", "o") format
specifier](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#Roundtrip)
in the SDK layer is ideal to keep the `DateTime` field preserved in ISO
standard, when binary encoding is enabled,

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)

## Closing issues

To automatically close an issue: closes #5132
# Pull Request Template

## Description

This PR adds support for VectorIndexShardKey from Preview Contract,
along with updating the tests for it.

## Type of change

Please delete options that are not relevant.

- [] New feature (non-breaking change which adds functionality)

## Closing issues

To automatically close an issue: closes #IssueNumber

---------

Co-authored-by: Debdatta Kunda <87335885+kundadebdatta@users.noreply.github.com>
Co-authored-by: Fabian Meiswinkel <fabianm@microsoft.com>
#5139)

## Description

Fixes flip of boolean switch for hybridSearchSkipOrderByRewrite. Adds
test coverage to ensure that we catch stuff like this in the future.

## Type of change
- [x] Bug fix (non-breaking change which fixes an issue)

Co-authored-by: Debdatta Kunda <87335885+kundadebdatta@users.noreply.github.com>
# Pull Request Template

## Description

Adds Version bump, changelog, and contracts for version 3.49.0 release

## Type of change

Please delete options that are not relevant.

- [] New feature (non-breaking change which adds functionality)


## Closing issues

To automatically close an issue: closes #IssueNumber
## Description
This changes allows the projections in a hybrid search query to be
undefined, bringing the behavior of hybrid search in line with other
base pipelines such as the order by pipeline stage and parallel cross
partition pipeline stage.

## Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
kirankumarkolli and others added 7 commits February 2, 2026 10:50
## Description

Adds guidance to the IssueFixAgent plan about fixing bugs at the source
of invalid state rather than adding defensive checks at callers.

### New Anti-Pattern Added

- **Bad:** Add null check at caller when source method returns null
incorrectly
- **Good:** Fix at source of truth - throw exception where invalid state
originates
- **Rule:** ALWAYS fix bugs at the source where invalid state originates

### Why This Matters
- Provides clear error messages at the source
- Prevents the same bug pattern in other callers
- Keeps error handling centralized

### Learned From
Issue #5596 investigation - the fix was to add isDisposed check in
GetStoreProxy() rather than improving the null check in
TransportHandler.

---
*Generated by GitHub Copilot CLI Agent*
## Description

🤖 **This PR was authored by GitHub Copilot**

Adds learnings from issue triage session to the IssueFixAgent plan.

## New Sections Added

### 16.29 GitHub CLI Workarounds
- \gh pr edit --body-file\ is unreliable - use \gh api\ with PATCH
instead
- \gh pr edit --title\ workaround

### 16.30 Sequence Diagrams in PRs
- When to add Mermaid diagrams
- Before/after format for behavior changes
- Benefits for reviewers

### 16.31 Review Feedback Workflow
- Step-by-step process for handling comments
- Reply format with commit SHA
- Re-review request process

## Updated Flaky Test Registry

Added newly discovered flaky tests:
- \RetryTransientIssuesTestAsync\ (EmulatorTests)
- \EmulatorTests_Release_Flaky\ (CI stage)

Added \pre_existing_failures\ section:
- Distinguishes baseline failures from flaky tests
- Lists known failing tests in master

---
*Generated by GitHub Copilot CLI Agent*
## Description

🤖 **This PR was authored by GitHub Copilot**

Adds documentation for the recurring issue where PR descriptions lose
formatting.

## Problem
PR body content gets corrupted:
- Newlines stripped (all content on one line)
- Emojis corrupted (🤖 becomes Γëí╞Æ├▒├╗)
- Markdown headers not rendered

## Root Causes
- PowerShell encoding issues with Out-File
- Using inline `--body` argument instead of `--body-file`
- String handling stripping newlines

## Workaround Added
```powershell
# 1. Write body to file with UTF8 encoding:
$body | Set-Content -Path "body.md" -Encoding UTF8

# 2. Use gh api with -F to read from file:
gh api repos/{owner}/{repo}/pulls/{pr_number} -X PATCH -F body=@body.md
```

## Prevention Rules
- NEVER use inline `--body` with multi-line content
- ALWAYS write to file first
- ALWAYS use UTF8 encoding
- VERIFY formatting after every PR create/update

---
*Generated by GitHub Copilot CLI Agent*
## Description

🤖 **This PR was authored by GitHub Copilot**

Updates PR monitoring guidance to specify consistent 5-10 minute
intervals for both CI and review comment checks.

## Changes

**Before:**
```yaml
frequency: "Check every session or when user requests status"
```

**After:**
```yaml
frequency: "Every 5-10 minutes while session is active"

monitoring_loop:
  interval: "5-10 minutes"
  check_ci: "gh pr checks {pr_number}"
  check_comments: "gh api .../pulls/{pr_number}/comments"
  check_reviews: "gh pr view {pr_number} --json reviews,reviewDecision"
```

## Why
- Consistent monitoring frequency for CI and comments
- Clear commands for each check type
- Explicit actions for each monitoring outcome

---
*Generated by GitHub Copilot CLI Agent*
…FullTextScore (#5582)

# Enabling users to choose global vs local/focused statistics for
FullTextScore

## Why? 

Cosmos DB’s implementation of FullTextScore computes BM25 statistics
(term frequency, inverse document frequency, and document length) across
all documents in the container, including all physical and logical
partitions.

While this provides a valid and comprehensive representation of
statistics for the entire dataset, it introduces challenges for several
common use cases.

In multi-tenant scenarios, it is often necessary to isolate queries to
data belonging to a specific tenant, typically defined by the partition
key or a component of a hierarchical partition key. This enables scoring
to reflect statistics that are accurate for that tenant’s dataset,
rather than for the entire container. For customers such as Veeam and
Sitecore, which operate large multi-tenant containers, this is not just
an optimization but a requirement. Their tenants often operate in very
different domains, which can significantly change the distribution and
importance of keywords and phrases. Using global statistics in these
cases leads to distorted relevance rankings.

In other scenarios involving hundreds or thousands of physical
partitions, computing statistics across the entire container can become
both time-consuming and expensive. Customers may prefer to use
statistics derived from only a subset of partitions to improve
performance and reduce RU consumption. Indeed, there is precedence for
this as Azure AI Search defaults to this “local” method.

## What? 

We propose extending the flexibility of BM25 scoring in Cosmos DB so
that developers can choose between a *global FullTextScore* (existing
behavior) or *Scoped FullTextScore* (statistics computed restricted to
the partition key(s) used in the query). The key aspects:

For _*global*_ BM25, FullTextScore retains its existing behavior and
computes BM25 statistics, such as IDF and average document length,
across all documents in the container regardless of any partition key
filters in the query. In _*scoped*_ BM25, when a query includes a
partition key filter or explicitly requests scoped scoring, the engine
computes these statistics only over the subset of documents within the
specified partition key values. Query results are still returned only
from the filtered partitions, and the resulting scores and ranking
reflect relevance within that partition-specific slice of data.

## How?

The user issues query like: 

```
SELECT TOP 10 * FROM c   
WHERE c.tenantId = @TenantID   
ORDER BY RANK FullTextScore(c.text, "keywords") 
```
 

And sets a new
[QueryRequestOption](../Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs)
called `FullTextScoreScope` which can be set to one of two values:
`local` or `global`. The request option is inspected, and the query uses
scoped/full stats accordingly.

## Type of change

Please delete options that are not relevant.

- [x] New feature (non-breaking change which adds functionality)
## Description

The main changes in this PR include -

* Added a new `DistributedTransactionCommitter` class that manages the
commit process for distributed transactions, including request
enrichment, error handling, and a placeholder for abort logic.
* Introduced `DistributedTransactionCommitterUtils` with a method to
resolve collection resource IDs (RIDs) for all operations in a
transaction, ensuring correct routing and execution.
* Added a `DistributedTransactionRequest` class to encapsulate
transaction operations and associated metadata, such as idempotency
tokens and operation types.
* Updated `CosmosClient` to pass the `ClientContext` when creating a
`DistributedWriteTransactionCore`, enabling downstream components to
access necessary context for transaction execution.# Pull Request
Template

These updates lay the groundwork for executing distributed transactions
with better serialization, error handling, and request management.

*TODO: Add comprehensive tests to test the end-to-end flow of DTS in
SDK*

## Type of change

Please delete options that are not relevant.

- [] Bug fix (non-breaking change which fixes an issue)
- [✓] New feature (non-breaking change which adds functionality)
- [] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [] This change requires a documentation update

## Closing issues

To automatically close an issue: closes #IssueNumber

---------

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

All good!

@yash2710 yash2710 changed the title Users/sync/update_msdata_direct_02_10_2026 msdata/direct: Update from master Feb 10, 2026
@yash2710 yash2710 changed the title msdata/direct: Update from master [Internal] Adds: msdata/direct update from master Feb 11, 2026
@yash2710 yash2710 changed the title [Internal] Adds: msdata/direct update from master [Internal] Direct package: Adds msdata/direct update from master Feb 11, 2026
@kirankumarkolli kirankumarkolli merged commit 72eabd9 into msdata/direct Feb 11, 2026
7 of 8 checks passed
@kirankumarkolli kirankumarkolli deleted the users/sync/update_msdata_direct_02_10_2026 branch February 11, 2026 20:27
microsoft-github-policy-service Bot pushed a commit that referenced this pull request Mar 18, 2026
…script (#5681)

# Pull Request Template

## Description

This PR adds a **Copilot agent** and **PowerShell helper script** to
automate the `msdata/direct` branch sync workflow, which merges the v3
`master` branch into `msdata/direct` and syncs files from the internal
msdata CosmosDB repository.

### Problem

The msdata/direct sync process ([documented
here](docs/sync_up_msdata_direct.md)) is a manual, multi-step workflow
involving branch creation, merging, conflict resolution, file syncing
via `msdata_sync.ps1`, build validation, and PR creation. This process
is error-prone and time-consuming when done manually.

### Solution

Two new automation tools:

#### 1. Copilot Agent
(`.github/agents/msdata-direct-sync-agent.agent.md`)

A structured agent with 5 workflow phases:

| Phase | Description |
|-------|-------------|
| **Phase 1: Environment Setup** | Validates prerequisites (git, dotnet,
gh CLI), prompts for msdata repo path |
| **Phase 2: Branch Preparation** | Creates feature branch from
`msdata/direct`, merges latest `master`, resolves conflicts |
| **Phase 3: msdata File Sync** | Configures and runs `msdata_sync.ps1`
with user-provided repo path, handles missing files |
| **Phase 4: Build Validation** | Runs `dotnet build` to verify sync
succeeded, provides troubleshooting guidance |
| **Phase 5: PR Creation** | Stages, commits, pushes, creates draft PR
with proper format and reviewers |

**Usage:**
```
Follow the msdata/direct sync agent plan in .github/agents/msdata-direct-sync-agent.agent.md
Sync the msdata/direct branch with the latest v3 master and msdata direct codebase.
```

#### 2. PowerShell Helper Script (`tools/msdata-direct-sync-helper.ps1`)

Automates the mechanical parts of the workflow. Can run the full
workflow or individual phases:

```powershell
# Full workflow
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB"

# Individual phases
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase Setup
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase Branch
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase Sync
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase Build
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase PR
```

**Key features:**
- Prompts for msdata repo path at runtime (no hardcoded paths)
- Auto-detects GitHub username for branch naming
- Branch naming: `users/<username>/update_msdata_direct_<mm_dd_yyyy>`
- Automatically reverts `msdata_sync.ps1` path changes after sync
- Creates draft PR with standard reviewers and description
- Phase-by-phase execution for debugging or re-running failed steps

#### 3. Documentation Update (`docs/sync_up_msdata_direct.md`)

Updated to reference the new agent and helper script as recommended
automated alternatives, and added the latest sample PR (#5612).

### Design Decisions

- **msdata repo path prompted at runtime**: Different developers have
the repo at different local paths
- **`[Internal]` PR prefix**: This is internal tooling, not
customer-facing
- **Draft PR by default**: Follows repository convention of creating
drafts first
- **Conflict resolution strategy**: Accept incoming master changes by
default, with manual review flagged for critical files

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## Does this pull request offer a public API change?

No - this is internal tooling only (agent + script), no SDK API changes.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
Meghana-Palaparthi pushed a commit that referenced this pull request Mar 19, 2026
…script (#5681)

# Pull Request Template

## Description

This PR adds a **Copilot agent** and **PowerShell helper script** to
automate the `msdata/direct` branch sync workflow, which merges the v3
`master` branch into `msdata/direct` and syncs files from the internal
msdata CosmosDB repository.

### Problem

The msdata/direct sync process ([documented
here](docs/sync_up_msdata_direct.md)) is a manual, multi-step workflow
involving branch creation, merging, conflict resolution, file syncing
via `msdata_sync.ps1`, build validation, and PR creation. This process
is error-prone and time-consuming when done manually.

### Solution

Two new automation tools:

#### 1. Copilot Agent
(`.github/agents/msdata-direct-sync-agent.agent.md`)

A structured agent with 5 workflow phases:

| Phase | Description |
|-------|-------------|
| **Phase 1: Environment Setup** | Validates prerequisites (git, dotnet,
gh CLI), prompts for msdata repo path |
| **Phase 2: Branch Preparation** | Creates feature branch from
`msdata/direct`, merges latest `master`, resolves conflicts |
| **Phase 3: msdata File Sync** | Configures and runs `msdata_sync.ps1`
with user-provided repo path, handles missing files |
| **Phase 4: Build Validation** | Runs `dotnet build` to verify sync
succeeded, provides troubleshooting guidance |
| **Phase 5: PR Creation** | Stages, commits, pushes, creates draft PR
with proper format and reviewers |

**Usage:**
```
Follow the msdata/direct sync agent plan in .github/agents/msdata-direct-sync-agent.agent.md
Sync the msdata/direct branch with the latest v3 master and msdata direct codebase.
```

#### 2. PowerShell Helper Script (`tools/msdata-direct-sync-helper.ps1`)

Automates the mechanical parts of the workflow. Can run the full
workflow or individual phases:

```powershell
# Full workflow
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB"

# Individual phases
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase Setup
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase Branch
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase Sync
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase Build
.\tools\msdata-direct-sync-helper.ps1 -MsdataRepoPath "Q:\CosmosDB" -Phase PR
```

**Key features:**
- Prompts for msdata repo path at runtime (no hardcoded paths)
- Auto-detects GitHub username for branch naming
- Branch naming: `users/<username>/update_msdata_direct_<mm_dd_yyyy>`
- Automatically reverts `msdata_sync.ps1` path changes after sync
- Creates draft PR with standard reviewers and description
- Phase-by-phase execution for debugging or re-running failed steps

#### 3. Documentation Update (`docs/sync_up_msdata_direct.md`)

Updated to reference the new agent and helper script as recommended
automated alternatives, and added the latest sample PR (#5612).

### Design Decisions

- **msdata repo path prompted at runtime**: Different developers have
the repo at different local paths
- **`[Internal]` PR prefix**: This is internal tooling, not
customer-facing
- **Draft PR by default**: Follows repository convention of creating
drafts first
- **Conflict resolution strategy**: Accept incoming master changes by
default, with manual review flagged for critical files

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## Does this pull request offer a public API change?

No - this is internal tooling only (agent + script), no SDK API changes.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
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.