Fix live issue chat segment activity

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-06-16 13:27:39 +00:00
1 parent 52939c90c4
commit 4625611ffc
4 files changed
+44 -6

No files matched your search

+7 -3
View File
@@ -48,6 +48,7 @@ import { usePaperclipIssueRuntime, type PaperclipIssueRuntimeReassignment } from
import {
buildIssueChatMessages,
formatDurationWords,
isCoTSegmentActive,
stabilizeThreadMessages,
type IssueChatComment,
type IssueChatLinkedRun,
@@ -851,13 +852,16 @@ function IssueChatChainOfThought({
(p): p is ToolCallMessagePart => p.type === "tool-call",
);
const isActive = isMessageRunning;
const [expanded, setExpanded] = useState(isActive);
const rawSegments = Array.isArray(custom.chainOfThoughtSegments)
? (custom.chainOfThoughtSegments as SegmentTiming[])
: [];
const segmentTiming = myIndex >= 0 ? rawSegments[myIndex] ?? null : null;
const isActive = isCoTSegmentActive({
isMessageRunning,
segmentIndex: myIndex,
segmentCount: rawSegments.length,
});
const [expanded, setExpanded] = useState(isActive);
const liveElapsed = useLiveElapsed(segmentTiming?.startMs, isActive);
useEffect(() => {
+7 -3
View File
@@ -59,6 +59,7 @@ import { usePaperclipIssueRuntime, type PaperclipIssueRuntimeReassignment } from
import {
buildIssueChatMessages,
formatDurationWords,
isCoTSegmentActive,
stabilizeThreadMessages,
type IssueChatComment,
type IssueChatLinkedRun,
@@ -876,13 +877,16 @@ function IssueChatChainOfThought({
(p): p is ToolCallMessagePart => p.type === "tool-call",
);
const isActive = isMessageRunning;
const [expanded, setExpanded] = useState(isActive);
const rawSegments = Array.isArray(custom.chainOfThoughtSegments)
? (custom.chainOfThoughtSegments as SegmentTiming[])
: [];
const segmentTiming = myIndex >= 0 ? rawSegments[myIndex] ?? null : null;
const isActive = isCoTSegmentActive({
isMessageRunning,
segmentIndex: myIndex,
segmentCount: rawSegments.length,
});
const [expanded, setExpanded] = useState(isActive);
const liveElapsed = useLiveElapsed(segmentTiming?.startMs, isActive);
useEffect(() => {
+19
View File
@@ -3,6 +3,7 @@ import type { Agent } from "@paperclipai/shared";
import {
buildAssistantPartsFromTranscript,
buildIssueChatMessages,
isCoTSegmentActive,
stabilizeThreadMessages,
type IssueChatComment,
type IssueChatLinkedRun,
@@ -238,6 +239,24 @@ describe("buildAssistantPartsFromTranscript", () => {
}]);
});
it("marks only the latest chain-of-thought segment active while a run is live", () => {
expect(isCoTSegmentActive({
isMessageRunning: true,
segmentIndex: 0,
segmentCount: 2,
})).toBe(false);
expect(isCoTSegmentActive({
isMessageRunning: true,
segmentIndex: 1,
segmentCount: 2,
})).toBe(true);
expect(isCoTSegmentActive({
isMessageRunning: false,
segmentIndex: 1,
segmentCount: 2,
})).toBe(false);
});
it("keeps run errors while suppressing init and system transcript noise", () => {
const result = buildAssistantPartsFromTranscript([
{
+11
View File
@@ -538,6 +538,17 @@ export interface SegmentTiming {
endMs: number;
}
export function isCoTSegmentActive(args: {
isMessageRunning: boolean;
segmentIndex: number;
segmentCount: number;
}) {
const { isMessageRunning, segmentIndex, segmentCount } = args;
if (!isMessageRunning) return false;
if (segmentCount <= 0 || segmentIndex < 0) return true;
return segmentIndex === segmentCount - 1;
}
function computeSegmentTimings(entries: readonly IssueChatTranscriptEntry[]): SegmentTiming[] {
const timings: SegmentTiming[] = [];
let inSegment = false;