{"record":{"id":"583cd5e5b632d945","repo":"slopus/happy","slug":"tmux-window-created-but-no-pid-returned","errorCode":null,"errorMessage":"Tmux window created but no PID returned","messagePattern":"Tmux window created but no PID returned","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/happy-cli/src/daemon/run.ts","lineNumber":469,"sourceCode":"          // Add all safe daemon environment variables (filtering out undefined)\n          for (const [key, value] of Object.entries(buildSessionChildEnvironment(ambientEnvironment, extraEnv))) {\n            if (value !== undefined) {\n              tmuxEnv[key] = value;\n            }\n          }\n\n          const tmuxResult = await tmux.spawnInTmux([sanitizedTmuxCommand], {\n            sessionName: tmuxSessionName,\n            windowName: windowName,\n            cwd: directory\n          }, tmuxEnv);  // Pass complete environment for tmux session\n\n          if (tmuxResult.success) {\n            logger.debug(`[DAEMON RUN] Successfully spawned in tmux session: ${tmuxResult.sessionId}, PID: ${tmuxResult.pid}`);\n\n            // Validate we got a PID from tmux\n            if (!tmuxResult.pid) {\n              throw new Error('Tmux window created but no PID returned');\n            }\n\n            // Create a tracked session for tmux windows - now we have the real PID!\n            const trackedSession: TrackedSession = {\n              startedBy: 'daemon',\n              pid: tmuxResult.pid, // Real PID from tmux -P flag\n              tmuxSessionId: tmuxResult.sessionId,\n              directoryCreated,\n              message: directoryCreated\n                ? `The path '${directory}' did not exist. We created a new folder and spawned a new session in tmux session '${tmuxSessionName}'. Use 'tmux attach -t ${tmuxSessionName}' to view the session.`\n                : `Spawned new session in tmux session '${tmuxSessionName}'. Use 'tmux attach -t ${tmuxSessionName}' to view the session.`\n            };\n\n            // Add to tracking map so webhook can find it later\n            pidToTrackedSession.set(tmuxResult.pid, trackedSession);\n\n            // Wait for webhook to populate session with happySessionId (exact same as regular flow)\n            logger.debug(`[DAEMON RUN] Waiting for session webhook for PID ${tmuxResult.pid} (tmux)`);","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/daemon/run.ts#L451-L487","documentation":"spawnSession launches a session inside a tmux window using tmux -P (print) to capture the spawned process's PID. If tmux reports success but no PID came back, the daemon cannot track the session, so it throws rather than creating an untracked session.","triggerScenarios":"tmuxResult.success is true but tmuxResult.pid is falsy — the tmux -P output was empty or unparsed, e.g. an older tmux version or unexpected output format.","commonSituations":"tmux installed via an old version that doesn't print the pane PID as expected; tmux config (hooks, alternate formats) alters -P output; session spawning inside a wrapper that swallows tmux output.","solutions":["Upgrade tmux to a recent version (≥3.x) so -P returns the pane PID","Run the spawn command manually in tmux to inspect raw -P output","Clear custom tmux configs that change output formats and retry","Restart the daemon and retry spawning the session"],"exampleFix":"// before\nif (!tmuxResult.pid) {\n  throw new Error('Tmux window created but no PID returned');\n}\n// after\nif (!tmuxResult.pid) {\n  logger.warn('tmux returned no PID; falling back to pgrep lookup');\n  tmuxResult.pid = findPidBySessionId(tmuxResult.sessionId);\n}\nif (!tmuxResult.pid) {\n  throw new Error('Tmux window created but no PID returned');\n}","handlingStrategy":"try-catch","validationCode":"// Before spawning, verify tmux supports -P PID output\nclass CheckTmux {\n  static async version() {\n    const out = spawn.sync('tmux', ['-V']).stdout?.toString() || '';\n    return out; // expect tmux 3.x\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const session = await spawnSession(opts);\n} catch (err) {\n  if (err.message === 'Tmux window created but no PID returned') {\n    console.error('Upgrade tmux (>=3.x) or clear custom tmux output-format configs, then retry.');\n  } else throw err;\n}","preventionTips":["Keep tmux at a recent version (3.x+) so -P prints pane PIDs","Avoid tmux configs that alter -P / format output","Kill stale tmux servers (`tmux kill-server`) after failed spawns","Verify the session was spawned with `tmux list-windows` when in doubt"],"tags":["tmux","daemon","process"],"backgroundTag":"tmux-pid-not-returned","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}