fix(server): keep Codex's reset answer when the re-probe fails (#13363)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
f26ee083fe
commit
ffb5fcce73
3 files changed
+58
-6
No files matched your search
@@ -315,16 +315,19 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
|
||||
// The windows just changed; re-probe so the snapshot says so. A
|
||||
// failed probe republishes the pre-redemption limits rather than
|
||||
// marking them failed, so "confirmed" means `checkedAt` moved
|
||||
// past what was published before the redemption started.
|
||||
Effect.tap(() =>
|
||||
// past what was published before the redemption started. Only a
|
||||
// reset claims the limits changed, so only a reset reports an
|
||||
// unconfirmed refresh.
|
||||
Effect.tap((outcome) =>
|
||||
Effect.gen(function* () {
|
||||
const before = (yield* snapshot.getSnapshot).usageLimits?.checkedAt;
|
||||
const refreshed = yield* snapshot.refresh;
|
||||
const after = refreshed.usageLimits?.checkedAt;
|
||||
if (
|
||||
after === undefined ||
|
||||
after === before ||
|
||||
refreshed.usageLimits?.unavailable?.reason === "probeFailed"
|
||||
outcome === "reset" &&
|
||||
(after === undefined ||
|
||||
after === before ||
|
||||
refreshed.usageLimits?.unavailable?.reason === "probeFailed")
|
||||
) {
|
||||
return yield* new ProviderDriverError({
|
||||
driver: DRIVER_KIND,
|
||||
|
||||
@@ -338,6 +338,44 @@ describe("ProviderInstanceRegistryLive — multi-instance codex slice", () => {
|
||||
}).pipe(Effect.provide(testLayer)),
|
||||
);
|
||||
|
||||
it.live("reports Codex's answer when a redemption changed nothing", () =>
|
||||
Effect.gen(function* () {
|
||||
if (yield* isHostWindows) return;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const fixtures = yield* makeTildeProviderFixtures();
|
||||
yield* fileSystem.writeFileString(
|
||||
fixtures.codexScriptPath,
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off - fixed script document read by the external Codex mock peer.
|
||||
JSON.stringify({
|
||||
rootThreadId: "probe-thread",
|
||||
notifications: [],
|
||||
account: { type: "chatgpt", email: "[email protected]", planType: "plus" },
|
||||
failRateLimitsRead: true,
|
||||
resetCreditOutcome: "alreadyRedeemed",
|
||||
}),
|
||||
);
|
||||
const codexId = ProviderInstanceId.make("codex_reset");
|
||||
const { registry } = yield* makeProviderInstanceRegistry({
|
||||
drivers: [CodexDriver],
|
||||
configMap: {
|
||||
[codexId]: {
|
||||
driver: ProviderDriverKind.make("codex"),
|
||||
enabled: true,
|
||||
environment: [
|
||||
{ name: "T3_CODEX_COLLAB_SCRIPT", value: fixtures.codexScriptPath, sensitive: false },
|
||||
],
|
||||
config: makeCodexConfig({ enabled: true, binaryPath: fixtures.codexBinaryPath }),
|
||||
},
|
||||
},
|
||||
});
|
||||
const codex = yield* registry.getInstance(codexId);
|
||||
expect(codex).toBeDefined();
|
||||
// The usage read fails, so the re-probe cannot confirm new limits.
|
||||
yield* codex!.snapshot.refresh;
|
||||
expect(yield* codex!.consumeResetCredit!()).toBe("alreadyRedeemed");
|
||||
}).pipe(Effect.provide(testLayer)),
|
||||
);
|
||||
|
||||
it.live("runs Codex and Claude readiness probes from configured tilde paths", () =>
|
||||
Effect.gen(function* () {
|
||||
if (yield* isHostWindows) return;
|
||||
|
||||
@@ -84,7 +84,18 @@ rl.on("line", (line) => {
|
||||
return;
|
||||
}
|
||||
if (method === "account/read") {
|
||||
write({ id, result: { account: { type: "apiKey" }, requiresOpenaiAuth: false } });
|
||||
write({
|
||||
id,
|
||||
result: { account: script.account ?? { type: "apiKey" }, requiresOpenaiAuth: false },
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (method === "account/rateLimits/read" && script.failRateLimitsRead) {
|
||||
write({ id, error: { code: -32000, message: "usage unavailable" } });
|
||||
return;
|
||||
}
|
||||
if (method === "account/rateLimitResetCredit/consume" && script.resetCreditOutcome) {
|
||||
write({ id, result: { outcome: script.resetCreditOutcome } });
|
||||
return;
|
||||
}
|
||||
if (method === "skills/list" || method === "model/list") {
|
||||
|
||||
Reference in new issue
Block a user