Skip to content

Commit 7aa3518

Browse files
committed
fix(tui): forward directory-scoped events when TUI is in workspace mode (#26671)
The TUI's useEvent filter returned early in the workspace branch when the inbound event's workspace did not match the TUI's active workspace — including the common case where event.workspace was undefined because the session has no workspaceID. The early return meant directory-scoped events from external POSTs (web UI, SDK, curl) targeting a session running in the same directory were silently dropped, even though the server published them correctly with the right directory. Treat events without a workspace label as directory-scoped and fall through to the directory comparator so the TUI re-renders them. Also adds an explicit return after the global-event handler so a global event isn't forwarded twice. Test cases (a)-(c) in httpapi-promptasync-events.test.ts now all forward; (d) keeps cross-workspace events dropped. https://claude.ai/code/session_011VwDFG5W32dnu1qnT3SGr1
1 parent 4fdeb5a commit 7aa3518

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/context/event.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ export function useEvent() {
1515
// Special hack for truly global events
1616
if (event.directory === "global") {
1717
handler(event.payload)
18+
return
1819
}
1920

20-
if (project.workspace.current()) {
21+
// Workspace-scoped events match on workspace identity. Events without a
22+
// workspace label fall through to the directory check — a session with
23+
// no workspaceID can be live in the same directory as the TUI even when
24+
// the TUI itself is attached to a workspace (#26671).
25+
if (event.workspace !== undefined) {
2126
if (event.workspace === project.workspace.current()) {
2227
handler(event.payload)
2328
}
24-
2529
return
2630
}
2731

‎packages/opencode/test/server/httpapi-promptasync-events.test.ts‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
* in the TUI's client-side filter.
1818
*
1919
* Test 2 (synthetic filter): replicate the TUI useEvent filter shape from
20-
* packages/opencode/src/cli/cmd/tui/context/event.ts and prove the filter
21-
* drops events when the TUI has an active workspace but the inbound event has
22-
* workspace=undefined — even when the directory matches. That early `return`
23-
* in the workspace branch is the smoking gun.
20+
* packages/opencode/src/cli/cmd/tui/context/event.ts and lock in the fixed
21+
* behaviour: events without a workspace label fall through to a directory
22+
* comparison even when the TUI itself is attached to a workspace, so a
23+
* directory-mode session driven by an external POST is forwarded correctly.
2424
*/
2525

2626
import { afterEach, describe, expect, test } from "bun:test"
@@ -108,9 +108,10 @@ describe("session prompt_async events (issue #26671)", () => {
108108
expect(event.workspace).toBeUndefined()
109109
})
110110

111-
test("TUI useEvent filter drops events when active workspace is set but event.workspace is undefined", () => {
112-
// Mirrors the filter at packages/opencode/src/cli/cmd/tui/context/event.ts
113-
// exactly so we can document the behaviour that #26671 is observing.
111+
test("TUI useEvent filter forwards directory-scoped events even when the TUI has an active workspace", () => {
112+
// Mirrors the (fixed) filter at packages/opencode/src/cli/cmd/tui/context/event.ts.
113+
// If someone reverts the fix back to an early-return in the workspace
114+
// branch, case (c) below catches it.
114115
type IncomingEvent = {
115116
directory: string | undefined
116117
workspace: string | undefined
@@ -125,7 +126,7 @@ describe("session prompt_async events (issue #26671)", () => {
125126
if (event.payload.type === "sync") return false
126127
if (event.directory === "global") return true
127128

128-
if (activeWorkspace) {
129+
if (event.workspace !== undefined) {
129130
return event.workspace === activeWorkspace
130131
}
131132
return event.directory === activeDirectory
@@ -149,18 +150,27 @@ describe("session prompt_async events (issue #26671)", () => {
149150
}),
150151
).toBe(true)
151152

152-
// (c) THE BUG SHAPE FOR #26671:
153+
// (c) THE FIX FOR #26671:
153154
// TUI is in workspace mode, the inbound event has workspace=undefined
154-
// (because the session has no workspaceID and the external POST didn't
155-
// carry workspace context), but the directory still matches. The filter
156-
// bails out in the workspace branch without ever consulting directory,
157-
// so the event is dropped and the TUI never re-renders.
155+
// (the session has no workspaceID and the external POST didn't carry
156+
// workspace context), and the directory matches. The fixed filter
157+
// recognises that an event without a workspace label is directory-
158+
// scoped and consults the directory comparator, so this is forwarded.
158159
expect(
159160
tuiFilter({
160161
event: { directory: "/proj", workspace: undefined, payload: { type: "session.next.message.created" } },
161162
activeWorkspace: "W1",
162163
activeDirectory: "/proj",
163164
}),
165+
).toBe(true)
166+
167+
// (d) Cross-workspace events stay dropped.
168+
expect(
169+
tuiFilter({
170+
event: { directory: "/proj", workspace: "W2", payload: { type: "session.next.message.created" } },
171+
activeWorkspace: "W1",
172+
activeDirectory: "/proj",
173+
}),
164174
).toBe(false)
165175
})
166176
})

0 commit comments

Comments
 (0)