{"record":{"id":"9a54a57e6455a487","repo":"theonedev/onedev","slug":"no-job-context-found-for-specified-job-token","errorCode":null,"errorMessage":"No job context found for specified job token","messagePattern":"No job context found for specified job token","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/job/DefaultJobService.java","lineNumber":728,"sourceCode":"\t}\n\n\tprivate void log(Throwable e, TaskLogger logger) {\n\t\tif (find(e, TimeoutException.class) != null) {\n\t\t\tlogger.error(TIMEOUT_MESSAGE);\n\t\t} else {\n\t\t\tvar explicitException = find(e, ExplicitException.class);\n\t\t\tif (explicitException != null)\n\t\t\t\tlogger.error(explicitException.getMessage());\n\t\t\telse\n\t\t\t\tlogger.error(\"Error executing job\", e);\n\t\t}\n\t}\n\n\t@Override\n\tpublic JobContext getJobContext(String jobToken, boolean mustExist) {\n\t\tvar jobServer = jobServers.get(jobToken);\n\t\tif (mustExist && jobServer == null)\n\t\t\tthrow new ExplicitException(\"No job context found for specified job token\");\n\t\tif (jobServer != null) {\n\t\t\tvar jobContext = clusterService.runOnServer(jobServer, () -> jobContexts.get(jobToken));\n\t\t\tif (mustExist && jobContext == null)\n\t\t\t\tthrow new ExplicitException(\"No job context found for specified job token\");\n\t\t\treturn jobContext;\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate void markBuildError(Build build, String errorMessage) {\n\t\tbuild.setStatus(Build.Status.FAILED);\n\t\tlogService.newLogger(build.getLoggingSupport()).error(errorMessage);\n\t\tbuild.setFinishDate(new Date());\n\t\tbuildService.update(build);\n\t\tlistenerRegistry.post(new BuildFinished(build));\n\t}\n","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/job/DefaultJobService.java#L710-L746","documentation":"Thrown by DefaultJobService.getJobContext(jobToken, mustExist=true) when the given job token has no entry in the jobServers map — no build on this server (or cluster member) was ever assigned that token. OneDev keys running job contexts by the UUID token generated at submission time, so an unknown token means the caller's credentials/context don't correspond to any live job.","triggerScenarios":"An agent or script calls getJobContext with a stale, mistyped, or never-issued job token while mustExist=true; server restarted and jobServers map lost; job finished and its token was removed; token from a different OneDev instance.","commonSituations":"Custom agent scripts caching an old job token; restarting the server mid-job; pointing a runner at the wrong OneDev server; copying tokens between environments; job already completed and cleaned up.","solutions":["Use the job token assigned to the currently running build (build.getToken()), e.g. via the job's token placeholder in scripts.","Verify the runner is talking to the same OneDev instance that submitted the job.","Re-submit the job if the server was restarted — old tokens are not recoverable.","Pass mustExist=false if you only want to probe for context existence and handle null."],"exampleFix":"// before\nJobContext ctx = jobService.getJobContext(staleToken, true);\n\n// after: read the live token from the build context\nJobContext ctx = jobService.getJobContext(build.getToken(), true);\nif (ctx == null) { /* handle finished/unknown job */ }","handlingStrategy":"try-catch","validationCode":"// Only pass tokens obtained from build.getToken() of a live build on this instance\nString token = build.getToken();\nif (token == null || token.isEmpty()) {\n    throw new IllegalStateException(\"Build has no job token (not yet submitted?)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    JobContext ctx = jobService.getJobContext(token, true);\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"No job context found\")) {\n        // re-fetch build status from DB/API; token is stale or unknown\n    }\n}","preventionTips":["Never cache job tokens across server restarts","Verify runner points at the same OneDev instance that issued the token","Read the token from the live build object rather than hardcoding it"],"tags":["job-token","not-found","cluster","ci-pipeline"],"backgroundTag":"resource-not-found","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"}