Skip to content

fix(core): start the command watcher before the command so group signals cannot kill it - #498

Merged
lg2m merged 4 commits into
mainfrom
fix/command-watcher-race
Oct 29, 2026
Merged

lg2m merged 4 commits into
mainfrom
fix/command-watcher-race

Conversation

@lg2m

@lg2m lg2m commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the Linux main-CI flake in tools::shell::orphan_tests::a_killed_server_takes_its_commands_with_it (main run 40810178056).

What was broken for users: on Unix, each shell command's process group has a watcher that kills the group if QQ dies (SIGKILL included). The watcher was spawned after the command and joined its group. A command that signals its own group right away (kill -s TERM 0, common in scripts) could kill the watcher before trap '' … TERM ran. The command then outlived QQ.

Fix: the watcher now starts first, leading its own group. It sets its traps, writes one byte on stdout to say it is ready, and only then is the command spawned into the watcher's group. The guard and goal_check now use the watcher's group id instead of assuming the group id is the command's pid.

Verification

  • New tools::shell::watcher_tests::the_watcher_ignores_group_signals_before_a_command_joins reads the watcher's SigIgn mask from /proc when the watcher is handed over.

  • Orphan test under stress, 3000 iterations at 64 threads: 3 to 9 failures before the fix, 3000/3000 passing after.

  • With a busy loop before the watcher's trap, the old code failed 3 of 5 runs; with the fix, the same delay passes 20/20.

  • cargo xtask check passed.

  • tools::tests::a_command_starts_in_a_group_its_ready_watcher_leads runs a command through the shell tool and checks that it joined a group led by a watcher that already ignores TERM. It fails on the old code (the command leads its own group) and passes with the fix.

  • Because a command no longer leads its group, it can setsid() without forking and leave it. Stopping a command now also kills it directly on Linux (macOS already did). a_command_that_leaves_its_group_still_stops_on_timeout hung before this and passes now.

  • Startup checks cancellation again after the watcher is ready, so a cancel during watcher startup never launches the command.

Independent of #497 (Windows clippy fix); both are needed for main CI to be green.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T05:05:59.575165Z b4ae1b9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ba555e5eb

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-core/src/tools/shell.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 698237ba45

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-core/src/tools/shell.rs Resolved
@lg2m

lg2m commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9ca5f0987

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lg2m

lg2m commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: b4ae1b9910

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lg2m
lg2m merged commit 16bc417 into main Oct 29, 2026
8 checks passed
@lg2m
lg2m deleted the fix/command-watcher-race branch October 29, 2026 05:09
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