OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Question]: Clarify must_exist behavior on AsyncHTTPClient.session

Open ktz03 opened this issue 1 month ago • 4 comments

Issue Origin

Observed or reproduced in a real environment

Your Question

What is the supported meaning of must_exist=True on the lightweight Python SDK's AsyncHTTPClient.session()? The synchronous factory checks the session with this flag, while the asynchronous client's synchronous factory accepts the same keyword but does not use it.

Is this intentionally a handle-only operation for the asynchronous client, with callers expected to use await session_exists() separately? Please confirm the intended contract before an implementation change; I am not proposing a blocking factory or an awaitable API redesign.

Context

Checked at main 65e86ccb8fda3d3eae9d68837b7ffe856ca46f0e, with all nine imported Python SDK modules bound to its SDK tree. The relevant current bodies are the async client's factory and the synchronous factory.

On Windows, Python 3.12.14 and httpx 0.28.1, a local HTTP endpoint returned only successful responses for an existing session:

  • Async factory with either must_exist=False or True: returns the handle, zero HTTP requests.
  • Explicit async get_session() and session_exists(): one successful GET each.
  • Sync factory with must_exist=False: zero requests; with True: one successful GET.
  • Sync session_exists(): one successful GET.

The full control made four successful GETs. The minimal example below separately prints GETs: 0 after the factory and GETs: 1 after the explicit get.

This exercises current SDK calls against a controlled successful HTTP endpoint, not a complete OpenViking server, storage or model backend. No nonexistent-session response, injected failure or resulting error behavior was tested or asserted.

Historical context: PR #321 is titled “feat: expose session(must_exist) and session_exists() on public API”. Its title alone does not establish the contract of the newer lightweight asynchronous factory.

Code Example (Optional)

Run with the current Python SDK sources and httpx available:

import asyncio
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
import json
import threading

from openviking_sdk import AsyncHTTPClient

requests = []


class ExistingSessionHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        requests.append(self.path)
        data = json.dumps({"status": "ok", "result": {
            "session_id": "existing-session", "messages": []}}).encode()
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(data)))
        self.end_headers()
        self.wfile.write(data)

    def log_message(self, *_args):
        pass


async def main(url):
    client = AsyncHTTPClient(url=url)
    await client.initialize()
    try:
        session = client.session("existing-session", must_exist=True)
        print("factory:", session.session_id, "GETs:", len(requests))
        await client.get_session("existing-session")
        print("after explicit get:", "GETs:", len(requests))
    finally:
        await client.close()


server = ThreadingHTTPServer(("127.0.0.1", 0), ExistingSessionHandler)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
try:
    asyncio.run(main(f"http://127.0.0.1:{server.server_port}"))
finally:
    server.shutdown()
    server.server_close()
    thread.join()

Related Area

Session Management

Before Asking

ktz03 avatar Oct 22 '26 04:10 ktz03

Thanks for the detailed report. I'd like to work on this. Since AsyncHTTPClient.session() is a plain def, it can't await an existence check. Options I see:

  1. (Preferred) Raise ValueError when must_exist=True, pointing callers to await client.session_exists(...). No caller in the repo passes must_exist=True to the async client, and the flag currently has no effect, so this turns a silent no-op into an explicit error.
  2. Same as 1, but emit a DeprecationWarning first and raise in a later release.
  3. Leave it as is and only document that the async factory ignores the flag.

I'd avoid adding a new awaitable API or a lazy check stored on Session. Which direction would you accept?

kathy1207 avatar Oct 25 '26 19:10 kathy1207

@kathy1207 — I don't see an open PR or follow-up here since your comment, so unless you are already implementing this I plan to take the first option you listed: reject must_exist=True on AsyncHTTPClient.session() with a ValueError that points at await session_exists().

Scope is one factory in sdk/python/openviking_sdk/client.py, mirroring the sync guard (if session_id and must_exist), plus tests and a short README note. Nothing else changes: session() without the flag still returns a handle and performs no I/O, and session(must_exist=True) with no session_id keeps the sync client's no-op behaviour. The repository has no caller that passes must_exist=True to the async client.

@zhoujh01 @t0saki @ehz0ah — if you would rather keep the flag ignored and only document it, say so and I will switch to a documentation-only change instead.

zzx04-cool avatar Nov 07 '26 09:11 zzx04-cool

Opened #7193 for the AsyncHTTPClient.session(must_exist=...) contract described here: the async factory now raises ValueError instead of silently ignoring the flag, and session_exists() is documented as the explicit validation path.

Scope is 3 files / +70 lines (factory + docstring, 5 tests, one README paragraph). If maintainers prefer the flag to stay ignored, the change reduces to the docstring and README note.

zzx04-cool avatar Nov 07 '26 09:11 zzx04-cool

Hi, I'm still waiting for a maintainer to respond before opening a PR. That's how I try to respect others' input. I hope you could follow the same practice next time.

On Sat, Nov 7, 2026 at 1:05 AM Tsuki. @.***> wrote:

zzx04-cool left a comment (volcengine/OpenViking#6438) https://github.com/volcengine/OpenViking/issues/6438#issuecomment-6704839242

Opened #7193 https://github.com/volcengine/OpenViking/pull/7193 for the AsyncHTTPClient.session(must_exist=...) contract described here: the async factory now raises ValueError instead of silently ignoring the flag, and session_exists() is documented as the explicit validation path.

Scope is 3 files / +70 lines (factory + docstring, 5 tests, one README paragraph). If maintainers prefer the flag to stay ignored, the change reduces to the docstring and README note.

— Reply to this email directly, view it on GitHub https://github.com/volcengine/OpenViking/issues/6438?email_source=notifications&email_token=A5Q7UREQSL77MP7HFZLVQ535X3QV7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNZQGQ4DGOJSGQZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-6704839242, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5Q7URBVCAUOBKXFVJD4LGL5X3QV7AVCNFSNUABGKJSXA33TNF2G64TZHMYTCMRYGEZDGNJZGQ5US43TOVSTWNJZG4ZTEMJZGY2TFILWAI . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/A5Q7URFLS5GYCGXKZALR66D5X3QV7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNZQGQ4DGOJSGQZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y and Android https://github.com/notifications/mobile/android/A5Q7URAW4RP3DH6JQXOWHXL5X3QV7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMNZQGQ4DGOJSGQZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI. Download it today! You are receiving this because you were mentioned.Message ID: <volcengine/OpenViking/issues/6438/6704839242 @.*** com>

kathy1207 avatar Nov 07 '26 17:11 kathy1207