{"record":{"id":"367a3ce1089ed0d9","repo":"different-ai/openwork","slug":"automation-saved-script-version-not-found","errorCode":"automation_saved_script_version_not_found","errorMessage":"automation_saved_script_version_not_found","messagePattern":"automation_saved_script_version_not_found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-api/src/workflows.ts","lineNumber":576,"sourceCode":"      eq(ConfigObjectTable.id, ConfigObjectVersionTable.configObjectId),\n      eq(ConfigObjectTable.organizationId, organizationId),\n      eq(ConfigObjectTable.objectType, \"workflow\"),\n      eq(ConfigObjectTable.status, \"active\"),\n      isNull(ConfigObjectTable.deletedAt),\n    ))\n    .innerJoin(PluginConfigObjectTable, and(\n      eq(PluginConfigObjectTable.configObjectId, ConfigObjectTable.id),\n      eq(PluginConfigObjectTable.pluginId, pluginId),\n      isNull(PluginConfigObjectTable.removedAt),\n    ))\n    .where(and(\n      eq(ConfigObjectVersionTable.id, configObjectVersionId),\n      eq(ConfigObjectVersionTable.configObjectId, configObjectId),\n      eq(ConfigObjectVersionTable.organizationId, organizationId),\n      eq(ConfigObjectVersionTable.isDeletedVersion, false),\n    )).limit(1)\n  const version = rows[0]?.version\n  if (!version) throw new Error(\"automation_saved_script_version_not_found\")\n  const parsed = parseCodemodeScriptPayload(version.normalizedPayloadJson)\n  if (!parsed.ok) throw new Error(\"automation_saved_script_version_invalid\")\n  if (parsed.payload.inputSchema) {\n    const validation = validateCodemodeScriptInput(parsed.payload.inputSchema, input.action.input)\n    if (!validation.ok) throw new Error(\"automation_saved_script_input_invalid\")\n  }\n}\n\nexport async function saveWorkflow(input: {\n  organizationId: string\n  ownerMemberId: string\n  workflow: SaveWorkflowInput\n  buildTools: () => Promise<BuiltCodemodeTools>\n  context?: PluginArchActorContext\n}): Promise<{ pluginId: string; configObjectId: string; configObjectVersionId: string }> {\n  const organizationId = normalizeDenTypeId(\"organization\", input.organizationId)\n  const ownerMemberId = normalizeDenTypeId(\"member\", input.ownerMemberId)\n  const requestedPluginId = input.workflow.pluginId","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-api/src/workflows.ts#L558-L594","documentation":"Thrown in validateWorkflowAutomationAction when the ConfigObjectVersionTable lookup for the automation's saved-script version returns no row matching id + configObjectId + organizationId with isDeletedVersion = false. The automation references a script version that does not exist or has been soft-deleted.","triggerScenarios":"Creating/updating an automation pinned to a configObjectVersionId that was deleted, belongs to another config object/org, or never existed (stale id from a pruned version).","commonSituations":"Deleting/rolling back script versions while an automation still pins the old version id; copying automation config across environments; org migration with dangling version ids.","solutions":["Re-point the automation at the latest non-deleted version of the config object.","Create a new version of the script and update the automation's version reference.","Verify the version id belongs to the same organization and config object before saving the automation."],"exampleFix":"// before\naction: { configObjectVersionId: deletedVersionId, ... }\n// after\nconst [latest] = await db.select().from(ConfigObjectVersionTable)\n  .where(and(eq(ConfigObjectVersionTable.configObjectId, id), eq(ConfigObjectVersionTable.isDeletedVersion, false)))\n  .orderBy(desc(ConfigObjectVersionTable.createdAt)).limit(1)\naction: { configObjectVersionId: latest.id, ... }","handlingStrategy":"validation","validationCode":"const [v] = await db.select({ id: ConfigObjectVersionTable.id }).from(ConfigObjectVersionTable)\n  .where(and(eq(ConfigObjectVersionTable.id, versionId),\n    eq(ConfigObjectVersionTable.configObjectId, configObjectId),\n    eq(ConfigObjectVersionTable.organizationId, organizationId),\n    eq(ConfigObjectVersionTable.isDeletedVersion, false))).limit(1)\nconst versionUsable = !!v","typeGuard":null,"tryCatchPattern":"try {\n  await updateAutomation({ configObjectVersionId, ... })\n} catch (e) {\n  if (e.message === \"automation_saved_script_version_not_found\") {\n    // re-point to the latest non-deleted version\n  } else throw e\n}","preventionTips":["Pin automations to 'latest' semantics or update references on version deletion.","Block deleting versions referenced by active automations.","Validate version ids belong to the same org/config object."],"tags":["automation","not-found","version","den-api"],"backgroundTag":"resource-version-not-found","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}