somratpro commited on
Commit
4e5f895
·
1 Parent(s): d63dc26

fix: bypass gemini CLI relaunch mechanism using GEMINI_CLI_NO_RELAUNCH environment variable

Browse files
Files changed (2) hide show
  1. Dockerfile +13 -27
  2. start.sh +5 -2
Dockerfile CHANGED
@@ -69,37 +69,23 @@ RUN for cmd in claude codex; do \
69
  fi; \
70
  done
71
 
72
- # Gemini wrapper — definitive fix for "Failed to relaunch the CLI process":
73
  #
74
- # ROOT CAUSE: Gemini CLI checks process.execArgv for --max-old-space-size.
75
- # NODE_OPTIONS does NOT populate process.execArgv, so Gemini always tries to
76
- # relaunch itself with the flag as a CLI arg. That spawn fails in HF Spaces.
77
  #
78
- # FIX: Resolve the actual JS entry point at build time and invoke it directly
79
- # via `node --max-old-space-size=4096 <entry.js>` so the flag IS in execArgv.
80
- # Gemini sees it, skips the relaunch entirely.
81
  #
82
- # Also bake in headless env vars so they survive even when Paperclip spawns
83
- # gemini with a custom env object (no env inheritance fallback):
84
- # GEMINI_SANDBOX=false — skip Docker-sandbox attempt in containers
85
  # GEMINI_CLI_TRUST_WORKSPACE=true — skip interactive workspace-trust prompt
86
- RUN GEMINI_PKG="/usr/local/lib/node_modules/@google/gemini-cli" && \
87
- GEMINI_JS=$(node -e " \
88
- const pkg = require('$GEMINI_PKG/package.json'); \
89
- const bin = pkg.bin; \
90
- const entry = typeof bin === 'string' ? bin : (bin.gemini || bin[Object.keys(bin)[0]]); \
91
- console.log(require('path').resolve('$GEMINI_PKG', entry)); \
92
- ") && \
93
- echo "Gemini JS entry: $GEMINI_JS" && \
94
- mv /usr/local/bin/gemini /usr/local/bin/gemini-real && \
95
- { \
96
- echo '#!/bin/sh'; \
97
- echo 'unset NODE_OPTIONS'; \
98
- echo 'export NODE_OPTIONS="--no-deprecation --no-warnings"'; \
99
- echo 'export GEMINI_SANDBOX=false'; \
100
- echo 'export GEMINI_CLI_TRUST_WORKSPACE=true'; \
101
- echo "exec node --max-old-space-size=4096 $GEMINI_JS \"\$@\""; \
102
- } > /usr/local/bin/gemini && \
103
  chmod +x /usr/local/bin/gemini && \
104
  echo "=== gemini wrapper ===" && cat /usr/local/bin/gemini
105
 
 
69
  fi; \
70
  done
71
 
72
+ # Gemini wrapper — fix for "Failed to relaunch the CLI process":
73
  #
74
+ # ROOT CAUSE: relaunch.ts::relaunchAppInChildProcess() spawns a child process
75
+ # with stdio IPC. That spawn fails when Paperclip pipes gemini's stdio.
76
+ # Source: packages/cli/src/utils/relaunch.ts
77
  #
78
+ # FIX: GEMINI_CLI_NO_RELAUNCH=1 documented kill-switch in relaunch.ts that
79
+ # makes relaunchAppInChildProcess() return early (skip spawn entirely).
80
+ # The process then runs as the main process without a child.
81
  #
82
+ # Also bake in other headless vars so they survive even if Paperclip spawns
83
+ # gemini with a custom env object:
84
+ # GEMINI_SANDBOX=false — skip Docker-sandbox attempt
85
  # GEMINI_CLI_TRUST_WORKSPACE=true — skip interactive workspace-trust prompt
86
+ RUN mv /usr/local/bin/gemini /usr/local/bin/gemini-real && \
87
+ printf '#!/bin/sh\nunset NODE_OPTIONS\nexport NODE_OPTIONS="--max-old-space-size=4096 --no-deprecation --no-warnings"\nexport GEMINI_CLI_NO_RELAUNCH=1\nexport GEMINI_SANDBOX=false\nexport GEMINI_CLI_TRUST_WORKSPACE=true\nexec /usr/local/bin/gemini-real "$@"\n' \
88
+ > /usr/local/bin/gemini && \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  chmod +x /usr/local/bin/gemini && \
90
  echo "=== gemini wrapper ===" && cat /usr/local/bin/gemini
91
 
start.sh CHANGED
@@ -180,9 +180,12 @@ fi
180
  # Disable sandbox (would try to start Docker inside Docker)
181
  export GEMINI_SANDBOX=false
182
  # Trust the workspace — paperclip user runs from /app/paperclip (root-owned).
183
- # Without this, gemini's relaunch child fails the trust check and parent reports
184
- # "Failed to relaunch the CLI process."
185
  export GEMINI_CLI_TRUST_WORKSPACE=true
 
 
 
 
 
186
 
187
  # ── Background sync loop ──────────────────────────────────────────────────────
188
  if [ -n "${HF_TOKEN:-}" ]; then
 
180
  # Disable sandbox (would try to start Docker inside Docker)
181
  export GEMINI_SANDBOX=false
182
  # Trust the workspace — paperclip user runs from /app/paperclip (root-owned).
 
 
183
  export GEMINI_CLI_TRUST_WORKSPACE=true
184
+ # Kill-switch for relaunch.ts::relaunchAppInChildProcess() — the spawn inside
185
+ # fails when Paperclip pipes gemini's stdio (IPC channel setup fails).
186
+ # With this set, relaunchAppInChildProcess() returns early and gemini runs
187
+ # as the main process without spawning a child.
188
+ export GEMINI_CLI_NO_RELAUNCH=1
189
 
190
  # ── Background sync loop ──────────────────────────────────────────────────────
191
  if [ -n "${HF_TOKEN:-}" ]; then