opencode-pty icon indicating copy to clipboard operation
opencode-pty copied to clipboard

[Feature]: PTY exit notifications to use spawning conversation agent

Open Llacoste2000 opened this issue 9 months ago • 4 comments

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

  1. Disable notifyOnExit and poll with pty_read.
    • Not ideal: worse UX.
  2. Force users to keep default agent = active agent.
    • Not a real fix.

Use Case

  1. Default agent is agent1.
  2. User runs conversation with agent2 and starts a PTY with notifyOnExit: true.
  3. PTY exits.
  4. <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.

Llacoste2000 avatar Feb 17 '26 13:02 Llacoste2000

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

Llacoste2000 avatar Feb 17 '26 13:02 Llacoste2000

Sure, send a PR! @Llacoste2000

shekohex avatar Feb 17 '26 15:02 shekohex

Also check out #22

shekohex avatar Feb 17 '26 15:02 shekohex

@shekohex opened :)

Llacoste2000 avatar Feb 17 '26 15:02 Llacoste2000