TypeScript
fix(web): deleted forks no longer remain in Lineage (#29000)
shivam9bfecb8f1e91
diff --git a/apps/server/src/auth/RpcAuthorization.ts b/apps/server/src/auth/RpcAuthorization.tsindex f040dbc4594..3ba7af66de9 100644--- a/apps/server/src/auth/RpcAuthorization.ts+++ b/apps/server/src/auth/RpcAuthorization.ts@@ -51,6 +51,7 @@ export const RPC_REQUIRED_SCOPES = {[ORCHESTRATION_V2_WS_METHODS.searchThreadStream]: AuthOrchestrationReadScope,[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: AuthOrchestrationReadScope,[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: AuthOrchestrationReadScope,+ [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: AuthOrchestrationReadScope,[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: AuthOrchestrationReadScope,[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: AuthOrchestrationReadScope,[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: AuthOrchestrationReadScope,diff --git a/apps/server/src/observability/RpcInstrumentation.ts b/apps/server/src/observability/RpcInstrumentation.tsindex 17940b83717..89f93a9df2c 100644--- a/apps/server/src/observability/RpcInstrumentation.ts+++ b/apps/server/src/observability/RpcInstrumentation.ts@@ -24,6 +24,7 @@ const RPC_AGGREGATES = {[ORCHESTRATION_V2_WS_METHODS.searchThreadStream]: "orchestration",[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: "orchestration",[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: "orchestration",+ [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: "orchestration",[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: "orchestration",[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: "orchestration",[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: "orchestrationV2",diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.tsindex b4bdbd705c2..8ecd98c1c20 100644--- a/apps/server/src/orchestration-v2/Orchestrator.ts+++ b/apps/server/src/orchestration-v2/Orchestrator.ts@@ -477,6 +477,10 @@ export interface OrchestratorV2Shape {readonly findGuestShareThreadId: (shareId: GuestShareId,) => Effect.Effect<ThreadId | null, OrchestratorV2Error>;+ /** Titles of the given threads that exist, archived ones included. */+ readonly getThreadTitles: (+ threadIds: ReadonlyArray<ThreadId>,+ ) => Effect.Effect<Record<ThreadId, string>, OrchestratorV2Error>;readonly getThreadEventSequence: (threadId: ThreadId,) => Effect.Effect<number, OrchestratorV2Error>;@@ -14244,6 +14248,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio.findGuestShareThreadId(shareId).pipe(Effect.mapError(shellProjectionError));}),+ getThreadTitles: Effect.fn("OrchestratorV2.getThreadTitles")(function (threadIds) {+ return projectionStore.getThreadTitles(threadIds).pipe(Effect.mapError(shellProjectionError));+ }),getThreadEventSequence: Effect.fn("OrchestratorV2.getThreadEventSequence")(function (threadId) {return eventSink.latestSequence({ threadId })diff --git a/apps/server/src/orchestration-v2/ProjectionStore.test.ts b/apps/server/src/orchestration-v2/ProjectionStore.test.tsindex 8e315794ca6..c1772916022 100644--- a/apps/server/src/orchestration-v2/ProjectionStore.test.ts+++ b/apps/server/src/orchestration-v2/ProjectionStore.test.ts@@ -1224,7 +1224,7 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {creationSource: "web" as const,id: threadId,projectId: ProjectId.make("project:worktree-paths"),- title: id,+ title: `Title for ${id}`,providerInstanceId,modelSelection,runtimeMode: "full-access" as const,@@ -1271,6 +1271,17 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {{ threadId: ThreadId.make("thread:active"), worktreePath: "/worktrees/active" },{ threadId: ThreadId.make("thread:archived"), worktreePath: "/worktrees/archived" },]);+ assert.deepEqual(+ yield* store.getThreadTitles([+ deleted.id,+ ThreadId.make("thread:active"),+ ThreadId.make("thread:archived"),+ ]),+ {+ [ThreadId.make("thread:active")]: "Title for thread:active",+ [ThreadId.make("thread:archived")]: "Title for thread:archived",+ },+ );});const commandReadsSkipSettledLeafNodes = Effect.gen(function* () {@@ -2446,7 +2457,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {() => runlessNativeSubagentNeedsRecovery,);it.effect(- "worktree path lookup defaults to active threads and can include archived threads",+ "worktree path and title lookups skip deleted threads, and can include archived ones",() => threadWorktreePathsIncludeArchivedOnRequest,);diff --git a/apps/server/src/orchestration-v2/ProjectionStore.ts b/apps/server/src/orchestration-v2/ProjectionStore.tsindex 03d8152b8bf..bd6a61db903 100644--- a/apps/server/src/orchestration-v2/ProjectionStore.ts+++ b/apps/server/src/orchestration-v2/ProjectionStore.ts@@ -559,6 +559,10 @@ export interface ProjectionStoreV2Shape {readonly getThreadsWithPullRequests: (threadId?: ThreadId,) => Effect.Effect<ReadonlyArray<ProjectionThreadPullRequests>, ProjectionStoreV2Error>;+ /** Titles of the given threads that exist, archived ones included. */+ readonly getThreadTitles: (+ threadIds: ReadonlyArray<ThreadId>,+ ) => Effect.Effect<Record<ThreadId, string>, ProjectionStoreV2Error>;readonly getThreadWorktreePaths: (options?: {readonly includeArchived?: boolean;}) => Effect.Effect<@@ -7232,6 +7236,18 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =}));}, Effect.mapError(shellSnapshotReadError));+ const getThreadTitles = Effect.fn("ProjectionStore.getThreadTitles")(function* (+ threadIds: ReadonlyArray<ThreadId>,+ ) {+ if (threadIds.length === 0) return {};+ const rows = yield* sql<{ readonly thread_id: ThreadId; readonly title: string }>`+ SELECT thread_id, title+ FROM orchestration_v2_projection_threads+ WHERE deleted_at IS NULL AND thread_id IN ${sql.in(threadIds)}+ `;+ return Object.fromEntries(rows.map((row) => [row.thread_id, row.title]));+ }, Effect.mapError(shellSnapshotReadError));+const findGuestShareThreadId = Effect.fn("ProjectionStore.findGuestShareThreadId")(function* (shareId: GuestShareId,) {@@ -7398,6 +7414,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =getThread: readOnReader(getThread),getSettlementCandidates: readOnReader(getSettlementCandidates),getThreadsWithPullRequests: readOnReader(getThreadsWithPullRequests),+ getThreadTitles: readOnReader(getThreadTitles),getThreadWorktreePaths: readOnReader(getThreadWorktreePaths),getOpenRemoteDelegatedTasks: getOpenRemoteDelegatedTasks.pipe(NodeSqliteClient.readOnly),getThreadProjection: readOnReader(getThreadProjection),diff --git a/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnControlService.test.tsindex ad5341dd99e..55e2a9e50e3 100644--- a/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts+++ b/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts@@ -220,6 +220,7 @@ it.effect(listOlderSettledThreads: () => Effect.die("unused listOlderSettledThreads"),readShellSnapshot: () => Effect.die("unused readShellSnapshot"),getThreadShell: () => Effect.die("unused getThreadShell"),+ getThreadTitles: () => Effect.die("unused getThreadTitles"),findGuestShareThreadId: () => Effect.die("unused findGuestShareThreadId"),getThread: () => Ref.get(projection).pipe(Effect.map((state) => state.thread)),getSettlementCandidates: () => Effect.die("unused getSettlementCandidates"),diff --git a/apps/server/src/orchestration-v2/ThreadManagementService.ts b/apps/server/src/orchestration-v2/ThreadManagementService.tsindex ed2935fedbf..7aff0137562 100644--- a/apps/server/src/orchestration-v2/ThreadManagementService.ts+++ b/apps/server/src/orchestration-v2/ThreadManagementService.ts@@ -421,6 +421,7 @@ export interface ThreadManagementServiceShape {>;readonly getThreadShell: Orchestrator.OrchestratorV2["Service"]["getThreadShell"];readonly listAppOwnedChildThreadIds: Orchestrator.OrchestratorV2["Service"]["listAppOwnedChildThreadIds"];+ readonly getThreadTitles: Orchestrator.OrchestratorV2["Service"]["getThreadTitles"];/** Omit `projectId` to list every project's threads. Side chats are never listed. */readonly listProjectThreads: (input: {readonly projectId?: ProjectId | undefined;@@ -1536,6 +1537,7 @@ const make = Effect.gen(function* () {);},),+ getThreadTitles: orchestrator.getThreadTitles,listProjectThreads,sendToThread,assertProviderInstanceEnabled,diff --git a/apps/server/src/relay/AgentAwarenessRelay.test.ts b/apps/server/src/relay/AgentAwarenessRelay.test.tsindex f7edcc869f2..e76e2a6b64b 100644--- a/apps/server/src/relay/AgentAwarenessRelay.test.ts+++ b/apps/server/src/relay/AgentAwarenessRelay.test.ts@@ -203,6 +203,7 @@ const makeTestRelay = Effect.fnUntraced(function* (listActiveShellIndex: () => Effect.succeed([]),listOlderSettledThreads: unused,readShellSnapshot: unused,+ getThreadTitles: unused,ensureLegacyTranscript: unused,dispatch: unused,searchThread: () => Effect.die("unused"),diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.tsindex 3eba0e1e576..98c14b4861d 100644--- a/apps/server/src/ws.ts+++ b/apps/server/src/ws.ts@@ -2123,6 +2123,16 @@ export const layerWsRpc = (getOrchestrationV2ArchivedShellSnapshot,[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: (input) =>readOmittableShellRows({ familyOf: input.threadId }, "Failed to load the thread family"),+ [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: (input) =>+ threadManagement.getThreadTitles(input.threadIds).pipe(+ Effect.mapError(+ (cause) =>+ new OrchestrationV2GetShellSnapshotError({+ message: "Failed to load thread titles",+ cause,+ }),+ ),+ ),[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: (input) =>loadOlderSettledThreadsPage({sql,diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsxindex 1330f0057a6..59f9fb69adc 100644--- a/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx+++ b/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx@@ -9,6 +9,16 @@ const state = vi.hoisted(() => ({projection: null as unknown,commandSucceeds: false,relatedShells: [] as unknown[],+ threadTitles: {} as Record<string, string>,+ archivedThreads: [] as unknown[],+}));++vi.mock(import("../../state/query"), async (original) => ({+ ...(await original()),+ useEnvironmentQuery: ((atom: unknown) =>+ atom === null+ ? { data: null, isSuccess: false, isPending: false }+ : { data: state.threadTitles, isSuccess: true, isPending: false }) as never,}));vi.mock(import("@effect/atom-react"), async (original) => ({@@ -33,7 +43,9 @@ vi.mock(import("../../state/environments"), () => ({useEnvironmentProviders: (() => new Map()) as never,}));vi.mock(import("../../lib/archivedThreadsState"), () => ({- useArchivedThreadSnapshots: (() => ({ snapshots: [] })) as never,+ useArchivedThreadSnapshots: (() => ({+ snapshots: [{ environmentId: "environment", snapshot: { threads: state.archivedThreads } }],+ })) as never,}));vi.mock(import("../../state/use-atom-command"), () => ({useAtomCommand: (() => async () =>@@ -53,6 +65,8 @@ const threadId = ThreadId.make("fork");function setup() {state.commandSucceeds = false;state.relatedShells = [];+ state.threadTitles = { source: "Source" };+ state.archivedThreads = [];state.projection = {thread: {id: threadId,@@ -345,3 +359,37 @@ it("shows a delegated-from thread's full title in its tooltip even when its enviawait row.click({ force: true });expect(screen.router?.state.location.pathname).toBe("/environment/fork");});++it("hides a deleted fork and keeps unloaded and archived forks with their current titles", async () => {+ setup();+ const projection = makeThreadProjectionFixture();+ state.threadTitles = { "unloaded-fork": "Unloaded fork", "archived-fork": "Archived fork" };+ state.archivedThreads = [+ {+ ...projection.thread,+ id: ThreadId.make("archived-fork"),+ title: "Old archived title",+ archivedAt: projection.thread.updatedAt,+ lineage: { parentThreadId: projection.thread.id, relationshipToParent: "fork" },+ },+ ];+ state.projection = {+ ...projection,+ contextTransfers: ["deleted-fork", "unloaded-fork", "archived-fork"].map((id) => ({+ sourceThreadId: projection.thread.id,+ targetThreadId: ThreadId.make(id),+ status: "pending",+ })),+ };+ await using screen = await render(+ <ThreadRelationshipsPanel+ environmentId={environmentId}+ threadId={projection.thread.id}+ showLineage+ showSideChats+ />,+ );+ await expect.element(screen.getByText("Unloaded fork", { exact: true })).toBeVisible();+ await expect.element(screen.getByText("Archived fork", { exact: true })).toBeVisible();+ await expect.element(screen.getByText("deleted-fork", { exact: true })).not.toBeInTheDocument();+});diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.tsxindex c91d5acebc9..55abc90a0fa 100644--- a/apps/web/src/components/chat/ThreadRelationshipsControl.tsx+++ b/apps/web/src/components/chat/ThreadRelationshipsControl.tsx@@ -77,6 +77,7 @@ import {import { threadEnvironment } from "../../state/threads";import { orchestrationEnvironment } from "../../state/orchestration";import { useAtomCommand } from "../../state/use-atom-command";+import { useEnvironmentQuery } from "../../state/query";import { AgentElapsed } from "./AgentElapsed";import { ThreadRelationshipIcon, threadRelationshipStatusLabel } from "./ThreadRelationshipIcon";import { ThreadLineageWorkflowRow } from "./ThreadLineageWorkflowRow";@@ -499,6 +500,31 @@ export function ThreadRelationshipsPanel(props: {: { ...row, edge: { ...row.edge, status: workflowGroup.workflow.status } };});const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;+ const unlistedThreadIds = relationshipRows+ .filter(+ ({ threadId, edge }) =>+ !relationshipShells.some((thread) => thread.id === threadId) &&+ (edge.kind !== "subagent" || !subagentsByThreadId.get(threadId)?.title),+ )+ .map(({ threadId }) => threadId);+ const threadTitles = useEnvironmentQuery(+ unlistedThreadIds.length === 0+ ? null+ : orchestrationEnvironment.threadTitles({+ environmentId: props.environmentId,+ input: { threadIds: unlistedThreadIds },+ }),+ );+ const resolvedThreadTitles = threadTitles.data ?? {};+ // Omitted and archived threads remain reachable; only a settled lookup proves one is gone.+ const visibleRelationships = relationshipRows.filter(+ ({ threadId, edge }) =>+ edge.kind === "subagent" ||+ !unlistedThreadIds.includes(threadId) ||+ !threadTitles.isSuccess ||+ threadTitles.isPending ||+ Object.hasOwn(resolvedThreadTitles, threadId),+ );const canDetach = projection ? canDetachThreadProviderSession(projection) : false;const {@@ -506,7 +532,7 @@ export function ThreadRelationshipsPanel(props: {active = [],previous = [],sideChats = [],- } = groupBy(relationshipRows, ({ threadId, edge }) => {+ } = groupBy(visibleRelationships, ({ threadId, edge }) => {const isParent = isParentThreadRelationship(edge, props.threadId);if (!isParent && graph.nodes.get(threadId)?.thread?.lineage.sideChat === true)return "sideChats";@@ -681,7 +707,14 @@ export function ThreadRelationshipsPanel(props: {["pending", "running", "waiting"].includes(agent.status);const threadTitle = relationshipThreadTitle({title:- workflowGroup?.workflow.workflowName ?? node?.thread?.title ?? agent?.title ?? threadId,+ workflowGroup?.workflow.workflowName ??+ // Fresher than an archived snapshot's copy.+ (Object.hasOwn(resolvedThreadTitles, threadId)+ ? resolvedThreadTitles[threadId]+ : undefined) ??+ node?.thread?.title ??+ agent?.title ??+ threadId,isSubagent,});const provider = providers?.find(diff --git a/apps/web/src/state/orchestration.ts b/apps/web/src/state/orchestration.tsindex 8c6e1738857..49ba6867143 100644--- a/apps/web/src/state/orchestration.ts+++ b/apps/web/src/state/orchestration.ts@@ -1,5 +1,8 @@import { createOrchestrationEnvironmentAtoms } from "@t3tools/client-runtime/state/orchestration";import { connectionAtomRuntime } from "../connection/runtime";+import { environmentShell } from "./shell";-export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime);+export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime, {+ shellState: environmentShell.stateValueAtom,+});diff --git a/packages/client-runtime/src/state/orchestration.ts b/packages/client-runtime/src/state/orchestration.tsindex 94dc18582a5..f5be5e2f63c 100644--- a/packages/client-runtime/src/state/orchestration.ts+++ b/packages/client-runtime/src/state/orchestration.ts@@ -1,5 +1,6 @@import {ORCHESTRATION_V2_WS_METHODS,+ type EnvironmentId,type ThreadId,type OrchestrationGetTurnDiffResult,} from "@t3tools/contracts";@@ -24,11 +25,16 @@ import * as EnvironmentSupervisor from "../connection/supervisor.ts";import * as RemoteEnvironmentAuthorization from "../authorization/service.ts";import * as ManagedRelayDpopSigner from "../relay/managedRelay.ts";import { EnvironmentRpcUnavailableError } from "../rpc/client.ts";+import type { EnvironmentShellState } from "./shell.ts";import { fetchEnvironmentThreadTranscript } from "./threadTranscriptHttp.ts";export function createOrchestrationEnvironmentAtoms<R, E>(runtime: Atom.AtomRuntime<EnvironmentRegistry | HttpClient.HttpClient | R, E>,options: {+ /** Re-checks `threadTitles` when one of their threads leaves the shell. */+ readonly shellState?: (+ environmentId: EnvironmentId,+ ) => Atom.Atom<Pick<EnvironmentShellState, "removedAt">>;/** Runs on each turn-range and full-thread diff the server answers. */readonly onCheckpointDiffAnswer?: QueryAnswerHandler<{ readonly ignoreWhitespace?: boolean },@@ -40,7 +46,24 @@ export function createOrchestrationEnvironmentAtoms<R, E>(options.onCheckpointDiffAnswer === undefined? {}: { onAnswer: options.onCheckpointDiffAnswer };+ const shellState = options.shellState;return {+ threadTitles: createEnvironmentRpcQueryAtomFamily(runtime, {+ label: "environment-data:orchestration:thread-titles",+ tag: ORCHESTRATION_V2_WS_METHODS.getThreadTitles,+ staleTimeMs: 0,+ idleTtlMs: 0,+ // Deleting a thread the shell already left out keeps these ids, so the query would not rerun.+ // A removal can also be an archive, so it only prompts a re-check.+ refreshTrigger: ({ environmentId, input }) => {+ if (shellState === undefined) return undefined;+ const state = shellState(environmentId);+ return Atom.make((get) => {+ const { removedAt } = get(state);+ return Math.max(-1, ...input.threadIds.map((threadId) => removedAt.get(threadId) ?? -1));+ });+ },+ }),threadTranscript: createEnvironmentCommand(runtime, {label: "environment-data:orchestration:thread-transcript",execute: Effect.fn("orchestration.execute")(function* (input: {diff --git a/packages/client-runtime/src/state/runtime.test.ts b/packages/client-runtime/src/state/runtime.test.tsindex 04b6ec570db..381623f2320 100644--- a/packages/client-runtime/src/state/runtime.test.ts+++ b/packages/client-runtime/src/state/runtime.test.ts@@ -1,6 +1,8 @@import { describe, expect, it } from "@effect/vitest";import {EnvironmentId,+ ORCHESTRATION_V2_WS_METHODS,+ ThreadId,type ReviewDiffPreviewInput,type PreviewEvent,type TerminalAttachInput,@@ -21,6 +23,7 @@ import * as Queue from "effect/Queue";import * as Schema from "effect/Schema";import * as Stream from "effect/Stream";import * as SubscriptionRef from "effect/SubscriptionRef";+import type { HttpClient } from "effect/http";import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";import {@@ -35,9 +38,11 @@ import * as EnvironmentRegistry from "../connection/registry.ts";import * as EnvironmentSupervisor from "../connection/supervisor.ts";import { EnvironmentRpcUnavailableError } from "../rpc/client.ts";import type * as RpcSession from "../rpc/session.ts";+import { createOrchestrationEnvironmentAtoms } from "./orchestration.ts";import { createReviewEnvironmentAtoms } from "./review.ts";import { createPreviewEnvironmentAtoms } from "./preview.ts";import type { QueryPersistence } from "./queryPersistence.ts";+import type { EnvironmentShellState } from "./shell.ts";import { createTerminalEnvironmentAtoms } from "./terminal.ts";import {createAtomCommandScheduler,@@ -1017,6 +1022,64 @@ describe("environment query lifecycle", () => {}),),);++ it.effect("re-checks thread titles when one of their threads leaves the shell", () =>+ Effect.scoped(+ Effect.gen(function* () {+ const requests = yield* Queue.unbounded<Deferred.Deferred<Record<string, string>>>();+ const harness = yield* makeEnvironmentQueryHarness(Effect.void, {+ rpcSession: {+ client: {+ [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: () =>+ Effect.gen(function* () {+ const answer = yield* Deferred.make<Record<string, string>>();+ yield* Queue.offer(requests, answer);+ return yield* Deferred.await(answer);+ }),+ },+ } as unknown as RpcSession.RpcSession,+ });+ const shellState = Atom.make<Pick<EnvironmentShellState, "removedAt">>({+ removedAt: new Map(),+ }).pipe(Atom.keepAlive);+ const removed = (entries: ReadonlyArray<readonly [string, number]>) => ({+ removedAt: new Map(entries.map(([id, sequence]) => [ThreadId.make(id), sequence])),+ });+ // Thread titles never use the HTTP client.+ const runtime = harness.runtime as unknown as Atom.AtomRuntime<+ EnvironmentRegistry.EnvironmentRegistry | HttpClient.HttpClient+ >;+ const atom = createOrchestrationEnvironmentAtoms(runtime, {+ shellState: () => shellState,+ }).threadTitles({+ environmentId: QUERY_ENVIRONMENT.environmentId,+ input: { threadIds: [ThreadId.make("fork")] },+ });+ const registry = yield* mountEnvironmentQuery(atom);+ const settled: Array<Record<string, string>> = [];+ const unsubscribe = registry.subscribe(atom, (result) => {+ if (AsyncResult.isSuccess(result) && !result.waiting) settled.push(result.value);+ });+ yield* Effect.addFinalizer(() => Effect.sync(unsubscribe));++ yield* Deferred.succeed(yield* Queue.take(requests), { fork: "Fork" });+ expect(yield* readEnvironmentQuery(registry, atom)).toEqual({ fork: "Fork" });++ registry.set(shellState, removed([["other", 5]]));+ expect(registry.get(atom).waiting).toBe(false);++ // Archiving and then deleting the fork both remove it from the shell.+ registry.set(shellState, removed([["fork", 6]]));+ const beforeDelete = yield* Queue.take(requests);+ registry.set(shellState, removed([["fork", 7]]));+ const afterDelete = yield* Queue.take(requests);+ yield* Deferred.succeed(beforeDelete, { fork: "Fork" });+ yield* Deferred.succeed(afterDelete, {});+ expect(yield* readEnvironmentQuery(registry, atom)).toEqual({});+ expect(settled).toEqual([{ fork: "Fork" }, {}]);+ }),+ ),+ );});describe("executeAtomQuery", () => {diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.tsindex 785f41e3aa0..5eb2b6ed4bf 100644--- a/packages/contracts/src/orchestrationV2.ts+++ b/packages/contracts/src/orchestrationV2.ts@@ -3580,6 +3580,7 @@ export const ORCHESTRATION_V2_WS_METHODS = {searchThreadStream: "orchestration.searchThreadStream",getArchivedShellSnapshot: "orchestration.getArchivedShellSnapshot",getThreadFamily: "orchestration.getThreadFamily",+ getThreadTitles: "orchestration.getThreadTitles",getWorktreeThreadIds: "orchestration.getWorktreeThreadIds",getOlderSettledThreads: "orchestration.getOlderSettledThreads",getThreadProjection: "orchestration.getThreadProjection",@@ -3704,6 +3705,13 @@ export const OrchestrationV2ThreadFamily = Schema.Struct({});export type OrchestrationV2ThreadFamily = typeof OrchestrationV2ThreadFamily.Type;+export const OrchestrationV2GetThreadTitlesInput = Schema.Struct({+ threadIds: Schema.Array(ThreadId),+});++/** Titles of the requested threads that exist, archived ones included. Deleted and unknown ids are absent. */+export const OrchestrationV2ThreadTitles = Schema.Record(ThreadId, Schema.String);+export const OrchestrationV2GetWorktreeThreadIdsInput = Schema.Struct({worktreePath: TrimmedNonEmptyString,});@@ -4226,6 +4234,10 @@ export const OrchestrationV2RpcSchemas = {input: OrchestrationV2GetThreadFamilyInput,output: OrchestrationV2ThreadFamily,},+ getThreadTitles: {+ input: OrchestrationV2GetThreadTitlesInput,+ output: OrchestrationV2ThreadTitles,+ },getWorktreeThreadIds: {input: OrchestrationV2GetWorktreeThreadIdsInput,output: OrchestrationV2WorktreeThreadIds,diff --git a/packages/contracts/src/rpc.ts b/packages/contracts/src/rpc.tsindex 737059e8557..4171bdd7ff4 100644--- a/packages/contracts/src/rpc.ts+++ b/packages/contracts/src/rpc.ts@@ -1777,6 +1777,12 @@ const WsOrchestrationV2GetThreadFamilyRpc = Rpc.make(ORCHESTRATION_V2_WS_METHODSerror: Schema.Union([OrchestrationV2GetShellSnapshotError, EnvironmentAuthorizationError]),});+const WsOrchestrationV2GetThreadTitlesRpc = Rpc.make(ORCHESTRATION_V2_WS_METHODS.getThreadTitles, {+ payload: OrchestrationV2RpcSchemas.getThreadTitles.input,+ success: OrchestrationV2RpcSchemas.getThreadTitles.output,+ error: Schema.Union([OrchestrationV2GetShellSnapshotError, EnvironmentAuthorizationError]),+});+const WsOrchestrationV2GetWorktreeThreadIdsRpc = Rpc.make(ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds,{@@ -2191,6 +2197,7 @@ export const WsRpcGroup = RpcGroup.make(WsOrchestrationV2SearchThreadStreamRpc,WsOrchestrationV2GetArchivedShellSnapshotRpc,WsOrchestrationV2GetThreadFamilyRpc,+ WsOrchestrationV2GetThreadTitlesRpc,WsOrchestrationV2GetWorktreeThreadIdsRpc,WsOrchestrationV2GetOlderSettledThreadsRpc,WsOrchestrationV2GetThreadProjectionRpc,