{"record":{"id":"5a943bb88a22f54b","repo":"windmill-labs/windmill","slug":"a-draft-for-app-path-already-exists-use-writ","errorCode":null,"errorMessage":"A draft for app \"${path}\" already exists. Use write_app_file / write_app_runnable to modify it, or delete the existing draft first.","messagePattern":"A draft for app \"(.+?)\" already exists\\. Use write_app_file / write_app_runnable to modify it, or delete the existing draft first\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/chat/global/core.ts","lineNumber":5494,"sourceCode":"\t\tdetachAfterMs: waitSecondsToDetachMs(args.wait_seconds),\n\t\tloadScript: loadScriptForFlowStep,\n\t\tloadFlowPreviewValue: loadDraftFlowPreviewValue\n\t})\n}\n\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 } }","sourceCodeStart":5476,"sourceCodeEnd":5512,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/chat/global/core.ts#L5476-L5512","documentation":"The write_app tool creates a NEW app draft and refuses when a draft for the same app path already exists in the global draft store. Because existing drafts must be modified incrementally via write_app_file / write_app_runnable, blindly overwriting would clobber prior edits, so the tool throws with instructions.","triggerScenarios":"Calling the write_app tool when getGlobalDraft(workspace, 'app', path) returns an existing draft for that path.","commonSituations":"Re-running write_app after an earlier draft-creation call in the same chat session; the model retries the create call after a partial failure; the user asks to regenerate an app whose draft already exists.","solutions":["Use write_app_file / write_app_runnable to modify the existing draft instead of write_app.","Delete the existing app draft first, then call write_app again.","Use a different app path if a genuinely separate app was intended."],"exampleFix":"// before\nwriteApp({ path: 'f/newapp', framework: 'svelte' }) // second call, draft exists\n// after\nwriteAppFile({ path: 'f/newapp', filePath: 'App.svelte', content: '...' })","handlingStrategy":"try-catch","validationCode":"if (await getGlobalDraft(workspace, 'app', path)) {\n  // modify via write_app_file / write_app_runnable instead of write_app\n}","typeGuard":null,"tryCatchPattern":"try {\n  await writeApp(args)\n} catch (e) {\n  if (e.message.includes('already exists')) {\n    await writeAppFile({ path: args.path, filePath: 'App.svelte', content: newContent })\n  } else throw e\n}","preventionTips":["Track which app paths already have drafts in the session before calling write_app.","Treat write_app as create-only; use file/runnable tools for subsequent edits.","Delete stale drafts before regenerating an app from scratch."],"tags":["draft-state","apps","conflict"],"backgroundTag":"draft-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"}