{"record":{"id":"5bfa3c54dac9b792","repo":"bytedance/deer-flow","slug":"agent-name-only-exists-in-the-legacy-shared-la-5bfa3c","errorCode":null,"errorMessage":"Agent '{name}' only exists in the legacy shared layout and is not scoped to a user. Run scripts/migrate_user_isolation.py to move legacy agents into the per-user layout before deleting.","messagePattern":"Agent '(.+?)' only exists in the legacy shared layout and is not scoped to a user\\. Run scripts/migrate_user_isolation\\.py to move legacy agents into the per-user layout before deleting\\.","errorType":"http","errorClass":"HTTPException","httpStatus":409,"severity":"error","filePath":"backend/app/gateway/routers/agents.py","lineNumber":562,"sourceCode":"    Raises:\n        HTTPException: 404 if no per-user copy exists; 409 if only a legacy\n            shared copy exists (suggesting the migration script).\n    \"\"\"\n    _require_agents_api_enabled()\n    _validate_agent_name(name)\n    name = _normalize_agent_name(name)\n    user_id = get_effective_user_id()\n    store = get_agent_store()\n\n    try:\n        # Off the event loop: file rmtree or a DB delete plus memory cleanup.\n        outcome = await asyncio.to_thread(store.delete, name, user_id=user_id)\n    except Exception as e:\n        logger.error(f\"Failed to delete agent '{name}': {e}\", exc_info=True)\n        raise HTTPException(status_code=500, detail=f\"Failed to delete agent: {str(e)}\")\n\n    if outcome == \"legacy\":\n        raise HTTPException(\n            status_code=409,\n            detail=(f\"Agent '{name}' only exists in the legacy shared layout and is not scoped to a user. Run scripts/migrate_user_isolation.py to move legacy agents into the per-user layout before deleting.\"),\n        )\n    if outcome == \"missing\":\n        raise HTTPException(status_code=404, detail=f\"Agent '{name}' not found\")\n    if outcome == \"not-custom-agent\":\n        raise HTTPException(\n            status_code=409,\n            detail=(f\"Directory for '{name}' contains memory data but is not a custom agent because config.yaml is missing; it was preserved.\"),\n        )\n\n    logger.info(f\"Deleted agent '{name}'\")\n","sourceCodeStart":544,"sourceCodeEnd":575,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/app/gateway/routers/agents.py#L544-L575","documentation":"409 on DELETE `/agents/{name}`: the store returned outcome 'legacy' — the agent exists only in the legacy shared layout, not scoped to the deleting user. Deletion is blocked because removing a shared-layout agent would affect all users; the operator must migrate first. Same legacy-layout concept as the PUT-side 409, resolved by the same script.","triggerScenarios":"Deleting a pre-isolation shared agent on an upgraded file-backend deployment; admin cleanup scripts walking old agent names.","commonSituations":"Post-upgrade housekeeping hitting 409 on every legacy agent; mixed layouts after partial migration.","solutions":["Run `scripts/migrate_user_isolation.py` to move legacy agents into per-user scope, then delete the migrated copy","Alternatively remove the legacy shared agent manually with operator intent (it is shared — deleting it affects everyone)","Re-run the delete and expect 204 on success"],"exampleFix":"# before\nDELETE /agents/legacy-agent  # 409\n# after\npython scripts/migrate_user_isolation.py\nDELETE /agents/legacy-agent  # 204","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await api.deleteAgent(name); }\ncatch (e) {\n  if (e.status === 409 && /legacy shared layout/.test(e.detail)) {\n    showAdminNotice('Run scripts/migrate_user_isolation.py first; this agent is shared');\n    return;\n  }\n  throw e;\n}","preventionTips":["Treat legacy-layout 409 as an operations task, not a user error — surface it to admins","Deleting a shared agent affects all users; always route through the migration script","Include the migration script in upgrade runbooks before enabling delete flows"],"tags":["http-409","agents","migration","legacy-layout","delete"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}