Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-5415: fix(issues): keep running-agent transcript open
feige422b169a8f6
diff --git a/packages/views/common/task-transcript/transcript-button.tsx b/packages/views/common/task-transcript/transcript-button.tsxindex 5375143fda..535f4513ac 100644--- a/packages/views/common/task-transcript/transcript-button.tsx+++ b/packages/views/common/task-transcript/transcript-button.tsx@@ -36,6 +36,9 @@ interface TranscriptButtonProps {isLive?: boolean;className?: string;title?: string;+ renderButton?: boolean;+ open?: boolean;+ onOpenChange?: (open: boolean) => void;/*** Optional content rendered above the transcript event list. Used to* surface autopilot webhook payloads inline with the run history.@@ -64,11 +67,16 @@ export function TranscriptButton({isLive = false,className,title = "View transcript",+ renderButton = true,+ open: controlledOpen,+ onOpenChange: controlledOnOpenChange,headerSlot,}: TranscriptButtonProps) {- const [open, setOpen] = useState(false);+ const [uncontrolledOpen, setUncontrolledOpen] = useState(false);const [loading, setLoading] = useState(false);const [loadedItems, setLoadedItems] = useState<TimelineItem[] | null>(null);+ const open = controlledOpen ?? uncontrolledOpen;+ const setOpen = controlledOnOpenChange ?? setUncontrolledOpen;// Live cache mode: the running task feeds the shared task-messages cache, so// we render straight off that cache instead of a one-shot local snapshot.@@ -82,8 +90,14 @@ export function TranscriptButton({// authoritative backfill on the running→terminal transition.const [liveSession, setLiveSession] = useState(false);useEffect(() => {- if (!open) setLiveSession(false);- }, [open]);+ if (!open) {+ setLiveSession(false);+ return;+ }+ if (liveCacheMode) {+ setLiveSession(true);+ }+ }, [liveCacheMode, open]);// Live mode renders from the cache; lazy/provided modes from local state.const items = providedItems ?? loadedItems ?? [];@@ -115,7 +129,7 @@ export function TranscriptButton({}).finally(() => setLoading(false));},- [liveCacheMode, providedItems, loadedItems, task.id],+ [liveCacheMode, providedItems, loadedItems, setOpen, task.id],);useEffect(() => {@@ -129,29 +143,31 @@ export function TranscriptButton({return () => {window.removeEventListener("multica:navigate", handleGlobalNavigate);};- }, [open]);+ }, [open, setOpen]);return (<>- <Tooltip>- <TooltipTrigger- render={<button type="button" />}- onClick={handleClick}- disabled={loading}- aria-label={title}- className={cn(- "flex items-center justify-center rounded p-1 text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors disabled:opacity-50",- className,- )}- >- {loading ? (- <Loader2 className="h-3.5 w-3.5 animate-spin" />- ) : (- <ScrollText className="h-3.5 w-3.5" />- )}- </TooltipTrigger>- <TooltipContent>{title}</TooltipContent>- </Tooltip>+ {renderButton ? (+ <Tooltip>+ <TooltipTrigger+ render={<button type="button" />}+ onClick={handleClick}+ disabled={loading}+ aria-label={title}+ className={cn(+ "flex items-center justify-center rounded p-1 text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors disabled:opacity-50",+ className,+ )}+ >+ {loading ? (+ <Loader2 className="h-3.5 w-3.5 animate-spin" />+ ) : (+ <ScrollText className="h-3.5 w-3.5" />+ )}+ </TooltipTrigger>+ <TooltipContent>{title}</TooltipContent>+ </Tooltip>+ ) : null}{open &&(liveSession ? (diff --git a/packages/views/issues/components/execution-log-section.tsx b/packages/views/issues/components/execution-log-section.tsxindex 7c741891c7..aad4544247 100644--- a/packages/views/issues/components/execution-log-section.tsx+++ b/packages/views/issues/components/execution-log-section.tsx@@ -254,9 +254,11 @@ function useStatusLabel(status: AgentTask["status"]): string {export function ActiveTaskRow({task,issueId,+ onTranscriptOpenChange,}: {task: AgentTask;issueId: string;+ onTranscriptOpenChange?: (open: boolean) => void;}) {const { t } = useT("issues");const [cancelling, setCancelling] = useState(false);@@ -323,6 +325,7 @@ export function ActiveTaskRow({agentName=""isLive={task.status === "running"}title={t(($) => $.execution_log.transcript_tooltip)}+ onOpenChange={onTranscriptOpenChange}/>)}<Tooltip>diff --git a/packages/views/issues/components/issue-agent-header-chip.test.tsx b/packages/views/issues/components/issue-agent-header-chip.test.tsxindex b47ebd96a6..bb475c8aaf 100644--- a/packages/views/issues/components/issue-agent-header-chip.test.tsx+++ b/packages/views/issues/components/issue-agent-header-chip.test.tsx@@ -1,8 +1,12 @@// @vitest-environment jsdom-import { cleanup, screen } from "@testing-library/react";+import { cleanup, fireEvent, screen, waitFor } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import { beforeEach, describe, expect, it, vi } from "vitest";+import { api } from "@multica/core/api";+import { chatKeys } from "@multica/core/chat/queries";import type { AgentTask } from "@multica/core/types";+import type { TaskMessagePayload } from "@multica/core/types/events";import { renderWithI18n } from "../../test/i18n";const mockState = vi.hoisted(() => ({@@ -13,6 +17,12 @@ const mockState = vi.hoisted(() => ({triggerProps: undefined as Record<string, unknown> | undefined,}));+vi.mock("@multica/core/api", () => ({+ api: {+ listTaskMessages: vi.fn(),+ },+}));+vi.mock("@multica/core/workspace/hooks", () => ({useActorName: () => ({getActorName: (_type: string, id: string) =>@@ -29,9 +39,18 @@ vi.mock("@multica/core/workspace/hooks", () => ({}),}));-vi.mock("@multica/core/chat/queries", () => ({- taskMessagesOptions: mockState.taskMessagesOptions,-}));+vi.mock("@multica/core/chat/queries", async () => {+ const actual = await vi.importActual<typeof import("@multica/core/chat/queries")>(+ "@multica/core/chat/queries",+ );+ return {+ ...actual,+ taskMessagesOptions: (...args: Parameters<typeof actual.taskMessagesOptions>) => {+ mockState.taskMessagesOptions(...args);+ return actual.taskMessagesOptions(...args);+ },+ };+});vi.mock("@multica/ui/components/ui/popover", async () => {const React = await vi.importActual<typeof import("react")>("react");@@ -57,11 +76,44 @@ vi.mock("@multica/ui/components/ui/popover", async () => {});vi.mock("./execution-log-section", () => ({- ActiveTaskRow: ({ task }: { task: AgentTask }) => (- <div data-testid="active-task-row">{task.id}</div>+ ActiveTaskRow: ({+ task,+ onTranscriptOpenChange,+ }: {+ task: AgentTask;+ transcriptOpen?: boolean;+ onTranscriptOpenChange?: (open: boolean) => void;+ }) => (+ <div data-testid="active-task-row">+ <span>{task.id}</span>+ <button+ type="button"+ aria-label={`open transcript ${task.id}`}+ onClick={() => onTranscriptOpenChange?.(true)}+ >+ Open transcript+ </button>+ </div>),}));+vi.mock("../../common/task-transcript/agent-transcript-dialog", () => ({+ AgentTranscriptDialog: ({+ open,+ items,+ }: {+ open: boolean;+ items: Array<{ seq: number }>;+ }) =>+ open ? (+ <div role="dialog">+ {items.map((item) => (+ <div key={item.seq} data-testid="event" data-seq={item.seq} />+ ))}+ </div>+ ) : null,+}));+vi.mock("@tanstack/react-query", async () => {const actual =await vi.importActual<typeof import("@tanstack/react-query")>(@@ -75,16 +127,43 @@ vi.mock("@tanstack/react-query", async () => {if (opts.queryKey?.[0] === "issues" && opts.queryKey?.[1] === "tasks") {return { data: mockState.tasks };}- return { data: undefined };+ return actual.useQuery(opts as Parameters<typeof actual.useQuery>[0]);},};});import { IssueAgentHeaderChip } from "./issue-agent-header-chip";+const listTaskMessages = vi.mocked(api.listTaskMessages);++const LIVE_TASK_ID = "4a2e8d1c-7f9b-4e2a-9c1d-123456789abc";++const msg = (seq: number): TaskMessagePayload => ({+ task_id: LIVE_TASK_ID,+ issue_id: "issue-1",+ seq,+ type: "tool_use",+ tool: `Tool ${seq}`,+ input: { i: String(seq) },+});++function newClient() {+ return new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+}++function renderChip(qc: QueryClient, issueId = "issue-1") {+ return renderWithI18n(+ <QueryClientProvider client={qc}>+ <IssueAgentHeaderChip issueId={issueId} />+ </QueryClientProvider>,+ );+}+function makeTask(overrides: Partial<AgentTask>): AgentTask {return {- id: "task-1",+ id: LIVE_TASK_ID,agent_id: "agent-1",runtime_id: "runtime-1",issue_id: "issue-1",@@ -105,6 +184,8 @@ beforeEach(() => {vi.clearAllMocks();mockState.tasks = [];mockState.triggerProps = undefined;+ listTaskMessages.mockReset();+ listTaskMessages.mockResolvedValue([]);});describe("IssueAgentHeaderChip", () => {@@ -134,6 +215,69 @@ describe("IssueAgentHeaderChip", () => {expect(mockState.taskMessagesOptions).not.toHaveBeenCalled();});+ it("keeps the live transcript open after the clicked task row disappears from the active list", async () => {+ const qc = newClient();+ mockState.tasks = [makeTask({ id: LIVE_TASK_ID })];+ qc.setQueryData(chatKeys.taskMessages(LIVE_TASK_ID), [msg(1)]);+ listTaskMessages.mockResolvedValue([msg(1)]);++ const { rerender } = renderChip(qc);++ fireEvent.click(screen.getByRole("button", { name: `open transcript ${LIVE_TASK_ID}` }));++ await waitFor(() => {+ expect(screen.getByRole("dialog")).toBeInTheDocument();+ });+ await waitFor(() => {+ expect(screen.getAllByTestId("event")).toHaveLength(1);+ });+ expect(screen.getByTestId("active-task-row")).toHaveTextContent(LIVE_TASK_ID);+ expect(listTaskMessages).toHaveBeenCalledWith(LIVE_TASK_ID);++ mockState.tasks = [];+ rerender(+ <QueryClientProvider client={qc}>+ <IssueAgentHeaderChip issueId="issue-2" />+ </QueryClientProvider>,+ );++ expect(screen.queryByTestId("active-task-row")).not.toBeInTheDocument();+ expect(screen.getByRole("dialog")).toBeInTheDocument();+ expect(screen.getAllByTestId("event")).toHaveLength(1);+ });++ it("refreshes the transcript when the opened task completes", async () => {+ const qc = newClient();+ mockState.tasks = [makeTask({ id: LIVE_TASK_ID, status: "running" })];+ qc.setQueryData(chatKeys.taskMessages(LIVE_TASK_ID), [msg(1)]);+ listTaskMessages.mockResolvedValue([msg(1)]);++ const { rerender } = renderChip(qc);++ fireEvent.click(screen.getByRole("button", { name: `open transcript ${LIVE_TASK_ID}` }));++ await waitFor(() => {+ expect(listTaskMessages).toHaveBeenCalledTimes(1);+ });++ mockState.tasks = [+ makeTask({+ id: LIVE_TASK_ID,+ status: "completed",+ completed_at: "2026-06-08T08:05:00Z",+ }),+ ];+ rerender(+ <QueryClientProvider client={qc}>+ <IssueAgentHeaderChip issueId="issue-2" />+ </QueryClientProvider>,+ );++ await waitFor(() => {+ expect(listTaskMessages).toHaveBeenCalledTimes(2);+ });+ });+it("opens the activity card on hover, not only on click", () => {mockState.tasks = [makeTask({})];diff --git a/packages/views/issues/components/issue-agent-header-chip.tsx b/packages/views/issues/components/issue-agent-header-chip.tsxindex 6e06668bd6..6cf8440879 100644--- a/packages/views/issues/components/issue-agent-header-chip.tsx+++ b/packages/views/issues/components/issue-agent-header-chip.tsx@@ -1,6 +1,6 @@"use client";-import { memo, useMemo } from "react";+import { memo, useMemo, useState } from "react";import { useQuery } from "@tanstack/react-query";import {Popover,@@ -12,6 +12,7 @@ import { cn } from "@multica/ui/lib/utils";import { api } from "@multica/core/api";import { issueKeys } from "@multica/core/issues/queries";import type { AgentTask } from "@multica/core/types";+import { TranscriptButton } from "../../common/task-transcript";import { AgentAvatarStack } from "../../agents/components/agent-avatar-stack";import { ActiveTaskRow } from "./execution-log-section";import { useT } from "../../i18n";@@ -46,6 +47,7 @@ interface IssueAgentHeaderChipProps {export const IssueAgentHeaderChip = memo(function IssueAgentHeaderChip({issueId,}: IssueAgentHeaderChipProps) {+ const { t } = useT("issues");// Same query options as ExecutionLogSection so both observe one cache entry.const { data: tasks = [] } = useQuery({queryKey: issueKeys.tasks(issueId),@@ -74,19 +76,58 @@ export const IssueAgentHeaderChip = memo(function IssueAgentHeaderChip({return { running, queued };}, [tasks]);+ const [openedTranscriptTaskSnapshot, setOpenedTranscriptTaskSnapshot] =+ useState<AgentTask | null>(null);+ const openedTranscriptTask = openedTranscriptTaskSnapshot+ ? tasks.find((task) => task.id === openedTranscriptTaskSnapshot.id) ??+ openedTranscriptTaskSnapshot+ : null;+// No active work → render nothing.- if (running.length === 0 && queued.length === 0) return null;+ if (running.length === 0 && queued.length === 0 && !openedTranscriptTask) return null;- return <ActiveChip issueId={issueId} running={running} queued={queued} />;+ return (+ <>+ {running.length > 0 || queued.length > 0 ? (+ <ActiveChip+ issueId={issueId}+ running={running}+ queued={queued}+ onTranscriptOpenChange={(task, open) => {+ setOpenedTranscriptTaskSnapshot(open ? task : null);+ }}+ />+ ) : null}+ {openedTranscriptTask ? (+ <TranscriptButton+ task={openedTranscriptTask}+ agentName=""+ isLive={openedTranscriptTask.status === "running"}+ title={t(($) => $.execution_log.transcript_tooltip)}+ renderButton={false}+ open+ onOpenChange={(open) => {+ if (!open) setOpenedTranscriptTaskSnapshot(null);+ }}+ />+ ) : null}+ </>+ );});interface ActiveChipProps {issueId: string;running: AgentTask[];queued: AgentTask[];+ onTranscriptOpenChange: (task: AgentTask, open: boolean) => void;}-function ActiveChip({ issueId, running, queued }: ActiveChipProps) {+function ActiveChip({+ issueId,+ running,+ queued,+ onTranscriptOpenChange,+}: ActiveChipProps) {const { t } = useT("issues");const { getActorName } = useActorName();@@ -167,7 +208,14 @@ function ActiveChip({ issueId, running, queued }: ActiveChipProps) {</div><div className="flex flex-col gap-0.5">{activeTasks.map((task) => (- <ActiveTaskRow key={task.id} task={task} issueId={issueId} />+ <ActiveTaskRow+ key={task.id}+ task={task}+ issueId={issueId}+ onTranscriptOpenChange={(open) => {+ onTranscriptOpenChange(task, open);+ }}+ />))}</div></PopoverContent>diff --git a/server/internal/daemon/workdir_race_test.go b/server/internal/daemon/workdir_race_test.goindex f4061a1091..5624e8fb48 100644--- a/server/internal/daemon/workdir_race_test.go+++ b/server/internal/daemon/workdir_race_test.go@@ -444,9 +444,21 @@ func TestRunTask_PrepareTimeoutStopsLeaseDuringBlockedStartTask(t *testing.T) {t.Fatal("prepare lease request was never started while /start was blocked")}leaseCallsAtReturn := leaseCalls.Load()- time.Sleep(4 * taskPrepareLeaseRefresh)- if got := leaseCalls.Load(); got != leaseCallsAtReturn {- t.Fatalf("prepare lease requests kept starting after timeout: calls %d -> %d", leaseCallsAtReturn, got)+ lastLeaseCalls := leaseCallsAtReturn+ stableReads := 0+ deadline := time.Now().Add(12 * taskPrepareLeaseRefresh)+ for stableReads < 3 && time.Now().Before(deadline) {+ time.Sleep(taskPrepareLeaseRefresh)+ got := leaseCalls.Load()+ if got == lastLeaseCalls {+ stableReads+++ continue+ }+ lastLeaseCalls = got+ stableReads = 0+ }+ if stableReads < 3 {+ t.Fatalf("prepare lease kept extending after timeout: calls %d -> %d", leaseCallsAtReturn, leaseCalls.Load())}if got := taskRunFailureReason(err); got != "timeout" {t.Fatalf("taskRunFailureReason = %q, want retryable platform timeout", got)