fix(server): restore queued turn identity after restart #10611
Closedsaphid(GitHub profile, opens in a new tab)wants to merge 9 commits into
main fromrefs/pull/10611/headopened 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:L
- apps/server/src/orchestration/Layers/CheckpointReactor.ts line 797OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -756,3 +792,6 @@756792 const restored = yield* checkpointStore.restoreCheckpoint({757793 cwd: sessionRuntime.value.cwd,758794 checkpointRef: targetCheckpointRef,795+ ...(currentTurnCount > 0796+ ? {797+ fromCheckpointRef: thread.checkpoints.find(
- @@ -273,3 +273,5 @@273273 }),274274 );275275276+const CheckpointAndProviderCommandReactorsLive = ProviderCommandReactorLive.pipe(277+ Layer.provideMerge(CheckpointReactorLive),
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/orchestration/Layers/ProjectionPipeline.ts line 1532OutdatedResolvedby saphid(GitHub profile, opens in a new tab)@@ -1343,3 +1366,5 @@13431366 }),13441367 { concurrency: 1 },13451368 );1369+ yield* Effect.forEach(1370+ existingTurns.filter((turn) => turn.turnId !== null && turn.state === "running"),apps/server/src/serverRuntimeStartup.ts lines 633 to 635OutdatedResolvedby saphid(GitHub profile, opens in a new tab)@@ -606,0 +615,21 @@615+ yield* orchestrationEngine.dispatch({616+ type: "thread.activity.append",617+ commandId,618+ threadId: thread.id,619+ activity: {620+ id: eventId,621+ tone: "error",622+ kind: "provider.turn.start.failed",623+ summary: "Provider turn start failed",624+ payload: {625+ detail:626+ "The server restarted after the provider accepted this turn but before it started.",627+ requestId: submitted.messageId,628+ },629+ turnId: submitted.turnId,630+ createdAt,631+ },632+ createdAt,633+ });634+ }),635+ { concurrency: 1, discard: true },
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 1230OutdatedResolvedby saphid(GitHub profile, opens in a new tab)@@ -1183,3 +1210,21 @@1210+ ),1211+ Effect.retry({1212+ while: (cause) => !Cause.hasInterrupts(cause),1213+ schedule: Schedule.exponential("100 millis").pipe(1214+ Schedule.modifyDelay(({ duration }) =>1215+ Effect.succeed(Duration.min(duration, Duration.seconds(5))),1216+ ),1217+ ),1218+ }),1219+ Effect.catch((cause) => Effect.failCause(cause)),1220+ );1221+ },1222+ );1223+11831224 const processTurnStartRequested = Effect.fn("processTurnStartRequested")(function* (11841225 event: Extract<ProviderIntentEvent, { type: "thread.turn-start-requested" }>,11851226 ) {1227+ // Checkpoint and provider reactors consume the same ordered domain stream on1228+ // independent workers. Cross this sequence barrier before a later turn can1229+ // mutate files or provider history that an earlier revert is still restoring.1230+ yield* checkpointReactor.awaitDomainSequence(event.sequence);apps/server/src/persistence/Layers/ProjectionTurns.ts line 388OutdatedResolvedby saphid(GitHub profile, opens in a new tab)@@ -167,0 +249,21 @@249+ `,250+ });251+252+ const getAdoptableProjectionTurn = SqlSchema.findOneOption({253+ Request: GetProjectionAdoptableTurnStartInput,254+ Result: ProjectionPendingTurnStart,255+ execute: ({ threadId, turnId }) =>256+ sql`257+ SELECT258+ thread_id AS "threadId",259+ pending_message_id AS "messageId",260+ source_proposed_plan_thread_id AS "sourceProposedPlanThreadId",261+ source_proposed_plan_id AS "sourceProposedPlanId",262+ requested_at AS "requestedAt"263+ FROM projection_turns AS candidate264+ WHERE candidate.thread_id = ${threadId}265+ AND candidate.turn_id IS NULL266+ AND (267+ (candidate.state = 'submitted' AND candidate.submitted_turn_id = ${turnId})268+ OR (269+ candidate.state = 'pending'
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed