fix: clean up OpenCode streams and allow external working directories

Completed OpenCode requests left their event streams open across repeated and
parallel conversations. Each request now closes its own subscription on exit
without cancelling peer sessions, and cancellation preserves its original cause.

Direct-model Execute commands no longer restrict cwd to the workspace. Absolute
paths, parent-relative paths, and symlinks to external directories are accepted.
The workspace remains the default and relative-path base; Ask stays read-only,
and local execution binding, directory validation, and process cleanup remain.

Add real OpenCode lifecycle and real Shell tool-loop regressions, plus matching
feature documentation. Focused checks: 182 passed, 1 skipped; typecheck and lint
passed. Full shared-worktree suite: 3542 passed, 57 skipped, 1 unrelated sidebar
heading failure, reproduced separately and documented.

Release note: 修复 OpenCode 连续及并行对话结束后事件连接未释放的问题;直连模型 Execute 命令现在可直接指定工作区外的绝对路径、相对路径或符号链接目录,Ask 只读边界保持不变。
This commit is contained in:
mesalogo
2026-09-06 19:53:42 +08:00
parent 7003141e56
commit b03c25685c
15 changed files with 394 additions and 100 deletions
+4 -1
View File
@@ -1980,6 +1980,7 @@ export class OpenCodeRuntime implements AgentRuntime {
let knowledgeToolIds: string[] = []
let customMcpName: string | undefined
let customMcpToken: string | undefined
const subscriptionController = new AbortController()
try {
if (
request.knowledgeCapabilityToken &&
@@ -2193,7 +2194,7 @@ export class OpenCodeRuntime implements AgentRuntime {
{ directory },
{ signal: controlSignal }
),
signal
AbortSignal.any([signal, subscriptionController.signal])
)
const abortSession = (): void => {
@@ -2699,6 +2700,7 @@ export class OpenCodeRuntime implements AgentRuntime {
)
)
}
signal.throwIfAborted()
throw new Error('OpenCode 事件流意外结束')
} catch (error) {
abortSession()
@@ -2739,6 +2741,7 @@ export class OpenCodeRuntime implements AgentRuntime {
}
}
} finally {
subscriptionController.abort()
const cleanupSignal = AbortSignal.timeout(1_000)
if (knowledgeMcpName) {
await awaitWithAbort(