dsh-opencode-session-fallback
Manifest validdsh opencode go开启自动审查
dsh-opencode-session-fallback
A small DeepSeek Harness (DSH) plugin that gives
session-less LLM requests on OpenCode routes a fallback sessionId, so auto permission presets stop
failing every tool call with 400 MissingSessionID.
No global fetch patching, no provider config changes, no official package overrides.
The problem
OpenCode / OpenCode Go reject inference requests that do not carry an x-opencode-session header:
400 {"type":"error","error":{"type":"MissingSessionID","message":"Request is missing x-opencode-session ..."}}
DSH's @deepseek-ai/dsh-llm-pi-ai adapter only lets pi-ai add that header when the request carries a
sessionId. Main conversation calls do carry one — but
@deepseek-ai/dsh-experimental-auto-review builds its reviewer request by hand without a sessionId.
So with the auto permission preset on an opencode-go route:
- every tool call is first sent to the reviewer model,
- that request has no session header → gateway 400,
- the review fails → DSH fails closed → the tool body never runs:
Auto review of tool "pwsh" failed; its body was not executed:
auto-review: reviewer ended with error INVALID_REQUEST: 400: {"type":"MissingSessionID", ...}
The fix
Wrap ctx.llm.stream once at startup. Requests that already carry a sessionId, or that target a
provider outside the configured list, pass through untouched. Only session-less requests on OpenCode
routes (in practice: the auto-review reviewer call) get the configured fallback id; pi-ai then adds
x-opencode-session on its own.
ctx.llm.stream(options)
├─ options.sessionId present .......... pass through (main chat, subagents, compaction, titles)
├─ provider not opencode/opencode-go .. pass through (official DeepSeek etc. untouched)
└─ session-less + OpenCode route ...... { ...options, sessionId: <fallback> }
Why not patch globalThis.fetch (what some other plugins do)? Because replacing the global fetch wraps
every outbound call of the host — including the app's own networking — and can take the whole UI down
with connection errors. This plugin only touches the LLM service method.
Behavior guarantees
- Existing
sessionIds are never replaced → per-conversation routing / prompt-cache affinity is preserved. - Other providers (for example the official
deepseekprovider) are not affected at all. - Options objects passed by callers are never mutated (a copy is used, so frozen options are fine).
- Uninstalling restores the original
ctx.llm.streamautomatically. - If the service shape changes in a future DSH release, the plugin logs a warning and stays inert instead of breaking the boot.
Install
Plugins are assembled at DSH startup — restart DSH after installing.
From npm
dsh plugin --profile web add dsh-opencode-session-fallback
Or use the GUI: Settings → Plugins → install, package name dsh-opencode-session-fallback.
From this Git repository
dsh plugin --profile web add git+https://github.com/zlxlsy666/dsh-opencode-session-fallback.git
From a local checkout
dsh plugin --profile web add "file:C:\path\to\dsh-opencode-session-fallback"
The desktop application manages its own desktop profile: use its Plugin Manager UI for that profile
instead of the CLI.
After a successful start the log shows:
[opencode-session-fallback] active for providers [opencode, opencode-go], fallback session id "dsh-opencode-session-fallback"
Configuration (optional)
Override with the same entry id in the profile's cordis.patch.yml:
- id: opencode-session-fallback
name: dsh-opencode-session-fallback
config:
providers: [opencode, opencode-go] # routes that need a session id
fallbackSessionId: my-stable-id # value used when the request has none
debug: false # log every injection
Uninstall
dsh plugin --profile web remove dsh-opencode-session-fallback
Restart DSH afterwards.
Compatibility
- Built and verified against DSH
0.2.1-rc.2(desktop) withopencode-go+deepseek-v4.1-flash, where it fixed the failure end-to-end (auto preset, tools execute, reviewer returns normal allow/deny decisions). - Requires
ctx.llm.streamto exist (inject: ['llm']); otherwise the plugin logs a warning and does nothing. - Pairs well with any DSH version that ships the pi-ai OpenCode providers.
Development
node --check lib/index.js
node test/smoke.mjs # 5 assertions, no DSH runtime required
License
MIT
中文说明
解决的问题
OpenCode / OpenCode Go 要求每个推理请求都带 x-opencode-session 头,缺失会返回
400 MissingSessionID。DSH 的 dsh-llm-pi-ai 只在请求带 sessionId 时才让 pi-ai 补这个头,而
@deepseek-ai/dsh-experimental-auto-review 的 reviewer 请求是手工拼的、没有 sessionId。
结果:在 opencode-go 路由 + auto 权限预设下,每次工具调用先过 reviewer → reviewer 请求 400 →
审查失败 → fail-closed → 工具全部无法执行。
修复方式
启动时包一层 ctx.llm.stream:
- 已有
sessionId的请求(主对话、子代理、压缩、会话标题)原样透传; - 其他 provider(例如官方
deepseek)完全不受影响; - 只有「缺 sessionId 且命中 OpenCode 路由」的请求(实际就是 reviewer)补一个兜底 id,
pi-ai 随后自动加上
x-opencode-session。
不接管全局 fetch(那会把宿主自身的出网调用一起包住,可能直接让 UI 报 connection error),
也不修改 provider 配置、不覆盖任何官方包。
安装
插件在 DSH 启动时装配,装完必须重启 DSH。
- npm:
dsh plugin --profile web add dsh-opencode-session-fallback - GUI:设置 → 插件 → 安装,填包名
- Git:
dsh plugin --profile web add git+https://github.com/zlxlsy666/dsh-opencode-session-fallback.git - 本地目录:
dsh plugin --profile web add "file:C:\path\to\dsh-opencode-session-fallback"
桌面版的 desktop profile 由应用自己管理,请在应用的插件管理器里安装。
启动日志应出现:
[opencode-session-fallback] active for providers [opencode, opencode-go], fallback session id "dsh-opencode-session-fallback"
可选配置
在 profile 的 cordis.patch.yml 用同 id 覆盖:
- id: opencode-session-fallback
name: dsh-opencode-session-fallback
config:
providers: [opencode, opencode-go]
fallbackSessionId: my-stable-id
debug: false
卸载
从插件管理器卸载(或 dsh plugin --profile web remove dsh-opencode-session-fallback)后重启 DSH,
ctx.llm.stream 会自动恢复。
已验证环境
DSH 0.2.1-rc.2 桌面版 + opencode-go 路由 + deepseek-v4.1-flash:修复后 auto 预设下工具正常执行,
reviewer 能正常返回 allow/deny 决策。
许可
MIT
Comments
Loading…
Similar plugins
by CJYLZS
auto sync opencode-go models in dsh
★ 3
JavaScript
Sep 4, 2026
dsh plugin --profile web add dsh-opencode-go-autosyncby GarfieldGCat
Another dsh opencode go usage plugin
★ 0
NOASSERTION
JavaScript
Oct 17, 2026
dsh plugin --profile web add dsh-opencode-go-usageby 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 edynasty
DSH OpenCode Go provider plugin
★ 0
MIT
TypeScript
Aug 26, 2026
dsh plugin --profile web add dsh-opencode-go-providerby Retr67
DeepSeek Harness (DSH) plugin: one-click OpenCode Go model sync in the settings panel - fetch all server models, probe availability & vision, write back to llm-pi-ai config
★ 4
MIT
JavaScript
Oct 27, 2026
dsh plugin --profile web add dsh-opencode-modelsby jwilson411
DeepSeek Harness plugin: fail-closed URL host/scheme allowlist that runs before a request is opened
★ 0
MIT
JavaScript
Sep 21, 2026
dsh plugin --profile web add dsh-ssrf-guard