Skip to content

feat(session): add child_readonly config and restore/lock agent type for child sessions#390

Open
jensenojs wants to merge 1 commit into
sudo-tee:mainfrom
jensenojs:feat/child-session-improvements
Open

feat(session): add child_readonly config and restore/lock agent type for child sessions#390
jensenojs wants to merge 1 commit into
sudo-tee:mainfrom
jensenojs:feat/child-session-improvements

Conversation

@jensenojs
Copy link
Copy Markdown
Contributor

  • Add child_readonly config (default: true) to opt into messaging child sessions
  • Infer child session agent type from first assistant message (session.agent is unreliable — reflects last message agent, not creation agent)
  • Lock agent type in child sessions, reject user-initiated mode switches

Related: #381, #387

@jensenojs jensenojs force-pushed the feat/child-session-improvements branch from 2ba416d to 8c89875 Compare May 28, 2026 09:03
@jensenojs jensenojs marked this pull request as draft May 28, 2026 09:15
…for child sessions

- Add child_readonly config (default: true) to opt into messaging child sessions
- Infer child session agent type from first assistant message on switch
  (session.agent may be polluted by prior incorrect agent params)
- Lock agent type in child sessions, reject user-initiated mode switches
- Child sessions scan messages forward (first is reliable),
  parent sessions scan backward (most recent is current choice)
- Include subagents in agent validation list
- Send inferred agent type when messaging child sessions
  to override polluted session.agent on backend
@jensenojs jensenojs force-pushed the feat/child-session-improvements branch from a1d6d30 to 4a1642f Compare May 28, 2026 11:06
@jensenojs jensenojs marked this pull request as ready for review May 28, 2026 11:06
Copy link
Copy Markdown
Owner

@sudo-tee sudo-tee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Only 1 comment about the mode/model resolving.

Comment on lines +52 to +101
if selected_session and selected_session.parentID then
state.session.set_active(selected_session)
local ok, messages = pcall(function()
return session.get_messages(selected_session):await()
end)
local restored = false
if ok and messages then
local all_agents = vim.list_extend(config_file.get_opencode_agents():await(), config_file.get_subagents():await())
for i = 1, #messages do
local msg = messages[i]
if msg and msg.info and msg.info.mode then
if vim.tbl_contains(all_agents, msg.info.mode) then
state.model.set_mode(msg.info.mode)
if msg.info.providerID and msg.info.modelID then
state.model.set_model(msg.info.providerID .. '/' .. msg.info.modelID)
end
restored = true
break
end
end
end
end
if not restored then
-- Fallback to session.agent, then default_mode
if selected_session.agent then
local all_agents =
vim.list_extend(config_file.get_opencode_agents():await(), config_file.get_subagents():await())
if vim.tbl_contains(all_agents, selected_session.agent) then
state.model.set_mode(selected_session.agent)
else
state.model.set_mode(config.default_mode)
end
else
log.notify('Could not infer agent type for child session', vim.log.levels.WARN)
state.model.set_mode(config.default_mode)
end
end
elseif selected_session and selected_session.agent then
-- Parent session with agent info: restore directly
local available_agents = config_file.get_opencode_agents():await()
if vim.tbl_contains(available_agents, selected_session.agent) then
state.model.set_mode(selected_session.agent)
end
if selected_session.model then
local model_str = selected_session.model.providerID .. '/' .. selected_session.model.id
state.model.set_model(model_str)
end
else
agent_model.ensure_current_mode():await()
end
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split this into multiple little helpers as it's a bit hard to follow, there is a lot of nesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants