{"record":{"id":"7958b6002d28ae52","repo":"affaan-m/ECC","slug":"standard-input-remained-unavailable-after-maxret","errorCode":null,"errorMessage":"Standard input remained unavailable after ${maxRetryWaitMs}ms.","messagePattern":"Standard input remained unavailable after (.+?)ms\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/memory.js","lineNumber":175,"sourceCode":"    && retryOptions.maxRetryWaitMs >= 0\n    ? retryOptions.maxRetryWaitMs\n    : MAX_STDIN_RETRY_WAIT_MS;\n  const wait = typeof retryOptions.wait === 'function'\n    ? retryOptions.wait\n    : waitForStdinRetry;\n  const chunks = [];\n  let total = 0;\n  let remainingRetryWaitMs = maxRetryWaitMs;\n  while (total <= maxBytes) {\n    const buffer = Buffer.alloc(Math.min(64 * 1024, maxBytes + 1 - total));\n    let bytesRead;\n    try {\n      bytesRead = fs.readSync(0, buffer, 0, buffer.length, null);\n    } catch (error) {\n      const retryable = ['EAGAIN', 'EWOULDBLOCK', 'EINTR'].includes(error?.code);\n      if (!retryable) throw error;\n      if (remainingRetryWaitMs < retryDelayMs) {\n        throw new Error(\n          `Standard input remained unavailable after ${maxRetryWaitMs}ms.`\n        );\n      }\n      wait(retryDelayMs);\n      remainingRetryWaitMs -= retryDelayMs;\n      continue;\n    }\n    if (bytesRead === 0) break;\n    chunks.push(buffer.subarray(0, bytesRead));\n    total += bytesRead;\n  }\n  if (total > maxBytes) {\n    throw new Error(`memory body is too large (maximum ${maxBytes} bytes).`);\n  }\n  return decodeUtf8(Buffer.concat(chunks, total), 'memory body from standard input');\n}\n\nfunction readBody(options) {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/memory.js#L157-L193","documentation":"readBoundedStdin reads stdin with fs.readSync(0, ...). On non-blocking TTYs or interrupted reads the syscall can fail with EAGAIN/EWOULDBLOCK/EINTR; the function retries with delays up to maxRetryWaitMs. If stdin stays unavailable for the whole budget it throws 'Standard input remained unavailable after <maxRetryWaitMs>ms.' so callers know no body could be read.","triggerScenarios":"Running `node scripts/memory.js write` with no piped stdin in an environment where fd 0 is a non-blocking TTY (common in CI, docker run -t, or spawned processes without stdio inheritance).","commonSituations":"CI runners with detached stdin, `docker run` without `-i`, invoking the script from another tool that closes/doesn't forward stdin, or background jobs whose stdin is /dev/null with odd flags.","solutions":["Pipe the content explicitly: `echo \"note\" | node scripts/memory.js write --tags x` or `node scripts/memory.js write < body.txt`.","When spawning the script programmatically, pass `stdio: 'inherit'` or provide a pipe with the body written and ended.","When using docker, add `-i` (`docker run -i ...`) so stdin is attached.","If retries are timing out under load, increase the retry budget (maxRetryWaitMs) in the script or pre-buffer stdin before invoking."],"exampleFix":"// before\nnode scripts/memory.js write --tags note      # no stdin attached in CI\n// after\necho \"project decision\" | node scripts/memory.js write --tags note","handlingStrategy":"retry","validationCode":"if (process.stdin.isTTY && process.argv.includes('write') && !args.includes('--content')) {\n  console.error('This command reads stdin; pipe input or run interactively.');\n}","typeGuard":null,"tryCatchPattern":"try { body = readBoundedStdin(limit); } catch (e) { if (e.message.includes('Standard input remained unavailable')) { console.error('stdin unavailable — pipe input, e.g. `echo x | memory write`, or attach stdio in your runner'); process.exitCode = 2; } else throw e; }","preventionTips":["Always pipe stdin when invoking memory write non-interactively","Use stdio: 'inherit' or a provided pipe when spawning the script","Add -i when running under docker","Increase retry budget only after confirming stdin is actually expected"],"tags":["stdin","io","timeout"],"backgroundTag":"request-timeout","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}