Skip to content

feat: add list_running_requests and cancel_requests to MilvusClient - #3884

Merged
sre-ci-robot merged 5 commits into
milvus-io:masterfrom
czs007:feat/list-cancel-requests
Nov 12, 2026
Merged

sre-ci-robot merged 5 commits into
milvus-io:masterfrom
czs007:feat/list-cancel-requests

Conversation

@czs007

@czs007 czs007 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Expose the ListRunningRequests and CancelRequests RPCs (milvus-io/milvus-proto#670 and #696, served by milvus-io/milvus#54276, merged) on MilvusClient and AsyncMilvusClient, so an operator can see which search / hybrid search / query requests the cluster is executing and stop one by id.

res = client.list_running_requests(collection_name="c1", min_elapsed_ms=5000)
# ListRunningRequestsResult(requests=[RunningRequest(request_id=25-to03zu-rs, type='Search', db_name='default',
#     collection_name='c1', user='alice', state='Running', elapsed_ms=5230, proxy_id=25)], unanswered=[])
result = client.cancel_requests([res.requests[0].request_id], reason="runaway query")
# CancelRequestsResult(canceled=['25-to03zu-rs'], not_found=[], undetermined=[])

Three commits:

  1. The API:
    • list_running_requests(db_name=None, collection_name=None, user=None, min_elapsed_ms=0, timeout=None). Filters are ANDed; None / 0 is no constraint, so db_name=None lists every database rather than the client's current one.
    • cancel_requests(request_ids, reason="", user=None, timeout=None) -> CancelRequestsResult with canceled (the rows as they were when stopped), not_found, undetermined (a proxy did not answer, the id may still be running there) and the per-proxy node_results. An empty id list is rejected client side with ParamError.
    • Same two methods on AsyncMilvusClient.
  2. String request ids: Milvus names a running request "<proxy id>-<proxy start>-<sequence>" (enhance: make running-request ids opaque strings milvus-proto#696), so request_id, request_ids, not_found and undetermined are str; the proto submodule moves to that commit and is regenerated.
  3. Per-proxy results from the list: list_running_requests returns ListRunningRequestsResult(requests, node_results) with a complete property, instead of only the rows. The call succeeds as long as one proxy answered, so without node_results a caller could not tell a complete answer from one missing the requests of a proxy that did not answer (or that predates the feature during a rolling upgrade). This matches cancel_requests and the Go (feat: add ListRunningRequests and CancelRequests to the Go SDK milvus#55250) and Java (feat: add listRunningRequests and cancelRequests to MilvusClientV2 milvus-sdk-java#2180) SDKs. A warning per unanswered proxy is still logged.

New types RunningRequest, RequestNodeResult, ListRunningRequestsResult, CancelRequestsResult in pymilvus.client.types, exported from pymilvus.

Verification (head bd9f886):

  • ruff check pymilvus tests clean; tests/unit: 5728 passed, 1 skipped. Dropping node_results from the list result makes 3 tests fail.
  • Against standalone instances built from feat: list running DQL requests and cancel them by id milvus#54276: the cross-SDK live checks in the comment below (self-service, filters and fields, Query / HybridSearch, partial answer with a killed proxy, rolling upgrade, async client) pass again with this change; the partial-answer and rolling-upgrade checks now read node_results / complete instead of the log. The string-id end-to-end check (gRPC, REST read through Node JSON.parse, cause="cancel" metrics) passes 14/14.

🤖 Generated with Claude Code

@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

This pull request is merged.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.47887% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.88%. Comparing base (ed7d326) to head (3d6d312).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
pymilvus/milvus_client/milvus_client.py 33.33% 4 Missing ⚠️
pymilvus/client/types.py 98.52% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3884      +/-   ##
==========================================
+ Coverage   94.82%   94.88%   +0.06%     
==========================================
  Files          81       81              
  Lines       17421    17571     +150     
==========================================
+ Hits        16519    16673     +154     
+ Misses        902      898       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

czs007 and others added 2 commits November 5, 2026 10:11
Expose the ListRunningRequests and CancelRequests RPCs (milvus-proto milvus-io#670,
served by milvus #54276) on MilvusClient and AsyncMilvusClient.

list_running_requests(db_name, collection_name, user, min_elapsed_ms)
returns the Search / HybridSearch / Query requests the cluster is executing
as RunningRequest rows; the filters are ANDed and a None filter is no
constraint. The call succeeds as long as one proxy answered; a proxy that
did not, or that predates the feature during a rolling upgrade, is logged
as a warning since its requests are missing from the result.

cancel_requests(request_ids, reason, user) cancels by the ids the list
reported and returns a CancelRequestsResult that sorts every requested id
into canceled, not_found or undetermined (a proxy did not answer), plus the
per-proxy node results. An empty id list is rejected client side.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: czs007 <caozhenshan007@gmail.com>
Milvus now names a running request "<proxy id>-<proxy start>-<sequence>",
e.g. "25-to03zu-rs", so request_id, request_ids, not_found and undetermined
are strings in the proto (milvus-io/milvus-proto#696). Move the proto
submodule to that commit and regenerate, make RunningRequest.request_id and
the CancelRequestsResult id lists str, and accept only non-empty str ids in
cancel_requests; the old numeric form raises ParamError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: czs007 <caozhenshan007@gmail.com>
@czs007
czs007 force-pushed the feat/list-cancel-requests branch from cac5ef5 to c8d38e7 Compare November 5, 2026 23:35
@mergify mergify Bot added ci-passed and removed ci-passed labels Nov 5, 2026
@czs007

czs007 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Live check against a real cluster, run the same way for pymilvus (#3884), the Go SDK (milvus-io/milvus#55250) and the Java SDK (milvus-io/milvus-sdk-java#2180), on standalone instances built from milvus-io/milvus#54276 (merged). Data: 100,000 rows x 768 dims, FLAT. A slow search is nq 10,000.

scenario what is checked pymilvus Go Java
self-service (authorization on, a user with only collection read privileges) lists only their own requests; naming another user in list or cancel is denied (1401); another user's id comes back in not_found and that request keeps running; canceling their own request gives its client 3002 with the reason 6/6 x2 6/6 x2 6/6 x2
filters and fields every row field (id format, type, db, collection, user, nq, topk, state, times, cancellable, proxy id); db / collection / user / min-elapsed filters, matching and not matching; cancel returns the snapshot and the client gets 3002 with the reason; canceling again gives not_found; empty id list rejected 8/8 x2 8/8 x2 8/8 x2
other request types a Query and a HybridSearch are listed with their type and canceled; their clients get 3002 2/2 x2 2/2 x2 2/2 x2
partial answer (a second proxy SIGKILLed while its session is still registered) list succeeds and reports the proxy that did not answer; cancel of an unknown id gives undetermined, not not_found 2/2 2/2 2/2
rolling upgrade (a proxy built from master without the feature joins) exactly one node result is marked unimplemented; an unknown id is still not_found 2/2 2/2 2/2

pymilvus specifics:

  • AsyncMilvusClient: list, the self-service denial, another user's id hidden as not_found, and canceling a real running search (its client gets 3002 with the reason): 4/4.
  • An unanswered or too-old proxy shows up in cancel_requests(...).node_results; list_running_requests returns rows only and logs one warning per such proxy, which is what the partial-answer and rolling-upgrade checks look for.
  • Empty id list: ParamError on the client.

Tested at c8d38e7.

list_running_requests returned only the rows, so a caller could not tell a
complete answer from one missing the requests of a proxy that did not
answer; that was only logged. Return a ListRunningRequestsResult with
requests and node_results instead, plus a complete property, matching
cancel_requests and the Go and Java SDKs. The warning per unanswered proxy
is still logged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: czs007 <caozhenshan007@gmail.com>
@czs007

czs007 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up to the comment above: list_running_requests now returns ListRunningRequestsResult(requests, node_results) with a complete property (commit bd9f886), so a partial answer is visible to the caller rather than only in the log, as in the Go and Java SDKs. Reran with this head: unit tests 5728 passed; the pymilvus live checks (self-service 6/6, filters and fields 8/8, Query / HybridSearch 2/2, async 4/4, partial answer 2/2 and rolling upgrade 2/2, which now read node_results and complete) and the string-id end-to-end check 14/14 all pass.

@mergify mergify Bot added ci-passed and removed ci-passed labels Nov 7, 2026
Comment thread tests/unit/grpc_handler/test_utility.py Resolved
Comment thread pymilvus/client/types.py Resolved
- Remove five Parquet files that a local unit-test run wrote to
  bulk_writer/ and that were committed by mistake.
- RunningRequest.to_dict delegates to dataclasses.asdict, so a new field
  cannot be left out of the dictionary.
- The error-status tests of list_running_requests and cancel_requests now
  reach the mocked RPC (cancel_requests used to pass [1], which failed id
  validation first) and check that the server's code and reason reach the
  caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: czs007 <caozhenshan007@gmail.com>
@mergify mergify Bot added ci-passed and removed ci-passed labels Nov 11, 2026
Comment thread pymilvus/client/types.py Resolved
ListRunningRequestsResult.complete returned True when node_results was
empty, because all() over an empty list is True. A current server sends
one entry per proxy on every successful call, so an empty list means the
server did not report per-proxy results and completeness cannot be
confirmed. Return False in that case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: czs007 <caozhenshan007@gmail.com>
@mergify mergify Bot added ci-passed and removed ci-passed labels Nov 12, 2026
@XuanYang-cn

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: czs007, XuanYang-cn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot
sre-ci-robot merged commit 0811221 into milvus-io:master Nov 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants