Skip to content

feat(quota): add Anthropic daily VM session creation gate - #2441

Open
dofastted wants to merge 3 commits into
devfrom
feat/anthropic-daily-session-gate
Open

dofastted wants to merge 3 commits into
devfrom
feat/anthropic-daily-session-gate

Conversation

@dofastted

@dofastted dofastted commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

变更摘要

  • 改前:Anthropic/Claude 槽位仅按 5h/7d 配额利用率与并发席位调度,缺乏按自然日(可配 IANA 时区)限制单 Anthropic 账号新建主会话数的硬闸门;无法按账号聚合每日新建会话计数、跨进程重启恢复、同步阻断同账号兄弟槽或在面板按分档与单槽 3 态覆盖管理。
  • 改后:
    • 存储与配置:新增 SQLite 增量迁移 075_vm_daily_session_creations.sql 与 PostgreSQL 18 迁移 014_vm_daily_session_creations.sql、双库仓储 src/lib/db/repos/daily-session-gate-repo.mjs(PG 走非阻塞 pgPool)、以及 migrate-sqlite-to-pg.mjs / seed-mock-sqlite.mjs 对接;在 routing.quota.daily_session_gate 增加开关(默认关闭)、reset_timezone(默认 UTC,支持任意合法 IANA 时区)与 6 档 tier_limits(default/pro/max_5x/max_20x/team/enterprise),支持单槽 quota_override.daily_session_limit(null 跟随分档 / 0 不限 / 1..100000 上限)。
    • 核心闸门与调度:src/lib/pool/daily-session-gate.mjs 实现按 account_uuid(无 UUID 回退 vm_id)的日历日切换、DST、时区热切换、预占/幂等提交/预提交释放与并发重复会话零泄漏清理;接入 M3 Rust 调度器运行时(scheduler-runtime.mjs / failover-runner.mjs / pool-scheduler.mjs,含同账号兄弟槽 new_sessions_blocked 遥测同步与 explainDispatch 一致性)、Agent Sessions(handle-agent-sessions.mjs,按租户隔离 kernelSessionId 建键且延迟 sticky 绑定至提交点)以及 src/server.mjs(含 activateStandby 回填与备份恢复重绑)。
    • 错误码与状态映射:errors.mjs、handle-protocol.mjs 与 error-class.mjs 端到端保留 HTTP 429 daily_session_limit + Retry-After(归类 rate_limit 并计入 SLA_OK_ERROR_CODES);schedule-state.mjs 映射 restricted / new_session / 今日新会话上限;更新 docs/PANEL_API.md。
    • 前端面板:在「设置 → 配额」新增每日新会话闸门卡片与 6 档弹窗、修复 TimezonePicker 自定义 IANA 时区入口;在 VM 调度区抽出 vm-scheduling-model.ts 支持 3 态 daily_session_limit 覆盖并在详情状态板/列表展示实时用量、在途数与重置时间。
  • 未改 / 延后:不限制 Codex 槽位、续接已提交会话、子代理请求、探针与管理员 pinVmId;未修改 scheduler/ Rust 源码(树哈希保持 cac6c91fea2c1f4f5a798bd3a4c6d5d37a55f445);未修改 CHANGELOG.md。

验收记录(Run)

  • 环境与基线:Head SHA 90c7aff67(基于 origin/dev 7870fa8d52c7dcc4f2af6701a45f23f6a6a37248 rebase 后在独立工作树 <worktree> 完成全套复验,已解决 test/unit/routing-runtime-load.test.mjs 导入块冲突并按 Prettier 规范格式化 web/src/features/vm/vm-list-table.test.tsx)。
  • 已跑命令与结果:
    • find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check:PASS(exit 0)
    • ./node_modules/.bin/biome format(29 个变更/新增后端 .mjs 文件,check-only):PASS(Checked 29 files, 0 diffs)
    • KIN_SCHEDULER_BIN=<local bin/kin-scheduler> npm run test:ci:PASS(13/13 isolated files, exit 0)
    • KIN_SCHEDULER_BIN=<local bin/kin-scheduler> node --test test/unit/{routing-runtime-load,errors-map,error-class,vm-quota-override,scheduler-m3-runtime,rust-kernel-health,failover-runner,pool-scheduler,availability,sqlite-to-pg-migration,scheduler-m0-migrations,bg-migration-guard,database}.test.mjs:PASS(395 pass / 0 fail / 2 skipped live-PG)
    • node --test test/unit/schedule-state.test.mjs:11 pass / 1 fail(全部新增 daily_session_limit 断言通过;唯一失败项为 origin/dev 基线既有 crag_prompt_replace_empty_unsupported, license_invalid)
    • pnpm -C web exec prettier --check(19 个变更/新增前端文件):PASS(exit 0)
    • pnpm -C web test:ci:PASS(9/9 files, 99/99 tests)
    • pnpm -C web exec vitest run src/features/vm/proxy-timezone-copy.test.tsx src/features/settings/settings-routing-audit.test.tsx src/features/settings/index.test.tsx src/lib/vm-status.test.ts src/features/vm/vm-list-table.test.tsx src/features/vm/status-today.test.tsx src/features/pools/pools.test.ts:PASS(7/7 files, 129/129 tests)
    • pnpm -C web typecheck:PASS(tsc -b, exit 0)
    • pnpm -C web build:PASS(tsc -b && vite build, 4523 modules, built in 15.52s, exit 0)

回退与手破验证(Broken by hand)

  • 后端 src/lib/pool/daily-session-gate.mjs 关闭上限阻塞判断 -> test/unit/vm-quota-override.test.mjs FAIL(true !== false,10/11)-> 恢复原实现后 PASS(11/11)
  • 后端 src/lib/scheduler/scheduler-runtime.mjs 跳过 commitLease 内 dailyGate.commitReservation -> test/unit/scheduler-m3-runtime.test.mjs FAIL(0 !== 1,12/13)-> 恢复原实现后 PASS(13/13)
  • 后端 src/lib/protocol/handle-agent-sessions.mjs 跳过 if (gate) 每日会话过滤 -> test/unit/rust-kernel-health.test.mjs FAIL(0 !== 1,26/27)-> 恢复原实现后 PASS(27/27)
  • 后端 src/lib/core/errors.mjs 禁用 inboundCode === ErrorCode.DAILY_SESSION_LIMIT 分支 -> test/unit/errors-map.test.mjs FAIL('upstream_rate_limit' !== 'daily_session_limit',40/41)-> 恢复原实现后 PASS(41/41)
  • 后端 src/lib/protocol/handle-agent-sessions.mjs 将 boundCommitted 弱化为 Boolean(boundVm) -> test/unit/rust-kernel-health.test.mjs FAIL(重试漏计数 0 !== 1,27/28)-> 恢复原实现后 PASS(28/28)
  • 前端 web/src/features/settings/routing-draft.ts 将 dailySessions 待应用检测改为比较整个 quota 对象 -> web/src/features/settings/settings-routing-audit.test.tsx FAIL(P3-02 期望 dailySessions: false 实得 true,19/20)-> 恢复原实现后 PASS(20/20)
  • 前端 web/src/features/vm/vm-scheduling.tsx 在 patchOf 跳过 kind === 'int' 且值为 0 -> web/src/features/vm/vm-list-table.test.tsx FAIL(期望 { quota_override: { daily_session_limit: 0 } } 实得 {},28/29)-> 恢复原实现后 PASS(29/29)
  • 前端 web/src/features/vm/create-options.ts 回退 resolveTimezonePickerState 为旧逻辑 showCustom = custom && !preset -> web/src/features/vm/proxy-timezone-copy.test.tsx FAIL('UTC' 切换自定义返回 showCustom: false,1/3)-> 恢复原实现后 PASS(3/3)

真实使用(Real use)

  • 未执行真实线上生产流量或真实浏览器交互点击实测:未连接生产环境;后端通过真实 Rust kin-scheduler 二进制(cac6c91fea2c1f4f5a798bd3a4c6d5d37a55f445)在单测中拉起真实调度进程跑通预占/提交/释放/遥测链路,前端通过 Vitest SSR、状态钩子测试及 Vite 生产包构建验收。

未运行项(Not run)

  • 真实 PostgreSQL 18 集成测试:未配置 VM2API_TEST_PG_URL,2 个 live-PG 用例自动跳过(PG 异步仓储与 SQLite→PG 迁移表映射已通过单测与 mock 覆盖)。
  • 全量 556 个后端单测文件、真实浏览器 E2E 点击流程与 ARM64 镜像/生产发布:交由 PR CI 与后续发版流程覆盖,未执行生产部署。

Note

High Risk
Touches session admission, scheduler leases, and persistent quota accounting on the critical Anthropic request path; misconfiguration or hydration/race bugs could incorrectly block new sessions or over-admit past caps.

Overview
Adds a configurable daily limit on new Anthropic/Claude primary sessions per account (tiered global caps, IANA reset timezone, optional per-VM quota_override.daily_session_limit), backed by new SQLite/PG tables and a cross-process reserve → commit → release ledger.

Routing & panel: GET/PUT /routing exposes quota.daily_session_gate; VM list/detail returns daily_sessions runtime stats and surfaces daily_session_limit as restricted / new_session with reset time. Config reload pushes scheduler telemetry.

Admission path: After Rust picks a node, JS reserves a daily slot on the lease; blocked accounts get HTTP 429 daily_session_limit with Retry-After. Continuing sessions (prior-day commits via continuing_node_keys), subagents, probes, and admin pin bypass the cap. Rust admission also exempts continuing_node_keys and ephemeral probes from new_sessions_blocked.

Scheduler sync: Telemetry sets new_sessions_blocked on sibling VMs sharing an account when the cap is hit.

Also: zonedWallToMs DST gap handling for correct day boundaries; migration/seed scripts include the new tables.

Reviewed by Cursor Bugbot for commit 558bebf. Configure here.

## 变更摘要
- 改前:Anthropic/Claude 槽位仅按 5h/7d 配额利用率与并发席位调度,缺乏按自然日(可配 IANA 时区)限制单 Anthropic 账号新建主会话数的硬闸门;无法按账号聚合每日新建会话计数、跨进程重启恢复、同步阻断同账号兄弟槽或在面板按分档与单槽 3 态覆盖管理。
- 改后:
  - 存储与配置:新增 SQLite 增量迁移 `075_vm_daily_session_creations.sql` 与 PostgreSQL 18 迁移 `014_vm_daily_session_creations.sql`、双库仓储 `src/lib/db/repos/daily-session-gate-repo.mjs`(PG 走非阻塞 `pgPool`)、以及 `migrate-sqlite-to-pg.mjs` / `seed-mock-sqlite.mjs` 对接;在 `routing.quota.daily_session_gate` 增加开关(默认关闭)、`reset_timezone`(默认 `UTC`,支持任意合法 IANA 时区)与 6 档 `tier_limits`(`default`/`pro`/`max_5x`/`max_20x`/`team`/`enterprise`),支持单槽 `quota_override.daily_session_limit`(`null` 跟随分档 / `0` 不限 / `1..100000` 上限)。
  - 核心闸门与调度:`src/lib/pool/daily-session-gate.mjs` 实现按 `account_uuid`(无 UUID 回退 `vm_id`)的日历日切换、DST、时区热切换、预占/幂等提交/预提交释放与并发重复会话零泄漏清理;接入 M3 Rust 调度器运行时(`scheduler-runtime.mjs` / `failover-runner.mjs` / `pool-scheduler.mjs`,含同账号兄弟槽 `new_sessions_blocked` 遥测同步与 `explainDispatch` 一致性)、Agent Sessions(`handle-agent-sessions.mjs`,按租户隔离 `kernelSessionId` 建键且延迟 sticky 绑定至提交点)以及 `src/server.mjs`(含 `activateStandby` 回填与备份恢复重绑)。
  - 错误码与状态映射:`errors.mjs`、`handle-protocol.mjs` 与 `error-class.mjs` 端到端保留 HTTP 429 `daily_session_limit` + `Retry-After`(归类 `rate_limit` 并计入 `SLA_OK_ERROR_CODES`);`schedule-state.mjs` 映射 `restricted` / `new_session` / `今日新会话上限`;更新 `docs/PANEL_API.md`。
  - 前端面板:在「设置 → 配额」新增每日新会话闸门卡片与 6 档弹窗、修复 `TimezonePicker` 自定义 IANA 时区入口;在 VM 调度区抽出 `vm-scheduling-model.ts` 支持 3 态 `daily_session_limit` 覆盖并在详情状态板/列表展示实时用量、在途数与重置时间。
- 未改 / 延后:不限制 Codex 槽位、续接已提交会话、子代理请求、探针与管理员 `pinVmId`;未修改 `scheduler/` Rust 源码(树哈希保持 `cac6c91fea2c1f4f5a798bd3a4c6d5d37a55f445`);未修改 `CHANGELOG.md`。

## 验收记录(Run)
- 环境与基线:WSL2 Linux + Windows `git.exe`,基于 `origin/dev` `7870fa8d52c7dcc4f2af6701a45f23f6a6a37248` rebase 后在独立工作树 `/mnt/x/vm2api-wt-anthropic-daily-session-gate` 完成全套复验(已解决 `test/unit/routing-runtime-load.test.mjs` 导入块冲突并按 Prettier 规范格式化 `web/src/features/vm/vm-list-table.test.tsx`)。
- 已跑命令与结果:
  - `find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check`:PASS(exit 0)
  - `./node_modules/.bin/biome format`(29 个变更/新增后端 `.mjs` 文件,check-only):PASS(Checked 29 files, 0 diffs)
  - `KIN_SCHEDULER_BIN=/mnt/x/vm2api-wt-gemini-format-parity/bin/kin-scheduler npm run test:ci`:PASS(13/13 isolated files, exit 0)
  - `KIN_SCHEDULER_BIN=/mnt/x/vm2api-wt-gemini-format-parity/bin/kin-scheduler node --test test/unit/{routing-runtime-load,errors-map,error-class,vm-quota-override,scheduler-m3-runtime,rust-kernel-health,failover-runner,pool-scheduler,availability,sqlite-to-pg-migration,scheduler-m0-migrations,bg-migration-guard,database}.test.mjs`:PASS(395 pass / 0 fail / 2 skipped live-PG)
  - `node --test test/unit/schedule-state.test.mjs`:11 pass / 1 fail(全部新增 `daily_session_limit` 断言通过;唯一失败项为 `origin/dev` 基线既有 `crag_prompt_replace_empty_unsupported, license_invalid`)
  - `pnpm -C web exec prettier --check`(19 个变更/新增前端文件):PASS(exit 0)
  - `pnpm -C web test:ci`:PASS(9/9 files, 99/99 tests)
  - `pnpm -C web exec vitest run src/features/vm/proxy-timezone-copy.test.tsx src/features/settings/settings-routing-audit.test.tsx src/features/settings/index.test.tsx src/lib/vm-status.test.ts src/features/vm/vm-list-table.test.tsx src/features/vm/status-today.test.tsx src/features/pools/pools.test.ts`:PASS(7/7 files, 129/129 tests)
  - `pnpm -C web typecheck`:PASS(`tsc -b`, exit 0)
  - `pnpm -C web build`:PASS(`tsc -b && vite build`, 4523 modules, built in 15.52s, exit 0)

## 回退与手破验证(Broken by hand)
- 后端 `src/lib/pool/daily-session-gate.mjs` 关闭上限阻塞判断 -> `test/unit/vm-quota-override.test.mjs` FAIL(`true !== false`,10/11)-> 恢复原实现后 PASS(11/11)
- 后端 `src/lib/scheduler/scheduler-runtime.mjs` 跳过 `commitLease` 内 `dailyGate.commitReservation` -> `test/unit/scheduler-m3-runtime.test.mjs` FAIL(`0 !== 1`,12/13)-> 恢复原实现后 PASS(13/13)
- 后端 `src/lib/protocol/handle-agent-sessions.mjs` 跳过 `if (gate)` 每日会话过滤 -> `test/unit/rust-kernel-health.test.mjs` FAIL(`0 !== 1`,26/27)-> 恢复原实现后 PASS(27/27)
- 后端 `src/lib/core/errors.mjs` 禁用 `inboundCode === ErrorCode.DAILY_SESSION_LIMIT` 分支 -> `test/unit/errors-map.test.mjs` FAIL(`'upstream_rate_limit' !== 'daily_session_limit'`,40/41)-> 恢复原实现后 PASS(41/41)
- 后端 `src/lib/protocol/handle-agent-sessions.mjs` 将 `boundCommitted` 弱化为 `Boolean(boundVm)` -> `test/unit/rust-kernel-health.test.mjs` FAIL(重试漏计数 `0 !== 1`,27/28)-> 恢复原实现后 PASS(28/28)
- 前端 `web/src/features/settings/routing-draft.ts` 将 `dailySessions` 待应用检测改为比较整个 `quota` 对象 -> `web/src/features/settings/settings-routing-audit.test.tsx` FAIL(`P3-02` 期望 `dailySessions: false` 实得 `true`,19/20)-> 恢复原实现后 PASS(20/20)
- 前端 `web/src/features/vm/vm-scheduling.tsx` 在 `patchOf` 跳过 `kind === 'int'` 且值为 `0` -> `web/src/features/vm/vm-list-table.test.tsx` FAIL(期望 `{ quota_override: { daily_session_limit: 0 } }` 实得 `{}`,28/29)-> 恢复原实现后 PASS(29/29)
- 前端 `web/src/features/vm/create-options.ts` 回退 `resolveTimezonePickerState` 为旧逻辑 `showCustom = custom && !preset` -> `web/src/features/vm/proxy-timezone-copy.test.tsx` FAIL(`'UTC'` 切换自定义返回 `showCustom: false`,1/3)-> 恢复原实现后 PASS(3/3)

## 真实使用(Real use)
- 未执行真实线上 `ph24` 流量或真实浏览器交互点击实测:本次按沙箱与本地提交要求执行,未连接生产环境;后端通过真实 Rust `kin-scheduler` 二进制(`cac6c91fea2c1f4f5a798bd3a4c6d5d37a55f445`)在单测中拉起真实调度进程跑通预占/提交/释放/遥测链路,前端通过 Vitest SSR、状态钩子测试及 Vite 生产包构建验收。

## 未运行项(Not run)
- 真实 PostgreSQL 18 集成测试:未配置 `VM2API_TEST_PG_URL`,2 个 live-PG 用例自动跳过(PG 异步仓储与 SQLite→PG 迁移表映射已通过单测与 mock 覆盖)。
- 全量 556 个后端单测文件、真实浏览器 E2E 点击流程与 ARM64 镜像/生产发布:本次仅按用户指令完成本地原子提交,未推送远端、未开 PR、未部署。
@cursor

cursor Bot commented Dec 1, 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: 3e06daa5-0c11-42b5-8da3-fb67f292c7ae)

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Agentic security review found one HIGH issue: the daily new-session gate treats any client-supplied parent_session_id as a full exemption, including new primary Claude placements.

Open in Web View Automation 

Sent by Cursor Security Agent: Security Reviewer

Comment thread src/lib/pool/daily-session-gate.mjs Resolved
@dofastted

Copy link
Copy Markdown
Owner Author

评审结果(Codex 只读评审合并 origin/dev 3564984d4 后的树,head 90c7aff67;我核对了关键复现输入)

结论 = 需修改后合并,暂不合并。 当前实现不能按“账号每日新建主会话数硬闸门”验收;默认关闭也不满足“零行为变化”。已复现的问题(均为 Major):

阻断硬闸门验收

  1. 跨进程超发:_committed / _pending 都是实例内 Map,数据库只有提交后插入,没有账号上限检查或共享预占。两个闸门实例共享同一个真实内存 SQLite,上限 1,A 提交 s1、B 仍放行并提交 s2,库里 2 行。server.mjs:2074 的蓝绿交接路径(旧实例释放 leader 锁时仍有在途请求)会触发。(我不能据此断言 ph24 当前跑了几个实例。)
  2. 在途预占失效:预占默认 TTL 180s 到期直接删除,不检查请求是否仍在跑(Agent 上游默认超时 600s);跨日重建索引也排除前一天取得的在途预占;随后 commitReservation() 不重新检查上限。两种输入均复现上限 1、最终 used=2(等待 180001ms;23:59:30 预占、次日 00:00:01 另一会话预占)。
  3. PG 时区热切换放行空窗:_handleTimezoneChange() 先切窗口再异步 hydrate,reloadConfig() 同步返回、请求入口没有等 whenReady();18:00Z 从上海改 UTC 时 hydrate 完成前新会话获准,最终 used=2。
  4. PG 写入失败静默丢账:仓储立即返回异步成功,失败只交给可选 onError,生产构造未传;闸门先记内存去重、不再重试。注入 INSERT 连接错误后:recorded=true、重启前 used=1、新实例 hydrate 后 used=0。hydrate 失败(activateStandby 只告警、备份恢复空 catch)后以空账本继续服务。

其它 Major
5. Agent Sessions 跨日续接被拒:hasCommittedSession() 只查当日内存账本;第一天创建 old、第二天达到上限后续接 old,返回 429 且不调用上游。
6. Agent Key 准入抛异常泄漏预占:await acquireManagedKey() 在清理 try/finally 外,注入 rejection 后 pending=1, blocked=true 直到 TTL。
7. 解除每日限制时误清额度保护:#isClaudeQuotaGuardBlocking() 用 #claudeNodeGateContext(null),byVmId 为空、永远返回 false,账号已处于 5h/7d continuing 保护时释放每日预占会发 new_sessions_blocked:false 覆盖它(静态确定,未做真实 Rust 时序复现)。
8. America/Santiago 2026-09-06 跳过午夜:timezone.mjs:55 两轮墙钟换算错误(04:30Z 返回的当天起点实际是前一天 23:00;03:30Z 的 reset_at 已在过去)。这是复用工具函数的既有缺陷,被新功能带入。
9. 默认关闭不是零行为变化:迁移无条件应用、启动无条件 hydrate、commitReservation() 关闭时仍记录(真实内存 SQLite、enabled:false 提交一个会话后新表有 1 行);全局开关关闭也不会关闭正整数单槽覆盖。
10. 豁免不完整:Agent Sessions 管理员 pin(x-kin-pin-vm)仍返回 429 daily_session_limit;M3 的探针 / 子代理豁免依赖 Rust 先放行(全槽触顶、无有效父 sticky、无管理员 pin 的 isEphemeralProbe:true 仍被排除)。

迁移测试:pg-log-writer.test.mjs:184 断言最后一个迁移,实得 014_…、期望 012_…——这是基线上就红的断言(013 时已过期),不是本 PR 引入的;我另开 PR 修,修好后你合并最新 dev 即可。

已核对没问题的:三态解析(0 / null / 正整数)12 种组合;SQLite 075 与 PG 014 的 DDL 对齐、编号连续;导入脚本与 mock seed 对接;新增错误码在 error-class / 对外映射 / 文档里同步;生产接线没有“只在测试里注入”的依赖;M3 上游预提交失败、客户端取消、超时、故障转移换号会释放预占。

测试缺口:PG 延迟查询下的时区切换、两个实例共享真实库、预占超 180s / 跨午夜、Agent 跨日续接与准入抛异常、探针与管理员 pin 分开测、真实 Rust 收到 new_sessions_blocked 后拒绝、真实 PG18 SQL;新增的 server 接线测试是源码正则检查,PG 测试只是 mock pool。

这是新增存储、调度与对外错误码的 5000 行改动,修复项涉及设计选择(共享预占放哪、是否需要 PG 侧原子计数),所以我不替你改。修好后推送,我再整批复验。上述详细复现输入与文件:行号在我这边的评审记录里,需要可以让我贴出。

dofastted added a commit that referenced this pull request Dec 1, 2026
…ssert

test(pg): stop pinning migration 012 as the last PG migration in pg-log-writer (unblocks #2441)
@dofastted
dofastted marked this pull request as draft December 1, 2026 13:56
@dofastted

Copy link
Copy Markdown
Owner Author

我把这个 PR 临时转成了草稿(gh pr ready <N> 即可恢复),原因:上面评审评论里列的 Major 还没修,而这个仓库的 PR 可能被别的会话直接合并(#2446、#2447 刚被合入 dev)。不是否决,修好后推送并恢复为 Ready,我会按同一份清单复验后合并。

nxtreaming pushed a commit to nxtreaming/vm2api that referenced this pull request Dec 1, 2026
…rted a schedule-state row

## 变更摘要
- 改前:`src/lib/pool/upstream-error-policy.mjs` 会发出两个调度原因 `license_invalid`(单槽 resync + 退避重试后仍答 `license_invalid`、尚未提交,换槽重试且不冷却)和 `crag_prompt_replace_empty_unsupported`(旧 CRAG 不支持空 prompt replace,换槽重试且不冷却),但 `src/lib/pool/schedule-state.mjs` 的原因表里没有这两行。`test/unit/schedule-state.test.mjs` 的“every emitted reason has exactly one row in the table”因此在 `origin/dev` 基线上一直失败(`add these reasons to schedule-state.mjs: crag_prompt_replace_empty_unsupported, license_invalid`)。该文件不在 `test:ci` 固定集合里,平时没人发现;任何改到它的 PR(例如 dofastted#2441)CI 都会因它变红。
- 改后:两个原因归入 `STATELESS`(“不改变槽位状态”:它们都经 `continueWithoutCooldown` 发出,语义是换槽重试而不是冷却或摘除),并加进测试里已有的“不改变槽位状态”断言列表。
- 未改 / 延后:不改 `upstream-error-policy.mjs` 的发出逻辑,不改任何其它原因的归类,不动面板文案。

## 验收记录(Run)
- 本机(Node 24)`schedule-state` 12/12(修复前 11/12);Node 22.23.5 容器 + 真实 `kin-scheduler` 跑引用 `schedule-state` 的 5 个测试文件(`schedule-state`、`codex-slot-pool`、`crag-zombie-guard`、`organization-disabled-probe`、`scheduler-fastpath`)76/76。`biome format` 无需修改。

## 回退与手破验证(Broken by hand)
- 3 处手破(唯一锚点,还原后 sha256 一致):整行去掉、只去掉 `license_invalid`、只去掉 `crag_prompt_replace_empty_unsupported`,各让 `schedule-state` 变红。

## 真实使用(Real use)
- 不适用:只补原因表的归类,没有真实槽位或流量;没有 `ph24`。

## 未运行项(Not run)
- 面板上这两个原因的展示文案没有看(它们归入“不改变槽位状态”,面板不为它们显示状态);`npm run test:ci` 由 GitHub `ci` 检查覆盖。
nxtreaming pushed a commit to nxtreaming/vm2api that referenced this pull request Dec 1, 2026
…og-writer

## 变更摘要
- 改前:`test/unit/pg-log-writer.test.mjs` 的“PG migrations 011 and 012 …”用例断言 `applyPgMigrations()` 返回的最后一个迁移是 `012_optimize_usage_logs_and_attempts_indexes.sql`。`292743b1f`(2026-11-30)新增 `013_codex_slot_runtime.sql` 时没有同步它,用例自 11-30 起在 `origin/dev` 基线上就是红的(实得 `013_…`);它用 mock 池、不需要真实 PG 就会红,但文件不在 `test:ci` 固定集合里,所以一直没人发现。新增迁移的 PR(例如 dofastted#2441 的 `014_vm_daily_session_creations.sql`)每次都会让它多红一次。
- 改后:用例改为用迁移目录里按文件名排序的最后一个文件作为期望,并断言 011 与 012 都被应用且 012 在 011 之后;以后再增加迁移不必回头改它。只改这一个测试文件,没有改任何迁移或生产代码。
- 未改 / 延后:其它仍在基线上红的用例(例如 `scoped-intercept-session`、`scheduler-m0-migrations`、`issue-1776-active-usage-reconcile`、`kernel-switch-recovery`)不在本次范围。

## 验收记录(Run)
- 本机(Node 24)`pg-log-writer` 17 个用例 16 通过、0 失败(1 个依赖真实 PG 的用例被跳过);修复前该用例失败(实得 `013_codex_slot_runtime.sql`)。`biome format` 无需修改。

## 回退与手破验证(Broken by hand)
- 3 处手破(还原后 sha256 一致):往迁移目录临时加一个 `999_zz_tmp_probe.sql` 后用例仍绿(不再钉死 012);把断言改回 `mig012` 在存在新迁移文件时变红;把期望改成错误文件名变红。

## 真实使用(Real use)
- 不适用:只改测试,没有真实 PG;没有 `ph24`。

## 未运行项(Not run)
- 真实 PG18 上的迁移应用不在本测试范围;`npm run test:ci` 由 GitHub `ci` 检查覆盖。
…d merge origin/dev

## 变更摘要
- 改前:
  - 合并前分支基于旧 `dev`(迁移号 `075` / `014` 与最新 `origin/dev` `60f797b3e` 撞号,且 8 个文件存在合并冲突)。
  - Major 1:`DailySessionGate` 仅依赖实例内 Map 计数,双实例共享真实 SQLite/PG 库时可超发。
  - Major 2:在途预占默认 180s 直接过期、跨午夜重建索引丢失前一日在途预占、`commitReservation()` 不复核上限。
  - Major 3:PG 时区热切换后同步返回且请求入口未等 `whenReady()`,存在放行空窗。
  - Major 4:PG 写入失败仅交给可选 `onError`(生产未传)且内存先行去重导致静默丢账;hydrate 失败后以空账本继续服务。
  - Major 5:`hasCommittedSession()` 仅查当日内存账本,跨日续接会话在当日触顶后被 429 拒绝。
  - Major 6:Agent Sessions 路径存在重复选槽与 `acquireManagedKey()` 异常泄漏预占风险(且最新 `dev` 已统一收口至 `schedulerRuntime`)。
  - Major 7:`#isClaudeQuotaGuardBlocking()` 传入 `null` 快照导致永远返回 `false`,释放每日预占会误清 5h/7d `continuing` 保护。
  - Major 8:`timezone.mjs` `zonedWallToMs` 两轮换算在 `America/Santiago` 2026-09-06 跳过午夜时落回前一天 23:00、`reset_at` 指向过去。
  - Major 9:默认关闭(`enabled: false`)仍执行启动 hydrate、`commitReservation()` 仍写库、正整数单槽覆盖仍生效。
  - Major 10 + Cursor HIGH:`shouldGateSchedulerLease()` 凭客户端传入的 `parent_session_id` 盲目豁免新主会话;`isEphemeralProbe: true` 在全槽每日触顶时被 Rust `new_sessions_blocked` 误拒;Agent Sessions 管理员 pin 豁免与快速流式提交/释放竞态未闭环。
- 改后:
  - 合并 `origin/dev`(`60f797b3e`),将迁移顺延至 SQLite `076_vm_daily_session_creations.sql` 与 PG `015_vm_daily_session_creations.sql`,新增跨日会话索引与共享预占表 `vm_daily_session_reservations`,同步更新 `scripts/migrate-sqlite-to-pg.mjs` 与 `scripts/seed-mock-sqlite.mjs`。
  - Major 1:`DailySessionGateRepo` 实现 SQLite `BEGIN IMMEDIATE` 与 PG `pg_advisory_xact_lock` 跨进程原子预占/提交与共享计数,双实例共享库不再超发。
  - Major 2:活跃在途预占绑定请求生命周期 + 心跳续期(不因 180s 误删),跨午夜重建保留在途预占,`commitReservation()` / `commitReservationAsync()` 提交前复核上限。
  - Major 3:PG 时区热切换/启用期间标记 `hydrating`,异步入口等待 `whenReady()`、同步入口 fail-closed,消除空窗。
  - Major 4:生产 `server.mjs` 显式注入 `onError` 与 `onHydrated`;PG 写入失败不静默丢账并回滚乐观去重以支持重试;hydrate 失败置 fail-closed 并自动重试恢复;移除备份恢复空 `catch {}`。
  - Major 5:`hasCommittedSession()` / `hasCommittedSessionAsync()` 与 `findCommittedAccountsForSessionAsync()` 覆盖跨日历史账本;`scheduler-proto` 新增向后兼容可选字段 `continuing_node_keys` 与 `admission.rs` 配合,跨日续接会话即使在 Rust sticky 过期/重启后仍可放行。
  - Major 6 + Agent Sessions 统一收口:`handle-agent-sessions.mjs` 沿用最新 `dev` 的 `schedulerRuntime` 单一真值路径(`acquireManagedKey()` 先于 `rt.acquireNode()` 执行,无预占泄漏;`onHeaders` 仅 2xx/3xx 提交租约并等待 `commitLeasePromise` 避免快速流式响应下的提交/释放竞态)。
  - Major 7:`#isClaudeQuotaGuardBlocking()` 改为读取真实调度快照/VM 与 `accountQuota` 账本,释放每日预占不再覆盖 5h/7d `continuing` 保护。
  - Major 8:`timezone.mjs` `zonedWallToMs()` 修复春调跳空(含 `America/Santiago` 2026-09-06 跳过午夜)及秋调重小时(取首次出现),保证当天起点落在当日且 `reset_at` 严格在未来。
  - Major 9:`enabled: false` 为全局总开关,关闭时单槽正整数覆盖不激活、跳过启动/切主/恢复 hydrate、`tryReserveNewSession`/`commitReservation` 严格 no-op 零写库。
  - Major 10 + Cursor HIGH:移除 `shouldGateSchedulerLease()` 与 `#dailySessionBlockedStatusesFromExplain()` 中对未校验 `parent_session_id` 的盲目豁免(仅豁免 Rust 校验过的 `subagent_follow_parent`);Rust `admission.rs` 对 `is_ephemeral_probe` 免除 `new_sessions_blocked` 拦截;Agent Sessions `x-kin-pin-vm` 管理员诊断 pin 自动豁免。
- 未改 / 延后:无。

## 验收记录(Run)
- 环境与基线:WSL2 Debian + Windows 宿主,合并最新 `origin/dev` `60f797b3e` 后于独立工作树 `X:/vm2api-wt-anthropic-daily-session-gate` 验证。
- 已跑命令与结果:
  - `find src scripts -name "*.mjs" -print0 | xargs -0 -n1 node --check`: PASS(全量语法通过)
  - `npx biome check`(17 个改动 Node/测试文件)+ `pnpm -C web exec prettier --write`(2 个改动 Web 测试文件): PASS(0 error)
  - `cd scheduler && RUSTUP_TOOLCHAIN=1.86.0 cargo fmt --check && cargo clippy --workspace --all-targets -- -D warnings && cargo test --workspace --locked && cd .. && npm run build:scheduler`: PASS(Rust 141 passed, 0 failed;`bin/kin-scheduler` 构建成功;已清理 `/mnt/x/.cargo-build/pr2441`)
  - `node --test test/unit/vm-quota-override.test.mjs test/unit/timezone.test.mjs test/unit/scheduler-m3-runtime.test.mjs test/unit/rust-kernel-health.test.mjs test/unit/pool-scheduler.test.mjs test/unit/schedule-state.test.mjs test/unit/error-class.test.mjs test/unit/errors-map.test.mjs test/unit/routing-runtime-load.test.mjs test/unit/bg-migration-guard.test.mjs test/unit/scheduler-m0-migrations.test.mjs test/unit/sqlite-to-pg-migration.test.mjs test/unit/pg-log-writer.test.mjs`: PASS(262 passed, 0 failed, 3 skipped [PG_URL 未配置])
  - `npm run test:ci`: PASS(13/13 隔离套件全部通过,0 failed)
  - `pnpm -C web test:ci`: PASS(9/9 文件,99/99 passed)
  - `pnpm -C web exec vitest run src/features/pools/pools.test.ts src/features/settings/settings-routing-audit.test.tsx src/features/vm/proxy-timezone-copy.test.tsx src/features/vm/status-today.test.tsx src/features/vm/vm-list-table.test.tsx src/lib/vm-status.test.ts`: PASS(6/6 文件,131/131 passed)
  - `pnpm -C web typecheck && pnpm -C web build`: PASS(`tsc -b` + `vite build` 4523 modules)

## 回退与手破验证(Broken by hand)
- 注入禁用 `tryReserveAtomic` 跨进程 SQLite 事务路径 -> `DailySessionGate cross-process SQLite & PG cap enforcement prevents over-issuance across two instances` FAIL(`AssertionError: true !== false`)-> 恢复后 PASS
- 注入恢复 `shouldGateSchedulerLease` 中的 `if (req?.parent_session_id) return false` -> `DailySessionGate cross-day resume & shouldGateSchedulerLease parent_session_id security guard` FAIL(`forged parent_session_id on fresh placement must still be gated: false !== true`)-> 恢复后 PASS
- 回退 `timezone.mjs` `zonedWallToMs` 为原两轮换算 -> `zonedDayStartMs & zonedWallToMs handle America/Santiago 2026-09-06 skipped-midnight DST cleanly` FAIL(`1788663600000 !== 1788667200000`)-> 恢复后 PASS
- 注入 `#isClaudeQuotaGuardBlocking` 返回 `false`(复现旧 `null` 上下文)-> `M3 runtime + DailySessionGate: releasing daily reservation preserves active 5h/7d quota guard continuing block, and cross-day resume succeeds after restart` FAIL(`releasing daily reservation must NOT clear new_sessions_blocked when 5h/7d quota guard is in continuing mode: true !== false`)-> 恢复后 PASS
- 禁用 `#prepareDailySessionContinuingHints` 跨日提示 -> `handleAgentSessions + real kin-scheduler + DailySessionGate: pre-header release, cross-day resume, admin pin exemption, acquireManagedKey throw safety, and tenant isolation` FAIL(`429 !== 200`)-> 恢复后 PASS

## 真实使用(Real use)
- 通过真实编译产出的 `bin/kin-scheduler` 二进制与真实 `node:sqlite` 库在 `scheduler-m3-runtime.test.mjs` 与 `rust-kernel-health.test.mjs` 中完成端到端实测(含 `POST /v1/agent/sessions`、跨日续接、管理员 `x-kin-pin-vm`、独立 `isEphemeralProbe`、伪造 `parentSessionId` 拒绝、并发抢占切换)。未连接线上 `ph24` 生产环境。

## 未运行项(Not run)
- 真实 PostgreSQL 18 实例联调测试(3 条依赖 `PG_URL` 环境变量的迁移/仓储用例自动 skip;本地工作区未启动 PG18 服务,PG 路径已通过模拟事务连接池与 SQL 契约单测验证)。
- 全量 553 个 `npm run test:unit` 文件及 `test:e2e`(已完整覆盖 `test:ci` 13 套件 + 13 个直接关联单测套件 + Rust 141 项 + Web 15 个测试文件 230 项)。
- 线上 `ph24` 生产实测(按安全红线不操作生产机)。
@dofastted

Copy link
Copy Markdown
Owner Author

已合并最新 origin/dev(60f797b3e)并修复评审评论中的全部 10 项 Major + Cursor HIGH 安全问题,head SHA:914b6174f5325f6856b9e4f8f56eb457ed51114c。

变更摘要

  • 改前:
    • 分支基于旧 dev,SQLite 075 / PG 014 与最新 origin/dev 迁移编号撞号,且 8 个文件冲突。
    • Major 1–10 与 Cursor HIGH:DailySessionGate 实例内 Map 计数导致跨进程超发;在途预占 180s 误过期、跨午夜重建丢失且提交前不复核上限;PG 时区热切换存在放行空窗;PG 写入失败静默丢账且 hydrate 失败后空账本放行;跨日续接被拒;Agent Sessions acquireManagedKey 异常泄漏预占风险;#isClaudeQuotaGuardBlocking(null) 永远返回 false 误清 5h/7d continuing 保护;timezone.mjs America/Santiago 2026-09-06 跳过午夜换算落回前一日 23:00;默认关闭仍 hydrate/写库且激活单槽覆盖;shouldGateSchedulerLease 凭客户端 parent_session_id 盲目豁免新主会话,且 isEphemeralProbe / Agent Sessions x-kin-pin-vm 豁免不完整。
  • 改后:
    • 合并 origin/dev 60f797b3e,迁移顺延至 SQLite 076_vm_daily_session_creations.sql 与 PG 015_vm_daily_session_creations.sql(含跨日会话索引与共享预占表 vm_daily_session_reservations,并同步 migrate-sqlite-to-pg.mjs 与 seed-mock-sqlite.mjs)。
    • Major 1(跨进程硬上限):DailySessionGateRepo 新增 SQLite BEGIN IMMEDIATE 与 PG pg_advisory_xact_lock 原子预占/提交与共享计数,双实例共享库不再超发。
    • Major 2(在途预占与提交复核):活跃在途预占绑定请求生命周期 + 心跳续期(不因 180s 过期);跨午夜重建保留在途预占;commitReservation / commitReservationAsync 提交前复核上限。
    • Major 3(PG 时区热切换无空窗):热切换/启用期间置 hydrating,异步入口等待 whenReady(),同步入口 fail-closed。
    • Major 4(PG 写失败与 hydrate 失败):server.mjs 注入 onError / onHydrated 并移除恢复空 catch {};PG 写入失败不静默丢账并回滚乐观去重以允许重试;hydrate 失败 fail-closed 并在后续重试自动恢复。
    • Major 5(跨日续接):hasCommittedSession* 与 findCommittedAccountsForSessionAsync 覆盖跨日历史账本;scheduler-proto 新增向后兼容可选字段 continuing_node_keys 与 admission.rs 配合,跨日续接即使在 Rust sticky 过期/重启后仍放行且不占当日配额。
    • Major 6(Agent Sessions 收口与 Key 异常零泄漏):handle-agent-sessions.mjs 统一收口至最新 dev 的 schedulerRuntime(acquireManagedKey 先于 rt.acquireNode 执行,无预占泄漏;onHeaders 仅 < 400 提交租约并等待 commitLeasePromise,commitLease 在 IPC 前先认领预占以消除快速流式竞态)。
    • Major 7(不误清 5h/7d 额度保护):#isClaudeQuotaGuardBlocking() 读取真实调度快照/VM 与 accountQuota 账本,释放每日预占不再覆盖 5h/7d continuing 保护。
    • Major 8(America/Santiago 跳过午夜 DST):timezone.mjs zonedWallToMs() 修复春调跳空与秋调重小时,2026-09-06 起点严格落在 04:00:00Z(当地 09-06 01:00)且 reset_at 严格在未来。
    • Major 9(默认关闭零行为变化):enabled: false 为总开关,关闭时单槽正整数覆盖不激活、跳过启动/切主/恢复 hydrate、tryReserveNewSession/commitReservation 零写库 no-op。
    • Major 10 + Cursor HIGH(豁免与防绕过):移除 shouldGateSchedulerLease 与 #dailySessionBlockedStatusesFromExplain 对未校验 parent_session_id 的盲目豁免(仅放行 Rust 校验的 subagent_follow_parent);Rust admission.rs 对 is_ephemeral_probe 免除 new_sessions_blocked 拦截;Agent Sessions x-kin-pin-vm 管理员 pin 豁免生效。
  • 未改 / 延后:无。

验收记录(Run)

  • 环境与基线:WSL2 Debian + Windows 宿主,合并 origin/dev 60f797b3e,head 914b6174f5325f6856b9e4f8f56eb457ed51114c。
  • 已跑命令与结果:
    • find src scripts -name "*.mjs" -print0 | xargs -0 -n1 node --check: PASS
    • npx biome check(17 个改动 Node/测试文件)+ pnpm -C web exec prettier --write(2 个改动 Web 测试文件): PASS
    • cd scheduler && RUSTUP_TOOLCHAIN=1.86.0 cargo fmt --check && cargo clippy --workspace --all-targets -- -D warnings && cargo test --workspace --locked && cd .. && npm run build:scheduler: PASS(141 passed, 0 failed)
    • node --test test/unit/vm-quota-override.test.mjs test/unit/timezone.test.mjs test/unit/scheduler-m3-runtime.test.mjs test/unit/rust-kernel-health.test.mjs test/unit/pool-scheduler.test.mjs test/unit/schedule-state.test.mjs test/unit/error-class.test.mjs test/unit/errors-map.test.mjs test/unit/routing-runtime-load.test.mjs test/unit/bg-migration-guard.test.mjs test/unit/scheduler-m0-migrations.test.mjs test/unit/sqlite-to-pg-migration.test.mjs test/unit/pg-log-writer.test.mjs: PASS(262 passed, 0 failed, 3 skipped [PG_URL 未配置])
    • npm run test:ci: PASS(13/13 隔离套件通过)
    • pnpm -C web test:ci: PASS(9/9 文件,99/99 passed)
    • pnpm -C web exec vitest run src/features/pools/pools.test.ts src/features/settings/settings-routing-audit.test.tsx src/features/vm/proxy-timezone-copy.test.tsx src/features/vm/status-today.test.tsx src/features/vm/vm-list-table.test.tsx src/lib/vm-status.test.ts: PASS(6/6 文件,131/131 passed)
    • pnpm -C web typecheck && pnpm -C web build: PASS(tsc -b + vite build 4523 modules)

回退与手破验证(Broken by hand)

  • 禁用 tryReserveAtomic 跨进程 SQLite 事务路径 -> DailySessionGate cross-process SQLite & PG cap enforcement prevents over-issuance across two instances FAIL(AssertionError: true !== false)-> 恢复后 PASS
  • 恢复 shouldGateSchedulerLease 中 if (req?.parent_session_id) return false -> DailySessionGate cross-day resume & shouldGateSchedulerLease parent_session_id security guard FAIL(forged parent_session_id on fresh placement must still be gated: false !== true)-> 恢复后 PASS
  • 回退 timezone.mjs zonedWallToMs 为原两轮换算 -> zonedDayStartMs & zonedWallToMs handle America/Santiago 2026-09-06 skipped-midnight DST cleanly FAIL(1788663600000 !== 1788667200000)-> 恢复后 PASS
  • 注入 #isClaudeQuotaGuardBlocking 返回 false -> M3 runtime + DailySessionGate: releasing daily reservation preserves active 5h/7d quota guard continuing block, and cross-day resume succeeds after restart FAIL(releasing daily reservation must NOT clear new_sessions_blocked when 5h/7d quota guard is in continuing mode: true !== false)-> 恢复后 PASS
  • 禁用 #prepareDailySessionContinuingHints -> handleAgentSessions + real kin-scheduler + DailySessionGate: pre-header release, cross-day resume, admin pin exemption, acquireManagedKey throw safety, and tenant isolation FAIL(429 !== 200)-> 恢复后 PASS

真实使用(Real use)

  • 通过真实编译产出的 bin/kin-scheduler 二进制与真实 node:sqlite 数据库在 scheduler-m3-runtime.test.mjs 与 rust-kernel-health.test.mjs 完成端到端验证(POST /v1/agent/sessions、跨日续接、管理员 x-kin-pin-vm、独立 isEphemeralProbe、伪造 parentSessionId 拦截、并发抢占与切换)。未连接线上 ph24。

未运行项(Not run)

  • 真实 PostgreSQL 18 实例联调测试(3 条需 PG_URL 的用例自动 skip;PG 路径已通过模拟事务连接池与 SQL 契约单测验证)。
  • 全量 553 个 npm run test:unit 及 test:e2e(已覆盖 test:ci 13 套件 + 13 个关联单测套件 + Rust 141 项 + Web 230 项)。
  • 线上 ph24 生产实测(按安全红线不操作生产机)。

@dofastted
dofastted marked this pull request as ready for review December 1, 2026 17:17

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Agentic security review of the Anthropic daily session gate found one remaining medium-severity issue: short one-shot Messages requests classified as ephemeral probes can still land on new_sessions_blocked Claude nodes and skip the daily cap.

The previous parent-session skip (req.parent_session_id) is addressed on this head.

Open in Web View Automation 

Sent by Cursor Security Agent: Security Reviewer

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

continue;
}
if st.new_sessions_blocked && !continuing {
if st.new_sessions_blocked && !continuing_known_session && !req.is_ephemeral_probe {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review
Severity: MEDIUM

Admission now skips new_sessions_blocked when req.is_ephemeral_probe is true, even for a brand-new primary placement. That flag is derived from isShortProbeRequest / skipSessionSeat (single user turn, no tools, trimmed text 1–64 chars), not from an operator-only health path. JS shouldGateSchedulerLease also no-ops on the same flag, so these requests never reserve the daily ledger.

Impact: After the daily cap or 5h/7d continuing-only guard has blocked an Anthropic account, an authenticated caller can keep sending short one-shot prompts onto those VMs and burn remaining shared-account quota that was reserved for existing conversations.

Fix in Cursor Fix in Web

Reviewed by Cursor Security Reviewer for commit 914b617. Configure here.

continue;
}
if st.new_sessions_blocked && !continuing {
if st.new_sessions_blocked && !continuing_known_session && !req.is_ephemeral_probe {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review
Severity: MEDIUM

Admission now skips new_sessions_blocked when req.is_ephemeral_probe is true, even for a brand-new primary placement. That flag is derived from isShortProbeRequest / skipSessionSeat (single user turn, no tools, trimmed text 1–64 chars), not from an operator-only health path. JS shouldGateSchedulerLease also no-ops on the same flag, so these requests never reserve the daily ledger.

Impact: After the daily cap or 5h/7d continuing-only guard has blocked an Anthropic account, an authenticated caller can keep sending short one-shot prompts onto those VMs and burn remaining shared-account quota that was reserved for existing conversations.

Fix in Cursor Fix in Web

Reviewed by Cursor Security Reviewer for commit 558bebf. Configure here.

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.

1 participant