{"record":{"id":"25a4e21584fb7a0d","repo":"stablyai/orca","slug":"refusing-to-patch-unexpected-node-pty-console-list","errorCode":null,"errorMessage":"Refusing to patch unexpected node-pty console-list agent source","messagePattern":"Refusing to patch unexpected node-pty console-list agent source","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/relay-assets/node-pty-1.1.0-console-list-agent-patch.cjs","lineNumber":46,"sourceCode":"  const source = readFileSync(agentPath, 'utf8')\n  return { agentPath, source }\n}\n\nfunction assertPatchedNodePtyConsoleListAgent(relayDir = process.cwd()) {\n  const inspected = inspectNodePtyConsoleListAgent(relayDir)\n  if (sourceSha256(inspected.source) !== PATCHED_SOURCE_SHA256) {\n    throw new Error('node-pty ConPTY console-list fallback is not installed')\n  }\n}\n\nfunction patchNodePtyConsoleListAgent(relayDir = process.cwd()) {\n  const inspected = inspectNodePtyConsoleListAgent(relayDir)\n  const sourceHash = sourceSha256(inspected.source)\n  if (sourceHash === PATCHED_SOURCE_SHA256) {\n    return\n  }\n  if (sourceHash !== ORIGINAL_SOURCE_SHA256) {\n    throw new Error('Refusing to patch unexpected node-pty console-list agent source')\n  }\n  const patchedSource = inspected.source.replace(ORIGINAL_BODY, PATCHED_BODY)\n  const temporaryPath = `${inspected.agentPath}.orca-patch-${process.pid}`\n  // Why: a terminated remote install must leave either known source version recoverable on reconnect.\n  try {\n    writeFileSync(temporaryPath, patchedSource)\n    renameSync(temporaryPath, inspected.agentPath)\n  } finally {\n    rmSync(temporaryPath, { force: true })\n  }\n  assertPatchedNodePtyConsoleListAgent(relayDir)\n}\n\nfunction sourceSha256(source) {\n  return createHash('sha256').update(source).digest('hex')\n}\n\nif (require.main === module) {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/relay-assets/node-pty-1.1.0-console-list-agent-patch.cjs#L28-L64","documentation":"Thrown by patchNodePtyConsoleListAgent when lib/conpty_console_list_agent.js hashes to neither ORIGINAL_SOURCE_SHA256 nor PATCHED_SOURCE_SHA256. The version check passed (still 1.1.0), but the file body is in an unrecognized state, so a blind string-replace patch could write corrupt JavaScript. The guard refuses rather than guess.","triggerScenarios":"The file was hand-edited; a previous failed/interrupted patch left a half-written file; an unrelated postinstall script also rewrites the agent; node-pty 1.1.0 was republished with a tweaked source (same version, different bytes).","commonSituations":"Manual edits to lib/conpty_console_list_agent.js for debugging that were not reverted; a code formatter (prettier/eslint --fix) rewrote the file; a concurrent patch process left a torn write despite the temp-file+rename guard; upstream node-pty republished 1.1.0 with a fix.","solutions":["Reinstall node-pty cleanly to restore the canonical 1.1.0 source (rm -rf node_modules/node-pty && pnpm install), then rerun the patch.","If you intentionally edited the agent, revert your edits or re-derive ORIGINAL_SOURCE_SHA256 from the freshly installed file.","Check whether upstream node-pty republished 1.1.0 by diffing lib/conpty_console_list_agent.js against the prior cached copy; if so, re-derive both hashes.","Ensure no other tool (formatter, linter, alternate patcher) runs over node_modules/node-pty/lib between install and patch."],"exampleFix":"// before — file drifted from both known hashes\n// node config/relay-assets/node-pty-1.1.0-console-list-agent-patch.cjs\n// -> 'Refusing to patch unexpected node-pty console-list agent source'\n\n// after — restore canonical source, then patch\n// rm -rf node_modules/node-pty && pnpm install\n// node config/relay-assets/node-pty-1.1.0-console-list-agent-patch.cjs","handlingStrategy":"validation","validationCode":"const { createHash } = require('node:crypto')\nconst { readFileSync } = require('node:fs')\n\nfunction assertAgentSourceRecognized(agentPath, originalSha, patchedSha) {\n  const sha = createHash('sha256').update(readFileSync(agentPath, 'utf8')).digest('hex')\n  if (sha !== originalSha && sha !== patchedSha) {\n    throw new Error(`${agentPath} is in an unrecognized state (sha ${sha}); reinstall node-pty before patching.`)\n  }\n}\n// assertAgentSourceRecognized(agentPath, ORIGINAL_SOURCE_SHA256, PATCHED_SOURCE_SHA256) before patching","typeGuard":null,"tryCatchPattern":"try {\n  patchNodePtyConsoleListAgent(relayDir)\n} catch (error) {\n  if (/unexpected node-pty console-list agent source/.test(error.message)) {\n    console.error(`${error.message}\\nFile is in an unknown state. Run 'rm -rf node_modules/node-pty && pnpm install' then retry.`)\n    process.exit(1)\n  }\n  throw error\n}","preventionTips":["Never hand-edit node_modules/node-pty/lib/conpty_console_list_agent.js — always reinstall to reset.","Ensure no formatter/linter runs over node_modules between install and patch.","When upstream node-pty republishes 1.1.0 with different bytes, re-derive hashes immediately."],"tags":["node-pty","patch","integrity","sha256","relay"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}