GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(clients): unloaded thread links show their title and project icon… · adampeterhiggins/t3code@23e3465

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps
    • mobile/src/state
      • entities.test.ts
      • entities.ts
      • orchestration.ts
    • server/src
      • auth
        • RpcAuthorization.ts
      • observability
        • RpcInstrumentation.ts
      • orchestration-v2
        • Orchestrator.ts
        • ProjectionStore.test.ts
        • ProjectionStore.ts
        • ProviderTurnControlService.test.ts
        • ThreadManagementService.ts
      • relay
        • AgentAwarenessRelay.test.ts
      • ws.ts
    • web/src/components
      • ThreadContextChip.tsx
      • chat
        • MarkdownThreadLink.browser.test.tsx
        • MarkdownThreadLink.tsx
  • packages
    • client-runtime/src/state
      • orchestration.ts
      • runtime.test.ts
    • contracts/src
      • orchestrationV2.ts
      • rpc.ts
      • server.ts
    • shared/src
      • threadLinks.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/state/entities.test.ts‎

Copy file name to clipboard
+72Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { EnvironmentId, ProjectId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
2+
import * as Cause from "effect/Cause";
3+
import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
4+
import { expect, it, vi } from "vite-plus/test";
5+
6+
const state = vi.hoisted(() => ({ reply: null as unknown }));
7+
vi.mock(import("./threads"), async () => {
8+
const { Atom } = await import("effect/reactivity");
9+
return {
10+
environmentThreadDetails: {} as never,
11+
environmentThreadShells: {
12+
threadShellAtom: () => Atom.make(null),
13+
threadRefsAtom: Atom.make([{ environmentId: "remote", threadId: "older-thread" }]),
14+
} as never,
15+
};
16+
});
17+
vi.mock(import("./orchestration"), () => ({
18+
orchestrationEnvironment: { threadLinkMetadata: () => state.reply } as never,
19+
}));
20+
vi.mock(import("./atom-registry"), () => ({ appAtomRegistry: {} as never }));
21+
vi.mock(import("./projects"), () => ({ environmentProjects: {} as never }));
22+
vi.mock(import("./server"), () => ({
23+
environmentServerConfigsAtom: {} as never,
24+
serverEnvironment: {} as never,
25+
}));
26+
vi.mock(import("./assets"), () => ({ projectFaviconUrlAtom: (() => null) as never }));
27+
vi.mock(import("../native/ProjectChipIconImages"), () => ({
28+
projectGlyphImageAtom: (() => null) as never,
29+
projectGlyphKey: (() => "") as never,
30+
}));
31+
32+
import { resolveThreadLink } from "./entities";
33+
34+
function setup() {
35+
const reply = Atom.make<
36+
AsyncResult.AsyncResult<Record<string, { title: string; projectId: ProjectId | null }>, string>
37+
>(AsyncResult.initial());
38+
state.reply = reply;
39+
return { registry: AtomRegistry.make(), reply };
40+
}
41+
42+
it("uses confirmed matches instead of provisional titles when resolving legacy links", () => {
43+
const { registry, reply } = setup();
44+
using _registry = { [Symbol.dispose]: () => registry.dispose() };
45+
const local: ScopedThreadRef = {
46+
environmentId: EnvironmentId.make("local"),
47+
threadId: ThreadId.make("older-thread"),
48+
};
49+
const remote: ScopedThreadRef = { ...local, environmentId: EnvironmentId.make("remote") };
50+
const link = { environmentId: null, threadId: local.threadId };
51+
const resolve = () => resolveThreadLink(registry.get.bind(registry), link, local.environmentId);
52+
const release = registry.mount(reply);
53+
try {
54+
expect(resolve()).toEqual(remote);
55+
registry.set(reply, AsyncResult.failure(Cause.fail("offline")));
56+
expect(resolve()).toEqual(remote);
57+
expect(resolveThreadLink(registry.get.bind(registry), local, remote.environmentId)).toEqual(
58+
local,
59+
);
60+
registry.set(
61+
reply,
62+
AsyncResult.success({
63+
[local.threadId]: { title: "Thread", projectId: ProjectId.make("project") },
64+
}),
65+
);
66+
expect(resolve()).toEqual(local);
67+
registry.set(reply, AsyncResult.success({}));
68+
expect(resolve()).toEqual(remote);
69+
} finally {
70+
release();
71+
}
72+
});
Collapse file

‎apps/mobile/src/state/entities.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/state/entities.ts
+39-10Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { threadChipTargets } from "../lib/enrichedLinkPresentation";
3232
import { resolveProjectChipIcon } from "../lib/projectIcon";
3333
import { projectGlyphImageAtom, projectGlyphKey } from "../native/ProjectChipIconImages";
3434
import { projectFaviconUrlAtom } from "./assets";
35+
import { orchestrationEnvironment } from "./orchestration";
3536
import { environmentProjects } from "./projects";
3637
import { environmentServerConfigsAtom, serverEnvironment } from "./server";
3738
import { environmentThreadDetails, environmentThreadShells } from "./threads";
@@ -55,12 +56,22 @@ const EMPTY_THREAD_LINK_TITLES_ATOM = Atom.make<ReadonlyMap<string, string>>(new
5556
const decodeThreadKey = Schema.decodeUnknownSync(Schema.Tuple([EnvironmentId, ThreadId]));
5657
const threadKey = (ref: ScopedThreadRef) => JSON.stringify([ref.environmentId, ref.threadId]);
5758

58-
// Null when this client doesn't know the thread. Keyed, so a link never walks an environment's threads.
59+
// Omitted and archived targets need only a metadata lookup, not their conversation history.
5960
const threadTitleAtom = Atom.family((key: string) => {
6061
const ref = scopeThreadRef(...decodeThreadKey(JSON.parse(key)));
61-
return Atom.make((get) => get(environmentThreadShells.threadShellAtom(ref))?.title ?? null).pipe(
62-
Atom.withLabel(`mobile-thread-title:${key}`),
63-
);
62+
return Atom.make((get) => {
63+
const shell = get(environmentThreadShells.threadShellAtom(ref));
64+
if (shell !== null) return shell.title;
65+
const titles = get(
66+
orchestrationEnvironment.threadLinkMetadata({
67+
environmentId: ref.environmentId,
68+
input: { threadIds: [ref.threadId] },
69+
}),
70+
);
71+
return AsyncResult.isSuccess(titles)
72+
? (titles.value[ref.threadId]?.title ?? (titles.waiting ? "Thread" : null))
73+
: "Thread";
74+
}).pipe(Atom.withLabel(`mobile-thread-title:${key}`));
6475
});
6576

6677
const decodeThreadKeys = Schema.decodeUnknownSync(Schema.Array(Schema.String));
@@ -92,11 +103,22 @@ const threadProjectChipIconAtom = Atom.family((key: string) => {
92103
const ref = scopeThreadRef(...decodeThreadKey(JSON.parse(key)));
93104
return Atom.make((get): string | null => {
94105
const shell = get(environmentThreadShells.threadShellAtom(ref));
95-
const project = shell
106+
const metadata =
107+
shell ??
108+
AsyncResult.getOrElse(
109+
get(
110+
orchestrationEnvironment.threadLinkMetadata({
111+
environmentId: ref.environmentId,
112+
input: { threadIds: [ref.threadId] },
113+
}),
114+
),
115+
() => null,
116+
)?.[ref.threadId];
117+
const project = metadata?.projectId
96118
? get(
97119
environmentProjects.projectAtom({
98120
environmentId: ref.environmentId,
99-
projectId: shell.projectId,
121+
projectId: metadata.projectId,
100122
}),
101123
)
102124
: null;
@@ -222,13 +244,20 @@ export function resolveThreadLink(
222244
link: ThreadLink,
223245
messageEnvironmentId: EnvironmentId,
224246
): ScopedThreadRef | null {
225-
const known = threadLinkCandidates(link, messageEnvironmentId).find(
226-
(ref) => read(threadTitleAtom(threadKey(ref))) !== null,
227-
);
247+
const known = threadLinkCandidates(link, messageEnvironmentId).find((ref) => {
248+
if (read(environmentThreadShells.threadShellAtom(ref)) !== null) return true;
249+
const metadata = read(
250+
orchestrationEnvironment.threadLinkMetadata({
251+
environmentId: ref.environmentId,
252+
input: { threadIds: [ref.threadId] },
253+
}),
254+
);
255+
return AsyncResult.getOrElse(metadata, () => null)?.[ref.threadId] !== undefined;
256+
});
228257
if (known) return known;
229258
return link.environmentId === null
230259
? guessThreadLinkRef(link, read(environmentThreadShells.threadRefsAtom))
231-
: null;
260+
: scopeThreadRef(link.environmentId, link.threadId);
232261
}
233262

234263
export function useThreadChipIcons(
Collapse file

‎apps/mobile/src/state/orchestration.ts‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { createOrchestrationEnvironmentAtoms } from "@t3tools/client-runtime/state/orchestration";
22

33
import { connectionAtomRuntime } from "../connection/runtime";
4+
import { environmentShell } from "./shell";
45
import { recordReviewTurnDiffAnswer } from "./reviewTurnDiffs";
56

67
export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime, {
8+
shellState: environmentShell.stateValueAtom,
79
onCheckpointDiffAnswer: recordReviewTurnDiffAnswer,
810
});
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/auth/RpcAuthorization.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const RPC_REQUIRED_SCOPES = {
5252
[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: AuthOrchestrationReadScope,
5353
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: AuthOrchestrationReadScope,
5454
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: AuthOrchestrationReadScope,
55+
[ORCHESTRATION_V2_WS_METHODS.getThreadLinkMetadata]: AuthOrchestrationReadScope,
5556
[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: AuthOrchestrationReadScope,
5657
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: AuthOrchestrationReadScope,
5758
[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: AuthOrchestrationReadScope,
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/observability/RpcInstrumentation.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const RPC_AGGREGATES = {
2525
[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: "orchestration",
2626
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: "orchestration",
2727
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: "orchestration",
28+
[ORCHESTRATION_V2_WS_METHODS.getThreadLinkMetadata]: "orchestration",
2829
[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: "orchestration",
2930
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: "orchestration",
3031
[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: "orchestrationV2",
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
OrchestrationV2ThreadLinkMetadata,
23
GuestShareId,
34
OrchestrationV2SearchThreadInput,
45
OrchestrationV2SearchThreadResult,
@@ -479,6 +480,9 @@ export interface OrchestratorV2Shape {
479480
shareId: GuestShareId,
480481
) => Effect.Effect<ThreadId | null, OrchestratorV2Error>;
481482
/** Titles of the given threads that exist, archived ones included. */
483+
readonly getThreadLinkMetadata: (
484+
threadIds: ReadonlyArray<ThreadId>,
485+
) => Effect.Effect<Record<ThreadId, OrchestrationV2ThreadLinkMetadata>, OrchestratorV2Error>;
482486
readonly getThreadTitles: (
483487
threadIds: ReadonlyArray<ThreadId>,
484488
) => Effect.Effect<Record<ThreadId, string>, OrchestratorV2Error>;
@@ -14540,6 +14544,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1454014544
.findGuestShareThreadId(shareId)
1454114545
.pipe(Effect.mapError(shellProjectionError));
1454214546
}),
14547+
getThreadLinkMetadata: Effect.fn("OrchestratorV2.getThreadLinkMetadata")(function (threadIds) {
14548+
return projectionStore
14549+
.getThreadLinkMetadata(threadIds)
14550+
.pipe(Effect.mapError(shellProjectionError));
14551+
}),
1454314552
getThreadTitles: Effect.fn("OrchestratorV2.getThreadTitles")(function (threadIds) {
1454414553
return projectionStore.getThreadTitles(threadIds).pipe(Effect.mapError(shellProjectionError));
1454514554
}),
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.test.ts
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,24 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {
13271327
{ threadId: ThreadId.make("thread:active"), worktreePath: "/worktrees/active" },
13281328
{ threadId: ThreadId.make("thread:archived"), worktreePath: "/worktrees/archived" },
13291329
]);
1330+
assert.deepEqual(
1331+
yield* store.getThreadLinkMetadata([
1332+
deleted.id,
1333+
ThreadId.make("thread:active"),
1334+
ThreadId.make("thread:archived"),
1335+
ThreadId.make("unknown"),
1336+
]),
1337+
{
1338+
[ThreadId.make("thread:active")]: {
1339+
title: "Title for thread:active",
1340+
projectId: ProjectId.make("project:worktree-paths"),
1341+
},
1342+
[ThreadId.make("thread:archived")]: {
1343+
title: "Title for thread:archived",
1344+
projectId: ProjectId.make("project:worktree-paths"),
1345+
},
1346+
},
1347+
);
13301348
assert.deepEqual(
13311349
yield* store.getThreadTitles([
13321350
deleted.id,
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.ts
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Stream from "effect/Stream";
66
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
77
import { makeThreadFind } from "./ThreadFind.ts";
88
import type {
9+
OrchestrationV2ThreadLinkMetadata,
910
OrchestrationV2SearchThreadInput,
1011
OrchestrationV2SearchThreadResult,
1112
OrchestrationV2ThreadHistoryPage,
@@ -562,6 +563,9 @@ export interface ProjectionStoreV2Shape {
562563
threadId?: ThreadId,
563564
) => Effect.Effect<ReadonlyArray<ProjectionThreadPullRequests>, ProjectionStoreV2Error>;
564565
/** Titles of the given threads that exist, archived ones included. */
566+
readonly getThreadLinkMetadata: (
567+
threadIds: ReadonlyArray<ThreadId>,
568+
) => Effect.Effect<Record<ThreadId, OrchestrationV2ThreadLinkMetadata>, ProjectionStoreV2Error>;
565569
readonly getThreadTitles: (
566570
threadIds: ReadonlyArray<ThreadId>,
567571
) => Effect.Effect<Record<ThreadId, string>, ProjectionStoreV2Error>;
@@ -7306,6 +7310,24 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
73067310
}));
73077311
}, Effect.mapError(shellSnapshotReadError));
73087312

7313+
const getThreadLinkMetadata = Effect.fn("ProjectionStore.getThreadLinkMetadata")(function* (
7314+
threadIds: ReadonlyArray<ThreadId>,
7315+
) {
7316+
if (threadIds.length === 0) return {};
7317+
const rows = yield* sql<{
7318+
readonly thread_id: ThreadId;
7319+
readonly title: string;
7320+
readonly project_id: ProjectId;
7321+
}>`
7322+
SELECT thread_id, title, project_id
7323+
FROM orchestration_v2_projection_threads
7324+
WHERE deleted_at IS NULL AND thread_id IN ${sql.in(threadIds)}
7325+
`;
7326+
return Object.fromEntries(
7327+
rows.map((row) => [row.thread_id, { title: row.title, projectId: row.project_id }]),
7328+
);
7329+
}, Effect.mapError(shellSnapshotReadError));
7330+
73097331
const getThreadTitles = Effect.fn("ProjectionStore.getThreadTitles")(function* (
73107332
threadIds: ReadonlyArray<ThreadId>,
73117333
) {
@@ -7485,6 +7507,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
74857507
getSettlementCandidates: readOnReader(getSettlementCandidates),
74867508
getThreadsWithPullRequests: readOnReader(getThreadsWithPullRequests),
74877509
getThreadTitles: readOnReader(getThreadTitles),
7510+
getThreadLinkMetadata: readOnReader(getThreadLinkMetadata),
74887511
getThreadWorktreePaths: readOnReader(getThreadWorktreePaths),
74897512
getOpenRemoteDelegatedTasks: getOpenRemoteDelegatedTasks.pipe(NodeSqliteClient.readOnly),
74907513
getThreadProjection: readOnReader(getThreadProjection),
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ it.effect(
221221
readShellSnapshot: () => Effect.die("unused readShellSnapshot"),
222222
getThreadShell: () => Effect.die("unused getThreadShell"),
223223
getThreadTitles: () => Effect.die("unused getThreadTitles"),
224+
getThreadLinkMetadata: () => Effect.die("unused getThreadLinkMetadata"),
224225
findGuestShareThreadId: () => Effect.die("unused findGuestShareThreadId"),
225226
getThread: () => Ref.get(projection).pipe(Effect.map((state) => state.thread)),
226227
getSettlementCandidates: () => Effect.die("unused getSettlementCandidates"),
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadManagementService.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ export interface ThreadManagementServiceShape {
423423
>;
424424
readonly getThreadShell: Orchestrator.OrchestratorV2["Service"]["getThreadShell"];
425425
readonly listAppOwnedChildThreadIds: Orchestrator.OrchestratorV2["Service"]["listAppOwnedChildThreadIds"];
426+
readonly getThreadLinkMetadata: Orchestrator.OrchestratorV2["Service"]["getThreadLinkMetadata"];
426427
readonly getThreadTitles: Orchestrator.OrchestratorV2["Service"]["getThreadTitles"];
427428
/** Omit `projectId` to list every project's threads. Side chats are never listed. */
428429
readonly listProjectThreads: (input: {
@@ -1609,6 +1610,7 @@ const make = Effect.gen(function* () {
16091610
},
16101611
),
16111612
getThreadTitles: orchestrator.getThreadTitles,
1613+
getThreadLinkMetadata: orchestrator.getThreadLinkMetadata,
16121614
listProjectThreads,
16131615
sendToThread,
16141616
assertProviderInstanceEnabled,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.