{"record":{"id":"413574c839d9ead9","repo":"affaan-m/ECC","slug":"open-failed-http-res-statuscode","errorCode":null,"errorMessage":"open failed (HTTP ${res.statusCode})","messagePattern":"open failed \\(HTTP (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/plan-canvas.js","lineNumber":233,"sourceCode":"async function cmdStatus({ stateDir, port }) {\n  const health = await healthCheck(port);\n  if (!health) {\n    return { server: 'not running', hint: 'open an artifact to start one', stateDir };\n  }\n  const sessions = await request(port, 'GET', '/api/sessions');\n  return { server: `http://${DEFAULT_HOST}:${port}`, version: health.version, sessions: sessions.body.sessions };\n}\n\nasync function cmdOpen(file, args, { stateDir, port }) {\n  if (!file) throw new Error('open requires a file path');\n  if (!fs.existsSync(path.resolve(file))) throw new Error(`artifact not found: ${file}`);\n  await ensureServer({ stateDir, port });\n  const res = await request(port, 'POST', '/api/sessions', {\n    file: path.resolve(file),\n    reopen: args.includes('--reopen')\n  });\n  if (res.statusCode === 409) return res.body;\n  if (res.statusCode !== 200) throw new Error(res.body.error || `open failed (HTTP ${res.statusCode})`);\n  const url = `http://${DEFAULT_HOST}:${port}${res.body.url}`;\n  const launched = args.includes('--no-open') ? false : openBrowser(url);\n  return {\n    status: 'open',\n    url,\n    browser: launched ? 'opened' : 'not opened',\n    next_step:\n      'Run `ecc-plan-canvas await <file>` and leave it running; it returns when the human sends feedback, a verdict, or ends the session.'\n  };\n}\n\nfunction awaitRequest(port, key, timeoutMs) {\n  if (!/^[a-f0-9]{12}$/.test(key)) throw new Error('invalid plan-canvas session key');\n  const params = new URLSearchParams({ key });\n  if (timeoutMs !== null) params.set('timeoutMs', String(timeoutMs));\n  return new Promise((resolve, reject) => {\n    const req = http.request(\n      requestOptions(port, 'GET', `/api/await?${params}`, {}),","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/plan-canvas.js#L215-L251","documentation":"Thrown by cmdOpen in scripts/plan-canvas.js when POST /api/sessions returns a status code that is neither 200 (success) nor 409 (conflict, session already open). The message prefers the server's own error body if present, falling back to the generic HTTP-status form shown. This indicates the canvas server received the request but rejected it.","triggerScenarios":"The server returns 400 (malformed session body), 500 (internal error during session creation), or any other non-200/409 code. If res.body.error is set by the server, that message is used; otherwise the generic `open failed (HTTP <code>)` is thrown.","commonSituations":"The artifact file watcher cannot read the file at session-creation time; the session store on disk is corrupted; a server bug during canonicalization; a version-skewed server that does not understand the request shape.","solutions":["If res.body.error was surfaced, address that specific message first.","Restart the server (`node scripts/plan-canvas.js stop`, then retry open) to clear transient state.","Inspect server.log in the state directory for the stack trace behind a 500.","Ensure the ECC version of the running server matches the CLI (a version mismatch normally triggers a clean restart, but a stale server.json can defeat that)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await cmdOpen(file, args, context);\n} catch (err) {\n  if (/open failed \\(HTTP/.test(err.message)) {\n    const log = fs.readFileSync(path.join(stateDir, 'server.log'), 'utf8');\n    console.error('Session creation failed. server.log tail:\\n', log.split('\\n').slice(-30).join('\\n'));\n    await cmdStop(context); // reset before retry\n  }\n  throw err;\n}","preventionTips":["Always read server.log when a non-200/409 is returned — the server-side error is logged there.","Stop and restart the canvas server between retries to clear corrupted session state.","Confirm the running server version matches the CLI before assuming a protocol error."],"tags":["plan-canvas","network","server","http"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}