wavetermdev/waveterm · error

no active window

Error message

no active window

What it means

BlocksListCommand with WindowId "current" resolves the current window via the client singleton's WindowIds focus list. If the client record has no windows (empty WindowIds), it cannot resolve a window and returns 'no active window'.

Source

Thrown at pkg/wshrpc/wshserver/wshserver.go:904

	// Resolve the set of workspaces to inspect
	var workspaceIDs []string
	if req.WorkspaceId != "" {
		workspaceIDs = []string{req.WorkspaceId}
	} else if req.WindowId != "" {
		win, err := wcore.GetWindow(ctx, req.WindowId)
		if err != nil {
			return nil, err
		}
		workspaceIDs = []string{win.WorkspaceId}
	} else {
		// "current" == first workspace in client focus list
		client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
		if err != nil {
			return nil, err
		}
		if len(client.WindowIds) == 0 {
			return nil, fmt.Errorf("no active window")
		}
		win, err := wcore.GetWindow(ctx, client.WindowIds[0])
		if err != nil {
			return nil, err
		}
		workspaceIDs = []string{win.WorkspaceId}
	}

	for _, wsID := range workspaceIDs {
		wsData, err := wcore.GetWorkspace(ctx, wsID)
		if err != nil {
			return nil, err
		}

		windowId, err := wstore.DBFindWindowForWorkspaceId(ctx, wsID)
		if err != nil {
			log.Printf("error finding window for workspace %s: %v", wsID, err)
		}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Create/open a window first so client.WindowIds is populated
  2. Pass an explicit WindowId or WorkspaceId instead of "current"
  3. Check for leaked/wrong client state in tests (seed a client with a window in fixtures)

Example fix

// before
blocks, err := client.BlocksListCommand(ctx, wshrpc.CommandBlocksListData{WindowId: "current"})
// after
blocks, err := client.BlocksListCommand(ctx, wshrpc.CommandBlocksListData{WorkspaceId: workspaceId})
Defensive patterns

Strategy: fallback

Validate before calling

client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
if err != nil || len(client.WindowIds) == 0 {
    // do not call with WindowId "current"
}

Type guard

func hasActiveWindow(c *waveobj.Client) bool {
    return c != nil && len(c.WindowIds) > 0
}

Try / catch

blocks, err := client.BlocksListCommand(ctx, wshrpc.CommandBlocksListData{WindowId: "current"})
if err != nil && strings.Contains(err.Error(), "no active window") {
    // fall back to explicit workspace/window ID or create a window first
    return nil
}

Prevention

When it happens

Trigger: Calling BlocksListCommand with WindowId="current" when the client's WindowIds list is empty — no window has been created or all windows were closed.

Common situations: Running wsh block commands headlessly or in tests before any window exists; server-side automation with no UI; client state not yet initialized.

Related errors


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