Skip to content

Commit dfaa72e

Browse files
committed
fix(session): restore subagent mode from messages
Hidden subagents are filtered out of the visible primary-agent list so primary agents cannot discover them by default. That visibility rule should not affect restoring an existing session's agent type. When restoring a session, the tabbar/footer and subsequent message routing should use the agent type recorded on the session messages. Filtering msg.info.mode through the visible primary-agent list caused hidden subagent sessions to keep a stale primary mode in state.current_mode.
1 parent 3798e7f commit dfaa72e

2 files changed

Lines changed: 3 additions & 14 deletions

File tree

lua/opencode/services/agent_model.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,7 @@ M.initialize_current_model = Promise.async(function(opts)
174174
state.model.set_model(model_str)
175175
end
176176
if msg.info.mode and state.current_mode ~= msg.info.mode then
177-
local available_agents = config_file.get_opencode_agents():await()
178-
if vim.tbl_contains(available_agents, msg.info.mode) then
179-
state.model.set_mode(msg.info.mode)
180-
end
177+
state.model.set_mode(msg.info.mode)
181178
end
182179
return state.current_model
183180
end

tests/unit/services_agent_model_spec.lua

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ describe('opencode.services.agent_model', function()
145145
state.model.set_model('openai/gpt-4.1')
146146
state.model.set_mode('plan')
147147

148-
stub(config_file, 'get_opencode_agents').returns(Promise.new():resolve({ 'plan', 'build' }))
149-
150148
state.renderer.set_messages({
151149
{
152150
info = {
@@ -163,16 +161,12 @@ describe('opencode.services.agent_model', function()
163161
assert.equal('anthropic/claude-3-opus', model)
164162
assert.equal('anthropic/claude-3-opus', state.current_model)
165163
assert.equal('build', state.current_mode)
166-
167-
config_file.get_opencode_agents:revert()
168164
end)
169165

170-
it('does not restore mode to a hidden agent from messages', function()
166+
it('restores mode from messages even if the agent is hidden', function()
171167
state.model.set_model('openai/gpt-4.1')
172168
state.model.set_mode('build')
173169

174-
stub(config_file, 'get_opencode_agents').returns(Promise.new():resolve({ 'plan', 'build' }))
175-
176170
state.renderer.set_messages({
177171
{
178172
info = {
@@ -188,8 +182,6 @@ describe('opencode.services.agent_model', function()
188182

189183
assert.equal('anthropic/claude-3-opus', model)
190184
assert.equal('anthropic/claude-3-opus', state.current_model)
191-
assert.equal('build', state.current_mode)
192-
193-
config_file.get_opencode_agents:revert()
185+
assert.equal('hidden-xyz', state.current_mode)
194186
end)
195187
end)

0 commit comments

Comments
 (0)