Problem Statement
When a PTY session is spawned with notifyOnExit: true, the exit notification (<pty_exited>) is posted back to the OpenCode conversation without explicitly setting the agent in the message payload.
In OpenCode, that causes the notification to be sent with the default configured agent, not necessarily the agent currently active in the conversation that launched the PTY session.
This breaks multi-agent workflows. Example: the active conversation agent is agent2, but the default agent is agent1. When the PTY session exits, the notification is emitted through agent1, and the conversation can continue with the wrong agent.
Proposed Solution
- Capture the active agent at
pty_spawn time.
- Store it in PTY session metadata.
- Reuse it when sending the exit notification (
body.agent).
- Keep fallback behavior when no agent metadata exists.
Alternatives Considered
- Disable
notifyOnExit and poll with pty_read.
- Force users to keep default agent = active agent.
Use Case
- Default agent is
agent1.
- User runs conversation with
agent2 and starts a PTY with notifyOnExit: true.
- PTY exits.
<pty_exited> should be posted with agent2, not agent1.
Additional Context
- Repro before fix: default
agent1, active agent2, PTY exit notification arrives as agent1.
- Acceptance criterion: PTY exit notifications must use the same conversation agent that spawned the PTY session.
Problem Statement
When a PTY session is spawned with
notifyOnExit: true, the exit notification (<pty_exited>) is posted back to the OpenCode conversation without explicitly setting the agent in the message payload.In OpenCode, that causes the notification to be sent with the default configured agent, not necessarily the agent currently active in the conversation that launched the PTY session.
This breaks multi-agent workflows. Example: the active conversation agent is
agent2, but the default agent isagent1. When the PTY session exits, the notification is emitted throughagent1, and the conversation can continue with the wrong agent.Proposed Solution
pty_spawntime.body.agent).Alternatives Considered
notifyOnExitand poll withpty_read.Use Case
agent1.agent2and starts a PTY withnotifyOnExit: true.<pty_exited>should be posted withagent2, notagent1.Additional Context
agent1, activeagent2, PTY exit notification arrives asagent1.