feat: add resize_pty protocol message for remote PTY resize#575
feat: add resize_pty protocol message for remote PTY resize#575willwashburn merged 3 commits intomainfrom
Conversation
When PTY agents are spawned by SDK clients (e.g. Electron apps), the worker process has no terminal attached, so SIGWINCH-based resize doesn't work. This adds a resize_pty message that flows from SDK → broker → worker, allowing clients to resize the PTY when their terminal emulator dimensions change. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
barryonthecape
left a comment
There was a problem hiding this comment.
Nice addition overall — wiring resize_pty through SDK → broker → worker is the right approach. I'm requesting changes for one behavior that can cause hard-to-debug terminal state issues.
Blocking issue:
- In
src/pty_worker.rs, the newresize_ptyhandler silently falls back torows=24/cols=80when payload fields are missing or invalid:frame.payload.get("rows")...unwrap_or(24)frame.payload.get("cols")...unwrap_or(80)
Why this is risky:
- A malformed frame can unexpectedly snap an active session back to 80x24 instead of failing fast.
- The broker already deserializes strongly typed
u16values forresize_pty; introducing permissive defaults in the worker creates inconsistent validation across layers. - This can hide protocol/client bugs and make UI resize issues intermittent.
Requested fix:
- Parse
rows/colsstrictly in the worker path (or decode asBrokerToWorker::ResizePty), and reject invalid payloads instead of defaulting. - Validate non-zero dimensions (
rows > 0 && cols > 0) before callingpty.resize. - Return or emit a structured worker error for invalid resize payloads so clients can surface actionable diagnostics.
After that, this looks good to me.
- Reject headless agents with unsupported_operation error - Validate rows/cols >= 1, return invalid_dimensions error for zeros - Use typed struct deserialization in pty_worker instead of manual JSON field extraction with silent defaults - Add BrokerToWorker::ResizePty round-trip test with wire format checks Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@barryonthecape All three points addressed in 511cff4:
Also added: broker rejects `resize_pty` for headless agents with `unsupported_operation`, and a round-trip test for the wire format. |
barryonthecape
left a comment
There was a problem hiding this comment.
Thanks for the fast follow-up — requested changes are addressed.\n\nVerified on latest commits:\n- Worker now strictly deserializes resize payloads (no silent 80x24 fallback) and returns structured worker_error invalid_payload on malformed input.\n- Broker and worker both reject zero dimensions with explicit invalid_dimensions errors.\n- Broker now rejects resize_pty for non-PTY agents with unsupported_operation.\n- Added protocol round-trip coverage for BrokerToWorker::ResizePty wire format.\n\nLGTM.
Summary
resize_ptyprotocol message across the full stack: Rust protocol types, broker dispatch, PTY worker handler, and TypeScript SDK client/typesresizePty(name, rows, cols)SDK method lets clients send terminal dimensions to the broker, which forwards them to the worker, which callspty.resize()Changes
src/protocol.rs: AddResizePty { rows, cols }toBrokerToWorkerenumsrc/main.rs: Addresize_ptyhandler in broker dispatch — validates agent exists, forwards to worker viasend_to_worker, returns confirmationsrc/pty_worker.rs: Handleresize_ptymessage in worker select loop — callspty.resize(rows, cols)packages/sdk/src/protocol.ts: Addresize_ptytoSdkToBrokerandBrokerToWorkertypespackages/sdk/src/client.ts: AddresizePty()method toAgentRelayClientTest plan
cargo checkpassestsc --noEmitpassesresizePty()on xterm resize, verify the agent TUI re-renders at the correct dimensions🤖 Generated with Claude Code