Skip to content

Commit 244f4b3

Browse files
committed
fix(session): restore subagent mode from messages
Restore the mode recorded in session message history without validating it against the current agent list. Hidden or disabled subagents can remain valid for existing sessions; filtering them out left state.current_mode stuck on a stale main agent mode, affecting both UI display and subsequent message routing.
1 parent 3798e7f commit 244f4b3

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)