{"record":{"id":"4215869d0b4f605b","repo":"jd-opensource/joyagent-jdgenie","slug":"a-plan-already-exists-delete-the-current-plan-fir","errorCode":null,"errorMessage":"A plan already exists. Delete the current plan first.","messagePattern":"A plan already exists\\. Delete the current plan first\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/agent/tool/common/PlanningTool.java","lineNumber":149,"sourceCode":"\n        Function<Map<String, Object>, String> handler = commandHandlers.get(command);\n        if (handler != null) {\n            return handler.apply(params);\n        } else {\n            throw new IllegalArgumentException(\"Unknown command: \" + command);\n        }\n    }\n\n    private String createPlan(Map<String, Object> params) {\n        String title = (String) params.get(\"title\");\n        List<String> steps = (List<String>) params.get(\"steps\");\n\n        if (title == null || steps == null) {\n            throw new IllegalArgumentException(\"title, and steps are required for create command\");\n        }\n\n        if (plan != null) {\n            throw new IllegalStateException(\"A plan already exists. Delete the current plan first.\");\n        }\n\n        plan = Plan.create(title, steps);\n        return \"我已创建plan\";\n    }\n\n    private String updatePlan(Map<String, Object> params) {\n        String title = (String) params.get(\"title\");\n        List<String> steps = (List<String>) params.get(\"steps\");\n\n        if (plan == null) {\n            throw new IllegalStateException(\"No plan exists. Create a plan first.\");\n        }\n\n        plan.update(title, steps);\n        return \"我已更新plan\";\n    }\n","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/agent/tool/common/PlanningTool.java#L131-L167","documentation":"PlanningTool holds a single current plan; createPlan throws IllegalStateException when a plan already exists and refuses to overwrite it. The existing plan must be deleted (or updated) before creating a new one.","triggerScenarios":"Calling command=create twice without an intervening delete/update of the plan.","commonSituations":"Agent retrying a create after a partial failure, LLM re-emitting a create command in a multi-turn loop, or not checking plan state before creating.","solutions":["Call command=delete before issuing another create","Use the update command to modify the existing plan instead","Check plan state (e.g. via a get/status command) before create"],"exampleFix":"// before\nplanningTool.execute(Map.of(\"command\", \"create\", \"title\", t, \"steps\", s));\n// after\nplanningTool.execute(Map.of(\"command\", \"delete\"));\nplanningTool.execute(Map.of(\"command\", \"create\", \"title\", t, \"steps\", s));","handlingStrategy":"try-catch","validationCode":"// check whether a plan already exists via the tool before issuing create","typeGuard":null,"tryCatchPattern":"try {\n    return planningTool.execute(createParams);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"plan already exists\")) {\n        planningTool.execute(Map.of(\"command\", \"delete\"));\n        return planningTool.execute(createParams);\n    }\n    throw e;\n}","preventionTips":["Delete or update the existing plan before create","Track plan state in the agent loop","Deduplicate repeated create commands from LLM output"],"tags":["java","tool","state-conflict"],"backgroundTag":"invalid-state-transition","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}