fix(server): changing the permission mode no longer ends the running turn #23082
Openmackinleysmith(GitHub profile, opens in a new tab)wants to merge 10 commits into
main fromrefs/pull/23082/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:M
- apps/server/src/orchestration-v2/ProviderSessionManager.ts lines 2160 to 2166OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2121,0 +2146,21 @@2146+ ) {2147+ // Restarting ends the process's background agents and commands,2148+ // so it waits for them like a Claude model change does.2149+ const probedRuntime = existing.runtime;2150+ if (2151+ probedRuntime.hasPendingBackgroundWork !== undefined &&2152+ (yield* probedRuntime.hasPendingBackgroundWork.pipe(2153+ Effect.catchCause(() => Effect.succeed(false)),2154+ ))2155+ ) {2156+ return yield* new ProviderSessionBackgroundWorkBlocksModeChangeError({2157+ providerSessionId: input.providerSessionId,2158+ });2159+ }2160+ // Only single-thread sessions lack in-place switching, so no2161+ // other thread shares the process being replaced.2162+ yield* releaseEntry({2163+ providerSessionId: input.providerSessionId,2164+ reason: "manual_shutdown",2165+ detail: "Runtime mode changed.",2166+ });
- @@ -162,3 +175,4 @@162175 readonly providerSessionId: ProviderSessionId;163176 readonly modelSelection: ModelSelection;164177 readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy;178+ readonly preserveRuntimeMode?: boolean;apps/server/src/orchestration-v2/ProviderSessionManager.ts line 2443OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2401,0 +2423,21 @@2423+ existing !== undefined &&2424+ input.preserveRuntimeMode !== true &&2425+ existing.runtimeMode !== input.runtimePolicy.runtimeMode &&2426+ !existing.runtime.providerSession.capabilities.sessions2427+ .supportsRuntimeModeSwitchInSession2428+ ) {2429+ if (existing.supportsMultipleProviderThreads) {2430+ return yield* new ProviderSessionOpenError({2431+ instanceId: input.modelSelection.instanceId,2432+ providerSessionId: input.providerSessionId,2433+ cause:2434+ "Cannot restart a shared provider session to change its permission mode.",2435+ });2436+ }2437+ // Restarting ends the process's background agents and commands,2438+ // so it waits for them like a Claude model change does.2439+ const probedRuntime = existing.runtime;2440+ if (2441+ probedRuntime.hasPendingBackgroundWork !== undefined &&2442+ (yield* probedRuntime.hasPendingBackgroundWork.pipe(2443+ Effect.catchCause(() => Effect.succeed(false)),@@ -792,3 +792,6 @@792792 providerSessionId,793793 modelSelection: run.modelSelection,794794 runtimePolicy: resolvedRuntimePolicy,795+ // Buffered provider continuations drain the live process before a new mode can replace it.796+ preserveRuntimeMode:797+ message.createdBy === "agent" && message.creationSource === "provider",
- @@ -2401,0 +2423,21 @@2423+ existing !== undefined &&2424+ input.preserveRuntimeMode !== true &&2425+ existing.runtimeMode !== input.runtimePolicy.runtimeMode &&2426+ !existing.runtime.providerSession.capabilities.sessions2427+ .supportsRuntimeModeSwitchInSession2428+ ) {2429+ if (existing.supportsMultipleProviderThreads) {2430+ return yield* new ProviderSessionOpenError({2431+ instanceId: input.modelSelection.instanceId,2432+ providerSessionId: input.providerSessionId,2433+ cause:2434+ "Cannot restart a shared provider session to change its permission mode.",2435+ });2436+ }2437+ // Restarting ends the process's background agents and commands,2438+ // so it waits for them like a Claude model change does.2439+ const probedRuntime = existing.runtime;2440+ if (2441+ probedRuntime.hasPendingBackgroundWork !== undefined &&2442+ (yield* probedRuntime.hasPendingBackgroundWork.pipe(2443+ Effect.catchCause(() => Effect.succeed(true)),
tanstack-source added labelsbug
- apps/server/src/orchestration-v2/ProviderSessionManager.ts line 2504OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2439,4 +2494,11 @@24392494 providerInstanceId: existing.runtime.instanceId,24402495 });24412496 yield* touchActivity(input.providerSessionId);2442- return existing.exposedRuntime;2497+ const runtime = existing.exposedRuntime;2498+ const runtimeMode = existing.runtimeMode;2499+ if (2500+ input.preserveRuntimeMode === true &&2501+ !runtime.providerSession.capabilities.sessions.supportsRuntimeModeSwitchInSession2502+ ) {2503+ return {2504+ ...runtime,
- @@ -2425,0 +2450,21 @@2450+ !existing.runtime.providerSession.capabilities.sessions2451+ .supportsRuntimeModeSwitchInSession2452+ ) {2453+ if (existing.supportsMultipleProviderThreads) {2454+ return yield* new ProviderSessionOpenError({2455+ instanceId: input.modelSelection.instanceId,2456+ providerSessionId: input.providerSessionId,2457+ cause:2458+ "Cannot restart a shared provider session to change its permission mode.",2459+ });2460+ }2461+ // Restarting ends the process's background agents and commands,2462+ // so it waits for them like a Claude model change does.2463+ const probedRuntime = existing.runtime;2464+ if (2465+ probedRuntime.hasPendingBackgroundWork !== undefined &&2466+ (yield* probedRuntime.hasPendingBackgroundWork.pipe(2467+ Effect.catchCause(() => Effect.succeed(true)),2468+ ))2469+ ) {2470+ return yield* new ProviderSessionBackgroundWorkBlocksModeChangeError({@@ -2425,0 +2454,21 @@2454+ return yield* new ProviderSessionOpenError({2455+ instanceId: input.modelSelection.instanceId,2456+ providerSessionId: input.providerSessionId,2457+ cause:2458+ "Cannot restart a shared provider session to change its permission mode.",2459+ });2460+ }2461+ // Restarting ends the process's background agents and commands,2462+ // so it waits for them like a Claude model change does.2463+ const probedRuntime = existing.runtime;2464+ if (2465+ probedRuntime.hasPendingBackgroundWork !== undefined &&2466+ (yield* probedRuntime.hasPendingBackgroundWork.pipe(2467+ Effect.catchCause(() => Effect.succeed(true)),2468+ ))2469+ ) {2470+ return yield* new ProviderSessionBackgroundWorkBlocksModeChangeError({2471+ providerSessionId: input.providerSessionId,2472+ });2473+ }2474+ yield* releaseEntry({@@ -448,0 +492,21 @@492+ hasPendingBackgroundWork: options.probeDefects493+ ? Effect.die("background work probe failed")494+ : Effect.succeed(options.backgroundWork),495+ })),496+ ),497+ });498+499+ const result = yield* Effect.gen(function* () {500+ const orchestrator = yield* Orchestrator.OrchestratorV2;501+ const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;502+ const send = (step: string) =>503+ Effect.gen(function* () {504+ const settled = yield* orchestrator.streamDomainEvents.pipe(505+ Stream.filter(506+ (event) =>507+ (event.type === "provider-turn.updated" && event.payload.status === "running") ||508+ (event.type === "run.updated" && event.payload.status === "failed"),509+ ),510+ Stream.take(1),511+ Stream.runDrain,512+ Effect.forkScoped,
juliusmarminge added labelstakeover:in-progress
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelstakeover:needs-julius
juliusmarminge removed labelstakeover:in-progress
Sign in to join this conversation.







macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed