Skip to content

Background Terminal:补齐模型输出清洗、session 磁盘预算与 Windows 终止验证 #72

Closed

Description

@tt-a1i

背景

Background Terminal 已经有较完整的进程组终止、单流 spill 上限、TUI 清洗和 POSIX 测试,但当前 main 仍有三个相关的运行时硬化缺口。它们共享同一个边界:不受模型控制的外部进程输出和生命周期,进入 OpenPI 的模型上下文、磁盘和清理承诺。

1. 模型侧输出未经过终端文本清洗

extensions/background-terminals/src/prompt.ts:135-181 将 retained stdout/stderr 截断后直接拼进 bg_status 和完成 follow-up。

TUI 与 watch 路径使用了 sanitizeTerminalText,但 model-facing outputSection 没有。ANSI 控制串、OSC、bidi 与其他控制字符可能进入模型上下文。

验收

  • status、单条完成通知、批量完成通知都使用同一共享清洗函数;
  • 先清洗还是先截断的顺序有测试,不能通过分块控制串绕过;
  • 保留换行和可读日志,不改变原始 spill 文件作为证据。

2. 只有单流上限,没有 session 总量上限

当前每个 stream 上限 256 MiB,每个 terminal 有 stdout/stderr,session 可跟踪多条 terminal;prune 只回收内存条目,spill 目录要到 disposeAll 才整体删除。

长 session 中已 prune 的文件仍占磁盘,理论上总量远高于单流限制。

验收

  • 有明确的 per-session spill byte budget;
  • 达到预算时 fail closed,结果中说明完整日志不再可用;
  • prune 后不会留下无引用的大文件,或明确采用带总预算的保留策略;
  • session dispose 仍能清理整个私有目录。

3. Windows taskkill 未被等待,CI 无 Windows 语义验证

extensions/background-terminals/src/manager.ts:195-224 启动 taskkill 后立即 unref() 返回;SIGTERM deadline 到期后可能再次启动 taskkill /F,两次操作没有顺序完成证据。

当前 CI 只运行 Ubuntu;关键 SIGTERM→SIGKILL / process-tree 测试在 win32 跳过。

验收

  • Windows 终止 helper 返回可等待结果,graceful 与 force 阶段确定性串行;
  • taskkill 启动失败、非零退出、目标已退出均有明确处理;
  • CI 增加最小 Windows runner,至少覆盖 process tree、timeout、kill、dispose;
  • 用户可见的 Killed/settled 只在所承诺的终止边界得到证据后报告。

不纳入本 Issue 的内容

POSIX 下主动 setsid 逃离原进程组属于更强的恶意进程模型;当前先不把它宣称为已有“完整进程树保证”的漏洞。如需支持,应单独定义可移植身份追踪与清理合同。

Activity

  1. added
    bug
    on Aug 22, 2026
  2. 627150795 commented on Aug 28, 2026

    @627150795
    Contributor

    Hi! I am working on a focused sub-scope of this issue: sanitize all model-facing background-terminal stdout/stderr before tail truncation in status and completion messages, with regression tests. The session spill-byte budget and Windows taskkill/CI work are separate follow-ups and are out of scope for this PR.

  3. 627150795 commented on Aug 28, 2026

    @627150795
    Contributor

    Implementation is ready in PR #236: #236. This PR covers only the model-facing output sanitization sub-scope; the session spill-byte budget and Windows taskkill/CI items remain separate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions