[Feature]: PTY exit notifications to use spawning conversation agent
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_spawntime. - 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
notifyOnExitand poll withpty_read.- Not ideal: worse UX.
- Force users to keep default agent = active agent.
- Not a real fix.
Use Case
- Default agent is
agent1. - User runs conversation with
agent2and starts a PTY withnotifyOnExit: true. - PTY exits.
<pty_exited>should be posted withagent2, notagent1.
Additional Context
- Repro before fix: default
agent1, activeagent2, PTY exit notification arrives asagent1. - Acceptance criterion: PTY exit notifications must use the same conversation agent that spawned the PTY session.
Hello ! I have the code ready to be pushed in a PR, feel free to open it or respond if you feel like something is missing :) Thanks
Sure, send a PR! @Llacoste2000
Also check out #22
@shekohex opened :)