The best way to control Claude Code, Codex and more from any computer or phone
fix(server): refresh linking tools in existing agent sessions (#26737)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
shivam committed
Nov 8, 2026 at 10:43 UTC
20fcc6ca57195cf9180114387e4f659d8e1ee2b4
4 files changed
+273
-16
apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
+44
-6
@@ -3631,6 +3631,9 @@ it.effect(
3631
() =>
3632
Effect.gen(function* () {
3633
const state = yield* Ref.make(emptyState);
3634
+ const settings = yield* ServerSettings.ServerSettingsService.pipe(
3635
+ Effect.provide(ServerSettings.layerTest()),
3636
+ );
3637
const effect = Effect.gen(function* () {
3638
const eventSink = yield* EventSink.EventSinkV2;
3639
const idAllocator = yield* IdAllocator.IdAllocatorV2;
@@ -3737,6 +3740,11 @@ it.effect(
3740
assert.equal((yield* Ref.get(state)).resumeCount, 2);
3741
yield* resumeSecondThread;
3742
assert.equal((yield* Ref.get(state)).resumeCount, 3);
3743
+ // regression: #26722 a Linked environments change reloads only the idle thread's tools.
3744
+ yield* settings.updateSettings({ linkedEnvironmentsEnabled: true });
3745
+ yield* resumeSecondThread;
3746
+ assert.equal((yield* Ref.get(state)).resumeCount, 4);
3747
+ assert.deepEqual((yield* Ref.get(state)).unloadedNativeThreadIds, ["native-thread"]);
3748
const subscribe = firstRuntime.subscribeEvents;
3749
assert.isDefined(subscribe);
3750
if (subscribe === undefined) return;
@@ -3768,15 +3776,18 @@ it.effect(
3776
runtimePolicy,
3777
});
3778
yield* resumeSecondThread;
3771
- assert.equal((yield* Ref.get(state)).resumeCount, 4);
3779
+ assert.equal((yield* Ref.get(state)).resumeCount, 5);
3780
3773
- assert.deepEqual((yield* Ref.get(state)).unloadedNativeThreadIds, []);
3781
+ assert.deepEqual((yield* Ref.get(state)).unloadedNativeThreadIds, ["native-thread"]);
3782
3783
yield* manager.detach({ providerSessionId, threadId: firstThreadId });
3784
assert.isTrue(Option.isSome(yield* manager.get(providerSessionId)));
3785
assert.equal((yield* Ref.get(state)).closeCount, 0);
3786
assert.equal((yield* Ref.get(state)).interruptCount, 1);
3779
- assert.deepEqual((yield* Ref.get(state)).unloadedNativeThreadIds, ["native-thread"]);
3787
+ assert.deepEqual((yield* Ref.get(state)).unloadedNativeThreadIds, [
3788
+ "native-thread",
3789
+ "native-thread",
3790
+ ]);
3791
3792
yield* manager.detach({ providerSessionId, threadId: secondThreadId });
3793
yield* TestClock.adjust("1 second");
@@ -3784,7 +3795,15 @@ it.effect(
3795
assert.equal((yield* Ref.get(state)).closeCount, 1);
3796
});
3797
3787
- yield* effect.pipe(Effect.provide(layerTest({ state, idleTimeoutMs: 1000 })));
3798
+ yield* effect.pipe(
3799
+ Effect.provide(
3800
+ layerTest({
3801
+ state,
3802
+ idleTimeoutMs: 1000,
3803
+ serverSettingsLayer: Layer.succeed(ServerSettings.ServerSettingsService, settings),
3804
+ }),
3805
+ ),
3806
+ );
3807
}),
3808
);
3809
@@ -4187,10 +4206,13 @@ it.effect(
4206
);
4207
4208
it.effect(
4190
- "ProviderSessionManagerV2 rejects a second thread when the provider runtime is exclusive",
4209
+ "ProviderSessionManagerV2 rejects a second thread when the provider runtime is exclusive, and reopens it when Linked environments changes",
4210
() =>
4211
Effect.gen(function* () {
4212
const state = yield* Ref.make(emptyState);
4213
+ const settings = yield* ServerSettings.ServerSettingsService.pipe(
4214
+ Effect.provide(ServerSettings.layerTest()),
4215
+ );
4216
const effect = Effect.gen(function* () {
4217
const eventSink = yield* EventSink.EventSinkV2;
4218
const idAllocator = yield* IdAllocator.IdAllocatorV2;
@@ -4235,11 +4257,27 @@ it.effect(
4257
4258
assert.equal(error._tag, "ProviderSessionOpenError");
4259
assert.equal((yield* Ref.get(state)).openCount, 1);
4260
+
4261
+ // regression: #26722 an exclusive runtime configures MCP at open, so it reopens.
4262
+ yield* settings.updateSettings({ linkedEnvironmentsEnabled: true });
4263
+ yield* manager.open({
4264
+ threadId: firstThreadId,
4265
+ providerSessionId,
4266
+ modelSelection,
4267
+ runtimePolicy,
4268
+ });
4269
+ assert.equal((yield* Ref.get(state)).openCount, 2);
4270
+ assert.equal((yield* Ref.get(state)).closeCount, 1);
4271
});
4272
4273
yield* effect.pipe(
4274
Effect.provide(
4242
- layerTest({ state, idleTimeoutMs: 1000, capabilities: ExclusiveCapabilities }),
4275
+ layerTest({
4276
+ state,
4277
+ idleTimeoutMs: 1000,
4278
+ capabilities: ExclusiveCapabilities,
4279
+ serverSettingsLayer: Layer.succeed(ServerSettings.ServerSettingsService, settings),
4280
+ }),
4281
),
4282
);
4283
}),
apps/server/src/orchestration-v2/ProviderSessionManager.ts
+226
-10
@@ -218,6 +218,9 @@ export class ProviderSessionManagerV2 extends Context.Service<
218
interface LiveSessionEntry {
219
readonly attachedThreadIds: ReadonlySet<ThreadId>;
220
readonly loadedProviderThreadKeyByThread: ReadonlyMap<ThreadId, string>;
221
+ /** null marks an unknown catalog; undefined means MCP refresh is not configured. */
222
+ readonly openedWithLinkedEnvironments: boolean | null | undefined;
223
+ readonly linkedEnvironmentsByThread: ReadonlyMap<ThreadId, boolean | null>;
224
/** Scope revocation to recorded credential ids so superseded sessions cannot revoke replacements opened before detach. */
225
readonly mcpCredentialIdByThread: ReadonlyMap<ThreadId, string>;
226
readonly supportsMultipleProviderThreads: boolean;
@@ -384,6 +387,13 @@ export const layerWithOptions = (
387
);
388
},
389
);
390
+ const readLinkedEnvironments = Effect.gen(function* () {
391
+ if (options.configureMcp === false || Option.isNone(serverSettings)) return undefined;
392
+ return yield* serverSettings.value.getSettings.pipe(
393
+ Effect.map((settings) => settings.linkedEnvironmentsEnabled),
394
+ Effect.orElseSucceed(() => null),
395
+ );
396
+ });
397
const layerScope = yield* Effect.scope;
398
// Group signals stop providers before restart capture; drop post-signal events so recovery owns that state.
399
const shutdownSignal = { received: false };
@@ -936,13 +946,14 @@ export const layerWithOptions = (
946
readonly providerSessionId: ProviderSessionId;
947
readonly onlyIfIdleGeneration?: number;
948
readonly keepIfBusyOtherThan?: ReadonlyArray<ProviderThreadId>;
949
+ readonly keepIf?: Effect.Effect<boolean>;
950
}): Effect.fn.Return<readonly [Option.Option<LiveSessionEntry>, DateTime.Utc]> {
951
const key = sessionKey(input.providerSessionId);
952
const candidate = (yield* Ref.get(sessions)).get(key);
953
if (candidate === undefined) {
954
return [Option.none<LiveSessionEntry>(), yield* DateTime.now] as const;
955
}
945
- const removed = yield* Effect.zip(
956
+ const remove = Effect.zip(
957
Ref.modify(sessions, (current) => {
958
const existing = current.get(key);
959
if (existing !== candidate) {
@@ -969,8 +980,13 @@ export const layerWithOptions = (
980
return ["removed", updated] as const;
981
}),
982
DateTime.now,
972
- ).pipe(candidate.requestEventPermit.withPermits(1));
973
- const [outcome, releasedAt] = removed;
983
+ );
984
+ const [outcome, releasedAt] = yield* Effect.gen(function* () {
985
+ if (input.keepIf !== undefined && (yield* input.keepIf)) {
986
+ return ["kept" as const, yield* DateTime.now] as const;
987
+ }
988
+ return yield* remove;
989
+ }).pipe(candidate.requestEventPermit.withPermits(1));
990
if (outcome === "changed") return yield* removeLiveEntry(input);
991
return [
992
outcome === "removed" ? Option.some(candidate) : Option.none<LiveSessionEntry>(),
@@ -1023,6 +1039,7 @@ export const layerWithOptions = (
1039
readonly cancelIdleFiber?: boolean;
1040
readonly onlyIfIdleGeneration?: number;
1041
readonly keepIfBusyOtherThan?: ReadonlyArray<ProviderThreadId>;
1042
+ readonly keepIf?: Effect.Effect<boolean>;
1043
readonly gracefulSubscribers?: boolean;
1044
}) =>
1045
Effect.acquireUseRelease(
@@ -1301,11 +1318,14 @@ export const layerWithOptions = (
1318
attachedThreadIds.delete(input.threadId);
1319
const loadedProviderThreadKeyByThread = new Map(entry.loadedProviderThreadKeyByThread);
1320
loadedProviderThreadKeyByThread.delete(input.threadId);
1321
+ const linkedEnvironmentsByThread = new Map(entry.linkedEnvironmentsByThread);
1322
+ linkedEnvironmentsByThread.delete(input.threadId);
1323
const updated = new Map(current);
1324
updated.set(key, {
1325
...entry,
1326
attachedThreadIds,
1327
loadedProviderThreadKeyByThread,
1328
+ linkedEnvironmentsByThread,
1329
});
1330
return updated;
1331
});
@@ -1324,10 +1344,12 @@ export const layerWithOptions = (
1344
),
1345
);
1346
1347
+ /** Pass the setting read before a native load; cache hits keep the earlier record. */
1348
const markProviderThreadLoaded = (input: {
1349
readonly providerSessionId: ProviderSessionId;
1350
readonly threadId: ThreadId;
1351
readonly providerThreadKey: string;
1352
+ readonly linkedEnvironments: boolean | null | undefined;
1353
}) =>
1354
Ref.update(sessions, (current) => {
1355
const key = sessionKey(input.providerSessionId);
@@ -1337,11 +1359,29 @@ export const layerWithOptions = (
1359
}
1360
const loadedProviderThreadKeyByThread = new Map(entry.loadedProviderThreadKeyByThread);
1361
loadedProviderThreadKeyByThread.set(input.threadId, input.providerThreadKey);
1362
+ const linkedEnvironmentsByThread = new Map(entry.linkedEnvironmentsByThread);
1363
+ if (
1364
+ input.linkedEnvironments !== undefined &&
1365
+ !linkedEnvironmentsByThread.has(input.threadId)
1366
+ ) {
1367
+ linkedEnvironmentsByThread.set(input.threadId, input.linkedEnvironments);
1368
+ }
1369
const updated = new Map(current);
1341
- updated.set(key, { ...entry, loadedProviderThreadKeyByThread });
1370
+ updated.set(key, {
1371
+ ...entry,
1372
+ loadedProviderThreadKeyByThread,
1373
+ linkedEnvironmentsByThread,
1374
+ });
1375
return updated;
1376
});
1377
1378
+ const loadNatively = <A, E>(load: Effect.Effect<A, E>) =>
1379
+ readLinkedEnvironments.pipe(
1380
+ Effect.flatMap((linkedEnvironments) =>
1381
+ load.pipe(Effect.map((loaded) => ({ loaded, linkedEnvironments }))),
1382
+ ),
1383
+ );
1384
+
1385
const ensureThreadAttached = (input: {
1386
readonly providerSessionId: ProviderSessionId;
1387
readonly threadId: ThreadId;
@@ -1631,6 +1671,15 @@ export const layerWithOptions = (
1671
if (!unloading) return "skipped" as const;
1672
yield* unloadThread({ providerThread: pending.providerThread }).pipe(
1673
Effect.timeout(UNLOAD_THREAD_TIMEOUT_MS),
1674
+ Effect.tap(() =>
1675
+ Ref.update(sessions, (current) => {
1676
+ const latest = current.get(key);
1677
+ if (latest?.runtime !== entry.runtime) return current;
1678
+ const linkedEnvironmentsByThread = new Map(latest.linkedEnvironmentsByThread);
1679
+ linkedEnvironmentsByThread.delete(input.threadId);
1680
+ return new Map(current).set(key, { ...latest, linkedEnvironmentsByThread });
1681
+ }),
1682
+ ),
1683
Effect.catchCause((cause) =>
1684
Effect.logWarning("orchestration-v2.driver-session.idle-unload-failed", {
1685
providerSessionId: input.providerSessionId,
@@ -1651,6 +1700,147 @@ export const layerWithOptions = (
1700
},
1701
);
1702
1703
+ /** A shared runtime reloads only this idle thread so the others keep their processes. */
1704
+ const unloadForLinkedEnvironments = Effect.fn(
1705
+ "ProviderSessionManager.unloadForLinkedEnvironments",
1706
+ )(function* (input: {
1707
+ readonly providerSessionId: ProviderSessionId;
1708
+ readonly threadId: ThreadId;
1709
+ readonly providerThread: OrchestrationV2ProviderThread;
1710
+ }) {
1711
+ const key = sessionKey(input.providerSessionId);
1712
+ const entry = (yield* Ref.get(sessions)).get(key);
1713
+ const loadedWith = entry?.linkedEnvironmentsByThread.get(input.threadId);
1714
+ const unloadThread = entry?.runtime.unloadThread;
1715
+ if (
1716
+ entry === undefined ||
1717
+ !entry.supportsMultipleProviderThreads ||
1718
+ unloadThread === undefined ||
1719
+ loadedWith === undefined ||
1720
+ input.providerThread.nativeThreadRef === null
1721
+ ) {
1722
+ return;
1723
+ }
1724
+ const linkedEnvironments = yield* readLinkedEnvironments;
1725
+ if (typeof linkedEnvironments !== "boolean" || linkedEnvironments === loadedWith) return;
1726
+ yield* threadAttachment.withLock(
1727
+ threadAttachmentKey(input),
1728
+ Effect.gen(function* () {
1729
+ if (hasBusyTurn(entry, input.providerThread.id)) return;
1730
+ // Unloading ends the thread's background work; a failed probe keeps it loaded too.
1731
+ const hasPendingWork =
1732
+ entry.runtime.hasPendingBackgroundWorkForThread === undefined
1733
+ ? false
1734
+ : yield* entry.runtime
1735
+ .hasPendingBackgroundWorkForThread(input.providerThread, {
1736
+ includeSubagents: true,
1737
+ })
1738
+ .pipe(Effect.catchCause(() => Effect.succeed(true)));
1739
+ if (hasPendingWork) return;
1740
+ // Forget the load first so a timed-out unload still resumes natively next turn.
1741
+ const unloading = yield* Ref.modify(sessions, (current) => {
1742
+ const latest = current.get(key);
1743
+ if (
1744
+ latest?.runtime !== entry.runtime ||
1745
+ latest.linkedEnvironmentsByThread.get(input.threadId) !== loadedWith ||
1746
+ hasBusyTurn(latest, input.providerThread.id)
1747
+ ) {
1748
+ return [false, current] as const;
1749
+ }
1750
+ const loadedProviderThreadKeyByThread = new Map(
1751
+ latest.loadedProviderThreadKeyByThread,
1752
+ );
1753
+ loadedProviderThreadKeyByThread.delete(input.threadId);
1754
+ return [
1755
+ true,
1756
+ new Map(current).set(key, { ...latest, loadedProviderThreadKeyByThread }),
1757
+ ] as const;
1758
+ });
1759
+ if (!unloading) return;
1760
+ yield* unloadThread({ providerThread: input.providerThread }).pipe(
1761
+ Effect.timeout(UNLOAD_THREAD_TIMEOUT_MS),
1762
+ Effect.tap(() =>
1763
+ Ref.update(sessions, (current) => {
1764
+ const latest = current.get(key);
1765
+ if (latest?.runtime !== entry.runtime) return current;
1766
+ const linkedEnvironmentsByThread = new Map(latest.linkedEnvironmentsByThread);
1767
+ linkedEnvironmentsByThread.delete(input.threadId);
1768
+ return new Map(current).set(key, { ...latest, linkedEnvironmentsByThread });
1769
+ }),
1770
+ ),
1771
+ Effect.catchCause((cause) =>
1772
+ Effect.logWarning("orchestration-v2.driver-session.links-unload-failed", {
1773
+ providerSessionId: input.providerSessionId,
1774
+ threadId: input.threadId,
1775
+ cause,
1776
+ }),
1777
+ ),
1778
+ );
1779
+ }),
1780
+ );
1781
+ });
1782
+
1783
+ /** An exclusive runtime configures MCP at open, so it reopens once nothing would be lost. */
1784
+ const releaseForLinkedEnvironments = Effect.fn(
1785
+ "ProviderSessionManager.releaseForLinkedEnvironments",
1786
+ )(function* (entry: LiveSessionEntry) {
1787
+ if (
1788
+ entry.supportsMultipleProviderThreads ||
1789
+ entry.runtime.canResumeAfterRestart === false ||
1790
+ entry.openedWithLinkedEnvironments === undefined ||
1791
+ entry.busyTurns.size > 0
1792
+ ) {
1793
+ return;
1794
+ }
1795
+ const linkedEnvironments = yield* readLinkedEnvironments;
1796
+ if (
1797
+ typeof linkedEnvironments !== "boolean" ||
1798
+ linkedEnvironments === entry.openedWithLinkedEnvironments
1799
+ ) {
1800
+ return;
1801
+ }
1802
+ const providerSessionId = entry.runtime.providerSessionId;
1803
+ // Any activity during these reads bumps the generation and keeps the runtime.
1804
+ const generation = entry.idleGeneration;
1805
+ const hasPendingWork =
1806
+ entry.runtime.hasPendingBackgroundWork === undefined
1807
+ ? false
1808
+ : yield* entry.runtime.hasPendingBackgroundWork.pipe(
1809
+ Effect.catchCause(() => Effect.succeed(true)),
1810
+ );
1811
+ if (hasPendingWork) return;
1812
+ // Checked under the request permit so a runless request mid-persist is not cancelled.
1813
+ const hasUnfinishedRecords = Effect.forEach(entry.attachedThreadIds, (threadId) =>
1814
+ projectionStore.getThreadRecords(threadId, ["runtimeRequests", "providerThreads"], {
1815
+ runtimeRequestStatuses: ["pending"],
1816
+ }),
1817
+ ).pipe(
1818
+ Effect.map((projections) =>
1819
+ projections.some(
1820
+ (projection) =>
1821
+ projection.runtimeRequests.some(
1822
+ (request) =>
1823
+ request.responseCapability.type === "live" &&
1824
+ request.responseCapability.providerSessionId === providerSessionId,
1825
+ ) ||
1826
+ projection.providerThreads.some(
1827
+ (providerThread) =>
1828
+ providerThread.providerSessionId === providerSessionId &&
1829
+ (providerThread.pendingBackgroundTasks ?? []).length > 0,
1830
+ ),
1831
+ ),
1832
+ ),
1833
+ Effect.orElseSucceed(() => true),
1834
+ );
1835
+ yield* releaseEntry({
1836
+ providerSessionId,
1837
+ reason: "idle_timeout",
1838
+ detail: "Linked environments changed; reopening the provider session.",
1839
+ onlyIfIdleGeneration: generation,
1840
+ keepIf: hasUnfinishedRecords,
1841
+ }).pipe(logReleaseFailure(providerSessionId));
1842
+ });
1843
+
1844
const observeActivity = (
1845
providerSessionId: ProviderSessionId,
1846
activity: Effect.Effect<void, ProviderSessionActivityError>,
@@ -1740,8 +1930,8 @@ export const layerWithOptions = (
1930
providerInstanceId: runtime.instanceId,
1931
}),
1932
).pipe(
1743
- Effect.andThen(runtime.ensureThread(input)),
1744
- Effect.tap((providerThread) =>
1933
+ Effect.andThen(loadNatively(runtime.ensureThread(input))),
1934
+ Effect.tap(({ loaded: providerThread, linkedEnvironments }) =>
1935
markProviderThreadLoaded({
1936
providerSessionId,
1937
threadId: input.threadId,
@@ -1750,8 +1940,10 @@ export const layerWithOptions = (
1940
modelSelection: input.modelSelection,
1941
runtimePolicy: input.runtimePolicy,
1942
}),
1943
+ linkedEnvironments,
1944
}),
1945
),
1946
+ Effect.map(({ loaded }) => loaded),
1947
),
1948
resumeThread: (input) => {
1949
const threadId = input.threadId ?? input.providerThread.appThreadId;
@@ -1780,13 +1972,25 @@ export const layerWithOptions = (
1972
providerThread: input.providerThread,
1973
}),
1974
),
1975
+ Effect.andThen(
1976
+ unloadForLinkedEnvironments({
1977
+ providerSessionId,
1978
+ threadId,
1979
+ providerThread: input.providerThread,
1980
+ }),
1981
+ ),
1982
Effect.andThen(
1983
isProviderThreadLoaded({ providerSessionId, threadId, providerThreadKey }),
1984
),
1985
Effect.flatMap((loaded) =>
1787
- loaded ? Effect.succeed(input.providerThread) : runtime.resumeThread(input),
1986
+ loaded
1987
+ ? Effect.succeed({
1988
+ loaded: input.providerThread,
1989
+ linkedEnvironments: undefined,
1990
+ })
1991
+ : loadNatively(runtime.resumeThread(input)),
1992
),
1789
- Effect.tap((providerThread) =>
1993
+ Effect.tap(({ loaded: providerThread, linkedEnvironments }) =>
1994
markProviderThreadLoaded({
1995
providerSessionId,
1996
threadId,
@@ -1799,8 +2003,10 @@ export const layerWithOptions = (
2003
? {}
2004
: { runtimePolicy: input.runtimePolicy }),
2005
}),
2006
+ linkedEnvironments,
2007
}),
2008
),
2009
+ Effect.map(({ loaded }) => loaded),
2010
);
2011
},
2012
forkThread: (input) =>
@@ -1812,8 +2018,8 @@ export const layerWithOptions = (
2018
providerInstanceId: runtime.instanceId,
2019
}),
2020
).pipe(
1815
- Effect.andThen(runtime.forkThread(input)),
1816
- Effect.tap((providerThread) =>
2021
+ Effect.andThen(loadNatively(runtime.forkThread(input))),
2022
+ Effect.tap(({ loaded: providerThread, linkedEnvironments }) =>
2023
markProviderThreadLoaded({
2024
providerSessionId,
2025
threadId: input.targetThreadId,
@@ -1826,8 +2032,10 @@ export const layerWithOptions = (
2032
? {}
2033
: { runtimePolicy: input.runtimePolicy }),
2034
}),
2035
+ linkedEnvironments,
2036
}),
2037
),
2038
+ Effect.map(({ loaded }) => loaded),
2039
),
2040
startTurn: (input) =>
2041
observeActivity(
@@ -2157,6 +2365,8 @@ export const layerWithOptions = (
2365
}
2366
}
2367
const key = sessionKey(input.providerSessionId);
2368
+ const live = (yield* Ref.get(sessions)).get(key);
2369
+ if (live !== undefined) yield* releaseForLinkedEnvironments(live);
2370
const existing = (yield* Ref.get(sessions)).get(key);
2371
if (existing !== undefined) {
2372
const attached = existing.attachedThreadIds.has(input.threadId);
@@ -2187,6 +2397,7 @@ export const layerWithOptions = (
2397
}),
2398
),
2399
);
2400
+ const openedWithLinkedEnvironments = yield* readLinkedEnvironments;
2401
const prepared = yield* prepareMcpSession(
2402
input.threadId,
2403
input.modelSelection.instanceId,
@@ -2258,6 +2469,8 @@ export const layerWithOptions = (
2469
const entry: LiveSessionEntry = {
2470
attachedThreadIds: new Set([input.threadId]),
2471
loadedProviderThreadKeyByThread: new Map(),
2472
+ openedWithLinkedEnvironments,
2473
+ linkedEnvironmentsByThread: new Map(),
2474
mcpCredentialIdByThread:
2475
mcpCredentialId === undefined
2476
? new Map()
@@ -2479,6 +2692,8 @@ export const layerWithOptions = (
2692
entry.loadedProviderThreadKeyByThread,
2693
);
2694
loadedProviderThreadKeyByThread.delete(input.threadId);
2695
+ const linkedEnvironmentsByThread = new Map(entry.linkedEnvironmentsByThread);
2696
+ linkedEnvironmentsByThread.delete(input.threadId);
2697
const mcpCredentialIdByThread =
2698
input.revokeMcpCredential === true
2699
? (() => {
@@ -2493,6 +2708,7 @@ export const layerWithOptions = (
2708
...entry,
2709
attachedThreadIds,
2710
loadedProviderThreadKeyByThread,
2711
+ linkedEnvironmentsByThread,
2712
mcpCredentialIdByThread,
2713
idleThreadUnloads,
2714
};
packages/provider-acp/src/server/adapter.ts
+1
@@ -8594,6 +8594,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8594
driver,
8595
providerSessionId: input.providerSessionId,
8596
providerSession,
8597
+ canResumeAfterRestart: canLoadSession || canResumeSession,
8598
events: Stream.fromEffectRepeat(Queue.take(events)),
8599
...(flavor.getModelContextWindow === undefined
8600
? {}
packages/provider-core/src/server/ProviderAdapter.ts
+2
@@ -609,6 +609,8 @@ export interface ProviderAdapterV2SessionRuntime {
609
readonly driver: ProviderDriverKind;
610
readonly providerSessionId: ProviderSessionId;
611
readonly providerSession: OrchestrationV2ProviderSession;
612
+ /** False keeps conversations alive when the provider cannot restore them after a restart. */
613
+ readonly canResumeAfterRestart?: boolean;
614
readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
615
/** Manager runtimes broadcast independent subscriptions; adapters may expose only a single-consumer stream. */
616
readonly subscribeEvents?: Effect.Effect<ProviderAdapterV2EventSubscription>;