{"record":{"id":"d999b20b6104055b","repo":"wavetermdev/waveterm","slug":"failed-to-authenticate-to-server-w","errorCode":null,"errorMessage":"failed to authenticate to server: %w","messagePattern":"failed to authenticate to server: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/jobmanager/mainserverconn.go","lineNumber":62,"sourceCode":"func (rds *routedDataSender) SendData(dataPk wshrpc.CommandStreamData) {\n\t// log.Printf(\"SendData: sending seq=%d, len=%d, eof=%t, error=%s, route=%s\",\n\t// \tdataPk.Seq, len(dataPk.Data64), dataPk.Eof, dataPk.Error, rds.route)\n\terr := wshclient.StreamDataCommand(rds.wshRpc, dataPk, &wshrpc.RpcOpts{NoResponse: true, Route: rds.route})\n\tif err != nil {\n\t\tlog.Printf(\"SendData: error sending stream data: %v\\n\", err)\n\t}\n}\n\nfunc (msc *MainServerConn) authenticateSelfToServer(jobAuthToken string) error {\n\tjobId, _ := WshCmdJobManager.GetJobAuthInfo()\n\tauthData := wshrpc.CommandAuthenticateJobManagerData{\n\t\tJobId:        jobId,\n\t\tJobAuthToken: jobAuthToken,\n\t}\n\terr := wshclient.AuthenticateJobManagerCommand(msc.WshRpc, authData, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})\n\tif err != nil {\n\t\tlog.Printf(\"authenticateSelfToServer: failed to authenticate to server: %v\\n\", err)\n\t\treturn fmt.Errorf(\"failed to authenticate to server: %w\", err)\n\t}\n\tmsc.SelfAuthenticated.Store(true)\n\tlog.Printf(\"authenticateSelfToServer: successfully authenticated to server\\n\")\n\treturn nil\n}\n\nfunc (msc *MainServerConn) AuthenticateToJobManagerCommand(ctx context.Context, data wshrpc.CommandAuthenticateToJobData) error {\n\tjobId, jobAuthToken := WshCmdJobManager.GetJobAuthInfo()\n\n\tclaims, err := wavejwt.ValidateAndExtract(data.JobAccessToken)\n\tif err != nil {\n\t\tlog.Printf(\"AuthenticateToJobManager: failed to validate token: %v\\n\", err)\n\t\treturn fmt.Errorf(\"failed to validate token: %w\", err)\n\t}\n\tif !claims.MainServer {\n\t\tlog.Printf(\"AuthenticateToJobManager: MainServer claim not set\\n\")\n\t\treturn fmt.Errorf(\"MainServer claim not set\")\n\t}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/jobmanager/mainserverconn.go#L44-L80","documentation":"The job manager client failed to authenticate itself to the main server over the control route. It sends an AuthenticateJobManagerCommand RPC with jobId and jobAuthToken; if that RPC errors (rejection, routing failure, wrong token), the error is logged and wrapped. Self-authentication gates subsequent privileged commands.","triggerScenarios":"authenticateSelfToServer() called from AuthenticateToJobManagerCommand when the AuthenticateJobManagerCommand RPC returns an error — server rejects the job auth token, the RPC times out, or the control route is unreachable.","commonSituations":"Expired or wrong jobAuthToken, jobId mismatch between client and server, server not running the job-manager handlers, or WSH routing problems in the blockfile/shell environment.","solutions":["Verify the jobAuthToken is current and matches the job's registered token; re-obtain it via the job creation flow.","Check that jobId matches the one the server knows; restart the job connection to refresh auth info.","Inspect the wrapped inner error for RPC-level causes (timeout, route not found) and fix connectivity."],"exampleFix":"// before\nerr := msc.authenticateSelfToServer(jobAuthToken)\n// after\nif err := msc.authenticateSelfToServer(jobAuthToken); err != nil {\n    // refresh token and retry once\n    jobId, jobAuthToken = WshCmdJobManager.GetJobAuthInfo()\n    err = msc.authenticateSelfToServer(jobAuthToken)\n    if err != nil {\n        return fmt.Errorf(\"job manager auth failed: %w\", err)\n    }\n}","handlingStrategy":"retry","validationCode":"jobId, jobAuthToken := WshCmdJobManager.GetJobAuthInfo()\nif jobAuthToken == \"\" {\n    return fmt.Errorf(\"no job auth token available; cannot authenticate\")\n}","typeGuard":null,"tryCatchPattern":"err := msc.authenticateSelfToServer(jobAuthToken)\nif err != nil {\n    // one retry after refreshing auth info\n    _, jobAuthToken = WshCmdJobManager.GetJobAuthInfo()\n    if retryErr := msc.authenticateSelfToServer(jobAuthToken); retryErr != nil {\n        return fmt.Errorf(\"job manager auth failed: %w\", retryErr)\n    }\n}","preventionTips":["Always obtain fresh job auth tokens via the job creation flow","Verify server job-manager handlers are registered and reachable","Check WSH control-route connectivity before job commands"],"tags":["authentication","rpc","jobmanager","security"],"backgroundTag":"authentication-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}