Skip to content

Commit 1fd15a2

Browse files
committed
fix(pty): reject writes to inactive sessions
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.
1 parent b6c2067 commit 1fd15a2

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎src/plugin/pty/output-manager.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import type { PTYSession, ReadResult, SearchResult } from './types.ts'
22

33
export class OutputManager {
44
write(session: PTYSession, data: string): boolean {
5+
if (session.status !== 'running' || !session.process) return false
56
try {
6-
session.process?.write(data)
7+
session.process.write(data)
78
return true
89
} catch {
9-
return true // allow write to exited process for tests
10+
return false
1011
}
1112
}
1213

‎test/integration.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ describe('Web Server Integration', () => {
114114
}
115115
)
116116

117+
expect(response.status).toBe(400)
117118
const result = await response.json()
118-
expect(result).toHaveProperty('success')
119+
expect(result).toEqual({ error: 'Failed to write to session' })
119120

120121
const errorPromise = new Promise((resolve) => {
121122
managedTestClient.errorCallbacks.push((message) => {

0 commit comments

Comments
 (0)