Skip to content

fix(gemini): ensure workspace dir exists before initialization#1784

Merged
piorpua merged 2 commits intomainfrom
fix/sentry-ELECTRON-6W
Mar 29, 2026
Merged

fix(gemini): ensure workspace dir exists before initialization#1784
piorpua merged 2 commits intomainfrom
fix/sentry-ELECTRON-6W

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

@kaizhou-lab kaizhou-lab commented Mar 27, 2026

Summary

  • Fixes Sentry ELECTRON-6W (949 occurrences) — ENOENT: no such file or directory, realpath 'gemini-temp-*'
  • Adds fs.promises.mkdir(path, { recursive: true }) at the start of GeminiAgent.initialize() to ensure the workspace directory exists before loadCliConfig calls loadServerHierarchicalMemory, which internally does await fs.realpath(workspace) without try-catch
  • The call is idempotent — it's a no-op if the directory already exists and preserves contents

Closes #1839

Test plan

  • New test file tests/unit/geminiWorkspaceRecovery.test.ts with 4 tests covering:
    • fs.realpath fails with ENOENT on deleted directory (reproduces the bug)
    • mkdir with recursive:true recreates a deleted directory
    • fs.realpath succeeds after mkdir recreation (verifies the fix)
    • mkdir is idempotent on existing directories (no side effects)
  • All 150 test files pass (1 pre-existing DOM test failure unrelated)
  • Lint, format, and type check pass

@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 27, 2026 05:06
…ation

The external library aioncli-core calls `await fs.realpath(workspace)` in
loadServerHierarchicalMemory without try-catch. When the temp workspace
directory (gemini-temp-*) is removed between creation and worker process
initialization (e.g. by OS cleanup or antivirus on Windows), this causes
an unhandled ENOENT promise rejection.

Add a defensive `fs.promises.mkdir(path, { recursive: true })` at the
start of GeminiAgent.initialize() to recreate the directory if missing.
The call is idempotent and preserves existing directory contents.

Fixes ELECTRON-6W (949 occurrences)
@kaizhou-lab kaizhou-lab force-pushed the fix/sentry-ELECTRON-6W branch from c7f8bf8 to 47cfc34 Compare March 28, 2026 05:53
@kaizhou-lab kaizhou-lab changed the title fix(gemini): ensure workspace directory exists before aioncli-core init fix(gemini): ensure workspace dir exists before initialization Mar 28, 2026
@piorpua piorpua added the bot:reviewing Review in progress (mutex) label Mar 29, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

CI 检查未通过

以下 job 在本次自动化 review 时未通过,请修复:

Job 结论
Code Quality ❌ CANCELLED
Unit Tests (ubuntu-latest) ❌ CANCELLED
Unit Tests (macos-14) ❌ CANCELLED
Unit Tests (windows-2022) ❌ CANCELLED
Coverage Test ❌ CANCELLED

本次自动化 review 暂缓,待 CI 全部通过后将重新处理。

@piorpua piorpua added bot:ci-waiting CI failed and author notified — snoozed until new commits are pushed and removed bot:reviewing Review in progress (mutex) labels Mar 29, 2026
@piorpua piorpua added bot:reviewing Review in progress (mutex) and removed bot:ci-waiting CI failed and author notified — snoozed until new commits are pushed labels Mar 29, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

Code Review:fix(gemini): ensure workspace dir exists before initialization (#1784)

变更概述

本 PR 修复了 Sentry 高频问题 ELECTRON-6W(949 次),根因是 aioncli-coreloadServerHierarchicalMemory 内部直接调用 fs.realpath(workspace) 而不捕获异常。当临时工作目录在创建后到 agent 初始化前被 OS 清理程序或杀毒软件删除时,会抛出未处理的 ENOENT rejection。修复方案是在 GeminiAgent.initialize() 开头调用 fs.promises.mkdir(path, { recursive: true }) 确保目录存在。新增测试文件 tests/unit/geminiWorkspaceRecovery.test.ts 验证修复行为。


方案评估

结论:✅ 方案合理

修复直接命中根因:在第三方代码的 realpath 调用前确保目录存在。{ recursive: true } 使调用幂等——目录已存在时不抛异常、不清除内容,对正常流程无任何影响。修复位置正确,置于所有依赖 workspace 路径的操作之前。无更优替代方案——在调用者侧修复比 fork aioncli-core 更合理。


问题清单

🔵 LOW — 测试验证的是 Node.js fs 行为而非 GeminiAgent 的调用

文件tests/unit/geminiWorkspaceRecovery.test.ts,全文

问题说明:4 个测试用例均直接调用 Node.js fs API,验证的是 mkdir/realpath 的内置行为,而非 GeminiAgent.initialize() 实际调用了 mkdir。若日后有人不小心删除 initialize() 里的 mkdir 调用,这批测试仍会全部通过,无法起到回归防护作用。

理想的补充测试应 mock fs.promises.mkdir 并断言它在 initialize() 中被调用(但这需要 mock aioncli-core 的整条依赖链,成本较高)。现有测试作为修复行为的文档说明仍有价值,不属于阻塞问题。


汇总

# 严重级别 文件 问题
1 🔵 LOW tests/unit/geminiWorkspaceRecovery.test.ts 测试验证 fs 内置行为而非 GeminiAgent.initialize() 的调用

结论

批准合并 — 修复精准、幂等,无阻塞性问题。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

✅ 已自动 review,无阻塞性问题,正在触发自动合并。

@piorpua piorpua merged commit b2fa2ad into main Mar 29, 2026
15 of 17 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-6W branch March 29, 2026 06:05
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(gemini): ENOENT on workspace realpath during agent initialization

2 participants