Skip to content

Commit fd018b9

Browse files
Fix: Prevent freezing in non-interactive Gemini CLI when debug mode is enabled
The CLI would hang indefinitely when the '--debug' or '-d' flag was used in non-interactive (e.g., scripting) mode. This was becauseof waiting for debugger to connect. This change ensures that the debug output mechanism does not block the process flow in headless environments.
1 parent 934b309 commit fd018b9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/cli/src/utils/sandboxUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ export function entrypoint(workdir: string, cliArgs: string[]): string[] {
136136
const quotedCliArgs = cliArgs.slice(2).map((arg) => quote([arg]));
137137
const cliCmd =
138138
process.env['NODE_ENV'] === 'development'
139-
? process.env['DEBUG']
139+
? process.env['DEBUG'] === 'true' || process.env['DEBUG'] === '1'
140140
? 'npm run debug --'
141141
: 'npm rebuild && npm run start --'
142-
: process.env['DEBUG']
142+
: process.env['DEBUG'] === 'true' || process.env['DEBUG'] === '1'
143143
? `node --inspect-brk=0.0.0.0:${process.env['DEBUG_PORT'] || '9229'} $(which gemini)`
144144
: 'gemini';
145145

scripts/start.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ try {
4646
// if debugging is enabled and sandboxing is disabled, use --inspect-brk flag
4747
// note with sandboxing this flag is passed to the binary inside the sandbox
4848
// inside sandbox SANDBOX should be set and sandbox_command.js should fail
49-
if (process.env.DEBUG && !sandboxCommand) {
49+
const isInDebugMode = process.env.DEBUG === '1' || process.env.DEBUG === 'true';
50+
51+
if (isInDebugMode && !sandboxCommand) {
5052
if (process.env.SANDBOX) {
5153
const port = process.env.DEBUG_PORT || '9229';
5254
nodeArgs.push(`--inspect-brk=0.0.0.0:${port}`);
@@ -64,7 +66,7 @@ const env = {
6466
DEV: 'true',
6567
};
6668

67-
if (process.env.DEBUG) {
69+
if (isInDebugMode) {
6870
// If this is not set, the debugger will pause on the outer process rather
6971
// than the relaunched process making it harder to debug.
7072
env.GEMINI_CLI_NO_RELAUNCH = 'true';

0 commit comments

Comments
 (0)