Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ function Task(props: ToolProps<typeof TaskTool>) {

onMount(() => {
if (props.metadata.sessionId && !sync.data.message[props.metadata.sessionId]?.length)
void sync.session.sync(props.metadata.sessionId)
void sync.session.sync(props.metadata.sessionId).catch(() => {})
})

const messages = createMemo(() => sync.data.message[props.metadata.sessionId ?? ""] ?? [])
Expand Down Expand Up @@ -2045,6 +2045,10 @@ function Task(props: ToolProps<typeof TaskTool>) {
return content.join("\n")
})

const childExists = createMemo(() =>
props.metadata.sessionId ? sync.data.session.some((s) => s.id === props.metadata.sessionId) : false,
)

return (
<InlineTool
icon="│"
Expand All @@ -2053,7 +2057,7 @@ function Task(props: ToolProps<typeof TaskTool>) {
pending="Delegating..."
part={props.part}
onClick={() => {
if (props.metadata.sessionId) {
if (props.metadata.sessionId && childExists()) {
navigate({ type: "session", sessionID: props.metadata.sessionId })
}
}}
Expand Down
24 changes: 24 additions & 0 deletions packages/opencode/test/cli/tui/task-missing-session.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Regression test for issue #26871
* "TUI crashes when task history references a missing child session"
*/
import { expect, test, describe } from "bun:test"

describe("Task component - missing child session", () => {
test(".catch() on fire-and-forget sync prevents crash", async () => {
const syncThatThrows = async (sessionId: string) => {
throw new Error(`Session not found: ${sessionId}`)
}

let unhandledRejection = false
const handler = () => { unhandledRejection = true }
process.on("unhandledRejection", handler)

void syncThatThrows("nonexistent-session-id").catch(() => {})

await new Promise((resolve) => setTimeout(resolve, 200))
process.off("unhandledRejection", handler)

expect(unhandledRejection).toBe(false)
})
})
Loading