@devries-cameron20 / t3code Mirror · read-only / commits / 9bfecb8f1e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 04:30 UTC

fix(web): deleted forks no longer remain in Lineage (#29000)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Albert Li <albertli_042@hotmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 5, 2026 at 07:01 UTC 9bfecb8f1e91892a5f87020203bde70694ab256e
16 files changed +246 -6
apps/server/src/auth/RpcAuthorization.ts
+1
@@ -51,6 +51,7 @@ export const RPC_REQUIRED_SCOPES = {
51 [ORCHESTRATION_V2_WS_METHODS.searchThreadStream]: AuthOrchestrationReadScope,
52 [ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: AuthOrchestrationReadScope,
53 [ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: AuthOrchestrationReadScope,
54 + [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: AuthOrchestrationReadScope,
55 [ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: AuthOrchestrationReadScope,
56 [ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: AuthOrchestrationReadScope,
57 [ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: AuthOrchestrationReadScope,
apps/server/src/observability/RpcInstrumentation.ts
+1
@@ -24,6 +24,7 @@ const RPC_AGGREGATES = {
24 [ORCHESTRATION_V2_WS_METHODS.searchThreadStream]: "orchestration",
25 [ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: "orchestration",
26 [ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: "orchestration",
27 + [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: "orchestration",
28 [ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: "orchestration",
29 [ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: "orchestration",
30 [ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: "orchestrationV2",
apps/server/src/orchestration-v2/Orchestrator.ts
+7
@@ -477,6 +477,10 @@ export interface OrchestratorV2Shape {
477 readonly findGuestShareThreadId: (
478 shareId: GuestShareId,
479 ) => 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>;
484 readonly getThreadEventSequence: (
485 threadId: ThreadId,
486 ) => Effect.Effect<number, OrchestratorV2Error>;
@@ -14244,6 +14248,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
14248 .findGuestShareThreadId(shareId)
14249 .pipe(Effect.mapError(shellProjectionError));
14250 }),
14251 + getThreadTitles: Effect.fn("OrchestratorV2.getThreadTitles")(function (threadIds) {
14252 + return projectionStore.getThreadTitles(threadIds).pipe(Effect.mapError(shellProjectionError));
14253 + }),
14254 getThreadEventSequence: Effect.fn("OrchestratorV2.getThreadEventSequence")(function (threadId) {
14255 return eventSink
14256 .latestSequence({ threadId })
apps/server/src/orchestration-v2/ProjectionStore.test.ts
+13 -2
@@ -1224,7 +1224,7 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {
1224 creationSource: "web" as const,
1225 id: threadId,
1226 projectId: ProjectId.make("project:worktree-paths"),
1227 - title: id,
1227 + title: `Title for ${id}`,
1228 providerInstanceId,
1229 modelSelection,
1230 runtimeMode: "full-access" as const,
@@ -1271,6 +1271,17 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {
1271 { threadId: ThreadId.make("thread:active"), worktreePath: "/worktrees/active" },
1272 { threadId: ThreadId.make("thread:archived"), worktreePath: "/worktrees/archived" },
1273 ]);
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 + );
1285 });
1286
1287 const commandReadsSkipSettledLeafNodes = Effect.gen(function* () {
@@ -2446,7 +2457,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
2457 () => runlessNativeSubagentNeedsRecovery,
2458 );
2459 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",
2461 () => threadWorktreePathsIncludeArchivedOnRequest,
2462 );
2463
apps/server/src/orchestration-v2/ProjectionStore.ts
+17
@@ -559,6 +559,10 @@ export interface ProjectionStoreV2Shape {
559 readonly getThreadsWithPullRequests: (
560 threadId?: ThreadId,
561 ) => 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>;
566 readonly getThreadWorktreePaths: (options?: {
567 readonly includeArchived?: boolean;
568 }) => Effect.Effect<
@@ -7232,6 +7236,18 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
7236 }));
7237 }, Effect.mapError(shellSnapshotReadError));
7238
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 +
7251 const findGuestShareThreadId = Effect.fn("ProjectionStore.findGuestShareThreadId")(function* (
7252 shareId: GuestShareId,
7253 ) {
@@ -7398,6 +7414,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
7414 getThread: readOnReader(getThread),
7415 getSettlementCandidates: readOnReader(getSettlementCandidates),
7416 getThreadsWithPullRequests: readOnReader(getThreadsWithPullRequests),
7417 + getThreadTitles: readOnReader(getThreadTitles),
7418 getThreadWorktreePaths: readOnReader(getThreadWorktreePaths),
7419 getOpenRemoteDelegatedTasks: getOpenRemoteDelegatedTasks.pipe(NodeSqliteClient.readOnly),
7420 getThreadProjection: readOnReader(getThreadProjection),
apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
+1
@@ -220,6 +220,7 @@ it.effect(
220 listOlderSettledThreads: () => Effect.die("unused listOlderSettledThreads"),
221 readShellSnapshot: () => Effect.die("unused readShellSnapshot"),
222 getThreadShell: () => Effect.die("unused getThreadShell"),
223 + getThreadTitles: () => Effect.die("unused getThreadTitles"),
224 findGuestShareThreadId: () => Effect.die("unused findGuestShareThreadId"),
225 getThread: () => Ref.get(projection).pipe(Effect.map((state) => state.thread)),
226 getSettlementCandidates: () => Effect.die("unused getSettlementCandidates"),
apps/server/src/orchestration-v2/ThreadManagementService.ts
+2
@@ -421,6 +421,7 @@ export interface ThreadManagementServiceShape {
421 >;
422 readonly getThreadShell: Orchestrator.OrchestratorV2["Service"]["getThreadShell"];
423 readonly listAppOwnedChildThreadIds: Orchestrator.OrchestratorV2["Service"]["listAppOwnedChildThreadIds"];
424 + readonly getThreadTitles: Orchestrator.OrchestratorV2["Service"]["getThreadTitles"];
425 /** Omit `projectId` to list every project's threads. Side chats are never listed. */
426 readonly listProjectThreads: (input: {
427 readonly projectId?: ProjectId | undefined;
@@ -1536,6 +1537,7 @@ const make = Effect.gen(function* () {
1537 );
1538 },
1539 ),
1540 + getThreadTitles: orchestrator.getThreadTitles,
1541 listProjectThreads,
1542 sendToThread,
1543 assertProviderInstanceEnabled,
apps/server/src/relay/AgentAwarenessRelay.test.ts
+1
@@ -203,6 +203,7 @@ const makeTestRelay = Effect.fnUntraced(function* (
203 listActiveShellIndex: () => Effect.succeed([]),
204 listOlderSettledThreads: unused,
205 readShellSnapshot: unused,
206 + getThreadTitles: unused,
207 ensureLegacyTranscript: unused,
208 dispatch: unused,
209 searchThread: () => Effect.die("unused"),
apps/server/src/ws.ts
+10
@@ -2123,6 +2123,16 @@ export const layerWsRpc = (
2123 getOrchestrationV2ArchivedShellSnapshot,
2124 [ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: (input) =>
2125 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 + ),
2136 [ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: (input) =>
2137 loadOlderSettledThreadsPage({
2138 sql,
apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx
+49 -1
@@ -9,6 +9,16 @@ const state = vi.hoisted(() => ({
9 projection: null as unknown,
10 commandSucceeds: false,
11 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,
22 }));
23
24 vi.mock(import("@effect/atom-react"), async (original) => ({
@@ -33,7 +43,9 @@ vi.mock(import("../../state/environments"), () => ({
43 useEnvironmentProviders: (() => new Map()) as never,
44 }));
45 vi.mock(import("../../lib/archivedThreadsState"), () => ({
36 - useArchivedThreadSnapshots: (() => ({ snapshots: [] })) as never,
46 + useArchivedThreadSnapshots: (() => ({
47 + snapshots: [{ environmentId: "environment", snapshot: { threads: state.archivedThreads } }],
48 + })) as never,
49 }));
50 vi.mock(import("../../state/use-atom-command"), () => ({
51 useAtomCommand: (() => async () =>
@@ -53,6 +65,8 @@ const threadId = ThreadId.make("fork");
65 function setup() {
66 state.commandSucceeds = false;
67 state.relatedShells = [];
68 + state.threadTitles = { source: "Source" };
69 + state.archivedThreads = [];
70 state.projection = {
71 thread: {
72 id: threadId,
@@ -345,3 +359,37 @@ it("shows a delegated-from thread's full title in its tooltip even when its envi
359 await row.click({ force: true });
360 expect(screen.router?.state.location.pathname).toBe("/environment/fork");
361 });
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 +});
apps/web/src/components/chat/ThreadRelationshipsControl.tsx
+35 -2
@@ -77,6 +77,7 @@ import {
77 import { threadEnvironment } from "../../state/threads";
78 import { orchestrationEnvironment } from "../../state/orchestration";
79 import { useAtomCommand } from "../../state/use-atom-command";
80 +import { useEnvironmentQuery } from "../../state/query";
81 import { AgentElapsed } from "./AgentElapsed";
82 import { ThreadRelationshipIcon, threadRelationshipStatusLabel } from "./ThreadRelationshipIcon";
83 import { ThreadLineageWorkflowRow } from "./ThreadLineageWorkflowRow";
@@ -499,6 +500,31 @@ export function ThreadRelationshipsPanel(props: {
500 : { ...row, edge: { ...row.edge, status: workflowGroup.workflow.status } };
501 });
502 const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;
503 + const unlistedThreadIds = relationshipRows
504 + .filter(
505 + ({ threadId, edge }) =>
506 + !relationshipShells.some((thread) => thread.id === threadId) &&
507 + (edge.kind !== "subagent" || !subagentsByThreadId.get(threadId)?.title),
508 + )
509 + .map(({ threadId }) => threadId);
510 + const threadTitles = useEnvironmentQuery(
511 + unlistedThreadIds.length === 0
512 + ? null
513 + : orchestrationEnvironment.threadTitles({
514 + environmentId: props.environmentId,
515 + input: { threadIds: unlistedThreadIds },
516 + }),
517 + );
518 + const resolvedThreadTitles = threadTitles.data ?? {};
519 + // Omitted and archived threads remain reachable; only a settled lookup proves one is gone.
520 + const visibleRelationships = relationshipRows.filter(
521 + ({ threadId, edge }) =>
522 + edge.kind === "subagent" ||
523 + !unlistedThreadIds.includes(threadId) ||
524 + !threadTitles.isSuccess ||
525 + threadTitles.isPending ||
526 + Object.hasOwn(resolvedThreadTitles, threadId),
527 + );
528 const canDetach = projection ? canDetachThreadProviderSession(projection) : false;
529
530 const {
@@ -506,7 +532,7 @@ export function ThreadRelationshipsPanel(props: {
532 active = [],
533 previous = [],
534 sideChats = [],
509 - } = groupBy(relationshipRows, ({ threadId, edge }) => {
535 + } = groupBy(visibleRelationships, ({ threadId, edge }) => {
536 const isParent = isParentThreadRelationship(edge, props.threadId);
537 if (!isParent && graph.nodes.get(threadId)?.thread?.lineage.sideChat === true)
538 return "sideChats";
@@ -681,7 +707,14 @@ export function ThreadRelationshipsPanel(props: {
707 ["pending", "running", "waiting"].includes(agent.status);
708 const threadTitle = relationshipThreadTitle({
709 title:
684 - workflowGroup?.workflow.workflowName ?? node?.thread?.title ?? agent?.title ?? threadId,
710 + workflowGroup?.workflow.workflowName ??
711 + // Fresher than an archived snapshot's copy.
712 + (Object.hasOwn(resolvedThreadTitles, threadId)
713 + ? resolvedThreadTitles[threadId]
714 + : undefined) ??
715 + node?.thread?.title ??
716 + agent?.title ??
717 + threadId,
718 isSubagent,
719 });
720 const provider = providers?.find(
apps/web/src/state/orchestration.ts
+4 -1
@@ -1,5 +1,8 @@
1 import { createOrchestrationEnvironmentAtoms } from "@t3tools/client-runtime/state/orchestration";
2
3 import { connectionAtomRuntime } from "../connection/runtime";
4 +import { environmentShell } from "./shell";
5
5 -export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime);
6 +export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime, {
7 + shellState: environmentShell.stateValueAtom,
8 +});
packages/client-runtime/src/state/orchestration.ts
+23
@@ -1,5 +1,6 @@
1 import {
2 ORCHESTRATION_V2_WS_METHODS,
3 + type EnvironmentId,
4 type ThreadId,
5 type OrchestrationGetTurnDiffResult,
6 } from "@t3tools/contracts";
@@ -24,11 +25,16 @@ import * as EnvironmentSupervisor from "../connection/supervisor.ts";
25 import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";
26 import * as ManagedRelayDpopSigner from "../relay/managedRelay.ts";
27 import { EnvironmentRpcUnavailableError } from "../rpc/client.ts";
28 +import type { EnvironmentShellState } from "./shell.ts";
29 import { fetchEnvironmentThreadTranscript } from "./threadTranscriptHttp.ts";
30
31 export function createOrchestrationEnvironmentAtoms<R, E>(
32 runtime: Atom.AtomRuntime<EnvironmentRegistry | HttpClient.HttpClient | R, E>,
33 options: {
34 + /** Re-checks `threadTitles` when one of their threads leaves the shell. */
35 + readonly shellState?: (
36 + environmentId: EnvironmentId,
37 + ) => Atom.Atom<Pick<EnvironmentShellState, "removedAt">>;
38 /** Runs on each turn-range and full-thread diff the server answers. */
39 readonly onCheckpointDiffAnswer?: QueryAnswerHandler<
40 { readonly ignoreWhitespace?: boolean },
@@ -40,7 +46,24 @@ export function createOrchestrationEnvironmentAtoms<R, E>(
46 options.onCheckpointDiffAnswer === undefined
47 ? {}
48 : { onAnswer: options.onCheckpointDiffAnswer };
49 + const shellState = options.shellState;
50 return {
51 + threadTitles: createEnvironmentRpcQueryAtomFamily(runtime, {
52 + label: "environment-data:orchestration:thread-titles",
53 + tag: ORCHESTRATION_V2_WS_METHODS.getThreadTitles,
54 + staleTimeMs: 0,
55 + idleTtlMs: 0,
56 + // Deleting a thread the shell already left out keeps these ids, so the query would not rerun.
57 + // A removal can also be an archive, so it only prompts a re-check.
58 + refreshTrigger: ({ environmentId, input }) => {
59 + if (shellState === undefined) return undefined;
60 + const state = shellState(environmentId);
61 + return Atom.make((get) => {
62 + const { removedAt } = get(state);
63 + return Math.max(-1, ...input.threadIds.map((threadId) => removedAt.get(threadId) ?? -1));
64 + });
65 + },
66 + }),
67 threadTranscript: createEnvironmentCommand(runtime, {
68 label: "environment-data:orchestration:thread-transcript",
69 execute: Effect.fn("orchestration.execute")(function* (input: {
packages/client-runtime/src/state/runtime.test.ts
+63
@@ -1,6 +1,8 @@
1 import { describe, expect, it } from "@effect/vitest";
2 import {
3 EnvironmentId,
4 + ORCHESTRATION_V2_WS_METHODS,
5 + ThreadId,
6 type ReviewDiffPreviewInput,
7 type PreviewEvent,
8 type TerminalAttachInput,
@@ -21,6 +23,7 @@ import * as Queue from "effect/Queue";
23 import * as Schema from "effect/Schema";
24 import * as Stream from "effect/Stream";
25 import * as SubscriptionRef from "effect/SubscriptionRef";
26 +import type { HttpClient } from "effect/http";
27 import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
28
29 import {
@@ -35,9 +38,11 @@ import * as EnvironmentRegistry from "../connection/registry.ts";
38 import * as EnvironmentSupervisor from "../connection/supervisor.ts";
39 import { EnvironmentRpcUnavailableError } from "../rpc/client.ts";
40 import type * as RpcSession from "../rpc/session.ts";
41 +import { createOrchestrationEnvironmentAtoms } from "./orchestration.ts";
42 import { createReviewEnvironmentAtoms } from "./review.ts";
43 import { createPreviewEnvironmentAtoms } from "./preview.ts";
44 import type { QueryPersistence } from "./queryPersistence.ts";
45 +import type { EnvironmentShellState } from "./shell.ts";
46 import { createTerminalEnvironmentAtoms } from "./terminal.ts";
47 import {
48 createAtomCommandScheduler,
@@ -1017,6 +1022,64 @@ describe("environment query lifecycle", () => {
1022 }),
1023 ),
1024 );
1025 +
1026 + it.effect("re-checks thread titles when one of their threads leaves the shell", () =>
1027 + Effect.scoped(
1028 + Effect.gen(function* () {
1029 + const requests = yield* Queue.unbounded<Deferred.Deferred<Record<string, string>>>();
1030 + const harness = yield* makeEnvironmentQueryHarness(Effect.void, {
1031 + rpcSession: {
1032 + client: {
1033 + [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: () =>
1034 + Effect.gen(function* () {
1035 + const answer = yield* Deferred.make<Record<string, string>>();
1036 + yield* Queue.offer(requests, answer);
1037 + return yield* Deferred.await(answer);
1038 + }),
1039 + },
1040 + } as unknown as RpcSession.RpcSession,
1041 + });
1042 + const shellState = Atom.make<Pick<EnvironmentShellState, "removedAt">>({
1043 + removedAt: new Map(),
1044 + }).pipe(Atom.keepAlive);
1045 + const removed = (entries: ReadonlyArray<readonly [string, number]>) => ({
1046 + removedAt: new Map(entries.map(([id, sequence]) => [ThreadId.make(id), sequence])),
1047 + });
1048 + // Thread titles never use the HTTP client.
1049 + const runtime = harness.runtime as unknown as Atom.AtomRuntime<
1050 + EnvironmentRegistry.EnvironmentRegistry | HttpClient.HttpClient
1051 + >;
1052 + const atom = createOrchestrationEnvironmentAtoms(runtime, {
1053 + shellState: () => shellState,
1054 + }).threadTitles({
1055 + environmentId: QUERY_ENVIRONMENT.environmentId,
1056 + input: { threadIds: [ThreadId.make("fork")] },
1057 + });
1058 + const registry = yield* mountEnvironmentQuery(atom);
1059 + const settled: Array<Record<string, string>> = [];
1060 + const unsubscribe = registry.subscribe(atom, (result) => {
1061 + if (AsyncResult.isSuccess(result) && !result.waiting) settled.push(result.value);
1062 + });
1063 + yield* Effect.addFinalizer(() => Effect.sync(unsubscribe));
1064 +
1065 + yield* Deferred.succeed(yield* Queue.take(requests), { fork: "Fork" });
1066 + expect(yield* readEnvironmentQuery(registry, atom)).toEqual({ fork: "Fork" });
1067 +
1068 + registry.set(shellState, removed([["other", 5]]));
1069 + expect(registry.get(atom).waiting).toBe(false);
1070 +
1071 + // Archiving and then deleting the fork both remove it from the shell.
1072 + registry.set(shellState, removed([["fork", 6]]));
1073 + const beforeDelete = yield* Queue.take(requests);
1074 + registry.set(shellState, removed([["fork", 7]]));
1075 + const afterDelete = yield* Queue.take(requests);
1076 + yield* Deferred.succeed(beforeDelete, { fork: "Fork" });
1077 + yield* Deferred.succeed(afterDelete, {});
1078 + expect(yield* readEnvironmentQuery(registry, atom)).toEqual({});
1079 + expect(settled).toEqual([{ fork: "Fork" }, {}]);
1080 + }),
1081 + ),
1082 + );
1083 });
1084
1085 describe("executeAtomQuery", () => {
packages/contracts/src/orchestrationV2.ts
+12
@@ -3580,6 +3580,7 @@ export const ORCHESTRATION_V2_WS_METHODS = {
3580 searchThreadStream: "orchestration.searchThreadStream",
3581 getArchivedShellSnapshot: "orchestration.getArchivedShellSnapshot",
3582 getThreadFamily: "orchestration.getThreadFamily",
3583 + getThreadTitles: "orchestration.getThreadTitles",
3584 getWorktreeThreadIds: "orchestration.getWorktreeThreadIds",
3585 getOlderSettledThreads: "orchestration.getOlderSettledThreads",
3586 getThreadProjection: "orchestration.getThreadProjection",
@@ -3704,6 +3705,13 @@ export const OrchestrationV2ThreadFamily = Schema.Struct({
3705 });
3706 export type OrchestrationV2ThreadFamily = typeof OrchestrationV2ThreadFamily.Type;
3707
3708 +export const OrchestrationV2GetThreadTitlesInput = Schema.Struct({
3709 + threadIds: Schema.Array(ThreadId),
3710 +});
3711 +
3712 +/** Titles of the requested threads that exist, archived ones included. Deleted and unknown ids are absent. */
3713 +export const OrchestrationV2ThreadTitles = Schema.Record(ThreadId, Schema.String);
3714 +
3715 export const OrchestrationV2GetWorktreeThreadIdsInput = Schema.Struct({
3716 worktreePath: TrimmedNonEmptyString,
3717 });
@@ -4226,6 +4234,10 @@ export const OrchestrationV2RpcSchemas = {
4234 input: OrchestrationV2GetThreadFamilyInput,
4235 output: OrchestrationV2ThreadFamily,
4236 },
4237 + getThreadTitles: {
4238 + input: OrchestrationV2GetThreadTitlesInput,
4239 + output: OrchestrationV2ThreadTitles,
4240 + },
4241 getWorktreeThreadIds: {
4242 input: OrchestrationV2GetWorktreeThreadIdsInput,
4243 output: OrchestrationV2WorktreeThreadIds,
packages/contracts/src/rpc.ts
+7
@@ -1777,6 +1777,12 @@ const WsOrchestrationV2GetThreadFamilyRpc = Rpc.make(ORCHESTRATION_V2_WS_METHODS
1777 error: Schema.Union([OrchestrationV2GetShellSnapshotError, EnvironmentAuthorizationError]),
1778 });
1779
1780 +const WsOrchestrationV2GetThreadTitlesRpc = Rpc.make(ORCHESTRATION_V2_WS_METHODS.getThreadTitles, {
1781 + payload: OrchestrationV2RpcSchemas.getThreadTitles.input,
1782 + success: OrchestrationV2RpcSchemas.getThreadTitles.output,
1783 + error: Schema.Union([OrchestrationV2GetShellSnapshotError, EnvironmentAuthorizationError]),
1784 +});
1785 +
1786 const WsOrchestrationV2GetWorktreeThreadIdsRpc = Rpc.make(
1787 ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds,
1788 {
@@ -2191,6 +2197,7 @@ export const WsRpcGroup = RpcGroup.make(
2197 WsOrchestrationV2SearchThreadStreamRpc,
2198 WsOrchestrationV2GetArchivedShellSnapshotRpc,
2199 WsOrchestrationV2GetThreadFamilyRpc,
2200 + WsOrchestrationV2GetThreadTitlesRpc,
2201 WsOrchestrationV2GetWorktreeThreadIdsRpc,
2202 WsOrchestrationV2GetOlderSettledThreadsRpc,
2203 WsOrchestrationV2GetThreadProjectionRpc,