Skip to content

#1874 item 1: persist auto-renew episode claims and Codex preheat gates - #1972

Open
dofastted wants to merge 4 commits into
devfrom
cursor/1874-renew-claim-persist-01a2
Open

dofastted wants to merge 4 commits into
devfrom
cursor/1874-renew-claim-persist-01a2

Conversation

@dofastted

@dofastted dofastted commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

问题与结果

此前 auto_renew 扫窗用进程内 renewFiredAt,stop/reload 会清掉状态,同一窗口可能重复续热;且在 gate 跳过前就登记,导致本可重试的窗口被“吃掉”。探测抛错时 cron 仍可放行,但续热路径不应发真实请求。Codex 预热 gate 未对齐调度器的额度判定。

改后:按 vmId + accountId + 旧 5h/7d reset(秒级) 生成 episode key,领取写入独立 vm_test_renew_claim:<vmId>;仅 gate 通过后才领取并发送;auto_renew 探测不可用记 probe_unavailable 且不发请求。生产 windowState 经 preheatWindowStateLikeServer(vm, () => routingConfig, …) 现读全局 routingConfig.codex.quota(Codex 不认 vm.policy.quota,与 evaluateCodexQuotaSchedule 一致的全局阈值)。续热 gate 跳过:同一 last_skipped 原因不重复写 SettingsRepo;原因变化时记一次;续热成功后清除内存去重表,同一原因再次拦下可再记。

Refs #1874

目标版本: ≥ 1.4.237(CHANGELOG / VERSION 本 PR 不改;发版说明只写此处)

Release notes(不落 CHANGELOG):

  • 自动续热 episode 领取持久化,重启/重载不会对同一 episode 重复发送。
  • 续热 gate 跳过不消耗领取;同原因多次扫窗不反复刷面板;探测失败时续热路径不发真实请求。
  • Codex 预热/续热 gate 仅使用路由全局 codex.quota 的 limit_5h / limit_7d;阈值由运营配置。

本 PR 不阻断(待后续 / ted 口径):

  • 领取后若发送失败、或 _run 早退,仍会消耗该 episode 领取且跨重启不重试。
  • Claude 槽 auto_renew 同样走持久领取与 probe_unavailable(口径 4 待 ted 确认)。
  • item 2/3(严格终态判定、恢复冷却 / 临时 P1)未实现。

实现

  • preheatOpenAIQuotaPolicy(全局 only)、preheatWindowStateLikeServer(server + 单测共用):vm-test-preheat-window.mjs
  • VM_TEST_RENEW_CLAIM_PREFIX、_maybeRecordRenewGateSkip、成功后续热清除 skip 内存:vm-test-schedule.mjs
  • server.mjs:preheatWindowStateLikeServer / renewEpisodeKey / onRenewGateSkip

验证

npx biome check src/lib/admin/vm-test-preheat-window.mjs src/lib/admin/vm-test-schedule.mjs src/server.mjs test/unit/issue-1874.test.mjs test/unit/vm-test-schedule.test.mjs
# Checked 5 files — OK

node --test test/unit/issue-1874.test.mjs test/unit/vm-test-schedule.test.mjs
# tests 40, pass 40, fail 0
Open in Web Open in Cursor 

Note

Medium Risk
Changes scheduled preheat/auto-renew behavior and persisted settings; mis-gating could skip or duplicate renew traffic, but does not touch auth or inference routing.

Reviewed by Cursor Bugbot for commit eb9d46e. Configure here.

@cursor

cursor Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 7ca069b3-bb95-426a-b8da-496d4be28b45)

cursoragent and others added 2 commits November 27, 2026 07:27
Store vm_test_renew_claim per VM so stop/reload cannot resend the same
5h/7d episode. Skips no longer consume claims; auto-renew treats probe
failures as probe_unavailable. Codex preheat probes honor isCodexSlotParked
and quota window reasons before firing.

Co-authored-by: ted <kuhlmangarry24@gmail.com>
Pass routingConfig soft limits via preheatWindowStateForVm on the server.
Gate-blocked auto-renew sweeps only throttle in-memory/debug logs, not
last_run fields in SettingsRepo.

Co-authored-by: ted <kuhlmangarry24@gmail.com>
@cursor
cursor Bot force-pushed the cursor/1874-renew-claim-persist-01a2 branch from 530946e to b125ff1 Compare November 27, 2026 07:28
cursoragent and others added 2 commits November 27, 2026 07:35
Read routingConfig.codex.quota at windowState call time; record auto-renew
gate skips only when the skip reason changes.

Co-authored-by: ted <kuhlmangarry24@gmail.com>
Drop vm.policy.quota from preheat policy; server calls
preheatWindowStateLikeServer. Clear renew gate-skip memory on success.

Co-authored-by: ted <kuhlmangarry24@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants