{"record":{"id":"ed8cab402f732a77","repo":"wavetermdev/waveterm","slug":"failed-to-create-remote-command-w","errorCode":null,"errorMessage":"failed to create remote command: %w","messagePattern":"failed to create remote command: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/remote/connutil.go","lineNumber":128,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot open local file %s: %w\", wshLocalPath, err)\n\t}\n\tdefer input.Close()\n\tinstallWords := map[string]string{\n\t\t\"installDir\":  filepath.ToSlash(filepath.Dir(wavebase.RemoteFullWshBinPath)),\n\t\t\"tempPath\":    wavebase.RemoteFullWshBinPath + \".temp\",\n\t\t\"installPath\": wavebase.RemoteFullWshBinPath,\n\t}\n\tvar installCmd bytes.Buffer\n\tif err := installTemplate.Execute(&installCmd, installWords); err != nil {\n\t\treturn fmt.Errorf(\"failed to prepare install command: %w\", err)\n\t}\n\tblocklogger.Infof(ctx, \"[conndebug] copying %q to remote server %q\\n\", wshLocalPath, wavebase.RemoteFullWshBinPath)\n\tgenCmd, err := genconn.MakeSSHCmdClient(client, genconn.CommandSpec{\n\t\tCmd: installCmd.String(),\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create remote command: %w\", err)\n\t}\n\tstdin, err := genCmd.StdinPipe()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get stdin pipe: %w\", err)\n\t}\n\tdefer stdin.Close()\n\tstderrBuf, err := genconn.MakeStderrSyncBuffer(genCmd)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get stderr pipe: %w\", err)\n\t}\n\tif err := genCmd.Start(); err != nil {\n\t\treturn fmt.Errorf(\"failed to start remote command: %w\", err)\n\t}\n\tcopyDone := make(chan error, 1)\n\tgo func() {\n\t\tdefer close(copyDone)\n\t\tdefer stdin.Close()\n\t\tif _, err := io.Copy(stdin, input); err != nil && err != io.EOF {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/remote/connutil.go#L110-L146","documentation":"CpWshToRemote creates an SSH exec session via genconn.MakeSSHCmdClient to run the rendered install command on the remote host. This error is wrapped when creating that remote command client fails. It indicates the SSH layer could not set up the exec request, so nothing was streamed to the remote host.","triggerScenarios":"genconn.MakeSSHCmdClient returns an error: underlying SSH client is disconnected/closed, SSH session allocation fails (server refuses exec), connection dropped between connect and command creation, or the command spec is rejected by the client implementation.","commonSituations":"SSH session limits (MaxSessions) exhausted on the server; connection idle-timed out just before wsh install/update; server-side restriction (ForceCommand, restricted shell) preventing exec; using a client object after the connection was closed.","solutions":["Verify the SSH connection is still alive (reconnect if idle) and retry InstallWsh/UpdateWsh.","Check remote sshd config for MaxSessions limits or ForceCommand restrictions blocking exec channels.","Ensure the genconn client passed to CpWshToRemote is the live client for the target connection, not a stale one.","Look at the wrapped error (%w) for the underlying SSH failure reason (e.g. 'connection lost', 'channel open failure')."],"exampleFix":"// before\nclient := staleClient // connection already closed\nerr := connutil.CpWshToRemote(ctx, client, os, arch)\n// after\nif client == nil || isClosed(client) {\n    client = reconnect(connName)\n}\nerr := connutil.CpWshToRemote(ctx, client, os, arch)","handlingStrategy":"retry","validationCode":"// ensure the SSH client is alive before install\ntimeoutCtx, cancel := context.WithTimeout(ctx, 10*time.Second)\ndefer cancel()\nif _, _, err := genconn.RunSimpleCommand(timeoutCtx, client, genconn.CommandSpec{Cmd: \"true\"}); err != nil {\n    return fmt.Errorf(\"ssh connection not ready: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := connutil.CpWshToRemote(ctx, client, os, arch)\nif err != nil && strings.Contains(err.Error(), \"failed to create remote command\") {\n    client = reconnect(connName)\n    err = connutil.CpWshToRemote(ctx, client, os, arch)\n}","preventionTips":["Ping the remote with a trivial command before long-running install/update flows.","Reconnect idle SSH sessions before creating exec channels.","Check sshd MaxSessions/ForceCommand settings on hosts where installs fail.","Do not reuse client objects after their connection has been closed."],"tags":["go","ssh","remote-execution","wsh"],"backgroundTag":"ssh-session-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}