{"record":{"id":"90b5676d2a2ca328","repo":"windmill-labs/windmill","slug":"an-app-already-exists-at-path-use-read-works","errorCode":null,"errorMessage":"An app already exists at \"${path}\". Use read_workspace_item + write_app_file / write_app_runnable to modify it.","messagePattern":"An app already exists at \"(.+?)\"\\. Use read_workspace_item \\+ write_app_file / write_app_runnable to modify it\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/chat/global/core.ts","lineNumber":5499,"sourceCode":"\nasync function initApp(\n\targs: {\n\t\tpath: string\n\t\tsummary?: string\n\t\tframework: FrameworkKey\n\t},\n\tctx: WriteDraftCtx\n): Promise<string> {\n\tconst { workspace, toolId, toolCallbacks } = ctx\n\tconst { path, summary, framework } = args\n\n\tif (await getGlobalDraft(workspace, 'app', path)) {\n\t\tthrow new Error(\n\t\t\t`A draft for app \"${path}\" already exists. Use write_app_file / write_app_runnable to modify it, or delete the existing draft first.`\n\t\t)\n\t}\n\tif (await AppService.existsApp({ workspace, path })) {\n\t\tthrow new Error(\n\t\t\t`An app already exists at \"${path}\". Use read_workspace_item + write_app_file / write_app_runnable to modify it.`\n\t\t)\n\t}\n\n\ttoolCallbacks.setToolStatus(toolId, {\n\t\tcontent: `Saving app \"${path}\" draft (${framework} template)…`\n\t})\n\n\tconst template = FRAMEWORK_TEMPLATES[framework]\n\tconst value: AppDraftValue = {\n\t\tsummary,\n\t\tfiles: { ...template },\n\t\trunnables: { [STARTER_RUNNABLE_KEY]: { ...STARTER_RUNNABLE } }\n\t}\n\tawait recomputeAppPolicy(value)\n\tconst result = await saveAppDraft(workspace, path, value)\n\treturn finishAppDraftWrite(result, ctx, () => ({\n\t\tcontent: `Saved app \"${path}\" draft (${framework})`,","sourceCodeStart":5481,"sourceCodeEnd":5517,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/chat/global/core.ts#L5481-L5517","documentation":"Beyond draft conflicts, write_app also refuses when a deployed app already exists at the given path. Creating would overwrite an existing app, so the tool throws and directs the caller to read the existing app and modify it with write_app_file / write_app_runnable rather than recreating it from a template.","triggerScenarios":"Calling the write_app tool when AppService.existsApp({ workspace, path }) is true and no draft exists — i.e. the target path already has a deployed app.","commonSituations":"Scaffolding an app at a path that already hosts a production app; reusing an old app path for a new generated app; the model guessed a path without checking existence.","solutions":["Pick a new, unused app path for the write_app call.","Call read_workspace_item on the existing app and modify it via write_app_file / write_app_runnable.","Delete or rename the existing app if it should be replaced, then re-run write_app."],"exampleFix":"// before\nwriteApp({ path: 'f/existing_app', framework: 'svelte' }) // already deployed\n// after\nwriteApp({ path: 'f/existing_app_v2', framework: 'svelte' })\n// or: read_workspace_item('app', 'f/existing_app') then writeAppFile(...)","handlingStrategy":"validation","validationCode":"if (await AppService.existsApp({ workspace, path })) {\n  // path taken: read existing app and modify, or choose a new path\n}","typeGuard":null,"tryCatchPattern":"try {\n  await writeApp(args)\n} catch (e) {\n  if (e.message.startsWith('An app already exists at')) {\n    const existing = await readWorkspaceItem('app', args.path)\n    // modify via write_app_file/write_app_runnable or pick a new path\n  } else throw e\n}","preventionTips":["Check existence (read_workspace_item / existsApp) before creating an app.","Generate unique paths (suffix -v2, timestamp) when scaffolding new apps.","Never assume a path is free — deployed apps block write_app."],"tags":["apps","conflict","validation"],"backgroundTag":"resource-already-exists","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}