Skip to content

feat: badge background Bash tasks by reusing the launch card#23

Merged
william0wang merged 2 commits into
mainfrom
feat/background-task-badge
Jul 18, 2026
Merged

feat: badge background Bash tasks by reusing the launch card#23
william0wang merged 2 commits into
mainfrom
feat/background-task-badge

Conversation

@william0wang

Copy link
Copy Markdown
Owner

Solution: reuse the launch card

让 BackgroundTaskListener 把后台生命周期路由回发起卡片,单卡呈现完整生命周期,不再产生重复卡片。

Changes

1. translators/event-translator.ts + translators/types.ts — 透传 background 标志

  • input.run_in_background 识别后台 Bash,缓存到 backgroundCallIds: Set<string>
  • ToolCallNew / ToolCallUpdatebackground?: boolean 字段
  • 解决了 tool.updated { kind:"result" }inputOmitted:true 难题——通过 scheduled 阶段缓存的 callId 查询

2. handlers/dispatch.ts — 后台 Bash 发起卡保持 in_progress

  • dispatchTerminalUpdate 新增 skipExit 选项
  • 后台 Bash 的 result 阶段跳过 terminal_exit,只发 terminal_output,卡片保持 in_progress
  • terminalSentData 留空标记,作为"这是被跟踪的发起卡"信号给 BackgroundTaskListener

3. handlers/background-tasks.ts — 复用发起卡片 + 完成时收尾

  • onTaskStatus 检测到 session.updated.toolCallIdterminalSentData 中时,复用该 toolCallId(不再新建 bg_*
  • 完成态发 terminal_output(若 launch text 没流过)+ terminal_exit 收尾,清理 terminalSentData
  • markCancelled 对复用卡片同样补 terminal_exit
  • 回退路径:toolCallId 缺失或未跟踪(子代理场景)仍走原来的 bg_* 新建卡片逻辑,feat: sync sub-agent and background task events to ACP client #21 完全不受影响

4. docs/PROTOCOL.md — 新增 "Background Bash" 小节,说明复用机制与 Agent 子代理(新建 bg_*)的区别

Fallback matrix

场景 行为
后台 Bash(terminalSentData 有 toolCallId) 复用发起卡片 ✅ 新行为
Agent/Task 子代理(无 toolCallId 或未跟踪) 新建 bg_* 卡片(#21 原行为)
toolCallId 存在但未跟踪(老后端) 新建 bg_* 卡片(安全回退)

Verification

  • pnpm typecheck
  • pnpm test ✅ 271 tests passed(含新增 16 个)
  • 新增测试覆盖:
    • translator: background 标志从 streaming cache / scheduled payload / 缺失 三种情况(5 个)
    • background-tasks: 卡片复用 / 完成收尾 / 空 marker 流 output / 回退 / 取消(7 个)
  • probe 脚本确认真实事件流与本设计一致(脚本已清理,不入库)

Untouched

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request implements support for background Bash tasks by reusing the original launch terminal card instead of creating a duplicate background card. It updates the protocol documentation, tracks launch card reuse in BackgroundTaskListener, threads the background flag through the event translator, and adds corresponding unit tests. The review feedback identifies a critical bug in src/handlers/background-tasks.ts where the actual command output is incorrectly skipped on completion if the launch acknowledgement was already streamed. To resolve this, the reviewer suggests removing the !alreadyStreamed check to rely on prefix-diffing, and provides a corresponding test update to assert that the final output is correctly streamed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/handlers/background-tasks.ts Outdated
Comment thread tests/background-tasks.test.ts Outdated
@william0wang
william0wang merged commit 69b0c54 into main Jul 18, 2026
1 check passed
@william0wang
william0wang deleted the feat/background-task-badge branch July 18, 2026 12:19
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