Skip to content

Enable exception-less execution for 404/1002, 403, and 400 status codes#5560

Merged
kirankumarkolli merged 1 commit intousers/kirankk/enable_exception_lessfrom
copilot/sub-pr-5205-again
Jan 15, 2026
Merged

Enable exception-less execution for 404/1002, 403, and 400 status codes#5560
kirankumarkolli merged 1 commit intousers/kirankk/enable_exception_lessfrom
copilot/sub-pr-5205-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 15, 2026

Enables exception-less execution for session-not-found (404/1002), forbidden (403), and bad-request (400) responses. These scenarios now return status codes instead of throwing exceptions, eliminating exception handling overhead during retries.

Changes

  • RequestMessage.cs: Set UseStatusCodeFor4041002, UseStatusCodeFor403, and UseStatusCodeForBadRequest to true by default
  • ExceptionLessTests.cs: Added FirstChanceException monitoring to validate zero exceptions thrown for these scenarios in both Gateway and Direct modes

Context

Session consistency with stale LSN tokens produces 404/1002 responses during normal operation. Exception-based handling incurs unnecessary overhead:

// Before: Exception thrown and caught during retry
// After: Status code checked, no exception overhead
ResponseMessage response = await container.ReadItemStreamAsync(id, pk, 
    new ItemRequestOptions { SessionToken = staleToken });
// response.StatusCode == 404, SubStatusCode == 1002

Impact

  • Performance: Eliminates exception stack unwinding for common retry scenarios
  • Compatibility: Stream APIs unaffected (already status-code based). Typed APIs catching these specific exceptions will see behavior change.

Reference: https://msdata.visualstudio.com/CosmosDB/_git/CosmosDB?path=/Product/SDK/.net/Microsoft.Azure.Cosmos.Friends/tests/ExceptionLessTests.cs


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add enabling exceptionless for 404 and 403 status codes Enable exception-less execution for 404/1002, 403, and 400 status codes Jan 15, 2026
Copilot AI requested a review from kirankumarkolli January 15, 2026 03:40
@kirankumarkolli kirankumarkolli marked this pull request as ready for review January 15, 2026 03:49
@kirankumarkolli kirankumarkolli merged commit 2d0af85 into users/kirankk/enable_exception_less Jan 15, 2026
2 checks passed
@kirankumarkolli kirankumarkolli deleted the copilot/sub-pr-5205-again branch January 15, 2026 03:49
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.

2 participants