diff --git a/apps/backend/internal/agent/lifecycle/manager_execution.go b/apps/backend/internal/agent/lifecycle/manager_execution.go index 0bda584d02..700835e38e 100644 --- a/apps/backend/internal/agent/lifecycle/manager_execution.go +++ b/apps/backend/internal/agent/lifecycle/manager_execution.go @@ -11,6 +11,7 @@ import ( "github.com/kandev/kandev/internal/agentctl/tracing" "github.com/kandev/kandev/internal/common/appctx" + "github.com/kandev/kandev/internal/events" "github.com/kandev/kandev/internal/secrets" ) @@ -88,8 +89,16 @@ func (m *Manager) EnsureWorkspaceExecutionForSession(ctx context.Context, taskID return nil, err } + // Notify subscribers that agentctl is starting. createExecution already + // spawns waitForAgentctlReady which publishes AgentctlReady/AgentctlError, + // but AgentctlStarting is only published in the Launch path — add it here + // so workspace-only executions also notify the frontend. + m.eventPublisher.PublishAgentctlEvent(ctx, events.AgentctlStarting, execution, "") + // For workspace-only executions (no agent), wait for agentctl to be ready - // then connect the workspace stream so process output can be received + // then connect the workspace stream so process output can be received. + // Note: AgentctlReady/Error events are already handled by waitForAgentctlReady + // (started by createExecution), so this goroutine only connects the stream. go func() { // Use detached context that respects stopCh for graceful shutdown waitCtx, cancel := appctx.Detached(ctx, m.stopCh, 60*time.Second) diff --git a/apps/web/components/task/passthrough-terminal.tsx b/apps/web/components/task/passthrough-terminal.tsx index b9f513c0fd..2aef4747fb 100644 --- a/apps/web/components/task/passthrough-terminal.tsx +++ b/apps/web/components/task/passthrough-terminal.tsx @@ -101,13 +101,15 @@ export function PassthroughTerminal(props: PassthroughTerminalProps) { const storeSessionId = useAppStore((state) => state.tasks.activeSessionId); const sessionId = propSessionId ?? storeSessionId; - const { session, isActive } = useSession(sessionId); + const { session } = useSession(sessionId); const agentctlStatus = useSessionAgentctl(sessionId); const taskId = session?.task_id ?? null; // Gate WS connection on agentctl readiness. During a long prepare script // the backend terminal endpoint isn't accepting connections yet, and // spamming reconnects burns cycles and confuses the loading state. - const canConnect = Boolean(sessionId && isActive && agentctlStatus.isReady); + // Don't require isActive — restored workspaces (terminal-state sessions) + // have agentctl running but the session state stays COMPLETED/CANCELLED. + const canConnect = Boolean(sessionId && agentctlStatus.isReady); const wsBaseUrl = useWsBaseUrl(); const [isTerminalReady, setIsTerminalReady] = useState(false);