Skip to content

feat(sdk): Phase M SDK simplification — ordinary-document SDKs, async, quickstarts, self-hosted bootstrap - #638

Merged
decover-admin merged 17 commits into
mainfrom
devin/1795933214-phase-m-sdk
Nov 29, 2026
Merged

decover-admin merged 17 commits into
mainfrom
devin/1795933214-phase-m-sdk

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Implements the open Phase M – SDK simplification milestone in one PR. Adding Kosha to an app is now: install the SDK, set KOSHA_HOST / KOSHA_API_KEY, pick a namespace, write ordinary documents. The same code runs against managed and self-hosted Kosha.

Closes #590, closes #591, closes #592, closes #593, closes #594, closes #595, closes #596, closes #597, closes #598. Includes the async Python client from #611 (merged in here), so #611 can be closed when this merges.

How it was tested

  • Python: pytest clients/python/tests scripts/tests: 441 passed, 35 skipped. New: test_sdk.py, test_compat_594.py, and the async tests from feat(python): add AsyncKoshaClient with cancellation and lifecycle management #611.
  • TypeScript: tsc --noEmit (src and tests), and vitest: 60 passed. New: test/sdk.test.ts.
  • Go: go vet ./... and go test -race ./... pass. New: sdk_test.go.
  • By hand against deploy/selfhost/bootstrap.sh (decoverai/kosha:0.2.0):
    • selfhost_restart.sh passed all three restart scenarios.
    • quickstart/run.sh checkout passed for Python, TypeScript and Go.
    • Python semantic_search, hybrid_search, aggregate and list_branches returned the expected results.
  • Not run: the published-registry quickstarts. They need the new package versions to be released first.

Compatibility

  • The on-disk segment format (files under a segment, footer, posting/vector/filter layout)
  • The manifest, WAL, or Postgres schema
  • The /v1 wire contract (proto/kosha/v1/kosha.proto, request/response JSON)
  • None of the above

There are no server changes. Breaking SDK changes, covered in the SDK.md migration notes:

  • TS kosha.namespace() and Go c.Namespace() now return the ordinary-document facade. The old wire handle is NativeNamespace (ns.native / ns.Native()).
  • In the Python OpenSearch adapter, put_mapping, put_settings and indices.close now warn and return acknowledged: false instead of a fake success.

Checklist

  • cargo fmt --all -- --check (no Rust changes)
  • cargo clippy --all-targets --all-features -- -D warnings (no Rust changes)
  • cargo test --all-features (no Rust changes)
  • make client-python-test (if clients/python changed)
  • docker build -t kosha:ci . (if the Dockerfile or build configuration changed) (n/a)
  • New KOSHA_* variables have a row in docs/configuration.md (none on the server; KOSHA_COMPAT_STRICT is client-side and documented in SDK.md)
  • README / docs updated for user-visible changes

Link to Devin session: https://app.devin.ai/sessions/de1fc62167094befaf572158d8ca85e6
Open in Devin Desktop: https://app.devin.ai/desktop/session/de1fc62167094befaf572158d8ca85e6?variant=devin
Requested by: @ravi-decoverai


👀 Devin fixed 8 findings · 1 finding for you to triage · Follow Devin's work

Devin Review

khoap1220-hue and others added 6 commits November 29, 2026 01:54
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---
Co-Authored-By: Ravi Decover AI <[email protected]>

# Conflicts:
#	clients/python/README.md
…ase checks (Phase M)

Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:42:32Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 4.1 ms
  warm broad ("the")                 0.27 ms
  warm 2-term AND                    0.27 ms
  warm phrase                        0.27 ms
  warm wildcard w1*                  102.16 ms
---end kosha-bench---
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

…e-m-sdk

---kosha-bench---
microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory)
corpus: 8 segments × 4000 docs (32000 total), vocab ~20000
runner: Linux 6.6.141 x86_64 | rustc 1.100.1 (20ddd0171 2026-11-25) | 2026-11-29T06:44:09Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 2.8 ms
  warm broad ("the")                 0.10 ms
  warm 2-term AND                    0.14 ms
  warm phrase                        0.09 ms
  warm wildcard w1*                  44.59 ms
---end kosha-bench---
@github-actions
github-actions Bot force-pushed the devin/1795933214-phase-m-sdk branch from e2f2ed7 to 00c3df7 Compare November 29, 2026 06:44
Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:44:12Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 4.1 ms
  warm broad ("the")                 0.26 ms
  warm 2-term AND                    0.27 ms
  warm phrase                        0.26 ms
  warm wildcard w1*                  97.16 ms
---end kosha-bench---
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

kNN microbench — main vs this PR (knn_open_search)

✅ No kNN regression past its limit.

before = main 3c5da60f5 · after = PR 2d0f8bd90 · same runner, runs interleaved (2× / 2×), best p50 of each side

metric before after Δ limit
warm kNN p50 0.36 ms 0.33 ms -7.7% +25%
p90 (not gated) 0.43 ms 0.39 ms -7.8%
p99 (not gated) 0.63 ms 0.61 ms -3.0%
warm hybrid p50 0.46 ms 0.40 ms -13.3% +25%
p90 (not gated) 0.52 ms 0.49 ms -6.6%
p99 (not gated) 0.58 ms 0.58 ms +0.7%
cold kNN p50 2.40 ms 2.21 ms -8.1% +40%
p90 (not gated) 2.74 ms 2.74 ms +0.0%
p99 (not gated) 3.53 ms 3.19 ms -9.8%
open all segments p50 1.13 ms 1.13 ms -0.3% +40%
p90 (not gated) 1.25 ms 1.21 ms -3.2%
p99 (not gated) 1.41 ms 1.33 ms -5.7%
postings probed / query 100.0 100.0 +0.0% +10%

corpus 8 segs × 4000 docs, dim 256, 64 clusters · latency fails only past both the % limit and an absolute floor · postings/query is deterministic · label perf-regression-accepted to accept an intended cost

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

⏱ Microbench — main vs this PR (segment_memory, v2 format)

before = merge-base 3c5da60f5 · after = PR head 2d0f8bd90 · same runner, back to back

metric pctl before (main) after (PR) Δ
cold broad ("the") p50 2.83 ms 3.21 ms +13.7% ⚠️
p90 3.84 ms 4.36 ms +13.6% ⚠️
p99 4.14 ms 4.55 ms +9.9%
warm broad ("the") p50 0.093 ms 0.095 ms +2.3%
p90 0.098 ms 0.116 ms +17.8% ⚠️
p99 0.110 ms 0.137 ms +24.5% ⚠️
warm 2-term AND p50 0.108 ms 0.123 ms +13.6% ⚠️
p90 0.114 ms 0.198 ms +74.1% ⚠️
p99 0.134 ms 0.360 ms +168.9% ⚠️
warm 3-term AND broad p50 0.122 ms 0.154 ms +26.8% ⚠️
p90 0.158 ms 0.159 ms +1.2%
p99 0.169 ms 0.167 ms -1.3%
warm phrase p50 0.083 ms 0.082 ms -0.9%
p90 0.086 ms 0.086 ms -0.1%
p99 0.099 ms 0.102 ms +2.9%
warm wildcard w1* p50 43.1 ms 43.1 ms +0.1%
p90 48.3 ms 50.0 ms +3.4%
p99 56.0 ms 61.6 ms +10.1% ⚠️
resident while open — 13.1 MiB 13.1 MiB +0.0%

corpus 8 segs × 4000 docs · cold n=25, warm n=200 · nearest-rank percentiles · deltas within ±10% are usually runner noise

Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:53:48Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 4.2 ms
  warm broad ("the")                 0.27 ms
  warm 2-term AND                    0.27 ms
  warm phrase                        0.26 ms
  warm wildcard w1*                  107.80 ms
---end kosha-bench---
…e SDK from a clean copy

Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:53:58Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 6.0 ms
  warm broad ("the")                 0.32 ms
  warm 2-term AND                    0.31 ms
  warm phrase                        0.26 ms
  warm wildcard w1*                  97.20 ms
---end kosha-bench---
…filters

Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:08Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 6.1 ms
  warm broad ("the")                 0.37 ms
  warm 2-term AND                    0.31 ms
  warm phrase                        0.28 ms
  warm wildcard w1*                  101.83 ms
---end kosha-bench---
…oolean

Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:17Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 6.1 ms
  warm broad ("the")                 0.33 ms
  warm 2-term AND                    0.30 ms
  warm phrase                        0.28 ms
  warm wildcard w1*                  104.59 ms
---end kosha-bench---
Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:27Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 6.0 ms
  warm broad ("the")                 0.31 ms
  warm 2-term AND                    0.30 ms
  warm phrase                        0.28 ms
  warm wildcard w1*                  111.02 ms
---end kosha-bench---
Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:37Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 4.0 ms
  warm broad ("the")                 0.27 ms
  warm 2-term AND                    0.26 ms
  warm phrase                        0.31 ms
  warm wildcard w1*                  98.34 ms
---end kosha-bench---
…cknowledged false

Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:47Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 6.3 ms
  warm broad ("the")                 0.34 ms
  warm 2-term AND                    0.34 ms
  warm phrase                        0.28 ms
  warm wildcard w1*                  111.50 ms
---end kosha-bench---
Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:57Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 6.5 ms
  warm broad ("the")                 0.34 ms
  warm 2-term AND                    0.37 ms
  warm phrase                        0.32 ms
  warm wildcard w1*                  110.13 ms
---end kosha-bench---
… before the stack starts

Co-Authored-By: Ravi Decover AI <[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: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:58:12Z

latency (v2 = current lazy format, median of inner samples):
  cold broad ("the")                 6.1 ms
  warm broad ("the")                 0.37 ms
  warm 2-term AND                    0.31 ms
  warm phrase                        0.28 ms
  warm wildcard w1*                  107.62 ms
---end kosha-bench---
@decover-admin
decover-admin merged commit 7777f82 into main Nov 29, 2026
23 of 25 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Devin Review found 9 findings. Devin fixed 8 findings; 1 finding is left for you to triage below.

Fixed by Devin (8)
  • Bootstrap rejects valid key configurations — The check now rejects only the real failure, an unquoted ';' in the KOSHA_API_KEYS line of .env. Entries without scopes, or with spaces, are accepted. The check now runs before the stack starts, not after.
  • Durability smoke test deletes live data — The smoke test now refuses to start, before setting the cleanup trap, when deploy/selfhost/.env exists, so it can't delete a live deployment's volumes or credentials.
  • Go rounds stored 64-bit integers — Added integerText: declared integers and filters now format int/uint/json.Number exactly, and DecodeValue returns int64 beyond 2^53. Covered by a new test using 9007199254740993.
  • Async HTTPS proxy connections time out — A 2xx response to CONNECT is now treated as bodyless, so the tunnel starts TLS without waiting for EOF.
  • Go search fails on consistency fallback — consistency_fallback is now a string reason in Go (*string), TypeScript (string), the shared fixture and the docs, matching the server.
  • Quickstarts require namespace admin access — The self-host app key now has tenant-scoped namespace admin explicitly, so the create/delete calls in the quickstarts succeed. Verified live: the Python, TypeScript and Go checkout quickstarts pass against the bootstrapped stack.
  • Async writes continue after client closure — After _open_connection returns, _exchange_once checks _closed. If the transport was closed, it closes the new connection and raises before writing any bytes.
  • Self-hosted app keys gain admin access — Fixed the root cause: the key entry in .env is now single-quoted so ;scopes= survives sourcing, and bootstrap fails if the scopes are lost. The generated app key now explicitly has read+write+admin for tenant default only (no /v1/admin/*, no other tenants), so quickstarts can manage namespaces. The README documents this and shows how to add narrower keys.

View findings in Devin Review · Follow Devin's work

Devin Review

Comment on lines +575 to +587
except _TRANSPORT_ERRORS as e:
conn = state.get("conn")
if conn is not None:
self._pool.discard_active(conn, abort=True)
is_timeout = isinstance(e, _TIMEOUT_ERRORS)
stale = bool(state.get("reused")) and not is_timeout
if stale:
self._pool.clear_idle(pool_key)
if resend_stale and not self._closed:
resend_stale = False
continue
before_write = (not state.get("sent")) or stale
e._kosha_before_write = before_write # type: ignore[attr-defined]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🟡 Async retries replay unconfirmed writes

When a reused socket loses a write response, _send marks the failure as pre-write even after sending bytes. The retry policy then replays non-idempotent operations without opt-in.

Devin left this for you to triage: The async transport matches the sync transport already on main (transport.py: if stale or not sent): a non-timeout failure on a reused keep-alive socket counts as pre-write, so a write the server already applied could be replayed. Fixing this changes the RETRY.md policy for both transports, so I recommend a separate follow-up that marks stale write failures as post-write in both, rather than diverging only in async here.

Learn more

The async SDK marks a request as sent before queueing it on the socket. A connection reset or truncated HTTP body can happen after the server has already committed a write. The retry path nevertheless treats any non-timeout failure on a reused connection as proof the request was not sent. That bypasses the ordinary restriction on replaying namespace or branch creation.

Example: The server commits a branch on a reused connection but disconnects while sending its response. The SDK automatically sends the branch request again. The caller receives an already-exists error for the branch it just created.

Recommended fix: Do not infer before_write from connection reuse. Keep the read-only stale-connection resend, but use the recorded send state or positive evidence of a pre-write failure when deciding whether to replay writes.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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