wavetermdev/waveterm · error

error getting environment with PTY: %w

Error message

error getting environment with PTY: %w

What it means

The second probe of GetEnvironmentMaps runs the same environment capture WITH a PTY allocated. Failures in that PTY session (command error, PTY request denied, connection drop) are wrapped as 'error getting environment with PTY'.

Source

Thrown at pkg/remote/conncontroller/conncontroller.go:346

	}
	return true, clientVersion, "", nil
}

// for testing only -- trying to determine the env difference when attaching or not attaching a pty to an ssh session
func (conn *SSHConn) GetEnvironmentMaps(ctx context.Context) (map[string]string, map[string]string, error) {
	client := conn.GetClient()
	if client == nil {
		return nil, nil, fmt.Errorf("ssh client is not connected")
	}

	noPtyEnv, err := conn.getEnvironmentNoPty(ctx, client)
	if err != nil {
		return nil, nil, fmt.Errorf("error getting environment without PTY: %w", err)
	}

	ptyEnv, err := conn.getEnvironmentWithPty(ctx, client)
	if err != nil {
		return nil, nil, fmt.Errorf("error getting environment with PTY: %w", err)
	}

	return noPtyEnv, ptyEnv, nil
}

func runSessionWithContext(ctx context.Context, session *ssh.Session, cmd string) error {
	errCh := make(chan error, 1)

	go func() {
		errCh <- session.Run(cmd)
	}()

	select {
	case <-ctx.Done():
		session.Close()
		return ctx.Err()
	case err := <-errCh:
		return err

View on GitHub (pinned to a4447c1563)

Solutions

  1. Check sshd_config on the remote allows PTY allocation (PermitTTY yes) and ptys are available
  2. Inspect the wrapped inner error for the session/PTY failure detail
  3. Reproduce with ssh -t host 'env' to see the PTY-mode failure directly
  4. Fix interactive shell startup files that fail under PTY

Example fix

// server (sshd_config)
// before
PermitTTY no
// after
PermitTTY yes
Defensive patterns

Strategy: try-catch

Validate before calling

// pty availability precheck
out, err := client.CombinedOutput("ssh -T host true") // or test RequestPty
if err != nil {
    return fmt.Errorf("pty allocation may be unavailable: %v", err)
}

Try / catch

noPty, pty, err := conn.GetEnvironmentMaps(ctx)
if err != nil && strings.Contains(err.Error(), "environment with PTY") {
    log.Printf("env probe (pty) failed: %v", err) // fall back to noPty env
}

Prevention

When it happens

Trigger: conn.getEnvironmentWithPty returns an error — PTY allocation is refused by sshd, the shell fails under PTY, or the session errors before the env dump completes.

Common situations: sshd configured with PermitTTY no or limited ptys; shell profile that errors only in interactive/PTY mode; connection instability during interactive session setup; pty allocation limits hit (out of ptys).

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/eb57229a7b7049e1. Report an issue: GitHub.