feat: send x-session-id and x-parent-session-id headers in LLM API requests#12932
feat: send x-session-id and x-parent-session-id headers in LLM API requests#12932jverkoey wants to merge 2 commits intoanomalyco:devfrom
Conversation
…quests Forward opencode session identifiers as HTTP headers on all outgoing LLM API requests. This enables OpenAI-compatible servers to correlate requests belonging to the same session and reconstruct parent/child agent trees (e.g. when the task tool spawns sub-agents). Two new headers are sent: - x-session-id: always present, identifies the current session - x-parent-session-id: present only for sub-agent sessions, identifies the parent session that spawned this one This is a minimal, non-breaking change: - parentSessionID is optional on StreamInput - Existing callers (summary, title) that don't pass it simply omit the parent header - Headers are additive and ignored by providers that don't use them Closes anomalyco#12930
|
The following comment was made by an LLM, it may be inaccurate: Based on the search results, I found the following potentially related PRs (excluding the current PR #12932):
The current PR (#12932) appears to be addressing a specific issue (mentioned in "Closes #12930") by extending existing session handling mechanisms that were laid out in previous work. |
|
I'm also dealing with this issue, any plan to merge this? |
Summary
Forward opencode session identifiers as HTTP headers on all outgoing LLM API requests:
x-session-id: Always present — identifies the current opencode sessionx-parent-session-id: Present only for sub-agent (task tool) sessions — identifies the parent session that spawned itThis enables any OpenAI-compatible backend to correlate requests belonging to the same session and reconstruct the full agent workflow tree when sub-agents are spawned.
Motivation
When running opencode against a local OpenAI-compatible server, there is currently no way for the server to determine which session a request belongs to, or whether it comes from a sub-agent. All requests arrive as independent
/v1/chat/completionscalls with no identifying metadata.With these headers, a server can trivially build a tree view:
Changes
packages/opencode/src/session/llm.ts: Add optionalparentSessionIDtoStreamInputtype; sendx-session-idandx-parent-session-idheaders on all LLM requestspackages/opencode/src/session/prompt.ts: Passsession.parentIDthrough asparentSessionIDwhen building the stream inputDesign
parentSessionIDis optional — existing callers (summary, title agents) that don't pass it simply omit the parent headersession.parentIDis already set by the task tool when creating sub-agent sessions (seetool/task.ts:73)Related
Test plan
x-session-idheader is present on all outgoing LLM requestsx-parent-session-idis present when a task tool sub-agent makes requestsx-parent-session-idis absent for top-level session requests