@devries-cameron20 / t3code Mirror · read-only / commits / b9eb5524ae
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 10:45 UTC

fix(server): release retired provider scopes (#24777)

Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>

Maxwell Young committed Oct 31, 2026 at 10:46 UTC b9eb5524aede70f8b7df407cfef36597e63e6ae8
2 files changed +79 -2
apps/server/src/provider/ProviderInstanceRegistry.test.ts
+78
@@ -23,6 +23,8 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
23 import * as DateTime from "effect/DateTime";
24 import * as Deferred from "effect/Deferred";
25 import * as Effect from "effect/Effect";
26 +import * as Exit from "effect/Exit";
27 +import * as Scope from "effect/Scope";
28 import * as Fiber from "effect/Fiber";
29 import * as FileSystem from "effect/FileSystem";
30 import * as Layer from "effect/Layer";
@@ -41,6 +43,7 @@ import * as ModelManifest from "./ModelManifest.ts";
43 import * as ResetCreditCoordinator from "./resetCreditCoordinator.ts";
44 import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
45 import { makeProviderInstanceRegistry } from "./ProviderInstanceRegistry.ts";
46 +import { ProviderDriverError } from "./Errors.ts";
47 import * as ProviderOrchestrationAdapterInfrastructure from "./ProviderOrchestrationAdapterInfrastructure.ts";
48 import * as PortScanner from "../preview/PortScanner.ts";
49 import * as ProviderHostLive from "./ProviderHostLive.ts";
@@ -202,6 +205,81 @@ describe("ProviderInstanceRegistry — multi-instance codex slice", () => {
205 Layer.provideMerge(layerBase),
206 );
207
208 + it.effect.each(["replacement", "removal", "creation failure"] as const)(
209 + "detaches retired provider scopes after repeated %s",
210 + (scenario) =>
211 + Effect.gen(function* () {
212 + const parent = yield* Scope.make();
213 + const fileSystem = yield* FileSystem.FileSystem;
214 + const homePath = yield* fileSystem.makeTempDirectoryScoped();
215 + let creates = 0;
216 + let closes = 0;
217 + const driver: typeof CodexDriver = {
218 + ...CodexDriver,
219 + create: Effect.fn("ProviderInstanceRegistry.test.create")(function* (
220 + input: Parameters<typeof CodexDriver.create>[0],
221 + ) {
222 + creates++;
223 + yield* Effect.addFinalizer(() =>
224 + Effect.sync(() => {
225 + closes++;
226 + }),
227 + );
228 + if (input.config.binaryPath === "creation-failure") {
229 + return yield* new ProviderDriverError({
230 + driver: CodexDriver.driverKind,
231 + instanceId: input.instanceId,
232 + detail: "fixture creation failed",
233 + });
234 + }
235 + return yield* CodexDriver.create(input);
236 + }),
237 + };
238 + const siblingId = ProviderInstanceId.make("sibling");
239 + const retiredId = ProviderInstanceId.make("retired");
240 + const entry = {
241 + driver: CodexDriver.driverKind,
242 + enabled: false,
243 + config: makeCodexConfig({ homePath }),
244 + };
245 + yield* Effect.gen(function* () {
246 + const { registry, mutator } = yield* makeProviderInstanceRegistry({
247 + drivers: [driver],
248 + configMap: { [siblingId]: entry },
249 + });
250 + const sibling = yield* registry.getInstance(siblingId);
251 + const finalizerCount = () => {
252 + const state = parent.state;
253 + return state._tag === "Open" ? (state.finalizers?.size ?? 1) : 0;
254 + };
255 + const baseline = finalizerCount();
256 + for (let index = 0; index < 20; index++) {
257 + yield* mutator.reconcile({
258 + [siblingId]: entry,
259 + [retiredId]: {
260 + ...entry,
261 + config: makeCodexConfig({
262 + homePath,
263 + binaryPath: scenario === "creation failure" ? "creation-failure" : "unused-codex",
264 + customModels: [`revision-${index}`],
265 + }),
266 + },
267 + });
268 + if (scenario === "removal") yield* mutator.reconcile({ [siblingId]: entry });
269 + }
270 + yield* mutator.reconcile({ [siblingId]: entry });
271 + expect(yield* registry.getInstance(siblingId)).toBe(sibling);
272 + expect(closes).toBe(creates - 1);
273 + expect(parent.state._tag).toBe("Open");
274 + expect(finalizerCount()).toBe(baseline);
275 + }).pipe(
276 + Effect.provideService(Scope.Scope, parent),
277 + Effect.ensuring(Scope.close(parent, Exit.void)),
278 + );
279 + expect(closes).toBe(creates);
280 + }).pipe(Effect.provide(layerTest)),
281 + );
282 +
283 it.effect.each(["replacement", "removal"] as const)(
284 "hides retired instances during reconcile (%s)",
285 (scenario) =>
apps/server/src/provider/ProviderInstanceRegistry.ts
+1 -2
@@ -194,8 +194,7 @@ const buildEntry = Effect.fn("ProviderInstanceRegistry.buildEntry")(function* <R
194 };
195 }
196
197 - const childScope = yield* Scope.make();
198 - yield* Scope.addFinalizer(parentScope, Scope.close(childScope, Exit.void).pipe(Effect.ignore));
197 + const childScope = yield* Scope.fork(parentScope);
198
199 const createResult = yield* driver
200 .create({