{"record":{"id":"720b56f9a89998cc","repo":"theonedev/onedev","slug":"only-inactive-workspaces-can-be-reprovisioned","errorCode":null,"errorMessage":"Only inactive workspaces can be reprovisioned","messagePattern":"Only inactive workspaces can be reprovisioned","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java","lineNumber":151,"sourceCode":"\t\t\t\tthrow new NotAcceptableException(\"Pull request not found by id: \" + data.getPullRequestId());\n\t\t\tif (!request.getProject().equals(project))\n\t\t\t\tthrow new NotAcceptableException(\"Pull request does not belong to specified project\");\n\t\t}\n\n\t\tWorkspace workspace = workspaceService.create(user, project, issue, request, commitId,\n\t\t\t\tdata.getBranch(), data.getSpecName(), false);\n\t\treturn workspace.getId();\n\t}\n\n\t@Api(order=400, description=\"Reprovision inactive workspace\")\n\t@Path(\"/{workspaceId}/reprovision\")\n\t@POST\n\tpublic Response reprovisionWorkspace(@PathParam(\"workspaceId\") Long workspaceId) {\n\t\tWorkspace workspace = workspaceService.load(workspaceId);\n\t\tif (!SecurityUtils.canModifyOrDelete(workspace))\n\t\t\tthrow new UnauthorizedException();\n\t\tif (workspace.getStatus() != Status.INACTIVE)\n\t\t\tthrow new NotAcceptableException(\"Only inactive workspaces can be reprovisioned\");\n\t\tworkspaceService.reset(workspace);\n\t\treturn Response.ok().build();\n\t}\n\n\t@Api(order=500)\n\t@Path(\"/{workspaceId}\")\n\t@DELETE\n\tpublic Response deleteWorkspace(@PathParam(\"workspaceId\") Long workspaceId) {\n\t\tWorkspace workspace = workspaceService.load(workspaceId);\n\t\tif (!SecurityUtils.canModifyOrDelete(workspace))\n\t\t\tthrow new UnauthorizedException();\n\t\tworkspaceService.delete(workspace);\n\t\tvar oldAuditContent = VersionedXmlDoc.fromBean(workspace).toXML();\n\t\tauditService.audit(workspace.getProject(), \"deleted workspace \\\"\"\n\t\t\t\t+ workspace.getReference().toString(workspace.getProject())\n\t\t\t\t+ \"\\\" via RESTful API\", oldAuditContent, null);\n\t\treturn Response.ok().build();\n\t}","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java#L133-L169","documentation":"OneDev throws this 406 NotAcceptableException from the reprovision endpoint when the workspace's status is not INACTIVE. Reprovisioning (workspaceService.reset) is only valid for workspaces that have been deprovisioned/inactive; active or provisioning workspaces must go through other operations.","triggerScenarios":"POSTing /workspaces/{workspaceId}/reprovision for a workspace whose Status is ACTIVE (or any non-INACTIVE value such as in the middle of provisioning).","commonSituations":"Double-clicking or retrying a reprovision call after it already succeeded; scripts that reprovision unconditionally without checking status first; race conditions where the workspace was reactivated between status check and call.","solutions":["Check the workspace status first (GET the workspace) and only reprovision when status is INACTIVE.","If the workspace is active and you want a fresh environment, delete and recreate the workspace instead.","Wait for any in-progress provisioning to finish and deprovision the workspace before reprovisioning.","Make automation idempotent: skip the reprovision call if status is not INACTIVE."],"exampleFix":"// before\ncurl -X POST .../workspaces/42/reprovision  # unconditional\n// after\nstatus=$(curl .../workspaces/42 | jq -r .status)\n[ \"$status\" = \"INACTIVE\" ] && curl -X POST .../workspaces/42/reprovision","handlingStrategy":"validation","validationCode":"Workspace ws = workspaceService.load(workspaceId);\nif (ws.getStatus() != Status.INACTIVE)\n    throw new IllegalStateException(\"Cannot reprovision workspace in status \" + ws.getStatus());","typeGuard":"boolean canReprovision(Workspace ws) { return ws.getStatus() == Status.INACTIVE; }","tryCatchPattern":"try {\n    reprovision(workspaceId);\n} catch (NotAcceptableException e) {\n    if (e.getMessage().contains(\"Only inactive\")) {\n        deprovisionThenReprovision(workspaceId); // fallback path\n    } else throw e;\n}","preventionTips":["Poll workspace status and only reprovision INACTIVE workspaces","Make automation idempotent: skip reprovision when status check fails","Deprovision before reprovisioning when a fresh environment is needed"],"tags":["rest-api","workspace","state","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}