Repository navigation
feat(python): add AsyncKoshaClient with cancellation and lifecycle management - #611
Merged
decover-admin merged 2 commits intoNov 29, 2026
Conversation
ravi-decoverai
approved these changes
Nov 29, 2026
NativeNamespace._call and AsyncNamespace._call join the action onto
ns_path(ns, action) = /v1/namespaces/{ns}/{action}, so _call("POST",
"search", ...) is not a legacy unversioned route, same as client.py's
_request.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---kosha-bench---
microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory)
corpus: 8 segments × 4000 docs (32000 total), vocab ~20000
runner: Darwin 25.5.0 arm64 | rustc 1.97.1 (8bab26f4f 2026-07-14) | 2026-11-29T04:52:41Z
latency (v2 = current lazy format, median of inner samples):
cold broad ("the") 5.3 ms
warm broad ("the") 0.37 ms
warm 2-term AND 0.41 ms
warm phrase 0.39 ms
warm wildcard w1* 126.18 ms
---end kosha-bench---
7 of 11 tasks
khoap1220-hue
added a commit
to khoap1220-hue/khoap1220-hue.github.io
that referenced
this pull request
Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
In
clients/python/kosha_client/async_transport.py,clients/python/kosha_client/async_client.py,clients/python/kosha_client/native.py, andclients/python/kosha_client/transport.py, this PR adds an asynchronous Python client (AsyncKoshaClient), immutable namespace handles (AsyncNamespaceand matching synchronousNamespaceonKoshaClient), nonblockingasyncioHTTP/1.1 transport (AsyncTransport), async pagination (AsyncSearchIterator), and async bulk indexing (async_bulk_index).Addresses #595 (dependencies #591, #592, and #594 are still open, so this preserves the existing
KoshaClientOpenSearch compatibility surface and zero-dependencypyproject.tomlpackaging while aligning the native/v1client/namespace API withclients/typescriptandclients/go).Summary of changes
clients/python/kosha_client/transport.py: Factoredresolve_connection_config,build_request_url,build_request_headers,decode_response_or_error, and_BaseTransport(_backoff_ms,_should_retry_transport_error,_next_retry_delay_ms) soTransportandAsyncTransportshare one serialization, error-mapping, idempotency, andclients/conformance/RETRY.mdretry implementation.clients/python/kosha_client/async_transport.py: Added pure-stdlibasyncioHTTP/1.1AsyncTransportand client-scoped_AsyncPoolsupporting keep-alive connection reuse, stale-connection read resend,Content-Length/Transfer-Encoding: chunked/204framing, TLS, HTTP proxy forwarding,async with/ idempotentaclose()cleanup, and immediate socket abort onasyncio.CancelledErrorwithout retrying.clients/python/kosha_client/native.py: Added immutable syncNamespace, cancellation-safeAsyncSearchIterator(async_search_all, supportingaclose()andasync with), andasync_bulk_index(acceptingIterableandAsyncIterable, enforcing count/UTF-8 byte caps and last-occurrence-wins ordering, and cancelling all in-flight batch tasks onCancelledError).clients/python/kosha_client/async_client.py&clients/python/kosha_client/client.py: AddedAsyncKoshaClient/AsyncNamespaceand matching native sync methods (namespace,create_namespace,list_namespaces,delete_namespace,request,__enter__/__exit__) onKoshaClient; exported new public symbols inclients/python/kosha_client/__init__.py.clients/python/examples/async_agent_retrieval.py&clients/python/README.md: Added bounded-concurrency (asyncio.Semaphore) parallel agent retrieval example (retrieve_parallel) and documentedAsyncKoshaClientlifecycle and cancellation behavior.clients/python/tests/test_async_client.py&clients/python/tests/test_dsl_registry.py: Added 33 deterministicpytesttests (running viaasyncio.runwith no extra test-runner dependency) and registered the new nativeKoshaClientmethods inNOT_APIS.Mapping to #595 Done-When criteria
AsyncTransportoverasyncio.open_connectionverified bytest_delayed_http_does_not_block_independent_event_loop_taskandtest_concurrent_requests_run_in_parallel_not_serially.search_allpagination,bulk_index, andping(test_cancel_in_flight_request_aborts_socket_and_prevents_retries,test_cancel_during_retry_backoff_prevents_later_attempts,test_cancel_during_search_all_stops_paging_and_releases_resources,test_search_all_aclose_and_context_manager_prevent_later_fetches,test_cancel_during_bulk_index_aborts_inflight_batches_and_stops_dispatch,test_ping_propagates_cancellation_and_returns_false_on_error).test_keepalive_reuses_connection_and_aclose_releases_all_connections,test_async_context_manager_closes_on_normal_exit_and_exception,test_closed_client_rejects_requests_and_reentry,test_aclose_during_retry_backoff_prevents_further_attempts, and documented inclients/python/README.md.Retry-After, quota429, bare503,max_retry_after_ms, body vs header delay precedence,total_budget_ms,502/details.outcome == "unknown"idempotency, timeouts, refused connections, non-JSON error fallbacks, and byte-identical UTF-8 JSON replay.test_sync_and_async_namespace_crud_and_native_document_parity,test_namespace_handles_are_immutable_and_isolated,test_sync_and_async_search_all_parity_and_validation, andtest_sync_and_async_bulk_index_parity_and_async_iterable.clients/python/examples/async_agent_retrieval.py(retrieve_parallel) verified bytest_bounded_concurrency_agent_retrieval_example_enforces_boundandtest_bounded_concurrency_example_cancels_sibling_tasks_on_cancel.How it was tested
Full
clients/python/tests/suite ran on Python 3.12 with all new tests and existing non-symlink tests passing (on unprivileged Windows, pre-existingtest_ingest.py::test_iter_files_skips_symlinks_out_of_the_folderrequiresSeCreateSymbolicLinkPrivilegeandtest_keepalive.py's0.0stimer checks depend ontime.monotonic()tick resolution).Compatibility
Does this change any of the following?
/v1wire contract (proto/kosha/v1/kosha.proto, request/response JSON)Checklist
cargo fmt --all -- --check(no Rust files changed)cargo clippy --all-targets --all-features -- -D warnings(no Rust files changed)cargo test --all-features(no Rust files changed)make client-python-test(clients/python/tests/+scripts/tests/)docker build -t kosha:ci .(no Docker/build files changed)KOSHA_*variables have a row indocs/configuration.md(no new env vars added)