[orchestrator-v2] fix(orchestrator): Restore Claude session continuity for resume, wake, and idle release #3860
Mergedmwolson(GitHub profile, opens in a new tab)merged 3 commits into
t3code/codex-turn-mapping fromrefs/pull/3860/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -0,0 +22,21 @@22+ Effect.gen(function* () {23+ const ids = yield* IdAllocatorV2;24+ const requests = yield* ProviderContinuationRequests;25+ const threads = yield* ThreadManagementService;26+27+ const dispatchContinuation = Effect.fn("ProviderContinuationService.dispatchContinuation")(28+ function* (request: ProviderContinuationRequest) {29+ const projection = yield* threads.getThreadProjection(request.threadId);30+ if (projection.thread.archivedAt !== null) {31+ yield* Effect.logInfo("orchestration-v2.provider-continuation.thread-archived", {32+ threadId: request.threadId,33+ providerThreadId: request.providerThreadId,34+ });35+ return;36+ }37+ const messageId = yield* ids.allocate.message({38+ threadId: request.threadId,39+ ordinal: projection.messages.length + 1,40+ });41+ const commandId = CommandId.make(`provider-continuation:${messageId}`);42+ yield* threads.dispatch({@@ -3643,2 +3861,2 @@36433861 const idAllocator = yield* IdAllocatorV2;36443862 const queryRunner = yield* ClaudeAgentSdkQueryRunner;
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:XL
- apps/server/src/orchestration-v2/ProviderSessionManager.ts line 622Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -543,6 +602,21 @@543602 entry === undefined ||544603 entry.busyCount > 0 ||545604 entry.idleGeneration !== input.generation546605 ) {547606 return;548607 }608+ const hasPendingWork =609+ entry.runtime.hasPendingBackgroundWork === undefined610+ ? false611+ : yield* entry.runtime.hasPendingBackgroundWork.pipe(612+ Effect.catchCause(() => Effect.succeed(false)),613+ );614+ if (hasPendingWork) {615+ const now = yield* Clock.currentTimeMillis;616+ const pinnedSinceMs = entry.pinnedSinceMs ?? now;617+ if (now - pinnedSinceMs < maxIdlePinMs) {618+ yield* Effect.logInfo("orchestration-v2.driver-session.idle-release-deferred", {619+ providerSessionId: input.providerSessionId,620+ pinnedForMs: now - pinnedSinceMs,621+ });622+ yield* Ref.update(sessions, (latest) => {
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 3059Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2767,3 +3032,4 @@27673032 const message = input.message;27683033 const context = yield* Ref.get(activeTurn);27693034 if (context === null) {3035+ yield* bufferWakeMessage({ nativeThreadId: liveQuery.nativeThreadId, message });apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 3044Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2757,0 +3000,21 @@3000+ }3001+ const updated = new Set(current);3002+ updated.add(wakeInput.nativeThreadId);3003+ return [true, updated] as const;3004+ });3005+ if (!shouldOffer) {3006+ return;3007+ }3008+ const detail =3009+ (yield* Ref.get(wakeBuffers)).get(wakeInput.nativeThreadId)?.detail ?? null;3010+ yield* Effect.logInfo("orchestration-v2.claude-wake-turn-detected", {3011+ providerSessionId: input.providerSessionId,3012+ threadId: route.threadId,3013+ providerThreadId: route.providerThreadId,3014+ });3015+ yield* continuationRequests.offer({3016+ threadId: route.threadId,3017+ providerThreadId: route.providerThreadId,3018+ driver: CLAUDE_PROVIDER,3019+ detail,3020+ });apps/server/src/orchestration-v2/ProviderContinuationService.ts line 69Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +49,21 @@49+ dispatchMode: { type: "queue_after_active" },50+ createdBy: "agent",51+ creationSource: "provider",52+ });53+ },54+ );55+56+ yield* requests.take.pipe(57+ Effect.flatMap((request) =>58+ dispatchContinuation(request).pipe(59+ Effect.catchCause((cause) =>60+ Effect.logWarning("orchestration-v2.provider-continuation.dispatch-failed", {61+ threadId: request.threadId,62+ providerThreadId: request.providerThreadId,63+ cause,64+ }),65+ ),66+ ),67+ ),68+ Effect.forever,69+ Effect.forkScoped,
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 2305Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2150,2 +2261,21 @@21502261 input.context.subagentsByToolUseId.set(input.toolUseId, subagent);21512262 }2263+ // The same terminal protection, applied atomically: a concurrent2264+ // fiber (live stream vs continuation drain) may have terminalized2265+ // the registry entry after this update's lookup read it. A resume2266+ // re-open (task_started) bypasses it only when the registered entry2267+ // is still the terminal generation the lookup resolved; if a2268+ // concurrent fiber installed a newer terminal entry meanwhile, the2269+ // re-open must not clobber its result.2270+ yield* Ref.update(sessionSubagentsByTaskId, (current) => {2271+ const registered = current.get(input.taskId);2272+ if (2273+ registered !== undefined &&2274+ registered.task.status !== "running" &&2275+ input.status === "running" &&2276+ !(isReopen && registered === existingSubagent)2277+ ) {2278+ return current;2279+ }2280+ return new Map(current).set(input.taskId, subagent);2281+ });
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
juliusmarminge merged this798c458
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:
70c22255-c94b-4858-baa8-5df55643f46cYou 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)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share