fix(cosh-ng): [core] degrade gracefully when SIGINT registration fails - #2648
fix(cosh-ng): [core] degrade gracefully when SIGINT registration fails#2648SunnyQjm wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
[P2] SIGINT 失败路径目前只能通过推理验证,建议后续考虑引入可测试注入点。
[P2] headless 与 session-control 模式下 SIGINT 预期行为主要存在于注释,建议在模式判定附近补充更明确约束说明。
整体变更方向合理,主路径行为保持一致,退化策略符合描述语义。
🤖 Generated by Qoder • View workflow run
| @@ -195,8 +189,20 @@ fn is_agent_headless_mode(args: &cli::CliArgs) -> bool { | |||
| } | |||
|
|
|||
| #[cfg(unix)] | |||
There was a problem hiding this comment.
[P2] SIGINT 失败路径行为不可测试
wait_for_sigint 不再返回 Result,测试无法直接模拟注册失败并验证 "警告一次+永不完成" 语义。建议保留一个内部注入点(如 feature-gated hook 或私有 helper)以便构造失败路径,确保该受限环境退化行为在未来修改中不被破坏。
🤖 Generated by Qoder • Fix in Qoder
| @@ -195,8 +189,20 @@ fn is_agent_headless_mode(args: &cli::CliArgs) -> bool { | |||
| } | |||
There was a problem hiding this comment.
[P2] headless 模式下 SIGINT 行为差异未在代码层显式体现
注释说明受限环境下服务保持运行、SIGINT 仍用内核默认终止进程,但 headless/session-control 模式下的差异只存在于文字说明。建议在 is_agent_headless_mode 附近补充更明确的行为约束注释,帮助后续维护者理解不同模式下 SIGINT 的预期语义。
🤖 Generated by Qoder • Fix in Qoder
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8753de17d1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // If handler registration fails (restricted environments), fall back to | ||
| // the kernel default SIGINT disposition: warn once and never resolve, | ||
| // so the process keeps serving and Ctrl-C still terminates it. Exiting |
There was a problem hiding this comment.
Preserve termination when SIGINT is inherited as ignored
When handler registration fails under the restricted environments targeted here and the launcher has inherited SIGINT as ignored—an explicitly supported scenario in crates/cosh-core/tests/sigint.rs—the failed registration does not restore the kernel default because ignored dispositions survive exec. This pending future therefore leaves SIGINT ignored indefinitely, so neither Ctrl-C nor kill -INT terminates the headless process despite the comment and warning claiming otherwise. Avoid waiting forever unless termination is actually guaranteed, or retain an actionable failure path for this case.
AGENTS.md reference: AGENTS.md:L347-L349
Useful? React with 👍 / 👎.
|
PR number: #2648 Findings未发现 blocking package/module/public API 组织问题。
组织规则核对
Open Questions
Validation
|
When tokio::signal::ctrl_c() fails to register (restricted environments that deny sigaction), the current code exits with status 1 from inside tokio::select!. Because select! polls branches in random order, the run() branch may already have started by then -- in session-control mode it may even have exited with its own status -- so the failure behavior is nondeterministic, and headless serving dies at startup in such environments. Warn once and never resolve the signal branch instead: with no handler installed the kernel default SIGINT disposition stays in effect, so Ctrl-C still terminates the process while the service keeps running. Identified by the qoderai P1 review on the parallel PR alibaba#2624 (see the verification discussion there). Fixes: 24daa1e ("fix(cosh-ng): await SIGINT without polling")
8753de1 to
6df45a4
Compare
|
三条评审意见处理完毕(head 已更新为 6df45a4): @chatgpt-codex-connector [P2](inherited-ignored × 注册失败):意见成立,已采纳。 核实:ignored disposition 穿越 exec(tests/sigint.rs 钉住的 launcher 场景),注册失败时不会恢复 default——原文案"内核默认 disposition"在该格子不成立,Ctrl-C 与 @QoderAI [P2](headless/session-control 语义应在代码层显式):部分采纳。 已在 @QoderAI [P2](失败路径可测试注入点):不采纳,理由如下。 该路径唯一逻辑是"打印一行 + pending";引入注入点需把 验证:clippy 0 警告; |
|
To use Codex here, create a Codex account and connect to github. |
|
PR number: #2648 Findings未发现 blocking package/module/public API 组织问题。
行为核对
组织规则核对
剩余风险
Validation
|
Code Review Check: ✅ ApprovedReviewer audit of code-reviewer's analysis — all findings verified against source code. SummaryThis is a precise, minimal fix that correctly resolves the SIGINT registration failure race condition. The code-reviewer's analysis is accurate with no significant omissions. Verified points
Notecosh-ng CI checks (Test cosh-ng, Test cosh-ng fast checks, Build cosh-ng release) were still IN_PROGRESS at review time. Merge should wait for CI green. |
|
CI 失败分类(回应 auto-review P2 的合并前核对要求): 结论:suspected-flaky(PTY 时序类),与本 PR 无因果,rerun 已绿。
|
Code Review: PR #2648 — fix(cosh-ng): [core] degrade gracefully when SIGINT registration fails变更概述修改 审查结论:✅ LGTM正确性分析:
测试覆盖:
无问题发现。 变更范围小、逻辑清晰、注释充分,是一个高质量的缺陷修复。 @code-reviewer-leader 请继续委派 code-reviewer-check 进行审核。 |
Code Review Check: ✅ LGTMVerified code-reviewer's analysis against actual code — all 6 points confirmed correct:
No P0/P1 omissions found. Change scope is small (1 file, +28/-10), logic is clear, comments are thorough. Verdict: Approve — no blocking issues. |
Summary
修复 24daa1e("await SIGINT without polling")遗留的注册失败路径缺陷。该缺陷最早由 qoderai 在并行 PR #2624 的 P1 评审中识别,分析与验证讨论见该 PR(#2624 已因主体与 24daa1e 重复而关闭,本 PR 携带其唯一幸存增量)。
问题:
tokio::signal::ctrl_c()注册失败(受限环境禁 sigaction)时,现行代码在select!分支内exit(1)。tokio::select!默认随机化分支 poll 顺序——注册失败时run()分支可能已先启动(session-control 模式甚至已以自身状态码退出),失败行为不确定;且 headless 服务在此类环境下启动即死。修复:注册失败改为 stderr 告警一次 + future 永不完成。handler 未安装时 SIGINT 保持内核默认终止 disposition——Ctrl-C 仍可终止进程,服务继续运行。消除随机性,可用性优于启动即死。
验证
cargo clippy -p cosh-core --all-targets:0 警告cargo test -p cosh-core(alinux3 arm64 容器):失败集与同环境 origin/main 基线一致(4 个 root 权限类已知环境项;另有 1 例listing_distinguishes_persisted_shell_envelope_sessions单轮偶发,隔离连跑 5/5 通过,判定 suspected-flaky,与本改动无因果面),零新增失败focused green(cosh-core crate);全仓 gate 交 CI。