Add shell snapshot queries for orchestration state #1973
Mergedjuliusmarmingemerged 13 commits into
main fromrefs/pull/1973/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- @@ -726,0 +1014,21 @@1014+ updatedAt = maxIso(updatedAt, row.startedAt);1015+ }1016+ if (row.completedAt !== null) {1017+ updatedAt = maxIso(updatedAt, row.completedAt);1018+ }1019+ }1020+ for (const row of stateRows) {1021+ updatedAt = maxIso(updatedAt, row.updatedAt);1022+ }1023+1024+ const repositoryIdentities = new Map(1025+ yield* Effect.forEach(1026+ projectRows,1027+ (row) =>1028+ repositoryIdentityResolver1029+ .resolve(row.workspaceRoot)1030+ .pipe(Effect.map((identity) => [row.projectId, identity] as const)),1031+ { concurrency: repositoryIdentityResolutionConcurrency },1032+ ),1033+ );1034+ const latestTurnByThread = new Map(@@ -78,6 +53,18 @@78- }53+ wait: () => promise,54+ resolve: () => {55+ resolve?.();56+ resolve = null;57+ reject = null;58+ },59+ reject: (error: unknown) => {60+ reject?.(error);61+ resolve = null;62+ reject = null;63+ },64+ reset: () => {65+ promise = new Promise<void>((nextResolve, nextReject) => {66+ resolve = nextResolve;67+ reject = nextReject;7968 });80- inFlight = nextInFlight;81- return inFlight;8269 },8370 };apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts lines 577 to 594OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -417,0 +574,21 @@574+ `,575+ });576+577+ const listThreadActivityRowsByThread = SqlSchema.findAll({578+ Request: ThreadIdLookupInput,579+ Result: ProjectionThreadActivityDbRowSchema,580+ execute: ({ threadId }) =>581+ sql`582+ SELECT583+ activity_id AS "activityId",584+ thread_id AS "threadId",585+ turn_id AS "turnId",586+ tone,587+ kind,588+ summary,589+ payload_json AS "payload",590+ sequence,591+ created_at AS "createdAt"592+ FROM projection_thread_activities593+ WHERE thread_id = ${threadId}594+ ORDER BY created_at ASC, activity_id ASC
- @@ -221,0 +252,21 @@252+} {253+ const shell: ThreadShell = {254+ id: thread.id,255+ environmentId,256+ codexThreadId: null,257+ projectId: thread.projectId,258+ title: thread.title,259+ modelSelection: normalizeModelSelection(thread.modelSelection),260+ runtimeMode: thread.runtimeMode,261+ interactionMode: thread.interactionMode,262+ error: sanitizeThreadErrorMessage(thread.session?.lastError),263+ createdAt: thread.createdAt,264+ archivedAt: thread.archivedAt,265+ updatedAt: thread.updatedAt,266+ branch: thread.branch,267+ worktreePath: thread.worktreePath,268+ };269+ const session = thread.session ? mapSession(thread.session) : null;270+ const turnState: ThreadTurnState = {271+ latestTurn: thread.latestTurn,272+ };@@ -193,3 +196,21 @@193196 };194197 }195198199+function mapProjectShell(200+ project: OrchestrationShellSnapshot["projects"][number],201+ environmentId: EnvironmentId,202+): Project {203+ return {204+ id: project.id,205+ environmentId,206+ name: project.title,207+ cwd: project.workspaceRoot,208+ repositoryIdentity: project.repositoryIdentity ?? null,209+ defaultModelSelection: project.defaultModelSelection210+ ? normalizeModelSelection(project.defaultModelSelection)211+ : null,212+ createdAt: project.createdAt,213+ updatedAt: project.updatedAt,214+ scripts: mapProjectScripts(project.scripts),215+ };216+}
- @@ -565,3 +679,4 @@565679 ...existingRow.value,566680 updatedAt: event.occurredAt,567681 });682+ yield* refreshThreadShellSummary(event.payload.threadId);apps/web/src/environments/runtime/connection.ts line 166Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -320,8 +153,14 @@320153 environmentId,321154 knownEnvironment: input.knownEnvironment,322155 client: input.client,323- ensureBootstrapped: () => snapshotBootstrap.ensureSnapshotRecovery("bootstrap"),156+ ensureBootstrapped: () => bootstrapGate.wait(),324157 reconnect: async () => {325- await input.client.reconnect();326- await input.refreshMetadata?.();327- await snapshotBootstrap.ensureSnapshotRecovery("bootstrap");158+ bootstrapGate.reset();159+ try {160+ await input.client.reconnect();161+ await input.refreshMetadata?.();162+ await bootstrapGate.wait();163+ } catch (error) {164+ bootstrapGate.reject(error);165+ throw error;166+ }
- apps/web/src/environments/runtime/service.ts line 145Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -76,0 +125,21 @@125+ useStore.getState().syncServerThreadDetail(item.snapshot.thread, entry.environmentId);126+ return;127+ }128+ applyEnvironmentThreadDetailEvent(item.event, entry.environmentId);129+ },130+ );131+ return true;132+}133+134+function watchThreadDetailSubscriptionConnection(entry: ThreadDetailSubscriptionEntry): void {135+ if (entry.unsubscribeConnectionListener !== null) {136+ return;137+ }138+139+ entry.unsubscribeConnectionListener = subscribeEnvironmentConnections(() => {140+ if (attachThreadDetailSubscription(entry)) {141+ entry.lastAccessedAt = Date.now();142+ }143+ });144+ attachThreadDetailSubscription(entry);145+}@@ -224,0 +275,21 @@275+ threadId: event.payload.threadId,276+ }),277+ );278+ default:279+ if (event.aggregateKind !== "thread") {280+ return Effect.succeed(Option.none());281+ }282+ return projectionSnapshotQuery283+ .getThreadShellById(ThreadId.make(event.aggregateId))284+ .pipe(285+ Effect.map((thread) =>286+ Option.map(thread, (nextThread) => ({287+ kind: "thread-upserted" as const,288+ sequence: event.sequence,289+ thread: nextThread,290+ })),291+ ),292+ Effect.catch(() => Effect.succeed(Option.none())),293+ );294+ }295+ };
- @@ -63,2 +64,21 @@6364 import { respondToAuthError } from "./auth/http";646566+function isThreadDetailEvent(event: OrchestrationEvent): event is Extract<67+ OrchestrationEvent,68+ {69+ type:70+ | "thread.message-sent"71+ | "thread.proposed-plan-upserted"72+ | "thread.activity-appended"73+ | "thread.turn-diff-completed"74+ | "thread.reverted";75+ }76+> {77+ return (78+ event.type === "thread.message-sent" ||79+ event.type === "thread.proposed-plan-upserted" ||80+ event.type === "thread.activity-appended" ||81+ event.type === "thread.turn-diff-completed" ||82+ event.type === "thread.reverted"83+ );84+}apps/web/src/components/ChatView.browser.tsx line 426Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -415,12 +400,13 @@400+ updatedAt: thread.updatedAt,401+ archivedAt: thread.archivedAt,402+ session: thread.session,403+ latestUserMessageAt:404+ thread.messages.findLast((message) => message.role === "user")?.createdAt ?? null,405+ hasPendingApprovals: false,406+ hasPendingUserInput: false,407+ hasActionableProposedPlan: false,415408 };416409 }417410418-function createThreadSessionSetEvent(threadId: ThreadId, sequence: number): OrchestrationEvent {411+function toShellSnapshot(snapshot: OrchestrationReadModel) {419412 return {420- sequence,421- eventId: EventId.make(`event-thread-session-set-${sequence}`),422- aggregateKind: "thread",423- aggregateId: threadId,424- occurredAt: NOW_ISO,425- commandId: null,426- causationEventId: null,
- @@ -171,0 +186,21 @@186+ projectId: thread.projectId,187+ title: thread.title,188+ modelSelection: thread.modelSelection,189+ runtimeMode: thread.runtimeMode,190+ interactionMode: thread.interactionMode,191+ branch: thread.branch,192+ worktreePath: thread.worktreePath,193+ latestTurn: thread.latestTurn,194+ createdAt: thread.createdAt,195+ updatedAt: thread.updatedAt,196+ archivedAt: thread.archivedAt,197+ session: thread.session,198+ latestUserMessageAt:199+ thread.messages.findLast((message) => message.role === "user")?.createdAt ?? null,200+ hasPendingApprovals: false,201+ hasPendingUserInput: false,202+ hasActionableProposedPlan: false,203+ })),204+ updatedAt: snapshot.updatedAt,205+ };206+}
juliusmarminge merged thisf7fa62a
juliusmarminge closed this
Sign in to join this conversation.



Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
07254fda-24a9-4d63-86f5-33bb2cb2151bYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.