Skip to content

Commit 0408bb7

Browse files
fix(provider): keep usage ticks and terminal updates untraced
1 parent 8a10225 commit 0408bb7

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

‎packages/provider-core/src/server/managedProvider.ts‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,25 +192,26 @@ export const makeManagedServerProvider = Effect.fn("makeManagedServerProvider")(
192192
const applySnapshot = (nextSettings: Settings, options?: { readonly forceRefresh?: boolean }) =>
193193
refreshSemaphore.withPermits(1)(applySnapshotBase(nextSettings, options));
194194

195-
const applyUsageLimits: ManagedServerProvider["applyUsageLimits"] = Effect.fn(
196-
"managedProvider.applyUsageLimits",
197-
)(function* (update) {
198-
const snapshotToPublish = yield* Ref.modify(snapshotStateRef, (state) => {
199-
const usageLimits = applyUsageLimitsUpdate({
200-
previous: state.snapshot.usageLimits,
201-
update,
202-
checkedAt: update.checkedAt,
195+
// Providers call this on every token-usage tick, usually without changing the snapshot.
196+
const applyUsageLimits: ManagedServerProvider["applyUsageLimits"] = Effect.fnUntraced(
197+
function* (update) {
198+
const snapshotToPublish = yield* Ref.modify(snapshotStateRef, (state) => {
199+
const usageLimits = applyUsageLimitsUpdate({
200+
previous: state.snapshot.usageLimits,
201+
update,
202+
checkedAt: update.checkedAt,
203+
});
204+
if (usageLimits === state.snapshot.usageLimits) {
205+
return [null, state] as const;
206+
}
207+
const snapshot = withUsageLimits(state.snapshot, usageLimits);
208+
return [snapshot, { ...state, snapshot }] as const;
203209
});
204-
if (usageLimits === state.snapshot.usageLimits) {
205-
return [null, state] as const;
210+
if (snapshotToPublish !== null) {
211+
yield* PubSub.publish(changesPubSub, snapshotToPublish);
206212
}
207-
const snapshot = withUsageLimits(state.snapshot, usageLimits);
208-
return [snapshot, { ...state, snapshot }] as const;
209-
});
210-
if (snapshotToPublish !== null) {
211-
yield* PubSub.publish(changesPubSub, snapshotToPublish);
212-
}
213-
});
213+
},
214+
);
214215

215216
const refreshSnapshot = Effect.fn("refreshSnapshot")(function* () {
216217
const nextSettings = yield* input.getSettings;

‎packages/provider-core/src/server/providerAuthFlow.ts‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,22 +281,21 @@ export const make = Effect.fn("ProviderAuthFlow.make")(function* (options: {
281281
expiresAt: flow.expiresAt,
282282
...(returnUrl ? { returnUrl } : {}),
283283
...(callbackMode ? { callbackMode } : {}),
284-
setInteraction: Effect.fn("providerAuthFlow.setInteraction")(
285-
function* (interaction, respond, complete) {
286-
if (active !== flow) return;
287-
flow.respond = respond;
288-
flow.complete = complete;
289-
yield* publish(flow, {
290-
phase: "waiting",
291-
interaction,
292-
authorizationUrl:
293-
interaction.type === "browser" || interaction.type === "deviceCode"
294-
? interaction.url
295-
: null,
296-
message: "Complete sign-in to continue.",
297-
});
298-
},
299-
),
284+
// Terminal sign-in updates this for every output chunk within the auth operation.
285+
setInteraction: Effect.fnUntraced(function* (interaction, respond, complete) {
286+
if (active !== flow) return;
287+
flow.respond = respond;
288+
flow.complete = complete;
289+
yield* publish(flow, {
290+
phase: "waiting",
291+
interaction,
292+
authorizationUrl:
293+
interaction.type === "browser" || interaction.type === "deviceCode"
294+
? interaction.url
295+
: null,
296+
message: "Complete sign-in to continue.",
297+
});
298+
}),
300299
verifying: Effect.gen(function* () {
301300
flow.respond = undefined;
302301
flow.complete = undefined;

0 commit comments

Comments
 (0)