Skip to content

Commit 9bfecb8

Browse files
shivamhwpPR Batch TesterAlb11747claude
authored
fix(web): deleted forks no longer remain in Lineage (pingdotgg#29000)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Albert Li <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent c15e49a commit 9bfecb8

16 files changed

Lines changed: 246 additions & 6 deletions

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const RPC_REQUIRED_SCOPES = {
5151
[ORCHESTRATION_V2_WS_METHODS.searchThreadStream]: AuthOrchestrationReadScope,
5252
[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: AuthOrchestrationReadScope,
5353
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: AuthOrchestrationReadScope,
54+
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: AuthOrchestrationReadScope,
5455
[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: AuthOrchestrationReadScope,
5556
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: AuthOrchestrationReadScope,
5657
[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: AuthOrchestrationReadScope,

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const RPC_AGGREGATES = {
2424
[ORCHESTRATION_V2_WS_METHODS.searchThreadStream]: "orchestration",
2525
[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: "orchestration",
2626
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: "orchestration",
27+
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: "orchestration",
2728
[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: "orchestration",
2829
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: "orchestration",
2930
[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: "orchestrationV2",

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ export interface OrchestratorV2Shape {
477477
readonly findGuestShareThreadId: (
478478
shareId: GuestShareId,
479479
) => Effect.Effect<ThreadId | null, OrchestratorV2Error>;
480+
/** Titles of the given threads that exist, archived ones included. */
481+
readonly getThreadTitles: (
482+
threadIds: ReadonlyArray<ThreadId>,
483+
) => Effect.Effect<Record<ThreadId, string>, OrchestratorV2Error>;
480484
readonly getThreadEventSequence: (
481485
threadId: ThreadId,
482486
) => Effect.Effect<number, OrchestratorV2Error>;
@@ -14244,6 +14248,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1424414248
.findGuestShareThreadId(shareId)
1424514249
.pipe(Effect.mapError(shellProjectionError));
1424614250
}),
14251+
getThreadTitles: Effect.fn("OrchestratorV2.getThreadTitles")(function (threadIds) {
14252+
return projectionStore.getThreadTitles(threadIds).pipe(Effect.mapError(shellProjectionError));
14253+
}),
1424714254
getThreadEventSequence: Effect.fn("OrchestratorV2.getThreadEventSequence")(function (threadId) {
1424814255
return eventSink
1424914256
.latestSequence({ threadId })

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {
12241224
creationSource: "web" as const,
12251225
id: threadId,
12261226
projectId: ProjectId.make("project:worktree-paths"),
1227-
title: id,
1227+
title: `Title for ${id}`,
12281228
providerInstanceId,
12291229
modelSelection,
12301230
runtimeMode: "full-access" as const,
@@ -1271,6 +1271,17 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {
12711271
{ threadId: ThreadId.make("thread:active"), worktreePath: "/worktrees/active" },
12721272
{ threadId: ThreadId.make("thread:archived"), worktreePath: "/worktrees/archived" },
12731273
]);
1274+
assert.deepEqual(
1275+
yield* store.getThreadTitles([
1276+
deleted.id,
1277+
ThreadId.make("thread:active"),
1278+
ThreadId.make("thread:archived"),
1279+
]),
1280+
{
1281+
[ThreadId.make("thread:active")]: "Title for thread:active",
1282+
[ThreadId.make("thread:archived")]: "Title for thread:archived",
1283+
},
1284+
);
12741285
});
12751286

12761287
const commandReadsSkipSettledLeafNodes = Effect.gen(function* () {
@@ -2446,7 +2457,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
24462457
() => runlessNativeSubagentNeedsRecovery,
24472458
);
24482459
it.effect(
2449-
"worktree path lookup defaults to active threads and can include archived threads",
2460+
"worktree path and title lookups skip deleted threads, and can include archived ones",
24502461
() => threadWorktreePathsIncludeArchivedOnRequest,
24512462
);
24522463

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ export interface ProjectionStoreV2Shape {
559559
readonly getThreadsWithPullRequests: (
560560
threadId?: ThreadId,
561561
) => Effect.Effect<ReadonlyArray<ProjectionThreadPullRequests>, ProjectionStoreV2Error>;
562+
/** Titles of the given threads that exist, archived ones included. */
563+
readonly getThreadTitles: (
564+
threadIds: ReadonlyArray<ThreadId>,
565+
) => Effect.Effect<Record<ThreadId, string>, ProjectionStoreV2Error>;
562566
readonly getThreadWorktreePaths: (options?: {
563567
readonly includeArchived?: boolean;
564568
}) => Effect.Effect<
@@ -7232,6 +7236,18 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
72327236
}));
72337237
}, Effect.mapError(shellSnapshotReadError));
72347238

7239+
const getThreadTitles = Effect.fn("ProjectionStore.getThreadTitles")(function* (
7240+
threadIds: ReadonlyArray<ThreadId>,
7241+
) {
7242+
if (threadIds.length === 0) return {};
7243+
const rows = yield* sql<{ readonly thread_id: ThreadId; readonly title: string }>`
7244+
SELECT thread_id, title
7245+
FROM orchestration_v2_projection_threads
7246+
WHERE deleted_at IS NULL AND thread_id IN ${sql.in(threadIds)}
7247+
`;
7248+
return Object.fromEntries(rows.map((row) => [row.thread_id, row.title]));
7249+
}, Effect.mapError(shellSnapshotReadError));
7250+
72357251
const findGuestShareThreadId = Effect.fn("ProjectionStore.findGuestShareThreadId")(function* (
72367252
shareId: GuestShareId,
72377253
) {
@@ -7398,6 +7414,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
73987414
getThread: readOnReader(getThread),
73997415
getSettlementCandidates: readOnReader(getSettlementCandidates),
74007416
getThreadsWithPullRequests: readOnReader(getThreadsWithPullRequests),
7417+
getThreadTitles: readOnReader(getThreadTitles),
74017418
getThreadWorktreePaths: readOnReader(getThreadWorktreePaths),
74027419
getOpenRemoteDelegatedTasks: getOpenRemoteDelegatedTasks.pipe(NodeSqliteClient.readOnly),
74037420
getThreadProjection: readOnReader(getThreadProjection),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ it.effect(
220220
listOlderSettledThreads: () => Effect.die("unused listOlderSettledThreads"),
221221
readShellSnapshot: () => Effect.die("unused readShellSnapshot"),
222222
getThreadShell: () => Effect.die("unused getThreadShell"),
223+
getThreadTitles: () => Effect.die("unused getThreadTitles"),
223224
findGuestShareThreadId: () => Effect.die("unused findGuestShareThreadId"),
224225
getThread: () => Ref.get(projection).pipe(Effect.map((state) => state.thread)),
225226
getSettlementCandidates: () => Effect.die("unused getSettlementCandidates"),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ export interface ThreadManagementServiceShape {
421421
>;
422422
readonly getThreadShell: Orchestrator.OrchestratorV2["Service"]["getThreadShell"];
423423
readonly listAppOwnedChildThreadIds: Orchestrator.OrchestratorV2["Service"]["listAppOwnedChildThreadIds"];
424+
readonly getThreadTitles: Orchestrator.OrchestratorV2["Service"]["getThreadTitles"];
424425
/** Omit `projectId` to list every project's threads. Side chats are never listed. */
425426
readonly listProjectThreads: (input: {
426427
readonly projectId?: ProjectId | undefined;
@@ -1536,6 +1537,7 @@ const make = Effect.gen(function* () {
15361537
);
15371538
},
15381539
),
1540+
getThreadTitles: orchestrator.getThreadTitles,
15391541
listProjectThreads,
15401542
sendToThread,
15411543
assertProviderInstanceEnabled,

‎apps/server/src/relay/AgentAwarenessRelay.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ const makeTestRelay = Effect.fnUntraced(function* (
203203
listActiveShellIndex: () => Effect.succeed([]),
204204
listOlderSettledThreads: unused,
205205
readShellSnapshot: unused,
206+
getThreadTitles: unused,
206207
ensureLegacyTranscript: unused,
207208
dispatch: unused,
208209
searchThread: () => Effect.die("unused"),

‎apps/server/src/ws.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,16 @@ export const layerWsRpc = (
21232123
getOrchestrationV2ArchivedShellSnapshot,
21242124
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: (input) =>
21252125
readOmittableShellRows({ familyOf: input.threadId }, "Failed to load the thread family"),
2126+
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: (input) =>
2127+
threadManagement.getThreadTitles(input.threadIds).pipe(
2128+
Effect.mapError(
2129+
(cause) =>
2130+
new OrchestrationV2GetShellSnapshotError({
2131+
message: "Failed to load thread titles",
2132+
cause,
2133+
}),
2134+
),
2135+
),
21262136
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: (input) =>
21272137
loadOlderSettledThreadsPage({
21282138
sql,

‎apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ const state = vi.hoisted(() => ({
99
projection: null as unknown,
1010
commandSucceeds: false,
1111
relatedShells: [] as unknown[],
12+
threadTitles: {} as Record<string, string>,
13+
archivedThreads: [] as unknown[],
14+
}));
15+
16+
vi.mock(import("../../state/query"), async (original) => ({
17+
...(await original()),
18+
useEnvironmentQuery: ((atom: unknown) =>
19+
atom === null
20+
? { data: null, isSuccess: false, isPending: false }
21+
: { data: state.threadTitles, isSuccess: true, isPending: false }) as never,
1222
}));
1323

1424
vi.mock(import("@effect/atom-react"), async (original) => ({
@@ -33,7 +43,9 @@ vi.mock(import("../../state/environments"), () => ({
3343
useEnvironmentProviders: (() => new Map()) as never,
3444
}));
3545
vi.mock(import("../../lib/archivedThreadsState"), () => ({
36-
useArchivedThreadSnapshots: (() => ({ snapshots: [] })) as never,
46+
useArchivedThreadSnapshots: (() => ({
47+
snapshots: [{ environmentId: "environment", snapshot: { threads: state.archivedThreads } }],
48+
})) as never,
3749
}));
3850
vi.mock(import("../../state/use-atom-command"), () => ({
3951
useAtomCommand: (() => async () =>
@@ -53,6 +65,8 @@ const threadId = ThreadId.make("fork");
5365
function setup() {
5466
state.commandSucceeds = false;
5567
state.relatedShells = [];
68+
state.threadTitles = { source: "Source" };
69+
state.archivedThreads = [];
5670
state.projection = {
5771
thread: {
5872
id: threadId,
@@ -345,3 +359,37 @@ it("shows a delegated-from thread's full title in its tooltip even when its envi
345359
await row.click({ force: true });
346360
expect(screen.router?.state.location.pathname).toBe("/environment/fork");
347361
});
362+
363+
it("hides a deleted fork and keeps unloaded and archived forks with their current titles", async () => {
364+
setup();
365+
const projection = makeThreadProjectionFixture();
366+
state.threadTitles = { "unloaded-fork": "Unloaded fork", "archived-fork": "Archived fork" };
367+
state.archivedThreads = [
368+
{
369+
...projection.thread,
370+
id: ThreadId.make("archived-fork"),
371+
title: "Old archived title",
372+
archivedAt: projection.thread.updatedAt,
373+
lineage: { parentThreadId: projection.thread.id, relationshipToParent: "fork" },
374+
},
375+
];
376+
state.projection = {
377+
...projection,
378+
contextTransfers: ["deleted-fork", "unloaded-fork", "archived-fork"].map((id) => ({
379+
sourceThreadId: projection.thread.id,
380+
targetThreadId: ThreadId.make(id),
381+
status: "pending",
382+
})),
383+
};
384+
await using screen = await render(
385+
<ThreadRelationshipsPanel
386+
environmentId={environmentId}
387+
threadId={projection.thread.id}
388+
showLineage
389+
showSideChats
390+
/>,
391+
);
392+
await expect.element(screen.getByText("Unloaded fork", { exact: true })).toBeVisible();
393+
await expect.element(screen.getByText("Archived fork", { exact: true })).toBeVisible();
394+
await expect.element(screen.getByText("deleted-fork", { exact: true })).not.toBeInTheDocument();
395+
});

0 commit comments

Comments
 (0)