fix(cli): forward non-uuid session ids on remote resume (#5218)

`omnigent resume <id>` canonicalized every id through the local sqlite store's uuid rule (uuid_to_bytes), even when --server points at a remote server that owns its own id space. A deployment that keys sessions on non-uuid ids (e.g. numeric node ids) had every id rejected client-side with "Invalid session id." before any request was sent.

Only the local path binds the id to the Uuid16 column, so keep the strict uuid guard there; on the remote path forward the id untouched and let the server resolve it, matching how the runner and SDK already pass the id straight through.

Signed-off-by: aravind-segu <aravind.segu@databricks.com>
Signed-off-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
This commit is contained in:
Aravind Segu
2026-08-21 15:54:45 -07:00
committed by GitHub
parent 243b13abb3
commit 5d7aa85132
2 changed files with 50 additions and 11 deletions
+14 -11
View File
@@ -221,17 +221,20 @@ def _dispatch_by_runtime(
"""
from omnigent.db.db_models import InvalidUuidError, uuid_to_bytes
# Resolve the id the argument contains, then canonicalize to bare hex
# before any lookup: a paste drags punctuation along (trailing period,
# wrapping quotes or backticks), and none of it can ever be part of a
# valid id — so strip it and resume rather than erroring. A malformed
# id would otherwise surface as a raw StatementError traceback from
# the local store's Uuid16 bind, and downstream consumers key
# sessions on the bare spelling.
try:
target = uuid_to_bytes(target.strip(_PASTE_PUNCTUATION)).hex()
except InvalidUuidError as exc:
raise click.ClickException("Invalid session id.") from exc
# Paste punctuation (trailing period, wrapping quotes/backticks) is never
# part of an id, so strip it. Only the local path binds the id to the sqlite
# store's Uuid16 column, so it must be a real uuid — reject a malformed one
# loudly rather than surfacing a raw StatementError. The remote server owns
# its id space (a managed deployment keys sessions on non-uuid ids) and
# validates the id itself, so forward it untouched, like the runner and SDK.
stripped = target.strip(_PASTE_PUNCTUATION)
if server is None:
try:
target = uuid_to_bytes(stripped).hex()
except InvalidUuidError as exc:
raise click.ClickException("Invalid session id.") from exc
else:
target = stripped
if server is not None:
wrapper = _read_wrapper_label_remote(server=server, conv_id=target)
+36
View File
@@ -480,6 +480,42 @@ def test_dispatch_by_runtime_legacy_prefixed_id_canonicalized_to_bare_hex(
assert captured["session_id"] == "415c9954e2fe4b9276083a4d2c66f689"
def test_dispatch_by_runtime_remote_forwards_non_uuid_id(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""
A remote server owns its id space, so a non-uuid id (e.g. a managed
deployment's numeric node id) must reach the lookup and wrapper
unchanged. Forcing the local uuid rule on the remote path would
reject a valid id before the server — the one thing the server is
there to resolve — ever sees it.
"""
seen: dict[str, str] = {}
def _label(*, server: str, conv_id: str) -> str:
"""Record the id the remote lookup receives."""
seen["conv_id"] = conv_id
return "claude-code-native-ui"
monkeypatch.setattr(resume_dispatch, "_read_wrapper_label_remote", _label)
captured: dict[str, Any] = {}
def _capture(**kwargs: Any) -> None:
"""Record the kwargs ``run_claude_native`` was called with."""
captured.update(kwargs)
monkeypatch.setattr("omnigent.claude_native.run_claude_native", _capture)
resume_dispatch._dispatch_by_runtime(
target="2048200000527758",
server="https://example.com",
)
# The raw non-uuid id flows through untouched — not rejected, not reshaped.
assert seen["conv_id"] == "2048200000527758"
assert captured["session_id"] == "2048200000527758"
def test_dispatch_by_runtime_non_wrapper_local_raises_with_hint(
monkeypatch: pytest.MonkeyPatch,
) -> None: