{"record":{"id":"e69ba75a148f3464","repo":"theonedev/onedev","slug":"no-workspace-context-found-for-specified-token","errorCode":null,"errorMessage":"No workspace context found for specified token","messagePattern":"No workspace context found for specified token","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/workspace/DefaultWorkspaceService.java","lineNumber":1088,"sourceCode":"\t\t\t\treturn null;\n\t\t\t}\n\n\t\t});\n\t}\n\n\tprivate String getTerminalKey(Long workspaceId, String shellId) {\n\t\treturn workspaceId + \":\" + shellId;\n\t}\n\n\t@Override\n\tpublic WorkspaceContext getWorkspaceContext(String token, boolean mustExist) {\n\t\tvar contextMap = clusterService.runOnAllServers(() -> workspaceContexts.get(token));\n\t\tvar context = contextMap.values().stream()\n\t\t\t\t.filter(Objects::nonNull)\n\t\t\t\t.findFirst()\n\t\t\t\t.orElse(null);\n\t\tif (mustExist && context == null)\n\t\t\tthrow new ExplicitException(\"No workspace context found for specified token\");\n\t\treturn context;\n\t}\n\n\t@Sessional\n\t@Override\n\tpublic GitExecutionResult executeGitCommand(Workspace workspace, String[] gitArgs) {\t\t\n\t\tvar workspaceId = workspace.getId();\n\t\tvar server = workspaceServers.get(workspaceId);\n\t\tif (server == null)\n\t\t\tthrow new ExplicitException(\"Workspace server not found\");\n\n\t\treturn clusterService.runOnServer(server, () -> {\n\t\t\tvar runtime = workspaceRuntimes.get(workspaceId);\n\t\t\tif (runtime != null) {\n\t\t\t\treturn runtime.executeGitCommand(gitArgs);\n\t\t\t} else {\n\t\t\t\treturn new GitExecutionResult(new byte[0], \"Workspace is not active\".getBytes(UTF_8), 1);\n\t\t\t}","sourceCodeStart":1070,"sourceCodeEnd":1106,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/workspace/DefaultWorkspaceService.java#L1070-L1106","documentation":"Thrown by the internal context-lookup helper (used e.g. by getWorkspaceContext(token, mustExist)) when no server in the cluster holds a WorkspaceContext under the given access token and mustExist is true. Tokens identify active workspace contexts distributed across servers; an unknown token means no workspace is associated with it.","triggerScenarios":"Calling workspaceService.getWorkspaceContext(token, true) (or an API authenticating by that token) where the token is expired, revoked, mistyped, or belongs to a workspace that already terminated.","commonSituations":"Client automation using a stale workspace token after the workspace stopped; token copied with whitespace/truncation; server restarted and in-memory contexts cleared; connecting from an external tool before the workspace context was established.","solutions":["Regenerate the workspace access token and retry with the fresh value.","Confirm the workspace is running and its context was created before using the token.","Check the token for typos, truncation, or encoding issues.","Restart the workspace if the server was restarted and contexts were lost."],"exampleFix":"// before\nvar context = workspaceService.getWorkspaceContext(token, true);\n// after\nif (token == null || token.isBlank())\n    throw new ExplicitException(\"Workspace token is required\");\nvar context = workspaceService.getWorkspaceContext(token, true);","handlingStrategy":"validation","validationCode":"// Java\nif (token == null || token.isBlank())\n    throw new ExplicitException(\"A workspace token is required\");","typeGuard":null,"tryCatchPattern":"try { ctx = workspaceService.getWorkspaceContext(token, true); } catch (ExplicitException e) { token = requestNewToken(); ctx = workspaceService.getWorkspaceContext(token, true); }","preventionTips":["Regenerate tokens whenever a workspace is restarted","Trim/validate tokens at ingestion boundaries","Expire client sessions together with workspace lifecycle"],"tags":["onedev","workspace","token","authentication"],"backgroundTag":"invalid-credentials","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"}