The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(opencode): send ephemeral x-opencode-session header on one-shot requests
ericmaddox709cc2214c4f
diff --git a/agent/opencode_affinity.py b/agent/opencode_affinity.pyindex c4a1628e7cb..824e5df57fb 100644--- a/agent/opencode_affinity.py+++ b/agent/opencode_affinity.py@@ -17,6 +17,7 @@ so the header cannot drift per code path.from __future__ import annotations+import uuidfrom typing import Any, OptionalOPENCODE_SESSION_HEADER = "x-opencode-session"@@ -72,7 +73,13 @@ def opencode_session_headers()except Exception:key = str(session_id or "")- return {OPENCODE_SESSION_HEADER: key} if key else {}+ if not key:+ # Stateless one-shot requests (commit messages, summaries, standalone prompts outside+ # a session) lack an ambient conversation or session id. OpenCode Go strictly requires+ # x-opencode-session on every request (HTTP 400 MissingSessionID if absent, #105841)+ # so generate an ephemeral session id fallback.+ key = f"oneshot-{uuid.uuid4().hex[:16]}"+ return {OPENCODE_SESSION_HEADER: key}def merge_opencode_session_headers(diff --git a/tests/agent/test_opencode_session_affinity.py b/tests/agent/test_opencode_session_affinity.pyindex ee7877816f4..35ea5cd7250 100644--- a/tests/agent/test_opencode_session_affinity.py+++ b/tests/agent/test_opencode_session_affinity.py@@ -147,3 +147,17 @@ def test_tui_gateway_oneshot_runtime_snapshot_carries_the_session(monkeypatch, oaux.call_llm(task="title_generation", main_runtime=_main_runtime_from_agent(agent), messages=_MSGS)assert captured["extra_headers"]["x-opencode-session"] == "sess-desktop-1"+++def test_stateless_oneshot_still_sends_an_opencode_session_header(out_of_turn):+ """A one-shot with no live session (Desktop commit-message generation from the review panel with+ no active chat, standalone aux calls) has no conversation identity at all, yet the relay rejects+ header-less requests with 400 MissingSessionID (#105841). It must carry an ephemeral key instead+ of nothing; non-OpenCode targets stay untouched."""+ from agent.opencode_affinity import opencode_session_headers++ kwargs = aux._build_call_kwargs("opencode-go", "glm-5", _MSGS, base_url="https://opencode.ai/zen/go/v1")+ assert kwargs["extra_headers"]["x-opencode-session"]++ assert opencode_session_headers("opencode-go", None, session_id=None).get("x-opencode-session")+ assert opencode_session_headers("openrouter", "https://openrouter.ai/api/v1", session_id=None) == {}