Skip to content

Conversation

@coffeedeveloper
Copy link
Member

@coffeedeveloper coffeedeveloper commented Dec 26, 2025

Types

  • 🎉 New Features
  • 🐛 Bug Fixes
  • 📚 Documentation Changes
  • 💄 Code Style Changes
  • 💄 Style Changes
  • 🪚 Refactors
  • 🚀 Performance Improvements
  • 🏗️ Build System
  • ⏱ Tests
  • 🧹 Chores
  • Other Changes

Background

  • A debug launch with an invalid debug config like wrong cwd leaves a broken integrated terminal and a stale debug session. Subsequent launches reuse the bad terminal/session and fail until the page refreshes.

Solution

  • Detect invalid terminal processes (pid missing/<=0), remove the broken terminal, and create a fresh one.
  • Ensure failed debug session starts are destroyed to avoid blocking retries.
  • Add tests covering terminal reuse/cleanup and session start failure handling.

Changelog

  • Fix: recover debug launch after invalid debug config without requiring a refresh.
  • Fix: remove stuck terminals created during failed debug launches.
  • Test: add coverage for terminal pid validation and session cleanup on start failure.

Summary by CodeRabbit

发布说明

  • Bug 修复

    • 改进了调试会话启动失败时的处理流程,防止会话陷入阻塞状态
    • 增强了终端进程 ID 的验证机制,无效终端会被自动清理
  • 测试

    • 增加了调试会话管理器的测试覆盖率,包括启动失败和会话销毁场景
    • 新增调试会话终端的单元测试,验证终端的创建、验证和清理流程

✏️ Tip: You can customize this high-level summary in your review settings.

@opensumi opensumi bot added the 🐞 bug Something isn't working label Dec 26, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 26, 2025

走查(Walkthrough)

该PR针对调试会话的启动和终端处理流程进行了改进。在调试会话启动失败时添加了错误捕获和清理机制,防止阻塞会话残留。同时,对终端进程ID的验证逻辑进行了优化,增加了鲁棒的错误处理和清理流程。

变更(Changes)

文件群组 / 文件(s) 变更摘要
调试会话管理器测试
packages/debug/__tests__/browser/debug-session-manager.test.ts
替换原有的destroy-on-didDestroy流程,添加会话启动失败场景测试:构造失败会话,模拟会话工厂返回该会话,启动会话后验证terminateDebugSession被调用;重构destroy测试以异步方式等待onDidDestroyDebugSession事件。
调试会话终端测试
packages/debug/__tests__/browser/debug-session-terminal.test.ts
新增测试文件,包含TestDebugSession子类和createSession辅助方法,覆盖终端替换和进程ID验证场景,使用Jest模拟终端生命周期。
调试会话管理器实现
packages/debug/src/browser/debug-session-manager.ts
在启动失败时捕获session.start()异常,销毁会话以避免遗留阻塞的会话。
调试会话实现
packages/debug/src/browser/debug-session.ts
添加私有辅助方法getValidTerminalProcessId()用于验证和清理终端进程ID;在doRunInTerminal中增强了终端处理的鲁棒性:使用新辅助方法验证现有终端,对新建终端添加try/catch错误处理及清理机制。

预计代码审查工作量

🎯 3 (中等) | ⏱️ ~20 分钟

可能相关的PR

建议标签

🐞 bug

建议审查者

  • erha19
  • hacke2
  • Ricbet

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地总结了此PR的主要目的:修复在终端调试会话失败后恢复功能。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/optimize_debug

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/debug/src/browser/debug-session.ts (1)

341-377: 新创建的终端无法获取有效 processId 时应抛出错误,而非返回 undefined

当终端创建成功但 getValidTerminalProcessId 返回 undefined 时(第 368 行),函数会移除该终端但仍返回 { processId: undefined }。虽然 Debug Adapter Protocol 允许 processId 为可选项,但当终端创建后无法获取其进程 ID 时,应该抛出错误以表示操作失败,而不是静默返回 undefined。这会造成与已激活终端处理逻辑的不对称(行 350-353 处,如果无法获取 processId 会创建新终端,而不是继续使用旧终端)。建议在第 368 行之后添加检查:如果 processIdundefined,应抛出错误,这样可以防止调试器使用无效的进程 ID。

🧹 Nitpick comments (2)
packages/debug/src/browser/debug-session-manager.ts (1)

466-472: 考虑记录启动失败的错误

错误处理逻辑正确地销毁了失败的会话,但错误信息被静默吞没。建议至少记录错误以便调试,或者在销毁前传递错误上下文。

🔎 建议的改进
 session
   .start()
   .then(() => this.onDidStartDebugSessionEmitter.fire(session))
-  .catch(() => {
+  .catch((error) => {
     // 启动失败的时候清空,避免留下阻塞的session
+    // 注: session.start() 内部已处理错误消息显示
     this.destroy(session.id);
   });
packages/debug/src/browser/debug-session.ts (1)

360-374: 简化清理逻辑

在 catch 块中使用 getValidTerminalProcessId(createdTerminalId, true) 仅为触发终端移除有些间接。可以直接调用 removeTerm

🔎 建议的简化
     } catch (error) {
       if (createdTerminalId) {
-        await this.getValidTerminalProcessId(createdTerminalId, true);
+        this.terminalService.removeTerm(createdTerminalId);
       }
       throw error;
     }
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af6c397 and 584cb60.

📒 Files selected for processing (4)
  • packages/debug/__tests__/browser/debug-session-manager.test.ts
  • packages/debug/__tests__/browser/debug-session-terminal.test.ts
  • packages/debug/src/browser/debug-session-manager.ts
  • packages/debug/src/browser/debug-session.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/debug/src/browser/debug-session-manager.ts (1)
packages/debug/src/browser/view/debug-view-model.ts (1)
  • session (71-73)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: ubuntu-latest, Node.js 20.x
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
🔇 Additional comments (5)
packages/debug/src/browser/debug-session.ts (1)

323-339: LGTM! 辅助方法设计合理

getValidTerminalProcessId 方法职责清晰,正确处理了进程 ID 验证和可选的清理逻辑。错误处理也很完善。

packages/debug/__tests__/browser/debug-session-manager.test.ts (2)

171-209: LGTM! 启动失败场景测试完善

测试正确地模拟了会话启动失败的场景,并验证了 terminateDebugSession 被调用以清理资源。使用 setImmediate 来等待异步操作完成是合适的做法。


211-228: LGTM! 测试改进提升了可读性

将基于回调的测试重构为使用 async/await 和 Promise,使代码更清晰易读。

packages/debug/__tests__/browser/debug-session-terminal.test.ts (2)

7-11: LGTM! 测试类设计合理

通过继承 DebugSession 并暴露 runInTerminalForTest 方法来测试受保护的 doRunInTerminal 方法是一种合适的测试策略。


50-86: LGTM! 终端处理测试覆盖全面

两个测试场景都很重要:

  1. 替换无效的活动终端 - 验证了清理旧终端并创建新终端的逻辑
  2. 移除新创建的无效终端 - 验证了创建失败时的清理逻辑

模拟和断言都很准确,很好地覆盖了 PR 中描述的终端清理场景。

@codecov
Copy link

codecov bot commented Dec 26, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.76%. Comparing base (9d4a1bf) to head (85ff32d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/debug/src/browser/debug-session.ts 76.92% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4687      +/-   ##
==========================================
+ Coverage   52.66%   52.76%   +0.10%     
==========================================
  Files        1686     1686              
  Lines      104696   104718      +22     
  Branches    22749    22756       +7     
==========================================
+ Hits        55135    55257     +122     
+ Misses      41178    41091      -87     
+ Partials     8383     8370      -13     
Flag Coverage Δ
jsdom 48.26% <80.00%> (+0.10%) ⬆️
node 12.05% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coffeedeveloper
Copy link
Member Author

/next

@opensumi
Copy link
Contributor

opensumi bot commented Dec 26, 2025

🎉 PR Next publish successful!

3.9.1-next-1766735800.0

Copy link
Member

@Ricbet Ricbet left a comment

Choose a reason for hiding this comment

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

LGTM

@coffeedeveloper coffeedeveloper merged commit ca5f935 into main Jan 6, 2026
12 checks passed
@coffeedeveloper coffeedeveloper deleted the feat/optimize_debug branch January 6, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants