paperclip/ui/src/components/LiveRunWidget.tsx

171 lines
6.8 KiB
TypeScript
Raw Normal View History

import { useMemo, useState } from "react";
import { Link } from "@/lib/router";
import { useQuery, useQueryClient } from "@tanstack/react-query";
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
import { heartbeatsApi, type ActiveRunForIssue, type LiveRunForIssue } from "../api/heartbeats";
import { queryKeys } from "../lib/queryKeys";
import { formatDateTime } from "../lib/utils";
import { ExternalLink, Square } from "lucide-react";
import { Identity } from "./Identity";
import { RunChatSurface } from "./RunChatSurface";
import { StatusBadge } from "./StatusBadge";
import { useLiveRunTranscripts } from "./transcript/useLiveRunTranscripts";
interface LiveRunWidgetProps {
issueId: string;
companyId?: string | null;
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
liveRunsData?: LiveRunForIssue[];
activeRunData?: ActiveRunForIssue | null;
}
function toIsoString(value: string | Date | null | undefined): string | null {
if (!value) return null;
return typeof value === "string" ? value : value.toISOString();
}
function isRunActive(status: string): boolean {
return status === "queued" || status === "running";
}
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
export function LiveRunWidget({
issueId,
companyId,
liveRunsData,
activeRunData,
}: LiveRunWidgetProps) {
const queryClient = useQueryClient();
const [cancellingRunIds, setCancellingRunIds] = useState(new Set<string>());
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
const shouldFetchLiveRuns = liveRunsData === undefined;
const shouldFetchActiveRun = activeRunData === undefined;
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
const { data: fetchedLiveRuns } = useQuery({
queryKey: queryKeys.issues.liveRuns(issueId),
queryFn: () => heartbeatsApi.liveRunsForIssue(issueId),
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
enabled: !!issueId && shouldFetchLiveRuns,
refetchInterval: 3000,
});
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
const { data: fetchedActiveRun } = useQuery({
queryKey: queryKeys.issues.activeRun(issueId),
queryFn: () => heartbeatsApi.activeRunForIssue(issueId),
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
enabled: !!issueId && shouldFetchActiveRun,
refetchInterval: 3000,
});
Fix typing lag in long comment threads (PAPA-63) (#3163) ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The issue detail page displays comment threads with rich timeline rendering > - Long threads (100+ items) cause severe typing lag in the comment composer because every keystroke re-renders the entire timeline > - CDP tracing confirmed 110ms avg key→paint latency and 60 long tasks blocking the main thread for 3.7s total > - This pull request memoizes the timeline, stabilizes callback props, debounces editor observers, and reduces idle polling frequency > - The benefit is responsive typing (21ms avg, 5.3× faster) even on threads with 100+ timeline items ## What Changed - **CommentThread.tsx**: Memoize `TimelineList` with `useMemo` so typing state changes don't re-render 143 timeline items; extract `handleFeedbackVote` to `useCallback`; added missing deps (`pendingApprovalAction`, `onApproveApproval`, `onRejectApproval`) to useMemo array - **IssueDetail.tsx**: Extract inline callbacks (`handleCommentAdd`, `handleCommentVote`, `handleCommentImageUpload`, `handleCommentAttachImage`, `handleInterruptQueued`) to `useCallback` with `.mutateAsync` deps (not full mutation objects) for stable references; add conditional polling intervals (3s active / 30s idle) for `liveRuns`, `activeRun`, `linkedRuns`, and timeline queries - **MarkdownEditor.tsx**: Debounce `MutationObserver` and `selectionchange` handlers via `requestAnimationFrame` coalescing - **LiveRunWidget.tsx**: Accept optional `liveRunsData` and `activeRunData` props to reuse parent-fetched data instead of duplicate polling ## Verification - Navigated to [IP address]:3105/PAPA/issues/PAPA-32 (thread with 100+ items) - Typed in comment composer — lag eliminated, characters appear instantly - CDP trace test script (`test-typing-lag.mjs`) confirmed: avg 21ms key→paint (was 110ms), 5 long tasks (was 60), 0.5s blocking (was 3.7s) - Ran `pnpm test:run` locally — all tests pass ## Risks - Low risk. All changes are additive memoization and callback stabilization — no behavioral changes. Polling intervals are only reduced for idle state; active runs still poll at 3–5s. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) via Claude Code CLI, with tool use and extended context ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-04-08 17:54:03 -07:00
const liveRuns = liveRunsData ?? fetchedLiveRuns;
const activeRun = activeRunData ?? fetchedActiveRun;
const runs = useMemo(() => {
const deduped = new Map<string, LiveRunForIssue>();
for (const run of liveRuns ?? []) {
deduped.set(run.id, run);
}
if (activeRun) {
deduped.set(activeRun.id, {
id: activeRun.id,
status: activeRun.status,
invocationSource: activeRun.invocationSource,
triggerDetail: activeRun.triggerDetail,
startedAt: toIsoString(activeRun.startedAt),
finishedAt: toIsoString(activeRun.finishedAt),
createdAt: toIsoString(activeRun.createdAt) ?? new Date().toISOString(),
agentId: activeRun.agentId,
agentName: activeRun.agentName,
adapterType: activeRun.adapterType,
issueId,
});
}
return [...deduped.values()].sort(
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
);
}, [activeRun, issueId, liveRuns]);
const { transcriptByRun, hasOutputForRun } = useLiveRunTranscripts({ runs, companyId });
const handleCancelRun = async (runId: string) => {
setCancellingRunIds((prev) => new Set(prev).add(runId));
try {
await heartbeatsApi.cancel(runId);
queryClient.invalidateQueries({ queryKey: queryKeys.issues.liveRuns(issueId) });
queryClient.invalidateQueries({ queryKey: queryKeys.issues.activeRun(issueId) });
} finally {
setCancellingRunIds((prev) => {
const next = new Set(prev);
next.delete(runId);
return next;
});
}
};
if (runs.length === 0) return null;
return (
<div className="overflow-hidden rounded-xl border border-cyan-500/25 bg-background/80 shadow-[0_18px_50px_rgba(6,182,212,0.08)]">
<div className="border-b border-border/60 bg-cyan-500/[0.04] px-4 py-3">
<div className="text-xs font-semibold uppercase tracking-[0.18em] text-cyan-700 dark:text-cyan-300">
Live Runs
</div>
<div className="mt-1 text-xs text-muted-foreground">
Uses the shared chat-style run surface from issue activity.
</div>
</div>
<div className="divide-y divide-border/60">
{runs.map((run) => {
const isActive = isRunActive(run.status);
const transcript = transcriptByRun.get(run.id) ?? [];
return (
<section key={run.id} className="px-4 py-4">
<div className="mb-3 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
<div className="min-w-0">
<Link to={`/agents/${run.agentId}`} className="inline-flex hover:underline">
<Identity name={run.agentName} size="sm" />
</Link>
<div className="mt-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
<Link
to={`/agents/${run.agentId}/runs/${run.id}`}
className="inline-flex items-center rounded-full border border-border/70 bg-background/70 px-2 py-1 font-mono hover:border-cyan-500/30 hover:text-foreground"
>
{run.id.slice(0, 8)}
</Link>
<StatusBadge status={run.status} />
<span>{formatDateTime(run.startedAt ?? run.createdAt)}</span>
</div>
</div>
<div className="flex items-center gap-2">
{isActive && (
<button
onClick={() => handleCancelRun(run.id)}
disabled={cancellingRunIds.has(run.id)}
className="inline-flex items-center gap-1 rounded-full border border-red-500/20 bg-red-500/[0.06] px-2.5 py-1 text-[11px] font-medium text-red-700 transition-colors hover:bg-red-500/[0.12] dark:text-red-300 disabled:opacity-50"
>
<Square className="h-2.5 w-2.5" fill="currentColor" />
{cancellingRunIds.has(run.id) ? "Stopping…" : "Stop"}
</button>
)}
<Link
to={`/agents/${run.agentId}/runs/${run.id}`}
className="inline-flex items-center gap-1 rounded-full border border-border/70 bg-background/70 px-2.5 py-1 text-[11px] font-medium text-cyan-700 transition-colors hover:border-cyan-500/30 hover:text-cyan-600 dark:text-cyan-300"
>
Open run
<ExternalLink className="h-3 w-3" />
</Link>
</div>
</div>
<div className="max-h-[320px] overflow-y-auto pr-1">
<RunChatSurface
run={run}
transcript={transcript}
hasOutput={hasOutputForRun(run.id)}
companyId={companyId}
/>
</div>
</section>
);
})}
</div>
</div>
);
}