@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
56 lines • 2.8 kB
JavaScript
import { formatSelector } from "./chains.js";
/**
* A billing pin assumes the original's account cannot recover by retrying it. A sign-in changes
* that account, so when the original provider's login id moved since the episode began, the
* billing pin and the original's cooldown, unusable mark and circuit are released and the
* existing revert path tries it once. A still-dead original falls back again and pins with the
* fresh id. This step reads the store at a turn boundary only while a billing pin holds; the
* other read is `applyCandidate` (controller.ts), once when an episode begins at its first
* fallback switch, to record the starting id. A token refresh keeps the id or drops it to "", and
* an id that is gone ("") is no sign-in, so neither releases. Refusal pins hold: a new credential
* does not change the context that was refused (senpi#4099).
*/
export async function releaseOnCredentialChange(state, original, deps, unusable) {
if (!state.pinnedByBilling || state.recoveryRevision === undefined || !deps.recoveryRevision)
return;
const revision = await deps.recoveryRevision(original.provider);
if (!revision || revision === state.recoveryRevision)
return;
state.recoveryRevision = revision;
state.pinnedByBilling = false;
state.pinned = state.pinnedByRefusal;
const selector = formatSelector(original);
deps.cooldowns.clearModel(selector);
unusable.clear(original);
deps.circuits?.close(selector);
deps.logger.info("credential_recovery_released", {
chainKey: state.chainKey,
originalSelector: state.originalSelector,
trigger: "sign-in",
});
}
/**
* A billing pin a usage limit caused holds only until the reset that limit stated: the account serves again
* then, so the pin and the original's cooldown, unusable mark and circuit are released and the existing
* revert path tries it once, with no re-login (senpi#4085). A pin with no stated reset (an empty credit
* balance) still holds until a sign-in. A still-spent original falls back and pins again.
*/
export function releaseOnLimitReset(state, original, deps, unusable) {
if (!state.pinnedByBilling || state.pinnedUntil === undefined)
return;
if (deps.cooldowns.wallClock() < state.pinnedUntil)
return;
state.pinnedByBilling = false;
state.pinnedUntil = undefined;
state.pinned = state.pinnedByRefusal;
const selector = formatSelector(original);
deps.cooldowns.clearModel(selector);
unusable.clear(original);
deps.circuits?.close(selector);
deps.logger.info("credential_recovery_released", {
chainKey: state.chainKey,
originalSelector: state.originalSelector,
trigger: "limit-reset",
});
}
//# sourceMappingURL=credential-recovery.js.map