Skip to content

Conversation

@jeet1995
Copy link
Member

@jeet1995 jeet1995 commented Dec 26, 2025

Description

The objective of this PR is to add Owner Resource Not Found (1003) as sub-status code mapping when the owning resource is not found specifically the DocumentCollection resource. The main motivation is disambiguation - is it the child resource not present (such as a document) or its encapsulating resource such as a container. This can help an application developer debug better.

Scenarios tested and fixed

For Direct Mode and Gateway V2 Mode, ensure both container never existed and stale container cache scenarios are appropriately handled.

For Gateway Mode, ensure container never existed scenarios are appropriately handled.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@jeet1995
Copy link
Member Author

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995 jeet1995 changed the title Az cosmos remap sub status for doc requests against non existent container Owner Resource Not Found: Fixes sub-status to 1003 for requests to child resources against non-existent container. Dec 29, 2025
@jeet1995 jeet1995 changed the title Owner Resource Not Found: Fixes sub-status to 1003 for requests to child resources against non-existent container. Owner Resource Not Found (Gateway V2 Connection Mode and Direct Connection Mode): Fixes sub-status to 1003 for requests to child resources against non-existent container. Dec 29, 2025
@jeet1995 jeet1995 marked this pull request as ready for review December 29, 2025 13:32
@jeet1995 jeet1995 requested review from a team and kirankumarkolli as code owners December 29, 2025 13:32
Copilot AI review requested due to automatic review settings December 29, 2025 13:32
@jeet1995 jeet1995 requested a review from a team as a code owner December 29, 2025 13:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds sub-status code 1003 (Owner Resource Not Found) for requests to child resources (e.g., documents) when the owning container doesn't exist. The changes ensure proper error reporting across Direct Mode, Gateway V2 Mode, and Gateway Mode connection types.

Key Changes

  • Added error mapping logic to set sub-status code 1003 when container resolution fails during child resource operations
  • Introduced new setSubStatusCode method in CosmosException API via ImplementationBridgeHelpers
  • Added comprehensive test coverage for container not found scenarios across different connection modes

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
QueryPlanRetriever.java Added error mapping to set sub-status 1003 for 404 errors during query plan retrieval
RxCollectionCache.java Added error mapping handlers in collection resolution paths to set sub-status 1003 for child resource operations
StaleResourceRetryPolicy.java Added enclosingOperationTargetResourceType parameter and error mapping logic for retry scenarios
RxDocumentClientImpl.java Updated retry policy instantiation with ResourceType.Document parameter for point operations
ImplementationBridgeHelpers.java Added setSubStatusCode method to CosmosExceptionAccessor interface
CosmosException.java Implemented setSubStatusCode accessor method
CosmosNotFoundTests.java New comprehensive test class covering non-existent and deleted container scenarios
FaultInjectionTestBase.java Enhanced helper methods to support bulk operations and feed range testing
StaleResourceExceptionRetryPolicyTest.java Updated test constructor calls with new null parameter

@jeet1995 jeet1995 changed the title Owner Resource Not Found (Gateway V2 Connection Mode and Direct Connection Mode): Fixes sub-status to 1003 for requests to child resources against non-existent container. Owner Resource Not Found (Gateway V2 Connection Mode and Direct Connection Mode): Remaps sub-status to 1003 for requests to child resources against non-existent container. Dec 29, 2025
@jeet1995
Copy link
Member Author

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995
Copy link
Member Author

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

AtomicReference<String> oldCollectionRid = new AtomicReference<>();
return this.clientCollectionCache
.resolveByNameAsync(this.getMetadataDiagnosticsContext(), collectionLink, requestOptionProperties)
.resolveByNameAsync(this.getMetadataDiagnosticsContext(), collectionLink, requestOptionProperties, null, this.request, this.enclosingOperationTargetResourceType)
Copy link
Member

Choose a reason for hiding this comment

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

when would this.request.getOperationType != this.enclosingOperationTargetResourceType?

Copy link
Member Author

@jeet1995 jeet1995 Jan 2, 2026

Choose a reason for hiding this comment

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

Above is not expected to be unequal. This is primarily for defense in depth. The request entity is set once StaleResourceRetryPolicy is already instantiated whereas enclosingOperationTargetResourceType is set through the constructor (more guarantees to be initialized).


CosmosException cosmosException = Utils.as(throwable, CosmosException.class);

if (HttpConstants.StatusCodes.NOTFOUND == (cosmosException.getStatusCode())) {
Copy link
Member

Choose a reason for hiding this comment

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

sam question -> would this still be needed?

Copy link
Member Author

@jeet1995 jeet1995 Jan 2, 2026

Choose a reason for hiding this comment

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

Yes, I'd think - the QueryPlan call goes through RxGatewayStoreModel and gets a 404/0 back when the corresponding collection doesn't exist. This is slightly different for other Document calls whose call path peek into RxCollectionCache first. So remapping is done in QueryPlanRetriever (wanted to keep the transport layer devoid of business logic).

Copy link
Member

@xinlian12 xinlian12 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@jeet1995
Copy link
Member Author

jeet1995 commented Jan 2, 2026

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995
Copy link
Member Author

jeet1995 commented Jan 2, 2026

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jeet1995
Copy link
Member Author

jeet1995 commented Jan 3, 2026

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants