Skip to content

fix(cli-writer-login-shell): macOS 终端里的 agent 退出后可以转到聊天界面继续 - #63

Merged
Fartown merged 5 commits into
fork/integrationfrom
feat/cli-writer-login-shell
Oct 23, 2026
Merged

Fartown merged 5 commits into
fork/integrationfrom
feat/cli-writer-login-shell

Conversation

@Fartown

@Fartown Fartown commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​138 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​138
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​314 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​293

ELI5

在 Mac 上,Orca 开的每个终端外面都多套了一层系统的 login 进程。「把终端里的对话转到聊天界面」之前,Orca 会先确认终端里已经没有 agent 在跑,但它检查的是最外面那层 login,而不是里面真正的 shell,所以永远认为「还有东西在跑」。结果就是:哪怕 Codex 已经退出,也一直提示「Orca can't confirm Codex has exited in its terminal」,只有关掉整个终端才行。这个 PR 让检查穿过 login 这一层,看里面真正的 shell。

What Changed

  • 之前:macOS 上,终端里的 Codex/Claude 退出、shell 回到提示符后,从 Session History 选「在新聊天中恢复」仍被拒绝,聊天标签显示 Failed,弹出上面那条提示。
  • 之后:agent 退出后可以正常转到聊天界面,并载入原对话。agent 还在运行,或终端里还剩任何任务(前台、后台、挂起)时,照旧拒绝。
  • 机制:PTY 的根进程是 /usr/bin/login(TCC 隐私授权包装),shell 是它唯一的子进程。posixCliWriterShellAlone 原来要求根进程本身是 shell。现在新增 ptyShellRow(src/main/cli-writer-login-shell/):根进程是 login 时取它唯一的子进程作为 shell,零个或多个子进程则判不通过;后面「是 shell、在前台、没有任务」三条检查原样保留。上游文件只改 3 行。

Why

  • 不改 provider 报的 rootProcessId:它有多个读者(Codex 共享服务、tmux 识别、前台进程解析),改语义影响面大。
  • 不复用 confirmShellForegroundProcess:它只要求 shell 在前台,会放过后台任务,弱于这里「一个任务都不能剩」的要求。
  • 不关 login 包装:会破坏 macOS 隐私授权归属。

Linked Issue

无(用户直接反馈;fork 内修复,已登记为 fork 功能 cli-writer-login-shell,文档在 docs/issue/终端对话转聊天退出判定/)。

Visual Proof

截图含本机工作区信息,未上传;保存在本地 .docs/cli-chat-resume-ui-validation/2026-10-23/evidence/。

  • 修复前(login 包装开启,与正式包一致):Codex 退出后 Session History 恢复 → 「Codex Chat - Failed」+「can't confirm」提示。
  • 修复后:同样步骤 → 聊天打开并显示原来的提问和「OK」回复。

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • 单测 src/main/cli-writer-login-shell/login-wrapped-pty-shell.test.ts:用实测的 login → zsh → codex 进程链覆盖窗格与 Session History 两条入口。撤掉修复后该测试失败,修复后通过;上游 structured-agent-cli-writers.test.ts 也全部通过。

  • 本机真机(隐藏隔离实例,ORCA_BACKGROUND_LAUNCH=1,真实 Codex):开启 login 包装时修复前复现、修复后通过;关闭包装的对照组修复前就能恢复,印证了根因。

  • SSH 真机(隔离客户端 → 127.0.0.1:2222 sshd → 远端 orcad,SSH 侧 HOME 隔离):SSH 工作区的终端会话在窗格和 Session History 都不提供转聊天,修复前后完全一致。上游本来就只对本机执行的终端提供这个动作。

  • 平台:macOS 实测。Linux 的根进程本身就是 shell,规则不变;Windows 走单独分支,不受影响。

  • 门禁:pnpm tc、check:fork-features、check:fork-docs、check:architecture-policies --base Fartown/main、三项本地化门禁、check:code-quality:changed -- fork/integration 全部通过。

AI Disclosure

Claude Opus 5.5(Claude Code)完成复现、修复、测试与文档。

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • 安全:保护只对「login 下唯一子进程」放行,多出任何进程都拒绝,不会误放行并发写。
  • 兼容:不改协议,只在执行主机侧生效;旧版本主机仍会拒绝。
  • 已知未处理:Codex 运行中点窗格按钮必然失败,退出后按钮又消失,这是交互问题,不在本 PR 范围。

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code

zhangchao.zc and others added 2 commits October 23, 2026 14:51
…ue in chat after the agent exits

On macOS every terminal is spawned through /usr/bin/login for TCC attribution, so the PTY root is
login and the shell is its only child. The terminal-writer census required the root itself to be a
shell, so it refused to hand a conversation to Chat UI even after Codex or Claude had exited; only
closing the terminal helped. The census now inspects the shell below the login wrapper and keeps
every other rule (foreground, no job of any kind left).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-app validation

Requirement, design, test cases and the local and SSH real-app runs for the terminal-writer census
fix, plus the formatter's wrap of the new policy entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zhangchao.zc and others added 3 commits October 23, 2026 16:09
…ind the login wrapper

Adds the review's missing cases (background and suspended jobs under the login-wrapped shell, and
the pane entry for an extra login child), the rejected reuse of inspectSpawnFileChildProcessesFromRows,
and the plan to drop this fork patch once upstream ships the same fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-writer-login-shell

# Conflicts:
#	docs/issue/README.md
…-writer-login-shell

# Conflicts:
#	docs/issue/README.md
@Fartown
Fartown merged commit 321f33e into fork/integration Oct 23, 2026
46 checks passed
@Fartown
Fartown deleted the feat/cli-writer-login-shell branch October 23, 2026 10:56
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