@devries-cameron20 / t3code-1 / commits / 5e0127ca83
Fork 0

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

fix(acp-registry): observe delayed model discovery and avoid stale cache lock (#33170)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Sadman Habib committed Nov 15, 2026 at 02:37 UTC 5e0127ca834a8af5bf59d38fdf5261e014e46699
3 files changed +433 -44
packages/provider-acp-registry/src/server/driver.test.ts
+239 -7
@@ -29,8 +29,12 @@ import {
29 buildCheckedAcpRegistrySnapshot,
30 checkAcpRegistryProviderReadiness,
31 checkAcpRegistryProviderStatus,
32 + updateAcpRegistryEnrichmentCache,
33 } from "./driver.ts";
33 -import { normalizeAcpRegistryLiveConfiguration } from "./probe.ts";
34 +import {
35 + acpRegistryAdvertisesModelCatalog,
36 + normalizeAcpRegistryLiveConfiguration,
37 +} from "./probe.ts";
38
39 const decodeSettings = Schema.decodeSync(AcpRegistrySettings);
40 const identity = {
@@ -60,6 +64,41 @@ function catalogWithInspection(
64 };
65 }
66
67 +function providerWithModels(
68 + models: ReadonlyArray<{
69 + readonly id: string;
70 + readonly name: string;
71 + readonly description: string | null;
72 + }>,
73 + currentModelId: string | null,
74 +): ReturnType<typeof buildCheckedAcpRegistrySnapshot> {
75 + return buildCheckedAcpRegistrySnapshot({
76 + ...identity,
77 + settings: decodeSettings({ agentId: "test-agent" }),
78 + checkedAt: "2026-08-13T10:00:00.000Z",
79 + inspection: {
80 + status: "ready",
81 + agentId: "test-agent",
82 + version: "1.0.0",
83 + distribution: "npx",
84 + },
85 + probe: {
86 + probe: {
87 + instanceId: identity.instanceId,
88 + ready: true,
89 + icon: null,
90 + authMethods: [],
91 + models,
92 + currentModelId,
93 + configOptions: [],
94 + sessionManagement: noSessionManagement,
95 + },
96 + slashCommands: [],
97 + skills: [],
98 + },
99 + });
100 +}
101 +
102 describe("acpRegistrySnapshotReadiness", () => {
103 it("treats a live empty command advertisement as an authoritative replacement", () => {
104 const provider = buildCheckedAcpRegistrySnapshot({
@@ -138,7 +177,7 @@ describe("acpRegistrySnapshotReadiness", () => {
177 expect(
178 applyAcpRegistryLiveConfiguration(
179 snapshot,
141 - { models: [], currentModelId: null, configOptions: [] },
180 + { models: [], currentModelId: null, configOptions: [], modelsFromModelSelect: false },
181 [],
182 ).auth.status,
183 ).toBe("unknown");
@@ -185,6 +224,7 @@ describe("acpRegistrySnapshotReadiness", () => {
224 models: [{ id: "live-model", name: "Live model", description: null }],
225 currentModelId: "live-model",
226 configOptions: [],
227 + modelsFromModelSelect: false,
228 },
229 [],
230 ),
@@ -197,7 +237,7 @@ describe("acpRegistrySnapshotReadiness", () => {
237 expect(
238 applyAcpRegistryLiveConfiguration(
239 provider,
200 - { models: [], currentModelId: null, configOptions: [] },
240 + { models: [], currentModelId: null, configOptions: [], modelsFromModelSelect: false },
241 [],
242 ).models,
243 ).toEqual(provider.models);
@@ -214,7 +254,12 @@ describe("acpRegistrySnapshotReadiness", () => {
254 expect(
255 applyAcpRegistryLiveConfiguration(
256 provider,
217 - { models: [], currentModelId: null, configOptions: liveOptions },
257 + {
258 + models: [],
259 + currentModelId: null,
260 + configOptions: liveOptions,
261 + modelsFromModelSelect: false,
262 + },
263 [],
264 ).models,
265 ).toMatchObject([
@@ -534,6 +579,190 @@ describe("acpRegistrySnapshotReadiness", () => {
579 });
580 }),
581 );
582 +
583 + it("keeps a richer probed catalog when a live session reports one provisional model", () => {
584 + const provider = providerWithModels(
585 + [
586 + { id: "auto", name: "Auto", description: null },
587 + { id: "qmodel", name: "Qwen", description: null },
588 + { id: "kmodel", name: "Kimi", description: null },
589 + ],
590 + "auto",
591 + );
592 +
593 + const fallbackSelected = applyAcpRegistryLiveConfiguration(
594 + provider,
595 + {
596 + models: [{ id: "smodel", name: "Default", description: null }],
597 + currentModelId: "smodel",
598 + configOptions: [],
599 + modelsFromModelSelect: false,
600 + },
601 + [],
602 + );
603 + expect(fallbackSelected.models.map((m) => m.slug)).toEqual(["auto", "qmodel", "kmodel"]);
604 + expect(fallbackSelected.models.find((m) => m.slug === "auto")?.isDefault).toBe(true);
605 +
606 + const liveSelected = applyAcpRegistryLiveConfiguration(
607 + provider,
608 + {
609 + models: [{ id: "auto", name: "Auto", description: null }],
610 + currentModelId: "qmodel",
611 + configOptions: [],
612 + modelsFromModelSelect: false,
613 + },
614 + [],
615 + );
616 + expect(liveSelected.models.map((m) => m.slug)).toEqual(["auto", "qmodel", "kmodel"]);
617 + expect(liveSelected.models.find((m) => m.slug === "qmodel")?.isDefault).toBe(true);
618 + expect(liveSelected.models.find((m) => m.slug === "auto")?.isDefault).not.toBe(true);
619 + });
620 +
621 + it("honors an explicit single-model select even when it is absent from the probe catalog", () => {
622 + const provider = providerWithModels(
623 + [
624 + { id: "auto", name: "Auto", description: null },
625 + { id: "qmodel", name: "Qwen", description: null },
626 + { id: "kmodel", name: "Kimi", description: null },
627 + ],
628 + "auto",
629 + );
630 +
631 + const entitled = applyAcpRegistryLiveConfiguration(
632 + provider,
633 + {
634 + models: [{ id: "gmodel", name: "GPT-Pro", description: null }],
635 + currentModelId: "gmodel",
636 + configOptions: [],
637 + modelsFromModelSelect: true,
638 + },
639 + [],
640 + );
641 + expect(entitled.models.map((m) => m.slug)).toEqual(["gmodel"]);
642 + expect(entitled.models.find((m) => m.slug === "gmodel")?.isDefault).toBe(true);
643 +
644 + const narrowed = applyAcpRegistryLiveConfiguration(
645 + provider,
646 + {
647 + models: [{ id: "qmodel", name: "Qwen", description: null }],
648 + currentModelId: "qmodel",
649 + configOptions: [],
650 + modelsFromModelSelect: true,
651 + },
652 + [],
653 + );
654 + expect(narrowed.models.map((m) => m.slug)).toEqual(["qmodel"]);
655 + expect(narrowed.models.find((m) => m.slug === "qmodel")?.isDefault).toBe(true);
656 + });
657 +});
658 +
659 +describe("acpRegistryEnrichmentCache", () => {
660 + const settledConfiguration = {
661 + models: [
662 + { id: "auto", name: "Auto", description: null },
663 + { id: "qmodel", name: "Qwen", description: null },
664 + { id: "kmodel", name: "Kimi", description: null },
665 + ],
666 + currentModelId: "auto",
667 + configOptions: [],
668 + modelsFromModelSelect: true,
669 + };
670 +
671 + it("does not renew the cache deadline when live configuration is replayed unchanged", () => {
672 + const provider = providerWithModels(settledConfiguration.models, "auto");
673 + const cache = { generation: 1, entry: { provider, expiresAt: 1_000 } };
674 +
675 + const replayed = updateAcpRegistryEnrichmentCache({
676 + cache,
677 + configuration: settledConfiguration,
678 + customModels: [],
679 + now: 2_000,
680 + });
681 +
682 + expect(replayed).toBe(cache);
683 + expect(replayed.entry?.expiresAt).toBe(1_000);
684 + });
685 +
686 + it("updates the cache and promotes the expiry when live configuration discovers a catalog", () => {
687 + const provider = providerWithModels(
688 + [{ id: "smodel", name: "Default", description: null }],
689 + "smodel",
690 + );
691 + const cache = { generation: 1, entry: { provider, expiresAt: 1_000 } };
692 +
693 + const updated = updateAcpRegistryEnrichmentCache({
694 + cache,
695 + configuration: settledConfiguration,
696 + customModels: [],
697 + now: 5_000,
698 + });
699 +
700 + expect(updated.entry?.provider.models.map((m) => m.slug)).toEqual(["auto", "qmodel", "kmodel"]);
701 + expect((updated.entry?.expiresAt ?? 0) - 5_000).toBe(15 * 60 * 1_000);
702 + expect(updated.generation).toBe(2);
703 + });
704 +
705 + it("advances the cache epoch when a live update arrives before any probe lands", () => {
706 + const cache = { generation: 4, entry: null };
707 +
708 + const updated = updateAcpRegistryEnrichmentCache({
709 + cache,
710 + configuration: settledConfiguration,
711 + customModels: [],
712 + now: 5_000,
713 + });
714 +
715 + expect(updated.generation).toBe(5);
716 + expect(updated.entry).toBeNull();
717 + });
718 +});
719 +
720 +describe("acpRegistryAdvertisesModelCatalog", () => {
721 + it("counts choices inside option groups and available model state", () => {
722 + expect(
723 + acpRegistryAdvertisesModelCatalog([
724 + {
725 + id: "model",
726 + name: "Model",
727 + type: "select" as const,
728 + category: "model" as const,
729 + currentValue: "auto",
730 + options: [
731 + {
732 + groupId: "qwen",
733 + name: "Qwen",
734 + options: [
735 + { value: "auto", name: "Auto" },
736 + { value: "qmodel", name: "Qwen3.8-Max" },
737 + ],
738 + },
739 + ],
740 + },
741 + ]),
742 + ).toBe(true);
743 + expect(
744 + acpRegistryAdvertisesModelCatalog([
745 + {
746 + id: "model",
747 + name: "Model",
748 + type: "select" as const,
749 + category: "model" as const,
750 + currentValue: "smodel",
751 + options: [{ value: "smodel", name: "Sonus" }],
752 + },
753 + ]),
754 + ).toBe(false);
755 + expect(acpRegistryAdvertisesModelCatalog(undefined)).toBe(false);
756 + expect(
757 + acpRegistryAdvertisesModelCatalog(undefined, {
758 + availableModels: [
759 + { modelId: "auto", name: "Auto", description: null },
760 + { modelId: "qmodel", name: "Qwen", description: null },
761 + ],
762 + currentModelId: "auto",
763 + }),
764 + ).toBe(true);
765 + });
766 });
767
768 const fakeAgentSource = `
@@ -592,7 +821,7 @@ it.layer(driverLayer, { excludeTestServices: true })("AcpRegistryDriver", (it) =
821 const agentPath = path.join(directory, "agent.mjs");
822 const modelsPath = path.join(directory, "models.json");
823 yield* fileSystem.writeFileString(agentPath, fakeAgentSource);
595 - yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["old-model"]));
824 + yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["old-model", "other-model"]));
825 const coordinator = yield* AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator;
826
827 const instance = yield* AcpRegistryDriver.create({
@@ -625,7 +854,7 @@ it.layer(driverLayer, { excludeTestServices: true })("AcpRegistryDriver", (it) =
854 Stream.runHead,
855 );
856
628 - const probed = yield* waitForModels(["old-model"]).pipe(
857 + const probed = yield* waitForModels(["old-model", "other-model"]).pipe(
858 Effect.forkScoped({ startImmediately: true }),
859 );
860 yield* instance.snapshot.refresh;
@@ -634,7 +863,10 @@ it.layer(driverLayer, { excludeTestServices: true })("AcpRegistryDriver", (it) =
863 identity.instanceId,
864 normalizeAcpRegistryLiveConfiguration([], undefined, {
865 currentModelId: "old-model",
637 - availableModels: [{ modelId: "old-model", name: "old-model" }],
866 + availableModels: [
867 + { modelId: "old-model", name: "old-model" },
868 + { modelId: "session-model", name: "session-model" },
869 + ],
870 }),
871 );
872 yield* fileSystem.writeFileString(modelsPath, JSON.stringify(["old-model", "new-model"]));
packages/provider-acp-registry/src/server/driver.ts
+114 -22
@@ -16,6 +16,7 @@ import * as Digest from "effect/crypto/Digest";
16 import * as SecureRandom from "effect/crypto/SecureRandom";
17 import * as DateTime from "effect/DateTime";
18 import * as Effect from "effect/Effect";
19 +import * as Equal from "effect/Equal";
20 import * as Option from "effect/Option";
21 import * as Ref from "effect/Ref";
22 import * as Result from "effect/Result";
@@ -66,6 +67,53 @@ const DRIVER_KIND = ProviderDriverKind.make("acpRegistry");
67 const decodeSettings = Schema.decodeSync(AcpRegistrySettings);
68 // Cache only successful authenticated probes so sign-in changes remain visible.
69 const PROBE_SUCCESS_TTL_MS = 15 * 60 * 1_000;
70 +const PROBE_PROVISIONAL_TTL_MS = 30 * 1_000;
71 +
72 +function acpRegistryProbeTtlMs(provider: ServerProvider): number {
73 + const discoveredModels = provider.models.filter((model) => !model.isCustom);
74 + return discoveredModels.length <= 1 ? PROBE_PROVISIONAL_TTL_MS : PROBE_SUCCESS_TTL_MS;
75 +}
76 +
77 +interface AcpRegistryEnrichmentCache {
78 + readonly generation: number;
79 + readonly entry: {
80 + readonly provider: ServerProvider;
81 + readonly expiresAt: number;
82 + } | null;
83 +}
84 +
85 +export function updateAcpRegistryEnrichmentCache(input: {
86 + readonly cache: AcpRegistryEnrichmentCache;
87 + readonly configuration: AcpRegistryLiveConfiguration;
88 + readonly customModels: ReadonlyArray<string>;
89 + readonly now: number;
90 +}): AcpRegistryEnrichmentCache {
91 + const { cache, configuration, customModels, now } = input;
92 + if (cache.entry === null) {
93 + // No probe has landed yet, but the live session published its
94 + // configuration to the snapshot. Advance the cache epoch so a probe that
95 + // was still in flight cannot overwrite that newer state when it lands.
96 + return { ...cache, generation: cache.generation + 1 };
97 + }
98 + const provider = applyAcpRegistryLiveConfiguration(
99 + cache.entry.provider,
100 + configuration,
101 + customModels,
102 + );
103 + if (Equal.equals(provider, cache.entry.provider)) return cache;
104 + return {
105 + ...cache,
106 + // The live session advanced the provider past what an in-flight probe
107 + // started from; bump the epoch so the probe discards its stale result
108 + // instead of overwriting this entry and publishing it.
109 + generation: cache.generation + 1,
110 + entry: {
111 + ...cache.entry,
112 + provider,
113 + expiresAt: now + acpRegistryProbeTtlMs(provider),
114 + },
115 + };
116 +}
117 const EMPTY_CAPABILITIES = createModelCapabilities({ optionDescriptors: [] });
118 const MAINTENANCE = makeManualOnlyProviderMaintenanceCapabilities({
119 provider: DRIVER_KIND,
@@ -296,24 +344,39 @@ export function applyAcpRegistryLiveConfiguration(
344 // session/load may omit models (Kimi returns `{}`); keep the probed list
345 // and apply any live option descriptors to it.
346 const probedModels = provider.models.filter((model) => !model.isCustom);
299 - const discovery =
300 - configuration.models.length > 0
301 - ? configuration
302 - : {
303 - ...configuration,
304 - models: probedModels.map((model) => ({
305 - id: model.slug,
306 - name: model.name,
307 - description: null,
308 - })),
309 - currentModelId: probedModels.find((model) => model.isDefault)?.slug ?? null,
310 - };
347 + // A cold-start session can report one placeholder model before its catalog
348 + // settles, while the probe may already have observed the full catalog. A
349 + // single model enumerated by an explicit select is not that fallback but
350 + // the agent's deliberate statement, so it wins over the probe catalog.
351 + const liveCatalogIsProvisional =
352 + configuration.models.length === 1 &&
353 + !configuration.modelsFromModelSelect &&
354 + probedModels.length > 1;
355 + const useLiveCatalog =
356 + configuration.models.length > 1 ||
357 + (configuration.models.length === 1 && !liveCatalogIsProvisional);
358 + const selectedProbedModelId =
359 + configuration.currentModelId !== null &&
360 + probedModels.some((model) => model.slug === configuration.currentModelId)
361 + ? configuration.currentModelId
362 + : (probedModels.find((model) => model.isDefault)?.slug ?? null);
363 + const discovery = useLiveCatalog
364 + ? configuration
365 + : {
366 + ...configuration,
367 + models: probedModels.map((model) => ({
368 + id: model.slug,
369 + name: model.name,
370 + description: null,
371 + })),
372 + currentModelId: selectedProbedModelId,
373 + };
374 return {
375 ...snapshot,
376 status: provider.enabled ? "ready" : provider.status,
377 models:
315 - configuration.models.length === 0 && configuration.configOptions.length === 0
316 - ? provider.models
378 + !useLiveCatalog && configuration.configOptions.length === 0
379 + ? withAcpRegistryDefaultModel(provider.models, selectedProbedModelId)
380 : modelsFromDiscovery(
381 discovery,
382 customModels,
@@ -322,6 +385,23 @@ export function applyAcpRegistryLiveConfiguration(
385 };
386 }
387
388 +function withAcpRegistryDefaultModel(
389 + models: ReadonlyArray<ServerProviderModel>,
390 + currentModelId: string | null,
391 +): ReadonlyArray<ServerProviderModel> {
392 + if (currentModelId === null) return models;
393 + let changed = false;
394 + const next = models.map((model) => {
395 + if (model.isCustom) return model;
396 + const isDefault = model.slug === currentModelId;
397 + if ((model.isDefault ?? false) === isDefault) return model;
398 + changed = true;
399 + const { isDefault: _previous, ...rest } = model;
400 + return isDefault ? { ...rest, isDefault: true } : rest;
401 + });
402 + return changed ? next : models;
403 +}
404 +
405 function applyAcpRegistryUrlAuthAction(
406 provider: ServerProvider,
407 action: Option.Option<NonNullable<ServerProvider["auth"]["action"]>>,
@@ -651,13 +731,10 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
731 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
732 Effect.provideService(SecureRandom.SecureRandom, random),
733 );
654 - const enrichmentCache = yield* Ref.make<{
655 - readonly generation: number;
656 - readonly entry: {
657 - readonly provider: ServerProvider;
658 - readonly expiresAt: number;
659 - } | null;
660 - }>({ generation: 0, entry: null });
734 + const enrichmentCache = yield* Ref.make<AcpRegistryEnrichmentCache>({
735 + generation: 0,
736 + entry: null,
737 + });
738 const liveSnapshotSemaphore = yield* Semaphore.make(1);
739 const invalidateEnrichmentCache = Ref.update(enrichmentCache, (current) => ({
740 generation: current.generation + 1,
@@ -681,13 +758,14 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
758 }
759 const enriched = yield* enrichProvider;
760 if (enriched.status === "ready") {
761 + const completedAt = yield* Clock.currentTimeMillis;
762 yield* Ref.update(enrichmentCache, (current) =>
763 current.generation === cacheState.generation
764 ? {
765 ...current,
766 entry: {
767 provider: enriched,
690 - expiresAt: now + PROBE_SUCCESS_TTL_MS,
768 + expiresAt: completedAt + acpRegistryProbeTtlMs(enriched),
769 },
770 }
771 : current,
@@ -760,6 +838,20 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
838 liveSnapshotSemaphore.withPermit(
839 getSnapshot.pipe(
840 Effect.flatMap((current) => applyLiveConfiguration(current, configuration)),
841 + Effect.tap(() =>
842 + Clock.currentTimeMillis.pipe(
843 + Effect.flatMap((now) =>
844 + Ref.update(enrichmentCache, (cache) =>
845 + updateAcpRegistryEnrichmentCache({
846 + cache,
847 + configuration,
848 + customModels: effectiveConfig.customModels,
849 + now,
850 + }),
851 + ),
852 + ),
853 + ),
854 + ),
855 Effect.flatMap(publishSnapshot),
856 ),
857 ),
packages/provider-acp-registry/src/server/probe.ts
+80 -15
@@ -45,6 +45,9 @@ const MAX_DESCRIPTION_LENGTH = 1_024;
45 const MAX_COMMAND_LINE_LENGTH = 2_048;
46 const PROBE_TIMEOUT_MS = 60_000;
47 const COMMAND_ADVERTISEMENT_GRACE = "500 millis";
48 +// Agents that fetch their catalog after session setup (Qoder CLI, OpenCode)
49 +// settle it in seconds, not milliseconds; commands arrive much sooner.
50 +const MODEL_ADVERTISEMENT_GRACE = "5 seconds";
51 const PROBE_SESSION_DELETE_TIMEOUT = "5 seconds";
52
53 const boundedText = (value: string, maximumLength: number): string =>
@@ -202,6 +205,9 @@ export interface AcpRegistryLiveConfiguration {
205 readonly currentModelId: string | null;
206 readonly configOptions: AcpRegistryProbeResult["configOptions"];
207 readonly modelOptionIds?: NonNullable<AcpRegistryProbeResult["modelOptionIds"]>;
208 + // A single model from an explicit select is the agent's deliberate catalog
209 + // (e.g. an entitlement change), not a cold-start placeholder.
210 + readonly modelsFromModelSelect?: boolean;
211 }
212
213 export function normalizeAcpRegistryLiveConfiguration(
@@ -251,6 +257,7 @@ export function normalizeAcpRegistryLiveConfiguration(
257 modelOptionIds: descriptors
258 .filter((descriptor) => modelOptionIds.has(descriptor.id))
259 .map((descriptor) => descriptor.id),
260 + modelsFromModelSelect: modelOption !== undefined,
261 };
262 }
263
@@ -259,6 +266,17 @@ const emptyAcpRegistryAvailableCommands = (): AcpRegistryAvailableCommands => ({
266 skills: [],
267 });
268
269 +export function acpRegistryAdvertisesModelCatalog(
270 + configOptions: ReadonlyArray<EffectAcpSchema.SessionConfigOption> | null | undefined,
271 + modelState?: EffectAcpSchema.SessionModelState | null,
272 +): boolean {
273 + const modelOption = findModelConfigOption(configOptions);
274 + return (
275 + (modelOption !== undefined && flattenSelectChoices(modelOption.options).length > 1) ||
276 + (modelState?.availableModels?.length ?? 0) > 1
277 + );
278 +}
279 +
280 export function normalizeAcpRegistryCommands(
281 commands: ReadonlyArray<EffectAcpSchema.AvailableCommand>,
282 ): AcpRegistryAvailableCommands {
@@ -299,12 +317,15 @@ export function acpRegistryProbeResult(
317 started: AcpSessionRuntime.AcpSessionRuntimeStartResult,
318 icon: string | null = null,
319 spawn?: AcpRegistryAuthSpawnContext,
320 + liveConfiguration?: AcpRegistryLiveConfiguration,
321 ): AcpRegistryProbeResult {
303 - const liveConfiguration = normalizeAcpRegistryLiveConfiguration(
304 - started.sessionSetupResult.configOptions ?? [],
305 - parseSessionModeState(started.sessionSetupResult),
306 - started.sessionSetupResult.models,
307 - );
322 + const configuration =
323 + liveConfiguration ??
324 + normalizeAcpRegistryLiveConfiguration(
325 + started.sessionSetupResult.configOptions ?? [],
326 + parseSessionModeState(started.sessionSetupResult),
327 + started.sessionSetupResult.models,
328 + );
329 return AcpRegistryProbeResult.make({
330 instanceId,
331 ready: true,
@@ -318,7 +339,7 @@ export function acpRegistryProbeResult(
339 canDelete: started.initializeResult.agentCapabilities?.sessionCapabilities?.delete != null,
340 canConfigureProviders: started.initializeResult.agentCapabilities?.providers != null,
341 },
321 - ...liveConfiguration,
342 + ...configuration,
343 });
344 }
345
@@ -428,6 +449,10 @@ export const probeAcpRegistryConfiguration = Effect.fn("AcpRegistryProbe.probeCo
449 emptyAcpRegistryAvailableCommands(),
450 );
451 const commandsAdvertised = yield* Deferred.make<void>();
452 + const configOptionsRef = yield* Ref.make<
453 + ReadonlyArray<EffectAcpSchema.SessionConfigOption> | undefined
454 + >(undefined);
455 + const modelsAdvertised = yield* Deferred.make<void>();
456 yield* runtime.handleElicitation((request) =>
457 Effect.gen(function* () {
458 if (
@@ -459,12 +484,23 @@ export const probeAcpRegistryConfiguration = Effect.fn("AcpRegistryProbe.probeCo
484 );
485 yield* runtime.handleSessionUpdate((notification) => {
486 const update = notification.update;
462 - return update.sessionUpdate === "available_commands_update"
463 - ? Ref.set(commandsRef, normalizeAcpRegistryCommands(update.availableCommands)).pipe(
464 - Effect.andThen(Deferred.succeed(commandsAdvertised, undefined)),
465 - Effect.asVoid,
466 - )
467 - : Effect.void;
487 + if (update.sessionUpdate === "available_commands_update") {
488 + return Ref.set(commandsRef, normalizeAcpRegistryCommands(update.availableCommands)).pipe(
489 + Effect.andThen(Deferred.succeed(commandsAdvertised, undefined)),
490 + Effect.asVoid,
491 + );
492 + }
493 + if (update.sessionUpdate === "config_option_update") {
494 + const hasAdvertisedModels = acpRegistryAdvertisesModelCatalog(update.configOptions);
495 + return Ref.set(configOptionsRef, update.configOptions).pipe(
496 + Effect.andThen(
497 + hasAdvertisedModels
498 + ? Deferred.succeed(modelsAdvertised, undefined).pipe(Effect.asVoid)
499 + : Effect.void,
500 + ),
501 + );
502 + }
503 + return Effect.void;
504 });
505 const startResult = yield* Effect.result(runtime.start());
506 if (Result.isFailure(startResult)) {
@@ -482,10 +518,38 @@ export const probeAcpRegistryConfiguration = Effect.fn("AcpRegistryProbe.probeCo
518 .deleteSession(started.sessionId)
519 .pipe(Effect.timeoutOption(PROBE_SESSION_DELETE_TIMEOUT), Effect.ignore),
520 );
485 - yield* Deferred.await(commandsAdvertised).pipe(
486 - Effect.timeoutOption(COMMAND_ADVERTISEMENT_GRACE),
521 + const hasInitialModels = acpRegistryAdvertisesModelCatalog(
522 + started.sessionSetupResult.configOptions,
523 + started.sessionSetupResult.models,
524 + );
525 +
526 + yield* Effect.all(
527 + [
528 + hasInitialModels
529 + ? Effect.void
530 + : Deferred.await(modelsAdvertised).pipe(
531 + Effect.timeoutOption(MODEL_ADVERTISEMENT_GRACE),
532 + ),
533 + Deferred.await(commandsAdvertised).pipe(
534 + Effect.timeoutOption(COMMAND_ADVERTISEMENT_GRACE),
535 + ),
536 + ],
537 + { concurrency: "unbounded" },
538 + );
539 +
540 + // config_option_update replaces the full option set, so an empty notice is authoritative.
541 + const liveConfiguration = normalizeAcpRegistryLiveConfiguration(
542 + (yield* Ref.get(configOptionsRef)) ?? (yield* runtime.getConfigOptions),
543 + (yield* runtime.getModeState) ?? parseSessionModeState(started.sessionSetupResult),
544 + started.sessionSetupResult.models,
545 );
488 - return { resolved, started, commands: yield* Ref.get(commandsRef) };
546 +
547 + return {
548 + resolved,
549 + started,
550 + commands: yield* Ref.get(commandsRef),
551 + liveConfiguration,
552 + };
553 }).pipe(
554 Effect.scoped,
555 Effect.timeoutOrElse({
@@ -511,6 +575,7 @@ export const probeAcpRegistryConfiguration = Effect.fn("AcpRegistryProbe.probeCo
575 command: result.resolved.spawn.command,
576 args: result.resolved.spawn.args,
577 },
578 + result.liveConfiguration,
579 ),
580 slashCommands: result.commands.slashCommands,
581 skills: result.commands.skills,