feat(session): add child_readonly config and restore/lock agent type for child sessions#390
Open
jensenojs wants to merge 1 commit into
Open
feat(session): add child_readonly config and restore/lock agent type for child sessions#390jensenojs wants to merge 1 commit into
jensenojs wants to merge 1 commit into
Conversation
2ba416d to
8c89875
Compare
…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
a1d6d30 to
4a1642f
Compare
sudo-tee
reviewed
May 29, 2026
Owner
sudo-tee
left a comment
There was a problem hiding this comment.
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 |
Owner
There was a problem hiding this comment.
I would split this into multiple little helpers as it's a bit hard to follow, there is a lot of nesting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
child_readonlyconfig (default:true) to opt into messaging child sessionsRelated: #381, #387