Repository navigation
Conversation
Reject writes unless the session is running and has a process; return false when process.write throws instead of reporting success. Intentionally change POST /api/sessions/:id/input for inactive PTYs from HTTP 200 to 400. The shared manager also rejects pty_write when a session exits during permission checks in v1 and v2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OutputManager.write()returnstrueeven when nothing was written. An exited PTY answersPOST /api/sessions/:id/inputwith a success, andpty_writecan report "Sent N bytes" for input that never reached a process. This PR makeswrite()report the real outcome.In plain terms: if the agent or the web page tried to type into a terminal that had already finished, the plugin said the input was sent when nothing could receive it. Now it says the write failed.
Cause
write()swallowed every error and returnedtrue, with the comment "allow write to exited process for tests". It also never checked the session state:pty_writechecks that the session is running and then awaits the command permission check. If the PTY exits during that wait, the write still returnedtrueand the tool reported success.Changes
write()returnsfalseunless the session is running and has a process, and it returnsfalsewhen the native write throws. The only test that depended on the old behavior is updated.Behavior changes
POST /api/sessions/:id/inputon a session that is not running now answers 400 with{ "error": "Failed to write to session" }instead of 200.pty_writethrowsFailed to write to PTY '<id>'.when the session exits before the write, instead of reporting "Sent N bytes".pty_writewith an emptydatastring now fails instead of replying "Sent 0 bytes". The native write throws on an empty string (bun:ffi cannot convert argument to 'ptr'), and the old code hid that error.write(), as before.Validation
The integration test that wrote to an exited PTY now expects 400 and the error body. On main it fails with 200. Replacing the body of
write()withreturn truemakes it fail again.bun testovertest/*.test.ts, without the live and npm-pack suites, gives 184 passing.bun run typecheck,bun run lintandbunx biome format .are clean. I did not run the Playwright e2e suite locally. I found no e2e test or tool test that depends on writing to a finished PTY.Diff
Production: +1 line (+3/-2) in
src/plugin/pty/output-manager.ts.Tests: +1 line (+2/-1) in
test/integration.test.ts.