{"record":{"id":"6eaa611530ab42b5","repo":"can1357/oh-my-pi","slug":"command-timed-out-after-err-message-slice-timeo","errorCode":null,"errorMessage":"Command timed out after ${err.message.slice(\"timeout:\".length)} seconds","messagePattern":"Command timed out after (.+?) seconds","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/extensibility/legacy-pi-coding-agent-shim.ts","lineNumber":394,"sourceCode":"\t\t\tonData,\n\t\t\tsignal,\n\t\t\ttimeout,\n\t\t\tenv: spawn.env,\n\t\t});\n\t\tconst snapshot = legacyBashSnapshot(output);\n\t\tconst text = snapshot.text || \"(no output)\";\n\t\tif (result.exitCode !== 0 && result.exitCode !== null) {\n\t\t\tthrow new Error(appendStatus(text, `Command exited with code ${result.exitCode}`));\n\t\t}\n\t\treturn { content: [{ type: \"text\", text }], details: snapshot.details };\n\t} catch (err) {\n\t\tconst snapshot = legacyBashSnapshot(output);\n\t\tconst text = snapshot.text;\n\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\tthrow new Error(appendStatus(text, \"Command aborted\"));\n\t\t}\n\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\tthrow new Error(appendStatus(text, `Command timed out after ${err.message.slice(\"timeout:\".length)} seconds`));\n\t\t}\n\t\tthrow err;\n\t}\n}\n\n/**\n * Convert an image attachment to PNG using the legacy package-root contract.\n *\n * Invalid or unsupported image data returns `null`, matching Pi's historical\n * helper instead of surfacing Bun's decoder error to extensions.\n */\nexport async function convertToPng(\n\tbase64Data: string,\n\tmimeType: string,\n): Promise<{ data: string; mimeType: string } | null> {\n\tif (mimeType === \"image/png\") {\n\t\treturn { data: base64Data, mimeType };\n\t}","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/extensibility/legacy-pi-coding-agent-shim.ts#L376-L412","documentation":"The legacy bash command exceeded its configured timeout and was killed. The underlying spawn rejects with a message of the form 'timeout:N'; this handler rewrites it into a user-friendly 'Command timed out after N seconds' message, preserving captured output.","triggerScenarios":"executeLegacyBashOperations runs a command whose runtime exceeds the timeout passed to the spawn (err.message starts with 'timeout:'); the process is killed and this error is thrown.","commonSituations":"Long builds, installs, or interactive commands that never terminate; timeout set too low in tool options; commands waiting on stdin in non-interactive contexts.","solutions":["Increase the timeout option when creating/invoking the bash tool","Fix the command so it completes (remove interactive prompts, add input redirection)","Run genuinely long work in the background and poll it","Capture the partial output in the error to see how far the command got"],"exampleFix":"// before\ncreateBashToolDefinition(cwd, { timeout: 10 });\n// after\ncreateBashToolDefinition(cwd, { timeout: 120 });","handlingStrategy":"retry","validationCode":"// estimate worst-case runtime and compare against the configured timeout before running\nif (estimatedSeconds >= timeoutSeconds) throw new Error('command will exceed configured timeout; raise timeout or background it');","typeGuard":"function isTimeout(e: unknown): boolean { return e instanceof Error && e.message.includes('Command timed out after'); }","tryCatchPattern":"try { await bashTool.execute({ command }); } catch (err) {\n  if (err instanceof Error && err.message.includes('Command timed out after')) {\n    const secs = Number(err.message.match(/after (\\d+) seconds/)?.[1]);\n    return retryWith({ timeout: secs * 4 });\n  }\n  throw err;\n}","preventionTips":["Set timeouts above realistic worst-case runtimes for the commands your agent issues","Redirect stdin (/dev/null) so commands never block waiting for input","Background long jobs and poll instead of relying on a single long call","Parse the 'timed out after N seconds' message to size retry timeouts"],"tags":["bash","timeout","legacy-shim","process"],"backgroundTag":"command-timeout","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}