Skip to content

Return results for queries that cannot export a continuation token - #221

Merged
Mike Krüger (mkrueger) merged 8 commits into
mainfrom
dev/mkrueger/query-continuation-unsupported
Sep 28, 2026
Merged

Mike Krüger (mkrueger) merged 8 commits into
mainfrom
dev/mkrueger/query-continuation-unsupported

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Fixes #219.

Vector ORDER BY, ORDER BY RANK relevance ranking, and object-shaped DISTINCT queries failed with a continuation-token error even though the query itself succeeded. The Cosmos SDK throws from ResponseMessage.ContinuationToken when the pipeline cannot export a resumable token, and query read that property unconditionally.

  • Read the token through TryReadContinuationToken, which separates query execution from the ability to resume it. A pipeline that refuses to export a token no longer fails the command, and a token collected from an earlier page is dropped so the caller never receives one the service would reject.
  • MCP calls to a non-resumable query keep advancing the same iterator, including through empty intermediate pages, until the requested limit is reached instead of returning after a single page.
  • A result that is truncated by the limit and cannot be resumed is reported explicitly: the shell prints that the query cannot be resumed, and the MCP payload sets resultIncomplete. For these queries a null token alone no longer means the result set is exhausted.
  • Resumable pagination is unchanged: MCP still returns one page and its token, and interactive queries still page until the limit.

Documentation for query and the MCP payload, the MCP tool description, and the changelog are updated.

@github-code-quality

github-code-quality Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall line coverage in commit 733dde8 in the dev/mkrueger/query-c... branch remains at 63%, unchanged from commit c614f52 in the main branch.

Show a line coverage summary of the most impacted files.
File main c614f52 dev/mkrueger/query-c... 733dde8 +/-
D:\a\CosmosDBSh...CommandState.cs 92% 92% 0%
D:\a\CosmosDBSh...ponseFactory.cs 97% 97% 0%
D:\a\CosmosDBSh...QueryCommand.cs 40% 51% +11%

Updated September 25, 2026 10:38 UTC

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.

Copilot review overview

🟡 Changes recommended

Several documentation, regression-test, test-isolation, and exact-limit pagination issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity · 2 Low severity

Open (4)
What changed in this PR

This PR updates Cosmos query handling so successful queries that cannot export continuation tokens still return results and report incomplete MCP results.

Changes:

  • Handles non-resumable continuation tokens and pagination.
  • Adds incomplete-result state and MCP payload support.
  • Updates tests, documentation, localization, and changelog.
File Summary
l10n/​CosmosDBShell.json Adds localized query warning text.
docs/​mcp.md Documents MCP pagination and incomplete results.
docs/​commands.md Documents non-resumable query behavior.
CosmosDBShell/​lang/​en.ftl Adds the English query warning message.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Mcp/​McpResponseFactory.cs Adds resultIncomplete to MCP responses.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​CommandState.cs Tracks incomplete query results.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Commands/​QueryCommand.cs Handles continuation-token failures and pagination.
CosmosDBShell.Tests/​McpResponseFactoryTests.cs Tests incomplete-result payloads.
CosmosDBShell.Tests/​CommandTests/​QueryCommandTests.cs Adds query pagination and token-handling tests.
CHANGELOG.md Records the query continuation-token fix.

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

Comment thread CosmosDBShell.Tests/CommandTests/QueryCommandTests.cs
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/QueryCommand.cs Outdated
Comment thread docs/commands.md Outdated
Comment thread docs/mcp.md Outdated
Copilot AI review requested due to automatic review settings September 23, 2026 13:21

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.

Copilot review overview

🔵 Needs a closer look

Unresolved pagination/token-state, DISTINCT regression coverage, and MCP/documentation contract issues remain.

Review effort: Lite
Findings: 2 Medium severity · 2 Low severity

Open (4)
Previously missed (1)

In code that hasn't changed since last review

Low severity Broaden release note for DISTINCT projection behavior

CHANGELOG.md:12

The release note claims only DISTINCT projections without ORDER BY are affected, but the reported object-shaped DISTINCT reproduction has ORDER BY and still receives the unsupported-token response. Please make the note cover the broader set of DISTINCT projections so the documented fix matches the shipped behavior.

Copilot AI review requested due to automatic review settings September 23, 2026 13:38

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.

Copilot review overview

🟡 Changes recommended

Correct the MCP option description and qualify documentation guidance for resultIncomplete.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 2 Low severity

Open (3)
Resolved since last review (4)

Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/QueryCommand.cs
Comment thread docs/commands.md
Comment thread docs/mcp.md

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.

Copilot review overview

🔵 Needs a closer look

Unresolved findings require a multi-page stale-token regression test and documentation corrections for null tokens and MCP max behavior.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
Resolved since last review (5)
Previously missed (3)

In code that hasn't changed since last review

Medium severity Add regression test preventing stale tokens after later export failure

CosmosDBShell/​Azure.Data.Cosmos.Shell.Commands/​QueryCommand.cs:788

This branch is the only protection for the promise that a token from an earlier page is discarded when a later response rejects token export, but the added execution tests only exercise a throwing getter on the first page. Add a multi-page regression with a valid first-page token followed by a successful page whose getter throws, and assert the returned state never exposes the stale token; otherwise this caller-safety guarantee is untested.

Low severity Clarify null token exception for truncated non-resumable results

docs/​commands.md:395

The preceding MCP contract still says that a null token means there are no more pages, which contradicts the new non-resumable behavior: when resultIncomplete is true, the null token explicitly accompanies results that were truncated and cannot be resumed. Qualify that sentence so clients do not treat this response as exhausted.

Low severity Document resultIncomplete exception for null continuation tokens

docs/​mcp.md:131

The payload-shape table still defines a null continuationToken as meaning that no results remain, but this new field is emitted alongside a null token for truncated non-resumable queries. The two rows are therefore contradictory for the response shape introduced here; include the resultIncomplete exception in the token description so clients reading this table do not treat such results as exhausted.

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.

Copilot review overview

🟡 Changes recommended

Clarify the documentation in docs/commands.md and docs/mcp.md so clients handle null tokens with resultIncomplete correctly.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Low severity

Open (2)
Resolved since last review (3)

Comment thread docs/commands.md Outdated
Comment thread docs/mcp.md
Copilot AI review requested due to automatic review settings September 23, 2026 20:19

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.

Copilot review overview

🔵 Needs a closer look

Two moderate issues remain in QueryCommand.cs regarding token suppression and MCP-specific warning text.

Review effort: Lite
Findings: None

Resolved since last review (2)

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.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
Resolved since last review (2)

Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CommandState.cs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 25, 2026 09:55

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.

Copilot review overview

🔵 Needs a closer look

Two moderate issues remain in continuation-token state handling and the shared MCP pagination description.

Review effort: Lite
Findings: None

Resolved since last review (1)

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.

Copilot review overview

🟢 Approval recommended

The only remaining feedback is a minor MCP schema-description nit that does not block approval.

Review effort: Lite
Findings: None

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 25, 2026 10:33

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.

Copilot review overview

🔵 Needs a closer look

One or more issues must be addressed before approval.

Review effort: Lite
Findings: None

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.

Copilot review overview

🟢 Approval recommended

The implementation, documentation, localization, and focused regression coverage consistently satisfy the issue’s acceptance criteria.

Review effort: Balanced
Findings: None

@mkrueger
Mike Krüger (mkrueger) merged commit 345ddb8 into main Sep 28, 2026
13 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/query-continuation-unsupported branch September 28, 2026 12:21
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.

Valid vector, ranking, and DISTINCT queries fail when reading unsupported continuation tokens

3 participants