dsh-opencode-session
Manifest valid★ 15Attaches a stable per-conversation x-opencode-session header to OpenCode / OpenCode Go provider requests, fixing 400 MissingSessionID errors and keeping session affinity and prompt-cache routing intac
dsh-opencode-session
A DeepSeek Harness (DSH)
plugin that automatically sends the x-opencode-session request header on
model calls routed to OpenCode / OpenCode Go providers — one stable
session id per DSH conversation.
Why
Since 2026-09-05 OpenCode's relay requires an x-opencode-session header on
API requests (tracked upstream in
deepseek-harness discussion #5495);
without it, requests fail with 400 MissingSessionID-style errors. Requests
that share the same header value are pinned to the same upstream backend,
which is also what keeps OpenCode's prompt cache warm across the turns of one
conversation.
This plugin:
- fixes the 400 by always attaching the header to OpenCode(Go) requests,
- keeps the cache/affinity benefit by using a value that is unique per
conversation and stable across that conversation's turns (by default the
DSH session id itself, the same identity the official DeepSeek adapter
already sends as
x-deepseek-harness-session-id), - leaves every other provider, and every request that already carries the header, untouched.
Install
From the npm registry (once published):
dsh plugin --profile web add dsh-opencode-session
From a local checkout:
dsh plugin --profile web add ./path/to/dsh-opencode-session
Then fully restart your dsh profile (bundle layers are read at startup). The startup log shows:
[opencode-go-session-header] active for providers [opencode, opencode-go] with mode session-id
If you run DSH from a source checkout instead, load it as an overlay:
pnpm dsh web --patch ./cordis.patch.yml.
Configuration
The plugin row lives in the bundle's cordis.patch.yml; all keys are optional:
- insert:
- id: opencode-go-session-header
name: dsh-opencode-session
config:
providers: [opencode, opencode-go] # route keys to attach the header to
mode: session-id # 'session-id' | 'uuid'
debug: false
debugFile: null # optional absolute path
providers— provider route keys whose requests get the header. The defaults cover the pi-ai catalog idsopencodeandopencode-go; add your own route key when you serve OpenCode through a custom provider name.modesession-id(default) — header value = the DSH session id of the model call. Unique per conversation, stable across turns, compaction, retries and process restarts.uuid— a random UUID derived once per DSH session id (opaque; kept in memory, so it resets when the process restarts).
debug— log every streamed call that receives the header viactx.logger(the dsh process console).debugFile— optional absolute path. When set, every streamed call that receives the header appends one JSON line ({"ts","provider","model","session","header","value"}) to that file — handy when the dsh console is not visible.
To override configuration in a profile without editing the package, add a
row with the same id in the profile's own cordis.patch.yml (it replaces the
whole config, so restate every key).
How it works
- Listens on the
llm/streamwaterfall. A call whoseoptions.providernames a configured OpenCode route and which carries asessionIdis driven through anAsyncLocalStoragestore holding the header value. globalThis.fetchis patched once. While such a store is active, the outgoing request receivesx-opencode-session: <value>(unless it already carries the header — an existing value always wins).- Both registrations are fiber-scoped ctx effects: stopping / updating /
unloading the plugin restores the original
fetchand removes the listener.
Non-OpenCode providers, requests without a sessionId (some auxiliary
hand-built calls), and model discovery requests pass through untouched.
Notes / limitations
- The header is attached to chat/streaming requests inside an
llm/streamcall. The one-shot model listing used by the Models page (GET <baseURL>/models) is a separate flow and does not receive the header; if your OpenCode endpoint also rejects that listing, open an issue. - The plugin relies on DSH outbound LLM requests going through the Node
global
fetch. If a future DSH version swaps its network stack, the plugin stops injecting (symptom: the 400 comes back) — uninstall then.
Development
node --check lib/index.js
npm test # local behavior tests against an echo server
Publishing (for maintainers)
The package is plain ESM JavaScript with zero dependencies; npm test runs
automatically via prepublishOnly.
npm login # once, with your npm account
npm pack --dry-run # preview exactly what lands in the tarball
npm publish # files = lib/, cordis.patch.yml, README.md
Before publishing, double-check the name is free on the npm registry and fill
in author, homepage, and repository in package.json if you like.
License
MIT
Compatibility
Versions
| Latest version | Published | Size |
|---|---|---|
| 0.1.0 | — | — |
| 0.1.1 | — | — |
Comments
Loading…
Similar plugins
by beihzb
Per-conversation x-opencode-session injection for OpenCode Go in DeepSeek Harness - fixes 400 MissingSessionID without breaking other providers
★ 16
↓ 238/wk
MIT
JavaScript
Sep 7, 2026
dsh plugin --profile web add dsh-opencode-session-headerby a285292107s
DSH plugin: append x-opencode-session to model requests of selected providers/models
★ 0
MIT
JavaScript
Nov 4, 2026
dsh plugin --profile web add dsh-request-header-fixby yfwu2020
Adds an independent OpenCode Go connection with credential settings, manual model discovery, and per-conversation session headers.
★ 0
JavaScript
Oct 17, 2026
dsh plugin --profile web add dsh-opencode-go-secondby jitang-open
DSH 网页搜索 provider(走 OpenCode Go):自动注入 x-opencode-session、失败回退官方端点、查询缓存、result.content 总结,自带设置页
★ 0
MIT
JavaScript
Oct 13, 2026
dsh plugin --profile web add dsh-web-search-ocgoby itchenshi
Declares the OpenCode Go and Command Code route wire protocol and endpoint (so the API address never has to be typed), adds the DeepSeek V4.1 models to the OpenCode Go route and puts them first, compl
★ 1
MIT
JavaScript
Oct 5, 2026
dsh plugin --profile web add dsh-gateway-modelsby homily707
Injects an x-session-id HTTP header carrying the harness session id onto every LLM provider request, plus whitelisted gateway fetches during tool execution.
★ 10
MIT
JavaScript
Oct 6, 2026
dsh plugin --profile web add dsh-session-header