Skip to content

Commit f668cb4

Browse files
committed
fix(acp-registry): refresh GLM auth after a signed-out usage read
A usage-only recovery read now triggers a full refresh when the agent reports it is signed out, so the snapshot stops showing GLM as authenticated. The GLM read also turns defects into unavailable limits and logs the failure.
1 parent fc43a9a commit f668cb4

2 files changed

Lines changed: 35 additions & 13 deletions

File tree

‎packages/provider-acp-registry/src/server/driver.ts‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
type ProviderDriver,
3434
type ProviderInstance,
3535
} from "@t3tools/provider-core/server/driver";
36+
import type { ManagedServerProvider } from "@t3tools/provider-core/server/snapshot";
3637
import { providerModelsFromSettings } from "@t3tools/provider-core/server/snapshotProbe";
3738
import { makeManualOnlyProviderMaintenanceCapabilities } from "@t3tools/provider-core/server/maintenanceResolver";
3839
import {
@@ -633,17 +634,23 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
633634
}),
634635
);
635636
});
636-
const readUsageLimits: AcpRegistryUsageLimitsReader = scopedGlmUsageLimitsReader({
637-
instanceId,
638-
displayName,
639-
setAuthentication: (confirmed) => confirmedAuthentication.set(confirmed),
640-
read: (input) =>
641-
readAcpRegistryGlmUsageLimits(input).pipe(
642-
Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, catalog),
643-
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
644-
Effect.provideService(SecureRandom.SecureRandom, random),
645-
),
646-
});
637+
const makeUsageLimitsReader = (onSignedOut: Effect.Effect<void>) =>
638+
scopedGlmUsageLimitsReader({
639+
instanceId,
640+
displayName,
641+
setAuthentication: (confirmed) =>
642+
confirmedAuthentication
643+
.set(confirmed)
644+
.pipe(Effect.andThen(confirmed ? Effect.void : onSignedOut)),
645+
read: (input) =>
646+
readAcpRegistryGlmUsageLimits(input).pipe(
647+
Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, catalog),
648+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
649+
Effect.provideService(SecureRandom.SecureRandom, random),
650+
),
651+
});
652+
const readUsageLimits = makeUsageLimitsReader(Effect.void);
653+
const refreshScope = yield* Effect.scope;
647654
const checkProvider = checkAcpRegistryProvider({
648655
...readinessInput,
649656
cwd: host.paths.cwd,
@@ -713,7 +720,7 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
713720
return { provider: enriched, generation: cacheState.generation };
714721
});
715722
const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig);
716-
const snapshot = yield* makeManagedServerProvider<
723+
const snapshot: ManagedServerProvider = yield* makeManagedServerProvider<
717724
ProviderSnapshotSettings<AcpRegistrySettings>
718725
>({
719726
resolveMaintenance: () => Effect.succeed(MAINTENANCE),
@@ -724,7 +731,15 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
724731
checkProvider,
725732
...(isZaiUsageLimitsInstance(effectiveConfig)
726733
? {
727-
checkUsageLimits: readUsageLimits({
734+
// This read holds the refresh permit and republishes only limits, so a sign-out refreshes after it.
735+
checkUsageLimits: makeUsageLimitsReader(
736+
Effect.suspend(() =>
737+
clearLiveState.pipe(
738+
Effect.andThen(liveSnapshotSemaphore.withPermit(invalidateEnrichmentCache)),
739+
Effect.andThen(snapshot.refresh),
740+
),
741+
).pipe(Effect.forkIn(refreshScope), Effect.asVoid),
742+
)({
728743
instanceId,
729744
settings: effectiveConfig,
730745
cwd: host.paths.cwd,

‎packages/provider-acp-registry/src/server/probe.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { AcpRegistrySettings } from "../settings.ts";
1515
import { makeUnavailableUsageLimits } from "@t3tools/provider-core/server/usageLimits";
1616
import * as SecureRandom from "effect/crypto/SecureRandom";
17+
import * as Cause from "effect/Cause";
1718
import * as DateTime from "effect/DateTime";
1819
import * as Deferred from "effect/Deferred";
1920
import * as Duration from "effect/Duration";
@@ -644,7 +645,13 @@ export const readAcpRegistryGlmUsageLimits = Effect.fn("AcpRegistryProbe.readGlm
644645
effect.pipe(
645646
Effect.scoped,
646647
Effect.timeoutOrElse({ duration: GLM_USAGE_TIMEOUT, orElse: () => glmUsageReadFailed }),
648+
Effect.tapCause((cause) =>
649+
Cause.hasInterruptsOnly(cause)
650+
? Effect.void
651+
: Effect.logWarning("GLM usage read failed", cause),
652+
),
647653
Effect.catch(() => glmUsageReadFailed),
654+
Effect.catchDefect(() => glmUsageReadFailed),
648655
),
649656
);
650657

0 commit comments

Comments
 (0)