GeezerVison is showing github.com — fix(clients): unloaded thread links show their title and project icon… · adampeterhiggins/t3code@23e3465
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +72Lines changed: 72 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboardExpand all lines: apps/mobile/src/state/entities.ts +39-10Lines changed: 39 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,7 @@ import { threadChipTargets } from "../lib/enrichedLinkPresentation"; | 32 | 32 | import { resolveProjectChipIcon } from "../lib/projectIcon"; | 33 | 33 | import { projectGlyphImageAtom, projectGlyphKey } from "../native/ProjectChipIconImages"; | 34 | 34 | import { projectFaviconUrlAtom } from "./assets"; | | 35 | +import { orchestrationEnvironment } from "./orchestration"; | 35 | 36 | import { environmentProjects } from "./projects"; | 36 | 37 | import { environmentServerConfigsAtom, serverEnvironment } from "./server"; | 37 | 38 | import { environmentThreadDetails, environmentThreadShells } from "./threads"; | @@ -55,12 +56,22 @@ const EMPTY_THREAD_LINK_TITLES_ATOM = Atom.make<ReadonlyMap<string, string>>(new | 55 | 56 | const decodeThreadKey = Schema.decodeUnknownSync(Schema.Tuple([EnvironmentId, ThreadId])); | 56 | 57 | const threadKey = (ref: ScopedThreadRef) => JSON.stringify([ref.environmentId, ref.threadId]); | 57 | 58 |
| 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. | 59 | 60 | const threadTitleAtom = Atom.family((key: string) => { | 60 | 61 | 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}`)); | 64 | 75 | }); | 65 | 76 |
| 66 | 77 | const decodeThreadKeys = Schema.decodeUnknownSync(Schema.Array(Schema.String)); | @@ -92,11 +103,22 @@ const threadProjectChipIconAtom = Atom.family((key: string) => { | 92 | 103 | const ref = scopeThreadRef(...decodeThreadKey(JSON.parse(key))); | 93 | 104 | return Atom.make((get): string | null => { | 94 | 105 | 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 | 96 | 118 | ? get( | 97 | 119 | environmentProjects.projectAtom({ | 98 | 120 | environmentId: ref.environmentId, | 99 | | - projectId: shell.projectId, | | 121 | + projectId: metadata.projectId, | 100 | 122 | }), | 101 | 123 | ) | 102 | 124 | : null; | @@ -222,13 +244,20 @@ export function resolveThreadLink( | 222 | 244 | link: ThreadLink, | 223 | 245 | messageEnvironmentId: EnvironmentId, | 224 | 246 | ): 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 | + }); | 228 | 257 | if (known) return known; | 229 | 258 | return link.environmentId === null | 230 | 259 | ? guessThreadLinkRef(link, read(environmentThreadShells.threadRefsAtom)) | 231 | | - : null; | | 260 | + : scopeThreadRef(link.environmentId, link.threadId); | 232 | 261 | } | 233 | 262 |
| 234 | 263 | export function useThreadChipIcons( | |
Collapse file Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { createOrchestrationEnvironmentAtoms } from "@t3tools/client-runtime/state/orchestration"; | 2 | 2 |
| 3 | 3 | import { connectionAtomRuntime } from "../connection/runtime"; | | 4 | +import { environmentShell } from "./shell"; | 4 | 5 | import { recordReviewTurnDiffAnswer } from "./reviewTurnDiffs"; | 5 | 6 |
| 6 | 7 | export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime, { | | 8 | + shellState: environmentShell.stateValueAtom, | 7 | 9 | onCheckpointDiffAnswer: recordReviewTurnDiffAnswer, | 8 | 10 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/RpcAuthorization.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,6 +52,7 @@ export const RPC_REQUIRED_SCOPES = { | 52 | 52 | [ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: AuthOrchestrationReadScope, | 53 | 53 | [ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: AuthOrchestrationReadScope, | 54 | 54 | [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: AuthOrchestrationReadScope, | | 55 | + [ORCHESTRATION_V2_WS_METHODS.getThreadLinkMetadata]: AuthOrchestrationReadScope, | 55 | 56 | [ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: AuthOrchestrationReadScope, | 56 | 57 | [ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: AuthOrchestrationReadScope, | 57 | 58 | [ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: AuthOrchestrationReadScope, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/observability/RpcInstrumentation.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,7 @@ const RPC_AGGREGATES = { | 25 | 25 | [ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: "orchestration", | 26 | 26 | [ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: "orchestration", | 27 | 27 | [ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: "orchestration", | | 28 | + [ORCHESTRATION_V2_WS_METHODS.getThreadLinkMetadata]: "orchestration", | 28 | 29 | [ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: "orchestration", | 29 | 30 | [ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: "orchestration", | 30 | 31 | [ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: "orchestrationV2", | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { | | 2 | + OrchestrationV2ThreadLinkMetadata, | 2 | 3 | GuestShareId, | 3 | 4 | OrchestrationV2SearchThreadInput, | 4 | 5 | OrchestrationV2SearchThreadResult, | @@ -479,6 +480,9 @@ export interface OrchestratorV2Shape { | 479 | 480 | shareId: GuestShareId, | 480 | 481 | ) => Effect.Effect<ThreadId | null, OrchestratorV2Error>; | 481 | 482 | /** Titles of the given threads that exist, archived ones included. */ | | 483 | + readonly getThreadLinkMetadata: ( | | 484 | + threadIds: ReadonlyArray<ThreadId>, | | 485 | + ) => Effect.Effect<Record<ThreadId, OrchestrationV2ThreadLinkMetadata>, OrchestratorV2Error>; | 482 | 486 | readonly getThreadTitles: ( | 483 | 487 | threadIds: ReadonlyArray<ThreadId>, | 484 | 488 | ) => Effect.Effect<Record<ThreadId, string>, OrchestratorV2Error>; | @@ -14540,6 +14544,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | 14540 | 14544 | .findGuestShareThreadId(shareId) | 14541 | 14545 | .pipe(Effect.mapError(shellProjectionError)); | 14542 | 14546 | }), | | 14547 | + getThreadLinkMetadata: Effect.fn("OrchestratorV2.getThreadLinkMetadata")(function (threadIds) { | | 14548 | + return projectionStore | | 14549 | + .getThreadLinkMetadata(threadIds) | | 14550 | + .pipe(Effect.mapError(shellProjectionError)); | | 14551 | + }), | 14543 | 14552 | getThreadTitles: Effect.fn("OrchestratorV2.getThreadTitles")(function (threadIds) { | 14544 | 14553 | return projectionStore.getThreadTitles(threadIds).pipe(Effect.mapError(shellProjectionError)); | 14545 | 14554 | }), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.test.ts +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1327,6 +1327,24 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () { | 1327 | 1327 | { threadId: ThreadId.make("thread:active"), worktreePath: "/worktrees/active" }, | 1328 | 1328 | { threadId: ThreadId.make("thread:archived"), worktreePath: "/worktrees/archived" }, | 1329 | 1329 | ]); | | 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 | + ); | 1330 | 1348 | assert.deepEqual( | 1331 | 1349 | yield* store.getThreadTitles([ | 1332 | 1350 | deleted.id, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProjectionStore.ts +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import * as Stream from "effect/Stream"; | 6 | 6 | import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; | 7 | 7 | import { makeThreadFind } from "./ThreadFind.ts"; | 8 | 8 | import type { | | 9 | + OrchestrationV2ThreadLinkMetadata, | 9 | 10 | OrchestrationV2SearchThreadInput, | 10 | 11 | OrchestrationV2SearchThreadResult, | 11 | 12 | OrchestrationV2ThreadHistoryPage, | @@ -562,6 +563,9 @@ export interface ProjectionStoreV2Shape { | 562 | 563 | threadId?: ThreadId, | 563 | 564 | ) => Effect.Effect<ReadonlyArray<ProjectionThreadPullRequests>, ProjectionStoreV2Error>; | 564 | 565 | /** Titles of the given threads that exist, archived ones included. */ | | 566 | + readonly getThreadLinkMetadata: ( | | 567 | + threadIds: ReadonlyArray<ThreadId>, | | 568 | + ) => Effect.Effect<Record<ThreadId, OrchestrationV2ThreadLinkMetadata>, ProjectionStoreV2Error>; | 565 | 569 | readonly getThreadTitles: ( | 566 | 570 | threadIds: ReadonlyArray<ThreadId>, | 567 | 571 | ) => Effect.Effect<Record<ThreadId, string>, ProjectionStoreV2Error>; | @@ -7306,6 +7310,24 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> = | 7306 | 7310 | })); | 7307 | 7311 | }, Effect.mapError(shellSnapshotReadError)); | 7308 | 7312 |
| | 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 | + | 7309 | 7331 | const getThreadTitles = Effect.fn("ProjectionStore.getThreadTitles")(function* ( | 7310 | 7332 | threadIds: ReadonlyArray<ThreadId>, | 7311 | 7333 | ) { | @@ -7485,6 +7507,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> = | 7485 | 7507 | getSettlementCandidates: readOnReader(getSettlementCandidates), | 7486 | 7508 | getThreadsWithPullRequests: readOnReader(getThreadsWithPullRequests), | 7487 | 7509 | getThreadTitles: readOnReader(getThreadTitles), | | 7510 | + getThreadLinkMetadata: readOnReader(getThreadLinkMetadata), | 7488 | 7511 | getThreadWorktreePaths: readOnReader(getThreadWorktreePaths), | 7489 | 7512 | getOpenRemoteDelegatedTasks: getOpenRemoteDelegatedTasks.pipe(NodeSqliteClient.readOnly), | 7490 | 7513 | getThreadProjection: readOnReader(getThreadProjection), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -221,6 +221,7 @@ it.effect( | 221 | 221 | readShellSnapshot: () => Effect.die("unused readShellSnapshot"), | 222 | 222 | getThreadShell: () => Effect.die("unused getThreadShell"), | 223 | 223 | getThreadTitles: () => Effect.die("unused getThreadTitles"), | | 224 | + getThreadLinkMetadata: () => Effect.die("unused getThreadLinkMetadata"), | 224 | 225 | findGuestShareThreadId: () => Effect.die("unused findGuestShareThreadId"), | 225 | 226 | getThread: () => Ref.get(projection).pipe(Effect.map((state) => state.thread)), | 226 | 227 | getSettlementCandidates: () => Effect.die("unused getSettlementCandidates"), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadManagementService.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -423,6 +423,7 @@ export interface ThreadManagementServiceShape { | 423 | 423 | >; | 424 | 424 | readonly getThreadShell: Orchestrator.OrchestratorV2["Service"]["getThreadShell"]; | 425 | 425 | readonly listAppOwnedChildThreadIds: Orchestrator.OrchestratorV2["Service"]["listAppOwnedChildThreadIds"]; | | 426 | + readonly getThreadLinkMetadata: Orchestrator.OrchestratorV2["Service"]["getThreadLinkMetadata"]; | 426 | 427 | readonly getThreadTitles: Orchestrator.OrchestratorV2["Service"]["getThreadTitles"]; | 427 | 428 | /** Omit `projectId` to list every project's threads. Side chats are never listed. */ | 428 | 429 | readonly listProjectThreads: (input: { | @@ -1609,6 +1610,7 @@ const make = Effect.gen(function* () { | 1609 | 1610 | }, | 1610 | 1611 | ), | 1611 | 1612 | getThreadTitles: orchestrator.getThreadTitles, | | 1613 | + getThreadLinkMetadata: orchestrator.getThreadLinkMetadata, | 1612 | 1614 | listProjectThreads, | 1613 | 1615 | sendToThread, | 1614 | 1616 | assertProviderInstanceEnabled, | |
|