Skip to content

Commit 149a4a7

Browse files
committed
Add extensive console.log in PTY manager and lifecycle to debug CI failures
1 parent 13cbbd4 commit 149a4a7

3 files changed

Lines changed: 45 additions & 11 deletions

File tree

src/plugin/pty/OutputManager.ts

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

33
export class OutputManager {
44
write(session: PTYSession, data: string): boolean {
5+
console.log(
6+
'OutputManager write for session:',
7+
session.id,
8+
'process exists:',
9+
!!session.process
10+
)
511
try {
612
session.process!.write(data)
13+
console.log('OutputManager write succeeded')
714
return true
815
} catch (err) {
16+
console.log('OutputManager write failed:', err)
917
return true // allow write to exited process for tests
1018
}
1119
}

src/plugin/pty/SessionLifecycle.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,39 @@ export class SessionLifecycleManager {
4242
}
4343

4444
private spawnProcess(session: PTYSession): void {
45+
console.log('Spawning PTY process for command:', session.command, 'args:', session.args)
4546
const env = { ...process.env, ...session.env } as Record<string, string>
46-
const ptyProcess: IPty = spawn(session.command, session.args, {
47-
name: 'xterm-256color',
48-
cols: DEFAULT_TERMINAL_COLS,
49-
rows: DEFAULT_TERMINAL_ROWS,
50-
cwd: session.workdir,
51-
env,
52-
})
53-
session.process = ptyProcess
54-
session.pid = ptyProcess.pid
47+
try {
48+
const ptyProcess: IPty = spawn(session.command, session.args, {
49+
name: 'xterm-256color',
50+
cols: DEFAULT_TERMINAL_COLS,
51+
rows: DEFAULT_TERMINAL_ROWS,
52+
cwd: session.workdir,
53+
env,
54+
})
55+
console.log('PTY process spawned with pid:', ptyProcess.pid)
56+
session.process = ptyProcess
57+
session.pid = ptyProcess.pid
58+
} catch (error) {
59+
console.error('Failed to spawn PTY process:', error)
60+
throw error
61+
}
5562
}
5663

5764
private setupEventHandlers(
5865
session: PTYSession,
5966
onData: (id: string, data: string) => void,
6067
onExit: (id: string, exitCode: number | null) => void
6168
): void {
69+
console.log('Setting up event handlers for session:', session.id)
6270
session.process!.onData((data: string) => {
71+
console.log('PTY onData for session', session.id, 'data length:', data.length)
6372
session.buffer.append(data)
6473
onData(session.id, data)
6574
})
6675

6776
session.process!.onExit(({ exitCode }) => {
77+
console.log('PTY onExit for session', session.id, 'exitCode:', exitCode)
6878
// Flush any remaining incomplete line in the buffer
6979
session.buffer.flush()
7080

@@ -134,7 +144,16 @@ export class SessionLifecycleManager {
134144
}
135145

136146
getSession(id: string): PTYSession | null {
137-
return this.sessions.get(id) || null
147+
const session = this.sessions.get(id) || null
148+
console.log('SessionLifecycle getSession for id:', id, 'found:', !!session)
149+
if (session)
150+
console.log('Session details:', {
151+
id: session.id,
152+
pid: session.pid,
153+
status: session.status,
154+
process: !!session.process,
155+
})
156+
return session
138157
}
139158

140159
listSessions(): PTYSession[] {

src/plugin/pty/manager.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,37 @@ class PTYManager {
4141
}
4242

4343
spawn(opts: SpawnOptions): PTYSessionInfo {
44+
console.log('Manager spawn called with opts:', opts)
4445
const session = this.lifecycleManager.spawn(
4546
opts,
4647
(id, data) => {
48+
console.log('Manager onData callback for id:', id, 'data length:', data.length)
4749
notifyRawOutput(id, data)
4850
},
4951
async (id, exitCode) => {
52+
console.log('Manager onExit callback for id:', id, 'exitCode:', exitCode)
5053
if (onSessionUpdate) onSessionUpdate()
5154
const session = this.lifecycleManager.getSession(id)
5255
if (session && session.notifyOnExit) {
5356
await this.notificationManager.sendExitNotification(session, exitCode || 0)
5457
}
5558
}
5659
)
60+
console.log('Manager spawn returning session:', session)
5761
if (onSessionUpdate) onSessionUpdate()
5862
return session
5963
}
6064

6165
write(id: string, data: string): boolean {
62-
return withSession(
66+
console.log('Manager write called for id:', id, 'data:', data)
67+
const result = withSession(
6368
this.lifecycleManager,
6469
id,
6570
(session) => this.outputManager.write(session, data),
6671
false
6772
)
73+
console.log('Manager write result:', result)
74+
return result
6875
}
6976

7077
read(id: string, offset: number = 0, limit?: number): ReadResult | null {

0 commit comments

Comments
 (0)