fix(server): runs no longer get stuck #15048
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/15048/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/ProviderTurnStartService.ts line 133Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -124,8 +124,10 @@124124 }) => {125125 // Guards and background routing need live execution state, not a fresh126126 // allocation of every completed message and tool output in the thread.127+ // `false` means the run moved on or is gone. A failed read is an error,128+ // so the caller fails the start or the run instead of skipping it.127129 const isCurrentAttemptInStatus = (expectedStatus: OrchestrationV2Run["status"]) =>128130 projectionStore.getRuntimeRecoveryProjection(input.threadId).pipe(129131 Effect.map((current) => {130132 const run = current.runs.find((candidate) => candidate.id === input.runId);131133 return run?.activeAttemptId === input.attemptId && run.status === expectedStatus;apps/server/src/orchestration-v2/EventSink.ts line 254Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -226,0 +234,21 @@234+ // sequence they have applied. So a writer takes this lane as the last step235+ // of its transaction and holds it until it has published. Publishing never236+ // waits, so a writer that holds the transaction while it waits for the237+ // lane is not blocked for long.238+ const publishLane = yield* Semaphore.make(1);239+ const commitThenPublish = <A, E, R>(240+ transaction: Effect.Effect<A, E, R>,241+ publish: (committed: A) => Effect.Effect<void>,242+ ) =>243+ Effect.suspend(() => {244+ let holdsLane = false;245+ const takeLane = publishLane.take(1).pipe(246+ Effect.andThen(247+ Effect.sync(() => {248+ holdsLane = true;249+ }),250+ ),251+ Effect.uninterruptible,252+ );253+ return sql254+ .withTransaction(Effect.tap(transaction, () => takeLane))apps/server/src/orchestration-v2/ProviderSessionManager.ts line 639Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -629,4 +636,4 @@629636 (request) =>630637 request.status === "pending" &&631638 request.responseCapability.type === "live" &&632- request.responseCapability.providerSessionId === providerSessionId,639+ request.responseCapability.providerSessionId === providerSessionId &&
- @@ -710,0 +761,21 @@761+ );762+ if (Exit.isSuccess(exit) || Cause.hasInterruptsOnly(exit.cause)) return yield* exit;763+ yield* Effect.logWarning("orchestration-v2.provider-session-release-records-failed", {764+ providerSessionId,765+ cause: exit.cause,766+ });767+ // A failed SQL commit is a defect, so every failure but interruption768+ // is retried.769+ return yield* Effect.fail(exit.cause);770+ });771+ return attempt.pipe(772+ Effect.retry({773+ schedule: Schedule.exponential("1 second").pipe(774+ Schedule.modifyDelay(({ duration }) =>775+ Effect.succeed(Duration.min(duration, Duration.seconds(30))),776+ ),777+ ),778+ }),779+ Effect.delay("1 second"),780+ FiberSet.run(releaseRecordRetries),781+ );@@ -1286,12 +1288,9 @@12861288 checkpointScope: input.checkpointScope,12871289 providerThread,12881290 attempt: input.attempt,1289- ...(input.shouldFinalizeRun === undefined1290- ? {}1291- : { shouldFinalizeRun: input.shouldFinalizeRun }),1292- ...(input.hasUnpairedRunInterruptRequest === undefined1293- ? {}1294- : {1295- hasUnpairedRunInterruptRequest:1296- input.hasUnpairedRunInterruptRequest,1297- }),1291+ // The failure may be the ownership1292+ // read itself, so check in the write.1293+ writeIfRunCurrent: {1294+ activeAttemptId: input.attempt.id,1295+ expectedStatus: "running",1296+ },
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed