fix(broker): handle write_pty frames in PTY worker#921
Conversation
The HTTP `/api/input/{name}` route forwards a `write_pty` frame to the
PTY worker, but the worker only handled `resize_pty` and `snapshot_pty`,
so the frame fell through to the unknown-type branch and the bytes
never reached the child PTY — even though the HTTP caller saw a
successful response with `bytes_written`. Interactive clients (e.g.
Pear's terminal tabs) attached via `sendInput()` could not type into
the spawned Claude/Codex PTYs.
Add a `write_pty` handler that pulls the `data` string from the payload
and writes it through `pty.write_all`, emitting a `worker_error` frame
only on malformed payloads or PTY write failures.
Fixes #920
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PTY worker now accepts ChangesPTY Write Input Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #920.
AgentRelayClient.sendInput()/POST /api/input/{name}returned success for PTY workers but the bytes never reached the child process. The HTTP route forwards awrite_ptyframe viaworkers.send_to_worker(..., "write_pty", ...)(crates/broker/src/runtime/api.rs:893), butcrates/broker/src/pty_worker.rsonly handledresize_ptyandsnapshot_pty—write_ptyfell through to the catch-all and emittedworker_error: unsupported message type 'write_pty'. Interactive clients (e.g. Pear's terminal tabs attaching to a spawned Claude/Codex PTY) could not type into the terminal.Change
Add a
write_ptyarm to the PTY worker's stdin frame handler incrates/broker/src/pty_worker.rsthat:datastring from the payload (matchingruntime/api.rs'sjson!({ "data": data })shape).pty.write_all(data.as_bytes())to push the keystrokes through the existing write queue.worker_errorframe only on malformed payloads (invalid_payload) or PTY write failures (pty_write_failed, retryable).The HTTP route is already correct — this just teaches the worker to honor the frame the route is already sending.
Test plan
cargo build -p agent-relay-brokersucceeds.cargo test -p agent-relay-broker --lib pty— all 57 PTY tests pass.client.sendInput(name, 'printf READY\n\r'), confirm the snapshot now containsREADYand noworker_errorevent is emitted.Generated by Claude Code