Skip to content

Commit e5fcde0

Browse files
committed
fix: block sending messages to child sessions
Child sessions (sessions with a parentID) are read-only views of subagent progress. The OpenCode TUI does not allow messaging them directly, but the plugin had no such guard. Add a parentID check in messaging.send_message that returns false early, matching the existing pattern for missing active sessions. Add a test that verifies child session sends are blocked and api_client.create_message is never called.
1 parent 1a40067 commit e5fcde0

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lua/opencode/services/messaging.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ M.send_message = Promise.async(function(prompt, opts)
1717
return false
1818
end
1919

20+
if state.active_session.parentID then
21+
return false
22+
end
23+
2024
local mentioned_files = context.get_context().mentioned_files or {}
2125
local allowed, err_msg = util.check_prompt_allowed(config.prompt_guard, mentioned_files)
2226

tests/unit/services_messaging_spec.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ describe('opencode.services.messaging', function()
7171
state.api_client.create_message = orig
7272
end)
7373

74+
it('returns false when active session is a child session', function()
75+
state.ui.set_windows({ mock = 'windows' })
76+
state.session.set_active({ id = 'child1', parentID = 'parent1' })
77+
78+
local create_called = false
79+
local orig = state.api_client.create_message
80+
state.api_client.create_message = function(_, sid, params)
81+
create_called = true
82+
return Promise.new():resolve({ id = 'm1' })
83+
end
84+
85+
local sent = messaging.send_message('hello world'):wait()
86+
assert.is_false(sent)
87+
assert.is_false(create_called)
88+
state.api_client.create_message = orig
89+
end)
90+
7491
it('increments and decrements user_message_count correctly', function()
7592
state.ui.set_windows({ mock = 'windows' })
7693
state.session.set_active({ id = 'sess1' })

0 commit comments

Comments
 (0)