Skip to content

Commit 79c9b64

Browse files
committed
fix(restore): clamp preserved family routing safely
1 parent 05c8bf1 commit 79c9b64

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

lib/codex-manager.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4594,7 +4594,19 @@ async function persistAndSyncSelectedAccount({
45944594
!!storage.activeIndexByFamily &&
45954595
targetIndex === storage.activeIndex;
45964596
storage.activeIndex = targetIndex;
4597-
if (!shouldPreserveActiveIndexByFamily) {
4597+
storage.activeIndexByFamily = storage.activeIndexByFamily ?? {};
4598+
if (shouldPreserveActiveIndexByFamily) {
4599+
const maxIndex = Math.max(0, storage.accounts.length - 1);
4600+
for (const family of MODEL_FAMILIES) {
4601+
const raw = storage.activeIndexByFamily[family];
4602+
const candidate =
4603+
typeof raw === "number" && Number.isFinite(raw) ? raw : targetIndex;
4604+
storage.activeIndexByFamily[family] = Math.max(
4605+
0,
4606+
Math.min(candidate, maxIndex),
4607+
);
4608+
}
4609+
} else {
45984610
storage.activeIndexByFamily = storage.activeIndexByFamily ?? {};
45994611
for (const family of MODEL_FAMILIES) {
46004612
storage.activeIndexByFamily[family] = targetIndex;

0 commit comments

Comments
 (0)