{"record":{"id":"4c8e831751f136e9","repo":"slopus/happy","slug":"failed-to-extract-pid-from-tmux-output-createre","errorCode":null,"errorMessage":"Failed to extract PID from tmux output: ${createResult.stdout}","messagePattern":"Failed to extract PID from tmux output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/happy-cli/src/utils/tmux.ts","lineNumber":845,"sourceCode":"\n            // Add the command to run in the window (runs immediately when window is created)\n            createWindowArgs.push(fullCommand);\n\n            // Add -P flag to print the pane PID immediately\n            createWindowArgs.push('-P');\n            createWindowArgs.push('-F', '#{pane_pid}');\n\n            // Create window with command and get PID immediately\n            const createResult = await this.executeTmuxCommand(createWindowArgs, sessionName);\n\n            if (!createResult || createResult.returncode !== 0) {\n                throw new Error(`Failed to create tmux window: ${createResult?.stderr}`);\n            }\n\n            // Extract the PID from the output\n            const panePid = parseInt(createResult.stdout.trim());\n            if (isNaN(panePid)) {\n                throw new Error(`Failed to extract PID from tmux output: ${createResult.stdout}`);\n            }\n\n            logger.debug(`[TMUX] Spawned command in tmux session ${sessionName}, window ${windowName}, PID ${panePid}`);\n\n            // Return tmux session info and PID\n            const sessionIdentifier: TmuxSessionIdentifier = {\n                session: sessionName,\n                window: windowName\n            };\n\n            return {\n                success: true,\n                sessionId: formatTmuxSessionIdentifier(sessionIdentifier),\n                pid: panePid\n            };\n        } catch (error) {\n            logger.debug('[TMUX] Failed to spawn in tmux:', error);\n            return {","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/utils/tmux.ts#L827-L863","documentation":"After creating the tmux window with -F '#{pane_pid}', spawnInTmux parses stdout with parseInt and expects a numeric PID. If the output is empty or non-numeric (parseInt yields NaN), it throws this Error including the raw stdout, since the caller relies on the PID for process tracking.","triggerScenarios":"The new-window command returned 0 but stdout did not contain a pane PID: unusual tmux versions/formats where #{pane_pid} isn't supported, output polluted by warnings, a format-string substitution failing, or stdout containing locale-formatted or empty text.","commonSituations":"Very old or patched tmux builds lacking #{pane_pid}; terminal hooks or shell rc output injected into the captured stream; tmux wrapping the PID with extra characters; running under a tmux wrapper script that alters output format.","solutions":["Verify `tmux display-message -p -t <target> '#{pane_pid}'` prints a number in your environment.","Upgrade tmux to a version that supports the #{pane_pid} format variable.","Inspect the stdout in the error message to see what was actually returned and strip noise.","Disable shell/profile output that may pollute non-interactive command output.","As a fallback, resolve the PID afterwards via tmux list-panes -F '#{pane_pid}'."],"exampleFix":"// before\nconst panePid = parseInt(createResult.stdout.trim()); // NaN when stdout is 'PID: 12345'\n// after\nconst match = createResult.stdout.trim().match(/(\\d+)\\s*$/);\nif (!match) throw new Error(`No PID in tmux output: ${createResult.stdout}`);\nconst panePid = parseInt(match[1], 10);","handlingStrategy":"try-catch","validationCode":"// confirm #{pane_pid} works in your tmux before relying on it\nconst out = await execFileP('tmux', ['display-message', '-p', '#{pane_pid}']);\nif (!/^\\d+$/.test(out.trim())) throw new Error(`tmux #{pane_pid} unsupported: ${out}`);","typeGuard":"function isNumericPid(stdout: string): boolean {\n  return /^\\d+$/.test(stdout.trim());\n}","tryCatchPattern":"try {\n  await tmux.spawnInTmux(cmd);\n} catch (err) {\n  if ((err as Error).message.startsWith('Failed to extract PID')) {\n    const pid = await lookupPanePid(sessionName, windowName); // tmux list-panes fallback\n    logger.warn(`PID fallback resolved: ${pid}`);\n  } else throw err;\n}","preventionTips":["Use a tmux version that supports the #{pane_pid} format variable.","Keep non-interactive shell profiles silent so tmux output isn't polluted.","Test PID capture after any tmux upgrade.","Have a list-panes -F '#{pane_pid}' fallback ready."],"tags":["tmux","parsing","process","output-format"],"backgroundTag":"unexpected-command-output","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}