{"record":{"id":"1dc875525aefa786","repo":"coleam00/Archon","slug":"codebase-codebaseid-not-found","errorCode":null,"errorMessage":"Codebase ${codebaseId} not found","messagePattern":"Codebase (.+?) not found","errorType":"exception","errorClass":"CodebaseNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/core/src/db/codebases.ts","lineNumber":195,"sourceCode":"    values.push(data.repository_url);\n  }\n\n  if (data.default_branch !== undefined) {\n    updates.push(`default_branch = $${paramIndex++}`);\n    values.push(data.default_branch);\n  }\n\n  if (updates.length === 0) return;\n\n  updates.push(`updated_at = ${dialect.now()}`);\n  values.push(id);\n\n  const result = await pool.query(\n    `UPDATE remote_agent_codebases SET ${updates.join(', ')} WHERE id = $${paramIndex}`,\n    values\n  );\n  if ((result.rowCount ?? 0) === 0) {\n    throw new CodebaseNotFoundError(id);\n  }\n}\n\nexport async function listCodebases(): Promise<readonly Codebase[]> {\n  const result = await pool.query<Codebase>(\n    'SELECT * FROM remote_agent_codebases ORDER BY name ASC'\n  );\n  return result.rows;\n}\n\nexport async function deleteCodebase(id: string): Promise<void> {\n  getLog().debug({ codebaseId: id }, 'db.codebase_delete_cascade_started');\n  // First, unlink any sessions referencing this codebase (FK has no cascade)\n  await pool.query('UPDATE remote_agent_sessions SET codebase_id = NULL WHERE codebase_id = $1', [\n    id,\n  ]);\n  // Second, unlink any conversations referencing this codebase (FK has no cascade)\n  await pool.query(","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/codebases.ts#L177-L213","documentation":"updateCodebase builds a dynamic UPDATE for remote_agent_codebases and throws CodebaseNotFoundError (message 'Codebase ${id} not found') when rowCount is 0, i.e. no row matched the given id. This is the typed signal that the codebase identifier does not exist; callers (e.g. handleUpdateProject) catch it programmatically via its `name`.","triggerScenarios":"Calling updateCodebase with an id that has no row in remote_agent_codebases — deleted codebase, wrong/typo'd id, or an id from a different environment/database.","commonSituations":"A codebase was deleted by another operator while a workflow still referenced it; a stale id cached in config; pointing the app at a fresh database that lacks the row; copy-pasting an id from logs of another install.","solutions":["Verify the id: SELECT id, name FROM remote_agent_codebases; compare with the id being updated.","Re-create the codebase via the normal create/register flow if it was deleted, then retry the update.","Check which database the app is connected to (DSN) — the id may exist in another environment.","Clear stale references: update any config/workflow that caches the old codebase id to the current one.","Catch CodebaseNotFoundError in calling code and surface a user-facing 'codebase not found' instead of a generic 500."],"exampleFix":"// before\nawait updateCodebase(id, { name }); // throws if id unknown\n// after\ntry {\n  await updateCodebase(id, { name });\n} catch (e) {\n  if (e instanceof CodebaseNotFoundError) {\n    const all = await listCodebases();\n    throw new Error(`Codebase ${id} not found. Known: ${all.map(c => c.id).join(', ')}`);\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const { rows } = await pool.query('SELECT 1 FROM remote_agent_codebases WHERE id = $1', [id]);\nif (rows.length === 0) throw new Error(`codebase ${id} does not exist; create it first`);\nawait updateCodebase(id, updates);","typeGuard":"// Error-class narrowing is the idiomatic guard here\nfunction isCodebaseNotFound(e: unknown): e is CodebaseNotFoundError {\n  return e instanceof CodebaseNotFoundError;\n}","tryCatchPattern":"try {\n  await updateCodebase(id, updates);\n} catch (e) {\n  if (isCodebaseNotFound(e)) {\n    const known = (await listCodebases()).map(c => c.id);\n    throw new Error(`Codebase ${id} not found. Existing ids: ${known.join(', ')}`);\n  }\n  throw e;\n}","preventionTips":["Resolve codebase ids via listCodebases()/get-by-name rather than hardcoding or hand-copying ids.","Refresh cached ids when a codebase is deleted by another operator or session.","Catch CodebaseNotFoundError (typed, stable `name`) in orchestrator/adapter layers and map to a clean 404.","Verify DSN/environment before assuming the id is wrong."],"tags":["database","not-found","postgresql","update"],"backgroundTag":"record-not-found","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}