stablyai/orca · error

Refusing to patch unexpected node-pty console-list agent sou

Error message

Refusing to patch unexpected node-pty console-list agent source

What it means

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.

Source

Thrown at config/relay-assets/node-pty-1.1.0-console-list-agent-patch.cjs:46

  const source = readFileSync(agentPath, 'utf8')
  return { agentPath, source }
}

function assertPatchedNodePtyConsoleListAgent(relayDir = process.cwd()) {
  const inspected = inspectNodePtyConsoleListAgent(relayDir)
  if (sourceSha256(inspected.source) !== PATCHED_SOURCE_SHA256) {
    throw new Error('node-pty ConPTY console-list fallback is not installed')
  }
}

function patchNodePtyConsoleListAgent(relayDir = process.cwd()) {
  const inspected = inspectNodePtyConsoleListAgent(relayDir)
  const sourceHash = sourceSha256(inspected.source)
  if (sourceHash === PATCHED_SOURCE_SHA256) {
    return
  }
  if (sourceHash !== ORIGINAL_SOURCE_SHA256) {
    throw new Error('Refusing to patch unexpected node-pty console-list agent source')
  }
  const patchedSource = inspected.source.replace(ORIGINAL_BODY, PATCHED_BODY)
  const temporaryPath = `${inspected.agentPath}.orca-patch-${process.pid}`
  // Why: a terminated remote install must leave either known source version recoverable on reconnect.
  try {
    writeFileSync(temporaryPath, patchedSource)
    renameSync(temporaryPath, inspected.agentPath)
  } finally {
    rmSync(temporaryPath, { force: true })
  }
  assertPatchedNodePtyConsoleListAgent(relayDir)
}

function sourceSha256(source) {
  return createHash('sha256').update(source).digest('hex')
}

if (require.main === module) {

View on GitHub (pinned to 1136503c6a)

Solutions

  1. Reinstall node-pty cleanly to restore the canonical 1.1.0 source (rm -rf node_modules/node-pty && pnpm install), then rerun the patch.
  2. If you intentionally edited the agent, revert your edits or re-derive ORIGINAL_SOURCE_SHA256 from the freshly installed file.
  3. 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.
  4. Ensure no other tool (formatter, linter, alternate patcher) runs over node_modules/node-pty/lib between install and patch.

Example fix

// before — file drifted from both known hashes
// node config/relay-assets/node-pty-1.1.0-console-list-agent-patch.cjs
// -> 'Refusing to patch unexpected node-pty console-list agent source'

// after — restore canonical source, then patch
// rm -rf node_modules/node-pty && pnpm install
// node config/relay-assets/node-pty-1.1.0-console-list-agent-patch.cjs
Defensive patterns

Strategy: validation

Validate before calling

const { createHash } = require('node:crypto')
const { readFileSync } = require('node:fs')

function assertAgentSourceRecognized(agentPath, originalSha, patchedSha) {
  const sha = createHash('sha256').update(readFileSync(agentPath, 'utf8')).digest('hex')
  if (sha !== originalSha && sha !== patchedSha) {
    throw new Error(`${agentPath} is in an unrecognized state (sha ${sha}); reinstall node-pty before patching.`)
  }
}
// assertAgentSourceRecognized(agentPath, ORIGINAL_SOURCE_SHA256, PATCHED_SOURCE_SHA256) before patching

Try / catch

try {
  patchNodePtyConsoleListAgent(relayDir)
} catch (error) {
  if (/unexpected node-pty console-list agent source/.test(error.message)) {
    console.error(`${error.message}\nFile is in an unknown state. Run 'rm -rf node_modules/node-pty && pnpm install' then retry.`)
    process.exit(1)
  }
  throw error
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of stablyai/orca@1136503c6a (2026-08-12). Data as JSON: /api/errors/25a4e21584fb7a0d. Report an issue: GitHub.