Skip to content

fix(gemini): Unix control pool eviction and EMFILE license status - #1969

Open
dofastted wants to merge 3 commits into
devfrom
cursor/unix-pool-emfile-fix-45ef
Open

dofastted wants to merge 3 commits into
devfrom
cursor/unix-pool-emfile-fix-45ef

Conversation

@dofastted

@dofastted dofastted commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Refs #1953

问题与结果

在 origin/dev(a6d70adb,VERSION 1.4.236)上确认:scripts/gemini_host_native.py 的 _UnixConnectionPool 仅在 acquire(path) 时清理同一路径上过期的 keep-alive 套接字;kernel.sock 等路径退役后,其它路径桶内的过期 FD 永远不会被关闭。池仅有每路径 8 的上限、无全局空闲上限,长时间运行会导致 pipe2 / EMFILE,许可 CLI 失败后被 gemini-host.py 折叠为 license_unconfigured,面板误显「订阅未配置」。

修复后:在 acquire/release 的同一把锁下对所有路径执行过期清扫与空桶删除,并强制执行全局空闲上限(默认 128,模块级常量 CONTROL_CONN_POOL_MAX_IDLE_GLOBAL,非环境变量)。许可 CLI 在 EMFILE/ENFILE 等宿主资源错误时返回 gemini_host_resource_exhausted(503);后端 checkAdmission、调度器 FAILURES 与 routes.mjs HOST_ERRORS 透传该码,控制面/准入层不再折叠为 license_required / license_unconfigured。前端本轮补充:gemini-environments 在 FD 耗尽时不展示「绑定/重新绑定 CRAG 席位」;gemini-recovery 将该码归类为宿主故障并展示 Gemini 维护入口。

实现

  • _UnixConnectionPool:_sweep_idle_locked、_enforce_global_cap_locked;常量 CONTROL_CONN_POOL_MAX_* / CONTROL_CONN_POOL_IDLE_TTL。
  • Python:HOST_RESOURCE_ERROR_CODES(独立于 SANDBOX_ERROR_CODES)、classify_craggemini_license_host_error;license_status 使用 status: host_resource_exhausted。
  • Node:GEMINI_HOST_RESOURCE_ERROR_CODES / GEMINI_HOST_RESOURCE_MESSAGES;checkAdmission、scheduler.FAILURES、HOST_ERRORS 接线。
  • Web:CRAG_LICENSE_HOST_RESOURCE_CODES + gemini-recovery.hostIssues;gemini-account-status EMFILE/ENFILE 文案。

未改动 HTTP 协议、重试策略或在用连接逻辑(仅池内空闲套接字)。

验证

python3 test/unit/gemini-unix-connection-pool.py
python3 test/unit/gemini-host-license-resource.py
python3 test/unit/gemini-host-license-align.py
node --test test/unit/gemini-license-sandbox-admission.test.mjs
./node_modules/.bin/biome check src/lib/gemini/subscription.mjs src/lib/gemini/scheduler.mjs src/lib/gemini/routes.mjs
pnpm -C web exec prettier --check src/lib/gemini-account-status.ts src/features/import/gemini-environments.tsx src/lib/gemini-recovery.ts
pnpm -C web exec vitest run src/lib/gemini-account-status.test.ts src/lib/gemini-recovery.test.ts src/features/import/gemini-environments.test.tsx

本 head 对应 CI run 45959882265 为 path-filtered 短路径,未覆盖 format/Go/payload 全量检查(不是发版门)。

未在真实多路径 kernel.sock 轮换负载下复现 reporter 的 cached 100 open 100(无集成环境)。

Release notes(≥1.4.237)

  • Gemini 宿主 Unix 控制连接池:跨路径清理过期 keep-alive 套接字,全局空闲连接上限 128,降低许可 CLI 因 FD 耗尽失败的风险。
  • 许可/admission:gemini_host_resource_exhausted(503)在控制面与准入路径透传,避免误报「订阅未配置」;面板不再引导用户重绑席位,改为指向 Gemini 维护/重启宿主。
Open in Web Open in Cursor 

Note

Medium Risk
Touches long-running connection pooling and license error classification paths that affect when Gemini sessions are admitted and how failures are shown; behavior change is intentional but could alter responses for previously mislabeled exhaustion cases.

Reviewed by Cursor Bugbot for commit befb827. 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: 06a2ae88-866c-4343-aaeb-12764af9a5bd)

cursoragent and others added 3 commits November 27, 2026 07:38
Cross-path expiry eviction and a global idle cap prevent craggemini
license CLI subprocess failures from leaking kernel.sock pool FDs.
Map EMFILE/ENFILE host errors to gemini_host_resource_exhausted so
license status does not report subscription unconfigured.

Co-authored-by: ted <kuhlmangarry24@gmail.com>
Add dedicated host-resource error sets in Python and Node; pass 503
through checkAdmission, scheduler FAILURES, and routes HOST_ERRORS.
License-status returns host_resource_exhausted status, not unconfigured.

Co-authored-by: ted <kuhlmangarry24@gmail.com>
Treat FD exhaustion as host infrastructure in gemini-recovery and
crag license seat actions, not sandbox or seat binding issues.

Co-authored-by: ted <kuhlmangarry24@gmail.com>
@cursor
cursor Bot force-pushed the cursor/unix-pool-emfile-fix-45ef branch from 44ea8df to befb827 Compare November 27, 2026 07:38
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