@devries-cameron20 / t3code-1 / commits / b3011e9508
Fork 0

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

perf(server): narrow agent awareness startup reads (#30561)

Yash Singh committed Nov 3, 2026 at 20:57 UTC b3011e9508e57ea1e555e14a17b51ca50289e5c1
7 files changed +211 -47
apps/server/src/orchestration-v2/Orchestrator.ts
+13
@@ -444,6 +444,12 @@ export interface OrchestratorV2Shape {
444 Effect.Success<ReturnType<ProjectionStoreV2["Service"]["getPullRequestSnapshot"]>>,
445 OrchestratorV2Error
446 >;
447 + readonly getAgentAwarenessSnapshot: (
448 + threadId?: ThreadId,
449 + ) => Effect.Effect<
450 + Effect.Success<ReturnType<ProjectionStoreV2["Service"]["getAgentAwarenessSnapshot"]>>,
451 + OrchestratorV2Error
452 + >;
453 readonly getShellSnapshot: (
454 options?: ShellSnapshotOptions,
455 ) => Effect.Effect<OrchestrationV2ThreadShellSnapshot, OrchestratorV2Error>;
@@ -14189,6 +14195,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
14195 .getPullRequestSnapshot(options)
14196 .pipe(Effect.mapError(shellProjectionError));
14197 }),
14198 + getAgentAwarenessSnapshot: Effect.fn("OrchestratorV2.getAgentAwarenessSnapshot")(
14199 + function (threadId) {
14200 + return projectionStore
14201 + .getAgentAwarenessSnapshot(threadId)
14202 + .pipe(Effect.mapError(shellProjectionError));
14203 + },
14204 + ),
14205 getShellSnapshot: Effect.fn("OrchestratorV2.getShellSnapshot")(function (options) {
14206 return projectionStore.getShellSnapshot(options).pipe(Effect.mapError(shellProjectionError));
14207 }),
apps/server/src/orchestration-v2/ProjectionStore.test.ts
+43 -1
@@ -28,6 +28,7 @@ import {
28 TurnItemId,
29 type ThreadPullRequestLink,
30 isLiveSubagentShell,
31 + isListedThreadLineage,
32 } from "@t3tools/contracts";
33 import * as DateTime from "effect/DateTime";
34 import * as Effect from "effect/Effect";
@@ -96,8 +97,40 @@ const traceSqlStatements = () => {
97 /** The shell index flags every live shell and matches its shells on the fields subscriber trims read. */
98 const assertShellIndexCoversShells = Effect.fnUntraced(function* () {
99 const store = yield* ProjectionStore.ProjectionStoreV2;
99 - const shells = (yield* store.getShellSnapshot({ location: "active" })).threads;
100 + const snapshot = yield* store.getShellSnapshot();
101 + const shells = snapshot.threads;
102 const index = yield* store.listActiveShellIndex();
103 + const { tracer, statements, queryTransactions } = traceSqlStatements();
104 + const activity = yield* store.getAgentAwarenessSnapshot().pipe(Effect.withTracer(tracer));
105 + assert.equal(activity.snapshotSequence, snapshot.snapshotSequence);
106 + const awareness = (thread: Parameters<typeof projectThreadAwarenessV2>[0]["thread"]) =>
107 + projectThreadAwarenessV2({
108 + environmentId: EnvironmentId.make("test"),
109 + project: { title: "Test" },
110 + thread,
111 + });
112 + assert.deepEqual(
113 + activity.threads.map(awareness),
114 + shells.filter((thread) => isListedThreadLineage(thread.lineage)).map(awareness),
115 + );
116 + assert.deepEqual(
117 + activity.threads.map((thread) => [thread.id, thread.projectId, thread.latestRunCompletedAt]),
118 + shells
119 + .filter((thread) => isListedThreadLineage(thread.lineage))
120 + .map((thread) => [thread.id, thread.projectId, thread.latestRunCompletedAt]),
121 + );
122 + assert.isFalse(statements.some((statement) => /COUNT\(\*\)|GROUP BY/i.test(statement)));
123 + assert.isTrue(queryTransactions.every((transaction) => transaction !== null));
124 + assert.equal(new Set(queryTransactions).size, 1);
125 + for (const shell of [...shells, ...snapshot.archivedThreads]) {
126 + const targeted = yield* store
127 + .getAgentAwarenessSnapshot(shell.id)
128 + .pipe(Effect.withTracer(tracer));
129 + assert.deepEqual(targeted.threads.map(awareness), [awareness(shell)]);
130 + assert.deepEqual(targeted.threads[0]?.archivedAt, shell.archivedAt);
131 + }
132 + assert.isFalse(statements.some((statement) => /COUNT\(\*\)|GROUP BY/i.test(statement)));
133 +
134 const iso = (value: DateTime.Utc | null | undefined) =>
135 value == null ? null : DateTime.formatIso(value);
136 const trimmed = (
@@ -250,6 +283,7 @@ it.effect("routes full projection reads to readers and retains uncommitted write
283 },
284 });
285 const { queries, trace } = traceSqlRouting();
286 + yield* store.getAgentAwarenessSnapshot().pipe(trace);
287 const projection = yield* store.getThreadProjection(threadId).pipe(trace);
288 assert.equal(projection.thread.id, threadId);
289 assert.deepEqual(
@@ -309,6 +343,12 @@ it.effect("routes full projection reads to readers and retains uncommitted write
343 SET payload_json = json_set(payload_json, '$.title', 'Uncommitted title')
344 WHERE thread_id = ${threadId}
345 `;
346 + assert.equal(
347 + (yield* store.getAgentAwarenessSnapshot()).threads.find(
348 + (thread) => thread.id === threadId,
349 + )?.title,
350 + "Uncommitted title",
351 + );
352 assert.equal(
353 (yield* store.getThreadProjection(threadId)).thread.title,
354 "Uncommitted title",
@@ -8013,6 +8053,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
8053 });
8054 const project = { title: "Project" };
8055 const environmentId = EnvironmentId.make("environment:held-completion");
8056 + yield* assertShellIndexCoversShells();
8057 const held = yield* store.getThreadShell(threadId);
8058 assert.equal(
8059 held && projectThreadAwarenessV2({ environmentId, project, thread: held })?.phase,
@@ -8028,6 +8069,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
8069 occurredAt: releasedAt,
8070 payload: { ...providerThread, pendingBackgroundTasks: [], updatedAt: releasedAt },
8071 });
8072 + yield* assertShellIndexCoversShells();
8073 const released = yield* store.getThreadShell(threadId);
8074 const state =
8075 released && projectThreadAwarenessV2({ environmentId, project, thread: released });
apps/server/src/orchestration-v2/ProjectionStore.ts
+95 -2
@@ -1,3 +1,4 @@
1 +import type { ProjectThreadAwarenessV2Input } from "@t3tools/shared/agentAwareness";
2 import { pendingGuestMessageCount } from "@t3tools/contracts";
3 import { applyThreadPullRequestLinkUpdate } from "../sourceControl/threadPullRequests.ts";
4 import { projectTurnItemForWire } from "./WireProjection.ts";
@@ -491,6 +492,12 @@ export interface ProjectionStoreV2Shape {
492 },
493 ProjectionStoreV2Error
494 >;
495 + readonly getAgentAwarenessSnapshot: (
496 + threadId?: ThreadId,
497 + ) => Effect.Effect<
498 + { readonly snapshotSequence: number; readonly threads: ReadonlyArray<AgentAwarenessThread> },
499 + ProjectionStoreV2Error
500 + >;
501 readonly getShellSnapshot: (
502 options?: ShellSnapshotOptions,
503 ) => Effect.Effect<OrchestrationV2ThreadShellSnapshot, ProjectionStoreV2Error>;
@@ -980,6 +987,17 @@ type ShellPendingTurnItemRow = PayloadRow & {
987 readonly owning_provider_instance_id: string | null;
988 };
989
990 +export type AgentAwarenessThread = ProjectThreadAwarenessV2Input["thread"] &
991 + Pick<
992 + OrchestrationV2ThreadShell,
993 + | "projectId"
994 + | "latestRunCompletedAt"
995 + | "archivedAt"
996 + | "activeRunId"
997 + | "latestRunId"
998 + | "hasActionableProposedPlan"
999 + >;
1000 +
1001 type ShellThreadRow = {
1002 readonly thread_id: string;
1003 readonly payload_json: string;
@@ -6077,7 +6095,8 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6095 familyOf,
6096 worktreePath,
6097 threadIds,
6080 - }: ShellSnapshotOptions = {},
6098 + listedOnly = false,
6099 + }: ShellSnapshotOptions & { readonly listedOnly?: boolean } = {},
6100 ) =>
6101 sql<ShellThreadRow>`
6102 SELECT
@@ -6259,7 +6278,12 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6278 candidate.ordinal DESC, candidate.run_id DESC
6279 LIMIT 1
6280 ) AND blocked.status = 'failed'
6262 - WHERE t.deleted_at IS NULL${threadId === undefined ? sql`` : sql` AND t.thread_id = ${threadId}`}${
6281 + WHERE t.deleted_at IS NULL${
6282 + listedOnly
6283 + ? sql` AND json_extract(t.payload_json, '$.lineage.relationshipToParent') IS NOT 'subagent'
6284 + AND json_extract(t.payload_json, '$.lineage.sideChat') IS NOT 1`
6285 + : sql``
6286 + }${threadId === undefined ? sql`` : sql` AND t.thread_id = ${threadId}`}${
6287 projectId === undefined ? sql`` : sql` AND t.project_id = ${projectId}`
6288 }${
6289 location === "active"
@@ -6990,6 +7014,74 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
7014 return { snapshotSequence: sequenceRows[0]?.snapshot_sequence ?? 0, threads };
7015 }, Effect.mapError(shellSnapshotReadError));
7016
7017 + const getAgentAwarenessSnapshot = Effect.fn("ProjectionStore.getAgentAwarenessSnapshot")(
7018 + function* (threadId?: ThreadId) {
7019 + const { threadRows, providerThreadRows, pendingTurnItemRows, sequenceRows } =
7020 + yield* sql.withTransaction(
7021 + Effect.gen(function* () {
7022 + const threadRows = yield* selectShellThreadRows(
7023 + threadId,
7024 + threadId === undefined ? { location: "active", listedOnly: true } : {},
7025 + );
7026 + const ids = threadRows.map((row) => ThreadId.make(row.thread_id));
7027 + const providerThreadRows =
7028 + ids.length === 0 ? [] : yield* selectShellProviderThreadRows(ids);
7029 + const pendingTurnItemRows =
7030 + ids.length === 0
7031 + ? []
7032 + : yield* selectShellPendingTurnItemRows(
7033 + ids,
7034 + threadRows.flatMap((row) =>
7035 + row.active_run_id !== null && row.active_run_status === "running"
7036 + ? [row.active_run_id]
7037 + : [],
7038 + ),
7039 + );
7040 + const sequenceRows = yield* sql<{ readonly snapshot_sequence: number | null }>`
7041 + SELECT MAX(sequence) AS snapshot_sequence FROM orchestration_events
7042 + WHERE application_event_version = 2 AND aggregate_kind = 'thread'
7043 + `;
7044 + return { threadRows, providerThreadRows, pendingTurnItemRows, sequenceRows };
7045 + }),
7046 + );
7047 + const { providerThreadsByThreadId, pendingTurnItemsByThreadId } =
7048 + yield* pendingBackgroundDataByThreadId({ providerThreadRows, pendingTurnItemRows });
7049 + const threads = yield* Effect.forEach(threadRows, (row) =>
7050 + shellThreadStateFromRow({
7051 + row,
7052 + // Awareness never consumes timeline counts or inherited fork history.
7053 + runOrdinalsByThreadId: new Map(),
7054 + itemCountsByThreadId: new Map(),
7055 + shellItemCountsByThreadId: new Map(),
7056 + providerThreadsByThreadId,
7057 + pendingTurnItemsByThreadId,
7058 + }).pipe(
7059 + Effect.map((state): AgentAwarenessThread => ({
7060 + id: state.thread.id,
7061 + projectId: state.thread.projectId,
7062 + archivedAt: state.thread.archivedAt,
7063 + activeRunId: state.activeRunId,
7064 + latestRunId: state.latestRunId,
7065 + hasActionableProposedPlan: state.hasActionableProposedPlan,
7066 + title: state.thread.title,
7067 + lineage: state.thread.lineage,
7068 + modelSelection: state.thread.modelSelection,
7069 + settledOverride: state.thread.settledOverride,
7070 + updatedAt: state.updatedAt,
7071 + status: state.latestRunStatus,
7072 + activityRunStatus: state.activityRunStatus,
7073 + latestRunCompletedAt: state.latestRunCompletedAt,
7074 + latestRunStopRequested: state.latestRunStopRequested,
7075 + pendingRuntimeRequest: state.pendingRuntimeRequest,
7076 + pendingBackgroundTasks: state.pendingBackgroundTasks,
7077 + })),
7078 + ),
7079 + );
7080 + return { snapshotSequence: sequenceRows[0]?.snapshot_sequence ?? 0, threads };
7081 + },
7082 + Effect.mapError(shellSnapshotReadError),
7083 + );
7084 +
7085 const getShellSnapshot: ProjectionStoreV2Shape["getShellSnapshot"] = (options) =>
7086 sql
7087 .withTransaction(readShellSnapshotRows(options))
@@ -7257,6 +7349,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
7349
7350 return {
7351 apply,
7352 + getAgentAwarenessSnapshot: readOnReader(getAgentAwarenessSnapshot),
7353 getShellSnapshot: readOnReader(getShellSnapshot),
7354 getPullRequestSnapshot: readOnReader(getPullRequestSnapshot),
7355 listActiveSubagentThreadIds: readOnReader(listActiveSubagentThreadIds),
apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
+1
@@ -212,6 +212,7 @@ it.effect(
212 getLimitRecoveryCandidates: () => Effect.die("unused getLimitRecoveryCandidates"),
213 getLimitRecoveryWakeAt: () => Effect.die("unused getLimitRecoveryWakeAt"),
214 getOpenRemoteDelegatedTasks: Effect.die("unused getOpenRemoteDelegatedTasks"),
215 + getAgentAwarenessSnapshot: () => Effect.die("unused awareness snapshot"),
216 getShellSnapshot: () => Effect.die("unused getShellSnapshot"),
217 listActiveSubagentThreadIds: () => Effect.die("unused listActiveSubagentThreadIds"),
218 countThreads: () => Effect.die("unused countThreads"),
apps/server/src/orchestration-v2/ThreadManagementService.ts
+2
@@ -402,6 +402,7 @@ export interface ThreadManagementServiceShape {
402 ProjectionRecords<K>,
403 ThreadManagementProjectionLoadError | ThreadManagementThreadNotFoundError
404 >;
405 + readonly getAgentAwarenessSnapshot: Orchestrator.OrchestratorV2["Service"]["getAgentAwarenessSnapshot"];
406 readonly getShellSnapshot: (
407 options?: Pick<
408 ShellSnapshotOptions,
@@ -1520,6 +1521,7 @@ const make = Effect.gen(function* () {
1521 getThreadTranscript,
1522 getThreadSnapshotWindow,
1523 getProjectThreadRecords,
1524 + getAgentAwarenessSnapshot: orchestrator.getAgentAwarenessSnapshot,
1525 getShellSnapshot: orchestrator.getShellSnapshot,
1526 listActiveSubagentThreadIds: orchestrator.listActiveSubagentThreadIds,
1527 countThreads: orchestrator.countThreads,
apps/server/src/relay/AgentAwarenessRelay.test.ts
+48 -28
@@ -144,6 +144,7 @@ const makeTestRelay = Effect.fnUntraced(function* (
144 readonly linked?: boolean;
145 readonly readShell?: (threadId: ThreadId) => Effect.Effect<OrchestrationV2ThreadShell | null>;
146 readonly domainEvents?: Stream.Stream<OrchestrationV2DomainEvent>;
147 + readonly catchUpThreads?: ReadonlyArray<OrchestrationV2ThreadShell>;
148 } = {},
149 ) {
150 const values = new Map<string, Uint8Array>(
@@ -178,17 +179,23 @@ const makeTestRelay = Effect.fnUntraced(function* (
179 });
180 const currentShell = yield* Ref.make<OrchestrationV2ThreadShell | null>(shell());
181 const shellReads: ThreadId[] = [];
181 - const catchUp = { shellSnapshotReads: 0 };
182 + const catchUp = { activitySnapshotReads: 0 };
183 const threads = ThreadManagementService.ThreadManagementService.of({
183 - getThreadShell: (threadId) =>
184 - Effect.sync(() => shellReads.push(threadId)).pipe(
185 - Effect.andThen(options.readShell?.(threadId) ?? Ref.get(currentShell)),
186 - ),
187 - getShellSnapshot: () =>
188 - Effect.sync(() => {
189 - catchUp.shellSnapshotReads += 1;
190 - return { schemaVersion: 2, snapshotSequence: 1, threads: [], archivedThreads: [] };
191 - }),
184 + getThreadShell: unused,
185 + getShellSnapshot: unused,
186 + getAgentAwarenessSnapshot: (threadId) =>
187 + threadId === undefined
188 + ? Effect.sync(() => {
189 + catchUp.activitySnapshotReads += 1;
190 + return { snapshotSequence: 1, threads: options.catchUpThreads ?? [] };
191 + })
192 + : Effect.sync(() => shellReads.push(threadId)).pipe(
193 + Effect.andThen(options.readShell?.(threadId) ?? Ref.get(currentShell)),
194 + Effect.map((thread) => ({
195 + snapshotSequence: 1,
196 + threads: thread === null ? [] : [thread],
197 + })),
198 + ),
199 listActiveSubagentThreadIds: unused,
200 listAppOwnedChildThreadIds: unused,
201 countThreads: unused,
@@ -258,6 +265,16 @@ const makeTestRelay = Effect.fnUntraced(function* (
265 },
266 { preconnect: () => {} },
267 );
268 + const project = {
269 + id: PROJECT_ID,
270 + title: "Project",
271 + workspaceRoot: "/workspace",
272 + defaultModelSelection: null,
273 + scripts: [],
274 + createdAt: NOW,
275 + updatedAt: NOW,
276 + deletedAt: null,
277 + };
278 const relay = yield* AgentAwarenessRelay.make.pipe(
279 Effect.provideService(ServerSecretStore.ServerSecretStore, secrets),
280 Effect.provideService(ThreadManagementService.ThreadManagementService, threads),
@@ -271,21 +288,11 @@ const makeTestRelay = Effect.fnUntraced(function* (
288 update: unused,
289 delete: unused,
290 getByWorkspaceRoot: unused,
274 - snapshot: Effect.succeed({ projects: [] } as never),
291 + snapshot: Effect.succeed({ projects: [project], updatedAt: NOW }),
292 listPage: unused,
293 getShell: unused,
294 listShells: unused,
278 - getById: () =>
279 - Effect.succeedSome({
280 - id: PROJECT_ID,
281 - title: "Project",
282 - workspaceRoot: "/workspace",
283 - defaultModelSelection: null,
284 - scripts: [],
285 - createdAt: NOW,
286 - updatedAt: NOW,
287 - deletedAt: null,
288 - }),
295 + getById: () => Effect.succeedSome(project),
296 }),
297 Effect.provideService(FetchHttpClient.Fetch, fetch),
298 Effect.provide(NodeCrypto.layer),
@@ -831,24 +838,34 @@ describe("AgentAwarenessRelay", () => {
838
839 it.effect("catches up after startup without polling after success", () =>
840 Effect.gen(function* () {
834 - const { relay, secrets, secretReads, catchUp } = yield* makeTestRelay();
841 + const { relay, secrets, secretReads, catchUp, publications } = yield* makeTestRelay({
842 + catchUpThreads: [shell()],
843 + });
844 yield* relay.start();
845 yield* TestClock.adjust("1 second");
837 - assert.equal(catchUp.shellSnapshotReads, 1);
846 + yield* relay.drain;
847 + assert.equal(catchUp.activitySnapshotReads, 1);
848 + assert.equal(publications.length, 1);
849 + assert.include(publications[0]?.state, {
850 + threadId: THREAD_ID,
851 + projectTitle: "Project",
852 + threadTitle: "Thread",
853 + phase: "running",
854 + });
855
856 yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("false"));
857 yield* relay.requestCatchUp();
858 yield* TestClock.adjust("1 second");
842 - assert.equal(catchUp.shellSnapshotReads, 1);
859 + assert.equal(catchUp.activitySnapshotReads, 1);
860
861 yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("true"));
862 yield* relay.requestCatchUp();
863 yield* TestClock.adjust("1 second");
847 - assert.equal(catchUp.shellSnapshotReads, 2);
864 + assert.equal(catchUp.activitySnapshotReads, 2);
865
866 const readsBeforeIdle = secretReads.length;
867 yield* TestClock.adjust("10 minutes");
851 - assert.equal(catchUp.shellSnapshotReads, 2);
868 + assert.equal(catchUp.activitySnapshotReads, 2);
869 assert.equal(secretReads.length, readsBeforeIdle);
870
871 yield* secrets.set(
@@ -857,6 +874,9 @@ it.effect("catches up after startup without polling after success", () =>
874 );
875 yield* relay.requestCatchUp();
876 yield* TestClock.adjust("1 second");
860 - assert.equal(catchUp.shellSnapshotReads, 3);
877 + yield* relay.drain;
878 + assert.equal(catchUp.activitySnapshotReads, 3);
879 + assert.equal(publications.length, 2);
880 + assert.equal(publications[1]?.state?.threadId, THREAD_ID);
881 }).pipe(Effect.scoped),
882 );
apps/server/src/relay/AgentAwarenessRelay.ts
+9 -16
@@ -1,8 +1,8 @@
1 +import type { AgentAwarenessThread } from "../orchestration-v2/ProjectionStore.ts";
2 import {
3 isListedThreadLineage,
4 type EnvironmentId,
5 type OrchestrationV2DomainEvent,
5 - type OrchestrationV2ThreadShell,
6 type OrchestrationV2TurnItem,
7 type Project,
8 type ThreadId,
@@ -283,7 +283,7 @@ const makePublishProof = Effect.fn("makePublishProof")(function* (input: {
283 });
284
285 function describeThreadShellForAwareness(
286 - thread: Option.Option<OrchestrationV2ThreadShell>,
286 + thread: Option.Option<AgentAwarenessThread>,
287 ): Record<string, unknown> {
288 if (Option.isNone(thread)) {
289 return { found: false };
@@ -302,7 +302,7 @@ function describeThreadShellForAwareness(
302
303 function resolveAgentAwarenessRelayPublishSnapshot(input: {
304 readonly environmentId: EnvironmentId;
305 - readonly thread: Option.Option<OrchestrationV2ThreadShell>;
305 + readonly thread: Option.Option<AgentAwarenessThread>;
306 readonly project: Option.Option<Project>;
307 }): {
308 readonly projectId: string | null;
@@ -336,7 +336,7 @@ function resolveAgentAwarenessRelayPublishSnapshot(input: {
336 };
337 }
338
339 -function terminalWorkSinceStart(thread: OrchestrationV2ThreadShell, startedAt: number): boolean {
339 +function terminalWorkSinceStart(thread: AgentAwarenessThread, startedAt: number): boolean {
340 return (
341 thread.latestRunCompletedAt != null &&
342 DateTime.toEpochMillis(thread.latestRunCompletedAt) > startedAt
@@ -347,7 +347,7 @@ export function resolveAgentAwarenessRelayActiveThreadIds(input: {
347 readonly environmentId: EnvironmentId;
348 readonly startedAt: number;
349 readonly projects: ReadonlyArray<Pick<Project, "id" | "title">>;
350 - readonly threads: ReadonlyArray<OrchestrationV2ThreadShell>;
350 + readonly threads: ReadonlyArray<AgentAwarenessThread>;
351 }): ReadonlyArray<ThreadId> {
352 const projectById = new Map(input.projects.map((project) => [project.id, project]));
353 return input.threads
@@ -524,7 +524,7 @@ export const make = Effect.gen(function* () {
524 });
525
526 // Read only this thread; full shell reads would make each activity event scale with all threads.
527 - const threadShell = yield* threads.getThreadShell(threadId);
527 + const threadShell = (yield* threads.getAgentAwarenessSnapshot(threadId)).threads[0] ?? null;
528 if (
529 threadShell !== null &&
530 !isListedThreadLineage(threadShell.lineage) &&
@@ -535,7 +535,7 @@ export const make = Effect.gen(function* () {
535 }
536 const thread =
537 threadShell === null || threadShell.archivedAt !== null
538 - ? Option.none<OrchestrationV2ThreadShell>()
538 + ? Option.none<AgentAwarenessThread>()
539 : Option.some(threadShell);
540 const project = Option.isSome(thread)
541 ? yield* projects.getById(thread.value.projectId)
@@ -735,19 +735,12 @@ export const make = Effect.gen(function* () {
735 }
736 const environmentId = yield* serverEnvironment.getEnvironmentId;
737 const projectSnapshot = yield* projects.snapshot;
738 - // Subagents and side chats never publish awareness, and subagents are most threads.
739 - const topLevelThreadIds = (yield* threads.listActiveShellIndex()).flatMap((thread) =>
740 - isListedThreadLineage(thread.lineage) ? [thread.id] : [],
741 - );
742 - const shellSnapshot = yield* threads.getShellSnapshot({
743 - location: "active",
744 - threadIds: topLevelThreadIds,
745 - });
738 + const activitySnapshot = yield* threads.getAgentAwarenessSnapshot();
739 const activeThreadIds = resolveAgentAwarenessRelayActiveThreadIds({
740 environmentId,
741 startedAt,
742 projects: projectSnapshot.projects,
750 - threads: shellSnapshot.threads,
743 + threads: activitySnapshot.threads,
744 });
745 if (activeThreadIds.length === 0) {
746 yield* Effect.logDebug("agent activity snapshot has no publishable threads");