debug: add PTY lifecycle logging

- Log PTY PID and shell when spawned
- Log all PTY output data
- Log PTY exit events with exit code and signal
- Log when WebSocket cannot send PTY data

This will help identify if the PTY is exiting immediately
or if there's an issue with the PTY process.
This commit is contained in:
uroma
2026-01-19 19:19:45 +00:00
Unverified
parent 8730641efd
commit 879e729b9f
3 changed files with 6 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -67,6 +67,8 @@ class TerminalService {
env: process.env
});
console.log(`[TerminalService] PTY spawned with PID: ${pty.pid}, shell: ${shell}`);
// Store terminal info
const terminal = {
id: terminalId,
@@ -140,17 +142,20 @@ class TerminalService {
// Handle PTY output - send to client
terminal.pty.onData((data) => {
console.log(`[TerminalService] PTY data from ${terminalId}: ${data.replace(/\n/g, '\\n').replace(/\r/g, '\\r')}`);
if (ws.readyState === ws.OPEN) {
ws.send(JSON.stringify({
type: 'data',
data: data
}));
} else {
console.log(`[TerminalService] Cannot send PTY data - WebSocket not open (state: ${ws.readyState})`);
}
});
// Handle PTY exit
terminal.pty.onExit(({ exitCode, signal }) => {
console.log(`[TerminalService] Terminal ${terminalId} exited: ${exitCode || signal}`);
console.log(`[TerminalService] PTY EXIT for ${terminalId}: exitCode=${exitCode}, signal=${signal}`);
this.logCommand(terminalId, null, `Terminal exited: ${exitCode || signal}`);
if (ws.readyState === ws.OPEN) {