Skip to content

Commit de9622f

Browse files
vaststudiosclaude
andcommitted
fix: forks drop the launcher, and the fold toggle reports its real state
A fork copied its source thread's launchedByThreadId and nested under the source's launcher. The fold toggle read "unfolded" whenever the open thread kept a folded branch visible, so its first click did nothing visible. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ee3d3da commit de9622f

5 files changed

Lines changed: 65 additions & 20 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadForkService.test.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ function makeSourceRun(status: OrchestrationV2Run["status"]): OrchestrationV2Run
8383
};
8484
}
8585

86-
function makeSourceProjection(sourceRun: OrchestrationV2Run): OrchestrationV2ThreadProjection {
86+
function makeSourceProjection(
87+
sourceRun: OrchestrationV2Run,
88+
thread: OrchestrationV2AppThread = makeSourceThread(),
89+
): OrchestrationV2ThreadProjection {
8790
return {
88-
thread: makeSourceThread(),
91+
thread,
8992
runs: [sourceRun],
9093
attempts: [],
9194
nodes: [],
@@ -106,11 +109,11 @@ function makeSourceProjection(sourceRun: OrchestrationV2Run): OrchestrationV2Thr
106109
};
107110
}
108111

109-
const planFork = (sourceRun: OrchestrationV2Run) =>
112+
const planFork = (sourceRun: OrchestrationV2Run, sourceThread?: OrchestrationV2AppThread) =>
110113
Effect.gen(function* () {
111114
const service = yield* ThreadForkService.ThreadForkServiceV2;
112115
return yield* service.plan({
113-
sourceProjection: makeSourceProjection(sourceRun),
116+
sourceProjection: makeSourceProjection(sourceRun, sourceThread),
114117
sourceRun,
115118
sourceProviderThread: undefined,
116119
canonicalSourcePoint: {
@@ -168,6 +171,16 @@ it.effect("keeps a fork awake when its source thread is snoozed", () =>
168171
}),
169172
);
170173

174+
it.effect("does not carry the source thread's launcher over to the fork", () =>
175+
Effect.gen(function* () {
176+
const result = yield* planFork(makeSourceRun("completed"), {
177+
...makeSourceThread(),
178+
launchedByThreadId: ThreadId.make("thread:fork-source-launcher"),
179+
});
180+
assert.isNull(result.targetThread.launchedByThreadId);
181+
}),
182+
);
183+
171184
it.effect("forks from a usage-limited failed run", () =>
172185
Effect.gen(function* () {
173186
const result = yield* planFork(makeSourceRun("failed"));

‎apps/server/src/orchestration-v2/ThreadForkService.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const layer: Layer.Layer<ThreadForkServiceV2> = Layer.succeed(
9898
threadId: input.sourceProjection.thread.id,
9999
runId: input.sourceRun.id,
100100
},
101+
launchedByThreadId: null,
101102
createdAt: input.createdAt,
102103
updatedAt: input.createdAt,
103104
archivedAt: null,

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ interface SidebarThreadRowProps {
384384
launchedCount: number;
385385
/** Launched threads and subagents folded away below this one. */
386386
launchedHiddenCount: number;
387+
launchedFolded: boolean;
387388
launchDepth: number;
388389
isFirstLaunchedChild: boolean;
389390
isLastLaunchedChild: boolean;
@@ -445,6 +446,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
445446
const {
446447
launchedCount,
447448
launchedHiddenCount,
449+
launchedFolded,
448450
launchDepth,
449451
isFirstLaunchedChild,
450452
isLastLaunchedChild,
@@ -727,7 +729,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
727729
void attemptArchiveThread(threadRef);
728730
};
729731
const visibleLaunchDepth = Math.min(launchDepth, LAUNCHED_THREAD_MAX_VISIBLE_DEPTH);
730-
const launchedFolded = launchedHiddenCount > 0;
731732
const handleLaunchFoldClick = (event: React.MouseEvent<HTMLButtonElement>) => {
732733
event.preventDefault();
733734
event.stopPropagation();
@@ -853,17 +854,19 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
853854
data-launch-fold
854855
aria-expanded={!launchedFolded}
855856
aria-label={
856-
launchedFolded
857+
launchedFolded && launchedHiddenCount > 0
857858
? `Show ${launchedHiddenCount} folded ${launchedHiddenCount === 1 ? "thread" : "threads"}`
858-
: `Hide ${launchedCount} child ${launchedCount === 1 ? "thread" : "threads"}`
859+
: launchedFolded
860+
? `Unfold ${launchedCount} child ${launchedCount === 1 ? "thread" : "threads"}`
861+
: `Hide ${launchedCount} child ${launchedCount === 1 ? "thread" : "threads"}`
859862
}
860863
className="group/launch-fold relative inline-flex h-4 min-w-4 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/70 outline-hidden hover:text-sidebar-foreground focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring"
861864
onPointerDown={(event) => event.stopPropagation()}
862865
onDoubleClick={(event) => event.stopPropagation()}
863866
onKeyDown={(event) => event.stopPropagation()}
864867
onClick={handleLaunchFoldClick}
865868
>
866-
{launchedFolded ? (
869+
{launchedHiddenCount > 0 ? (
867870
<span className="text-2xs tabular-nums transition-opacity duration-150 group-hover/menu-sub-item:opacity-0 group-focus-visible/launch-fold:opacity-0">
868871
{launchedHiddenCount}
869872
</span>
@@ -1019,7 +1022,10 @@ interface SidebarProjectThreadListProps {
10191022
hiddenThreadStatus: ThreadStatusPill | null;
10201023
orderedProjectThreadKeys: readonly string[];
10211024
renderedThreads: readonly SidebarThreadSummary[];
1022-
launchFoldByThreadKey: ReadonlyMap<string, { childCount: number; hiddenCount: number }>;
1025+
launchFoldByThreadKey: ReadonlyMap<
1026+
string,
1027+
{ childCount: number; hiddenCount: number; folded: boolean }
1028+
>;
10231029
showEmptyThreadState: boolean;
10241030
shouldShowThreadPanel: boolean;
10251031
isThreadListExpanded: boolean;
@@ -1144,6 +1150,7 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
11441150
thread={thread}
11451151
launchedCount={launchFold?.childCount ?? 0}
11461152
launchedHiddenCount={launchFold?.hiddenCount ?? 0}
1153+
launchedFolded={launchFold?.folded ?? false}
11471154
launchDepth={launchTree?.depth ?? 0}
11481155
isFirstLaunchedChild={launchTree?.isFirstChild ?? true}
11491156
isLastLaunchedChild={launchTree?.isLastChild ?? true}
@@ -1343,9 +1350,9 @@ function useFoldedProjectThreads(
13431350
visibleProjectThreads,
13441351
orderedProjectThreadKeys: visibleProjectThreads.map(keyOf),
13451352
launchFoldByThreadKey: new Map(
1346-
foldedProjectThreads.map(({ thread, childCount, hiddenCount }) => [
1353+
foldedProjectThreads.map(({ thread, childCount, hiddenCount, folded }) => [
13471354
keyOf(thread),
1348-
{ childCount, hiddenCount },
1355+
{ childCount, hiddenCount, folded },
13491356
]),
13501357
),
13511358
};

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,13 @@ describe("sidebar thread lineage helpers", () => {
571571
(entry) => choices[entry.id],
572572
(entry) => "lineage" in entry,
573573
(entry) => entry.id === open,
574-
).map(({ thread, childCount, hiddenCount }) => `${thread.id}:${childCount}/${hiddenCount}`);
574+
).map(
575+
({ thread, childCount, hiddenCount, folded }) =>
576+
`${thread.id}:${childCount}/${hiddenCount}${folded ? " folded" : ""}`,
577+
);
575578

576579
expect(summarize({})).toEqual([
577-
"orchestrator:4/1",
580+
"orchestrator:4/1 folded",
578581
"child:1/0",
579582
"grandchild:0/0",
580583
"sibling:0/0",
@@ -588,15 +591,23 @@ describe("sidebar thread lineage helpers", () => {
588591
"sibling:0/0",
589592
"solo:0/0",
590593
]);
591-
expect(summarize({ orchestrator: true })).toEqual(["orchestrator:4/4", "solo:0/0"]);
594+
expect(summarize({ orchestrator: true })).toEqual(["orchestrator:4/4 folded", "solo:0/0"]);
592595
// The open thread's branch stays visible; its folded siblings stay folded.
593596
expect(summarize({ orchestrator: true }, "grandchild")).toEqual([
594-
"orchestrator:4/2",
597+
"orchestrator:4/2 folded",
595598
"child:1/0",
596599
"grandchild:0/0",
597600
"solo:0/0",
598601
]);
599-
expect(summarize({}, "helper")).toEqual(summarize({ orchestrator: false }));
602+
// A pinned subagent keeps the launcher folded even though nothing below it is hidden.
603+
expect(summarize({}, "helper")).toEqual([
604+
"orchestrator:4/0 folded",
605+
"child:1/0",
606+
"grandchild:0/0",
607+
"helper:0/0",
608+
"sibling:0/0",
609+
"solo:0/0",
610+
]);
600611
});
601612

602613
it("keeps threads in a launch cycle visible", () => {

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,36 +604,49 @@ export function nestLaunchedSidebarThreads<
604604
* Drops the threads folded under their launcher. `foldState` is the user's choice per launcher:
605605
* true folds every child, false shows every child, and undefined (no choice yet) shows launched
606606
* threads but folds subagents. A child branch holding a thread for which
607-
* `keepVisible` holds (the open thread) always stays visible.
607+
* `keepVisible` holds (the open thread) always stays visible, so `folded` reports the launcher's
608+
* fold state even when nothing below it is hidden.
608609
*/
609610
export function foldLaunchedSidebarThreads<T>(
610611
nested: ReadonlyArray<NestedSidebarThread<T>>,
611612
foldState: (thread: T) => boolean | undefined,
612613
isSubagent: (thread: T) => boolean,
613614
keepVisible: (thread: T) => boolean,
614-
): Array<NestedSidebarThread<T> & { readonly childCount: number; readonly hiddenCount: number }> {
615+
): Array<
616+
NestedSidebarThread<T> & {
617+
readonly childCount: number;
618+
readonly hiddenCount: number;
619+
readonly folded: boolean;
620+
}
621+
> {
615622
const subtreeEnd = (index: number) => {
616623
let end = index + 1;
617624
while (end < nested.length && nested[end]!.depth > nested[index]!.depth) end++;
618625
return end;
619626
};
620627
const result: Array<
621-
NestedSidebarThread<T> & { readonly childCount: number; readonly hiddenCount: number }
628+
NestedSidebarThread<T> & {
629+
readonly childCount: number;
630+
readonly hiddenCount: number;
631+
readonly folded: boolean;
632+
}
622633
> = [];
623634
const visit = (index: number) => {
624635
const entry = nested[index]!;
625636
const end = subtreeEnd(index);
626637
const state = foldState(entry.thread);
627638
const visibleChildren: number[] = [];
628639
let hiddenCount = 0;
640+
let folded = false;
629641
for (let child = index + 1; child < end; child = subtreeEnd(child)) {
630642
const childEnd = subtreeEnd(child);
631643
const foldable = state === true || (state === undefined && isSubagent(nested[child]!.thread));
632644
const pinned = nested.slice(child, childEnd).some((branch) => keepVisible(branch.thread));
645+
folded ||= foldable;
633646
if (foldable && !pinned) hiddenCount += childEnd - child;
634647
else visibleChildren.push(child);
635648
}
636-
result.push({ ...entry, childCount: end - index - 1, hiddenCount });
649+
result.push({ ...entry, childCount: end - index - 1, hiddenCount, folded });
637650
for (const child of visibleChildren) visit(child);
638651
};
639652
for (let index = 0; index < nested.length; index = subtreeEnd(index)) visit(index);

0 commit comments

Comments
 (0)