Skip to content

Commit 7d58d6c

Browse files
Alb11747codex
andcommitted
fix(web): hide deleted forks from thread lineage
Look up titles for related threads missing from live shells, including archived threads and excluding deleted rows. Hide non-subagent relationships only after a settled successful lookup confirms absence, and refresh on shell removals. Keep historical subagent results and transfer records intact. Cover omitted, archived, deleted, pending and failed lookups, stale archived titles, and the title query's deletion filter. Co-Authored-By: GPT-6.1 Sol at high effort <[email protected]> Co-Authored-By: GPT-6.1 Sol at xhigh effort, review subagent <[email protected]>
1 parent fa31b66 commit 7d58d6c

11 files changed

Lines changed: 233 additions & 5 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const RPC_REQUIRED_SCOPES = {
5050
[ORCHESTRATION_V2_WS_METHODS.searchThreadStream]: AuthOrchestrationReadScope,
5151
[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: AuthOrchestrationReadScope,
5252
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: AuthOrchestrationReadScope,
53+
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: AuthOrchestrationReadScope,
5354
[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: AuthOrchestrationReadScope,
5455
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: AuthOrchestrationReadScope,
5556
[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
@@ -23,6 +23,7 @@ const RPC_AGGREGATES = {
2323
[ORCHESTRATION_V2_WS_METHODS.searchThreadStream]: "orchestration",
2424
[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: "orchestration",
2525
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: "orchestration",
26+
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: "orchestration",
2627
[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: "orchestration",
2728
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: "orchestration",
2829
[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: "orchestrationV2",

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { projectThreadAwarenessV2 } from "@t3tools/shared/agentAwareness";
3939
import * as SqlitePersistence from "../persistence/Sqlite.ts";
4040
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
4141
import * as ProjectionStore from "./ProjectionStore.ts";
42+
import { readThreadTitles } from "./ThreadTitles.ts";
4243
import {
4344
buildBoundedThreadProjection,
4445
decodeThreadHistoryCursor,
@@ -820,7 +821,17 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {
820821
yield* create("thread:active", { worktreePath: "/worktrees/active" });
821822
yield* create("thread:archived", { worktreePath: "/worktrees/archived", archived: true });
822823
yield* create("thread:local", { worktreePath: null });
823-
const deleted = yield* create("thread:deleted", { worktreePath: "/worktrees/deleted" });
824+
const deleted = {
825+
...(yield* create("thread:deleted", { worktreePath: "/worktrees/deleted" })),
826+
title: "Renamed deleted thread",
827+
};
828+
yield* store.apply({
829+
id: EventId.make("event:thread:deleted:renamed"),
830+
type: "thread.metadata-updated",
831+
threadId: deleted.id,
832+
occurredAt: now,
833+
payload: deleted,
834+
});
824835
yield* store.apply({
825836
id: EventId.make("event:thread:deleted:deleted"),
826837
type: "thread.deleted",
@@ -829,6 +840,21 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {
829840
payload: { ...deleted, deletedAt: now },
830841
});
831842

843+
const sql = yield* SqlClient.SqlClient;
844+
assert.deepEqual(
845+
yield* readThreadTitles(sql, [
846+
deleted.id,
847+
ThreadId.make("missing"),
848+
ThreadId.make("thread:active"),
849+
ThreadId.make("thread:archived"),
850+
]),
851+
{
852+
"thread:active": "thread:active",
853+
"thread:archived": "thread:archived",
854+
},
855+
);
856+
assert.deepEqual(yield* readThreadTitles(sql, []), {});
857+
832858
assert.deepEqual(yield* store.getThreadWorktreePaths(), [
833859
{ threadId: ThreadId.make("thread:active"), worktreePath: "/worktrees/active" },
834860
]);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { ThreadId } from "@t3tools/contracts";
2+
import * as Effect from "effect/Effect";
3+
import type * as SqlClient from "effect/sql/SqlClient";
4+
5+
export const readThreadTitles = Effect.fn("ThreadTitles.read")(function* (
6+
sql: SqlClient.SqlClient,
7+
threadIds: ReadonlyArray<ThreadId>,
8+
) {
9+
if (threadIds.length === 0) return {};
10+
const rows = yield* sql<{ thread_id: ThreadId; title: string }>`
11+
SELECT thread_id, title FROM orchestration_v2_projection_threads
12+
WHERE deleted_at IS NULL AND thread_id IN ${sql.in(threadIds)}`;
13+
return Object.fromEntries(rows.map((row) => [row.thread_id, row.title]));
14+
});

‎apps/server/src/ws.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { OrchestrationDispatchCommandError } from "@t3tools/contracts";
22
import * as Context from "effect/Context";
33
import * as Crypto from "effect/Crypto";
44
import * as Orchestrator from "./orchestration-v2/Orchestrator.ts";
5+
import { readThreadTitles } from "./orchestration-v2/ThreadTitles.ts";
56
import * as PeerLinkRequests from "./peer/PeerLinkRequests.ts";
67
import * as PeerLinks from "./peer/PeerLinks.ts";
78

@@ -2026,6 +2027,16 @@ export const layerWsRpc = (
20262027
getOrchestrationV2ArchivedShellSnapshot,
20272028
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: (input) =>
20282029
readOmittableShellRows({ familyOf: input.threadId }, "Failed to load the thread family"),
2030+
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: (input) =>
2031+
readThreadTitles(sql, input.threadIds).pipe(
2032+
Effect.mapError(
2033+
(cause) =>
2034+
new OrchestrationV2GetShellSnapshotError({
2035+
message: "Failed to load thread titles",
2036+
cause,
2037+
}),
2038+
),
2039+
),
20292040
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: (input) =>
20302041
loadOlderSettledThreadsPage({
20312042
sql,

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

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

1422
vi.mock(import("@effect/atom-react"), async (original) => ({
@@ -31,7 +39,9 @@ vi.mock(import("../../state/environments"), () => ({
3139
useEnvironmentProviders: (() => new Map()) as never,
3240
}));
3341
vi.mock(import("../../lib/archivedThreadsState"), () => ({
34-
useArchivedThreadSnapshots: (() => ({ snapshots: [] })) as never,
42+
useArchivedThreadSnapshots: (() => ({
43+
snapshots: [{ environmentId: "environment", snapshot: { threads: state.archivedThreads } }],
44+
})) as never,
3545
}));
3646
vi.mock(import("../../state/use-atom-command"), () => ({
3747
useAtomCommand: (() => async () =>
@@ -51,6 +61,9 @@ const threadId = ThreadId.make("fork");
5161
function setup() {
5262
state.commandSucceeds = false;
5363
state.relatedShells = [];
64+
state.threadTitles = { source: "Source" };
65+
state.titleLookup = { isSuccess: true, isPending: false };
66+
state.archivedThreads = [];
5467
state.projection = {
5568
thread: {
5669
id: threadId,
@@ -343,3 +356,99 @@ it("shows a delegated-from thread's full title in its tooltip even when its envi
343356
await row.click({ force: true });
344357
expect(screen.router?.state.location.pathname).toBe("/environment/fork");
345358
});
359+
360+
it.each([
361+
{
362+
name: "an omitted existing fork",
363+
exists: true,
364+
success: true,
365+
pending: false,
366+
archived: false,
367+
visible: true,
368+
},
369+
{
370+
name: "a deleted fork",
371+
exists: false,
372+
success: true,
373+
pending: false,
374+
archived: false,
375+
visible: false,
376+
},
377+
{
378+
name: "an existing archived fork with a stale title",
379+
exists: true,
380+
success: true,
381+
pending: false,
382+
archived: true,
383+
visible: true,
384+
},
385+
{
386+
name: "a deleted fork in a stale archived snapshot",
387+
exists: false,
388+
success: true,
389+
pending: false,
390+
archived: true,
391+
visible: false,
392+
},
393+
{
394+
name: "an unresolved fork",
395+
exists: false,
396+
success: true,
397+
pending: true,
398+
archived: false,
399+
visible: true,
400+
},
401+
{
402+
name: "a fork after lookup failure",
403+
exists: false,
404+
success: false,
405+
pending: false,
406+
archived: false,
407+
visible: true,
408+
},
409+
])(
410+
"keeps or hides $name after checking its existence",
411+
async ({ exists, success, pending, archived, visible }) => {
412+
setup();
413+
const projection = makeThreadProjectionFixture();
414+
const deletedId = ThreadId.make("deleted-fork");
415+
const title = "Example fork";
416+
state.threadTitles = exists ? { [deletedId]: title } : {};
417+
state.titleLookup = { isSuccess: success, isPending: pending };
418+
if (archived)
419+
state.archivedThreads = [
420+
{
421+
...projection.thread,
422+
id: deletedId,
423+
title: "Old archived title",
424+
archivedAt: projection.thread.updatedAt,
425+
lineage: { parentThreadId: projection.thread.id, relationshipToParent: "fork" },
426+
},
427+
];
428+
state.projection = {
429+
...projection,
430+
contextTransfers: [
431+
{
432+
sourceThreadId: projection.thread.id,
433+
targetThreadId: deletedId,
434+
status: "pending",
435+
},
436+
],
437+
};
438+
await using screen = await render(
439+
<ThreadRelationshipsPanel
440+
environmentId={environmentId}
441+
threadId={projection.thread.id}
442+
showLineage
443+
showSideChats
444+
/>,
445+
);
446+
if (visible) {
447+
await expect
448+
.element(screen.getByText(exists || archived ? title : deletedId, { exact: true }))
449+
.toBeVisible();
450+
} else {
451+
await expect.element(screen.getByRole("region", { name: "Lineage" })).not.toBeInTheDocument();
452+
}
453+
},
454+
);

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import {
7474
import { threadEnvironment } from "../../state/threads";
7575
import { orchestrationEnvironment } from "../../state/orchestration";
7676
import { useAtomCommand } from "../../state/use-atom-command";
77+
import { useEnvironmentQuery } from "../../state/query";
7778
import { AgentElapsed } from "./AgentElapsed";
7879
import { ThreadRelationshipIcon, threadRelationshipStatusLabel } from "./ThreadRelationshipIcon";
7980
import { ThreadLineageWorkflowRow } from "./ThreadLineageWorkflowRow";
@@ -483,14 +484,38 @@ export function ThreadRelationshipsPanel(props: {
483484
: { ...row, edge: { ...row.edge, status: workflowGroup.workflow.status } };
484485
});
485486
const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;
487+
const unlistedThreadIds = relationshipRows
488+
.filter(
489+
({ threadId, edge }) =>
490+
!relationshipShells.some((thread) => thread.id === threadId) &&
491+
(edge.kind !== "subagent" || !subagentsByThreadId.get(threadId)?.title),
492+
)
493+
.map(({ threadId }) => threadId);
494+
const threadTitles = useEnvironmentQuery(
495+
unlistedThreadIds.length === 0
496+
? null
497+
: orchestrationEnvironment.threadTitles({
498+
environmentId: props.environmentId,
499+
input: { threadIds: unlistedThreadIds },
500+
}),
501+
);
502+
// Omitted and archived threads remain reachable; only a settled lookup proves one is gone.
503+
const visibleRelationships = relationshipRows.filter(
504+
({ threadId, edge }) =>
505+
edge.kind === "subagent" ||
506+
!unlistedThreadIds.includes(threadId) ||
507+
!threadTitles.isSuccess ||
508+
threadTitles.isPending ||
509+
threadTitles.data?.[threadId] !== undefined,
510+
);
486511
const canDetach = projection ? canDetachThreadProviderSession(projection) : false;
487512

488513
const {
489514
related = [],
490515
active = [],
491516
previous = [],
492517
sideChats = [],
493-
} = groupBy(relationshipRows, ({ threadId, edge }) => {
518+
} = groupBy(visibleRelationships, ({ threadId, edge }) => {
494519
const isParent = isParentThreadRelationship(edge, props.threadId);
495520
if (!isParent && graph.nodes.get(threadId)?.thread?.lineage.sideChat === true)
496521
return "sideChats";
@@ -663,7 +688,14 @@ export function ThreadRelationshipsPanel(props: {
663688
["pending", "running", "waiting"].includes(agent.status);
664689
const threadTitle = relationshipThreadTitle({
665690
title:
666-
workflowGroup?.workflow.workflowName ?? node?.thread?.title ?? agent?.title ?? threadId,
691+
workflowGroup?.workflow.workflowName ??
692+
(unlistedThreadIds.includes(threadId) && !isSubagent
693+
? threadTitles.data?.[threadId]
694+
: undefined) ??
695+
node?.thread?.title ??
696+
agent?.title ??
697+
threadTitles.data?.[threadId] ??
698+
threadId,
667699
isSubagent,
668700
});
669701
const provider = providers?.find(
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import { createOrchestrationEnvironmentAtoms } from "@t3tools/client-runtime/state/orchestration";
2+
import type { EnvironmentId } from "@t3tools/contracts";
3+
import { AsyncResult, Atom } from "effect/reactivity";
24

35
import { connectionAtomRuntime } from "../connection/runtime";
6+
import { environmentShell } from "./shell";
47

5-
export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime);
8+
// Deleting an already-omitted thread leaves the title query's IDs unchanged.
9+
const threadTitleRefreshes = Atom.family((environmentId: EnvironmentId) =>
10+
Atom.make(
11+
(get) =>
12+
AsyncResult.getOrElse(get(environmentShell.stateAtom(environmentId)), () => null)?.removedAt,
13+
),
14+
);
15+
16+
export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime, {
17+
threadTitlesRefreshTrigger: threadTitleRefreshes,
18+
});

‎packages/client-runtime/src/state/orchestration.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
ORCHESTRATION_V2_WS_METHODS,
3+
type EnvironmentId,
34
type ThreadId,
45
type OrchestrationGetTurnDiffResult,
56
} from "@t3tools/contracts";
@@ -29,6 +30,7 @@ import { fetchEnvironmentThreadTranscript } from "./threadTranscriptHttp.ts";
2930
export function createOrchestrationEnvironmentAtoms<R, E>(
3031
runtime: Atom.AtomRuntime<EnvironmentRegistry | HttpClient.HttpClient | R, E>,
3132
options: {
33+
readonly threadTitlesRefreshTrigger?: (environmentId: EnvironmentId) => Atom.Atom<unknown>;
3234
/** Runs on each turn-range and full-thread diff the server answers. */
3335
readonly onCheckpointDiffAnswer?: QueryAnswerHandler<
3436
{ readonly ignoreWhitespace?: boolean },
@@ -41,6 +43,13 @@ export function createOrchestrationEnvironmentAtoms<R, E>(
4143
? {}
4244
: { onAnswer: options.onCheckpointDiffAnswer };
4345
return {
46+
threadTitles: createEnvironmentRpcQueryAtomFamily(runtime, {
47+
label: "environment-data:orchestration:thread-titles",
48+
tag: ORCHESTRATION_V2_WS_METHODS.getThreadTitles,
49+
staleTimeMs: 0,
50+
idleTtlMs: 0,
51+
refreshTrigger: ({ environmentId }) => options.threadTitlesRefreshTrigger?.(environmentId),
52+
}),
4453
threadTranscript: createEnvironmentCommand(runtime, {
4554
label: "environment-data:orchestration:thread-transcript",
4655
execute: Effect.fn("orchestration.execute")(function* (input: {

‎packages/contracts/src/orchestrationV2.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,6 +3555,7 @@ export const ORCHESTRATION_V2_WS_METHODS = {
35553555
searchThreadStream: "orchestration.searchThreadStream",
35563556
getArchivedShellSnapshot: "orchestration.getArchivedShellSnapshot",
35573557
getThreadFamily: "orchestration.getThreadFamily",
3558+
getThreadTitles: "orchestration.getThreadTitles",
35583559
getWorktreeThreadIds: "orchestration.getWorktreeThreadIds",
35593560
getOlderSettledThreads: "orchestration.getOlderSettledThreads",
35603561
getThreadProjection: "orchestration.getThreadProjection",
@@ -4153,6 +4154,10 @@ export const OrchestrationV2RpcSchemas = {
41534154
input: OrchestrationV2GetThreadFamilyInput,
41544155
output: OrchestrationV2ThreadFamily,
41554156
},
4157+
getThreadTitles: {
4158+
input: Schema.Struct({ threadIds: Schema.Array(ThreadId) }),
4159+
output: Schema.Record(ThreadId, Schema.String),
4160+
},
41564161
getWorktreeThreadIds: {
41574162
input: OrchestrationV2GetWorktreeThreadIdsInput,
41584163
output: OrchestrationV2WorktreeThreadIds,

0 commit comments

Comments
 (0)