Skip to content

Commit 7a0d49c

Browse files
committed
Add extensive console.log for debugging CI PTY failures
- Log session creation, spawn, and API responses - Added logs in SessionLifecycle, manager, and API handlers - This will help identify why command is undefined in CI
1 parent 99e9461 commit 7a0d49c

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/plugin/pty/SessionLifecycle.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { spawn, type IPty } from 'bun-pty'
22
import { RingBuffer } from './buffer.ts'
3-
import type { PTYSession, PTYSessionInfo, SpawnOptions } from './types.ts'
3+
import type { PTYSession, PTYSessionInfo, SpawnOptions, PTYStatus } from './types.ts'
44
import { DEFAULT_TERMINAL_COLS, DEFAULT_TERMINAL_ROWS } from '../constants.ts'
55

66
const SESSION_ID_BYTE_LENGTH = 4
@@ -16,29 +16,32 @@ export class SessionLifecycleManager {
1616
private sessions: Map<string, PTYSession> = new Map()
1717

1818
private createSessionObject(opts: SpawnOptions): PTYSession {
19+
console.log('Creating session object with opts:', opts)
1920
const id = generateId()
2021
const args = opts.args ?? []
2122
const workdir = opts.workdir ?? process.cwd()
2223
const title =
2324
opts.title ?? (`${opts.command} ${args.join(' ')}`.trim() || `Terminal ${id.slice(-4)}`)
2425

2526
const buffer = new RingBuffer()
26-
return {
27+
const session = {
2728
id,
2829
title,
2930
description: opts.description,
3031
command: opts.command,
3132
args,
3233
workdir,
3334
env: opts.env,
34-
status: 'running',
35+
status: 'running' as PTYStatus,
3536
pid: 0, // will be set after spawn
3637
createdAt: new Date(),
3738
parentSessionId: opts.parentSessionId,
3839
notifyOnExit: opts.notifyOnExit ?? false,
3940
buffer,
4041
process: null, // will be set
4142
}
43+
console.log('Session object created:', session)
44+
return session
4245
}
4346

4447
private spawnProcess(session: PTYSession): void {
@@ -55,6 +58,12 @@ export class SessionLifecycleManager {
5558
console.log('PTY process spawned with pid:', ptyProcess.pid)
5659
session.process = ptyProcess
5760
session.pid = ptyProcess.pid
61+
console.log('Session after spawn:', {
62+
id: session.id,
63+
pid: session.pid,
64+
command: session.command,
65+
status: session.status,
66+
})
5867
} catch (error) {
5968
console.error('Failed to spawn PTY process:', error)
6069
throw error
@@ -152,6 +161,8 @@ export class SessionLifecycleManager {
152161
pid: session.pid,
153162
status: session.status,
154163
process: !!session.process,
164+
command: session.command,
165+
args: session.args,
155166
})
156167
return session
157168
}

src/plugin/pty/manager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ class PTYManager {
100100
return withSession(
101101
this.lifecycleManager,
102102
id,
103-
(session) => this.lifecycleManager.toInfo(session),
103+
(session) => {
104+
const info = this.lifecycleManager.toInfo(session)
105+
console.log('Manager get returning info:', info)
106+
return info
107+
},
104108
null
105109
)
106110
}

src/web/server/handlers/sessions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export async function getSession(req: BunRequest<'/api/sessions/:id'>): Promise<
4343
return new ErrorResponse('Invalid session ID', 400)
4444
}
4545
const session = manager.get(sessionId)
46+
console.log('API getSession for id:', sessionId, 'session:', session)
4647
if (!session) {
4748
return new ErrorResponse('Session not found', 404)
4849
}

0 commit comments

Comments
 (0)