{"record":{"id":"eadcb61ce84cb34b","repo":"theonedev/onedev","slug":"this-workspace-is-provisioned-on-server-previously","errorCode":null,"errorMessage":"This workspace is provisioned on server previously, and cannot be reprovisioned via %s","messagePattern":"This workspace is provisioned on server previously, and cannot be reprovisioned via (.+?)","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/workspace/AgentProvisionerUtils.java","lineNumber":37,"sourceCode":"import io.onedev.server.search.entity.agent.AgentQuery;\nimport io.onedev.server.service.AgentService;\nimport io.onedev.server.service.ResourceService;\n\npublic final class AgentProvisionerUtils {\n\n\tprivate static final Logger logger = LoggerFactory.getLogger(AgentProvisionerUtils.class);\n\n\tprivate static final ThreadLocal<Long> ALLOCATED_AGENT = new ThreadLocal<>();\n\n\tpublic static Long getAllocatedAgent() {\n\t\treturn ALLOCATED_AGENT.get();\n\t}\n\n\tpublic static <T> Future<T> submitTask(@Nullable String pinnedServerAddress, @Nullable Long pinnedAgentId,\n\t\t\t@Nullable String agentQuery, String resourceName, int concurrency,\n\t\t\tString cannotReprovisionVia, ClusterTask<T> task, TaskLogger logger) {\n\t\tif (pinnedServerAddress != null) {\n\t\t\tthrow new ExplicitException(String.format(\"\"\"\n\t\t\t\tThis workspace is provisioned on server previously, \\\n\t\t\t\tand cannot be reprovisioned via %s\"\"\", cannotReprovisionVia));\n\t\t}\n\n\t\tlogger.log(\"Pending resource allocation...\");\n\t\treturn getResourceService().submitAgentTask(\n\t\t\t\tpinnedAgentId,\n\t\t\t\tAgentQuery.parse(agentQuery, true),\n\t\t\t\tresourceName,\n\t\t\t\tconcurrency, 1,\n\t\t\t\tagentId -> {\n\t\t\t\t\tALLOCATED_AGENT.set(agentId);\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn task.call();\n\t\t\t\t\t} catch (Exception e) {\n\t\t\t\t\t\tthrow ExceptionUtils.unchecked(e);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tALLOCATED_AGENT.remove();","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/workspace/AgentProvisionerUtils.java#L19-L55","documentation":"AgentProvisionerUtils.submitTask refuses to provision a workspace that was previously provisioned on the server itself when the current request pins a remote target (pinnedServerAddress set), e.g. reprovisioning via a build runner/executor on an agent. The workspace's server affinity cannot be changed by remote provisioning.","triggerScenarios":"A job/step targets an agent (serverUrl/agent pinned via resourceName or runner settings) but the workspace cache was originally provisioned on the OneDev server; submitTask is then called with pinnedServerAddress != null.","commonSituations":"Moving a job between server-executed and agent-executed runners without clearing the workspace; reusing a project/workspace cache created by server-side builds; cluster setups where agents should run jobs but old workspaces linger.","solutions":["Delete the existing workspace cache so the next run provisions on the target (agent or current server).","Change the job/runner config so it runs on the server as before, matching the workspace's original provisioning.","Clear stale workspace caches on the server (Administration > Workspace Caches or project workspace cache cleanup) after changing executor assignment."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { provision(...); } catch (ExplicitException e) { if (e.getMessage().contains(\"cannot be reprovisioned\")) { clearWorkspaceCache(); retryOnTarget(); } }","preventionTips":["Clear workspace caches after moving jobs between server and agent executors.","Keep executor assignment stable per project/workspace."],"tags":["workspace","provisioning","cluster"],"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"}