Skip to content

Conversation

@stunningpixels
Copy link
Contributor

@stunningpixels stunningpixels commented Jan 13, 2026

Summary

This PR fixes a bug where dev servers would disappear from the preview panel when switching between sessions within the same workspace. The root cause was that the ActionsContext was using a session-scoped hook (useDevServer), which caused runningDevServers to be empty when viewing a different session than the one that started the dev server.

Changes

Backend (Rust)

  • New database query (crates/db/src/models/execution_process.rs): Added find_dev_servers_by_workspace() to query dev servers across all sessions in a workspace
  • New WebSocket endpoint (crates/server/src/routes/execution_processes.rs): Added /stream/workspace-dev-servers/ws?workspace_id={id} for workspace-scoped dev server streaming
  • Server-side filtering (crates/services/src/services/events/streams.rs): Implemented stream_dev_servers_for_workspace_raw() that streams only dev server processes belonging to the specified workspace

Frontend (React/TypeScript)

  • New hook (frontend/src/hooks/useWorkspaceDevServers.ts): Low-level hook that connects to the workspace dev servers WebSocket stream
  • Updated usePreviewDevServer (frontend/src/components/ui-new/hooks/usePreviewDevServer.ts): Changed from session-scoped to workspace-scoped data source
  • Fixed ActionsContext (frontend/src/contexts/ActionsContext.tsx): Switched from useDevServer to usePreviewDevServer for workspace-scoped visibility
  • Updated preview components: Removed unnecessary attemptId prop since workspace ID is now sourced from context

Why These Changes

Previously, dev servers were tracked at the session level. When a user started a dev server in Session A, then switched to Session B, the preview panel would show no running dev server because Session B's execution processes didn't include the dev server from Session A.

With this change, dev servers are now tracked at the workspace level, making them visible regardless of which session is currently active. This matches user expectations since dev servers are workspace-wide resources.

Implementation Details

  • The new WebSocket endpoint filters events server-side, only sending dev server processes that belong to sessions within the target workspace
  • Uses JSON Patch protocol (RFC 6902) for efficient incremental updates
  • Follows existing patterns in the codebase (useJsonPatchWsStream, similar streaming endpoints)

This PR was written using Vibe Kanban

…anges made:

## Summary

### Backend Changes

1. **`crates/db/src/models/execution_process.rs`**
   - Added new method `find_dev_servers_by_workspace()` that returns all dev servers for a workspace (not just running ones)

2. **`crates/services/src/services/events/streams.rs`**
   - Added new method `stream_dev_servers_for_workspace_raw()` that streams dev server processes for a workspace across all sessions
   - Added imports for `Session` model and `ExecutionProcessRunReason`

3. **`crates/server/src/routes/execution_processes.rs`**
   - Added `WorkspaceDevServerQuery` struct
   - Added new WebSocket endpoint `stream_dev_servers_by_workspace_ws` at `/stream/workspace-dev-servers/ws`
   - Registered the new route in the router

### Frontend Changes

4. **`frontend/src/hooks/useWorkspaceDevServers.ts`** (NEW FILE)
   - Created new hook that connects to the workspace dev server WebSocket endpoint
   - Exposes `devServers`, `runningDevServers`, and other state

5. **`frontend/src/components/ui-new/hooks/usePreviewDevServer.ts`**
   - Changed from `attemptId` to `workspaceId` parameter
   - Now uses `useWorkspaceDevServers` instead of `useAttemptExecution`
   - Updated query key to use `workspaceDevServers`

6. **`frontend/src/components/ui-new/containers/PreviewBrowserContainer.tsx`**
   - Removed `attemptId` prop (now uses `workspaceId` from `useWorkspaceContext()` directly)
   - Updated to use workspace-scoped dev server streaming

7. **`frontend/src/components/ui-new/containers/PreviewControlsContainer.tsx`**
   - Removed `attemptId` prop (now uses `workspaceId` from `useWorkspaceContext()` directly)
   - Updated to use workspace-scoped dev server streaming

8. **`frontend/src/components/ui-new/containers/WorkspacesLayout.tsx`**
   - Removed the `attemptId` props from `PreviewControlsContainer` and `PreviewBrowserContainer` usages

### Database Changes
- Ran `pnpm run prepare-db` to update the SQLx query cache for the new database query
…n-scoped `useDevServer` hook, which caused `runningDevServers` to be empty when the user switched sessions. This made the `ToggleDevServer` action think there was no running dev server and call `startDevServer()` instead of `stopDevServer()`.

Now `ActionsContext.tsx` uses `usePreviewDevServer` which is backed by the workspace-scoped `useWorkspaceDevServers` hook, so it correctly sees running dev servers across all sessions in the workspace.
@stunningpixels stunningpixels changed the title Create special stream just for dev server processes that gets all dev servers by workspace, not (vibe-kanban) Fix dev server visibility when switching sessions within a workspace (Vibe Kanban) Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants