fix(unix): detach Codex-launched gateways reliably - #845
Conversation
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_239517ed-bb9e-412e-9043-fce4c14b5cdf) |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe gateway now uses a dedicated session-detachment helper. Normal startup detaches from the client session, while ChangesGateway session detachment
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This PR changes Unix gateway startup so Codex-launched gateways detach before startup I/O and adds regression coverage; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What and why
Codex starts MCP children as process-group leaders. That made Toolport's
setsid()fail, leaving the gateway in Codex's terminal session. The login-shell PATH probe could then receive SIGTTIN and stop the whole gateway before its first response.Normal Unix startup now handles that launch shape and detaches before startup I/O or PATH discovery. Early diagnostic modes keep their existing terminal behavior.
Closes SBS-1063.
Testing
process_group(0)cargo clippy --manifest-path src-tauri/Cargo.toml --no-default-features --all-targetscargo test --manifest-path src-tauri/Cargo.toml --no-default-features --lib --bins --testsNotes
No Omarchy or client configuration changes are required.
Note
Medium Risk
Touches process-group and session leadership at gateway startup via unsafe POSIX calls. Failure modes are fail-open to the previous best-effort detach, but a bad detach could still affect job-control or child spawn on Unix.
Overview
Unix gateways launched as process-group leaders (Codex’s MCP spawn) now leave the client’s terminal session instead of failing
setsidwithEPERMand stopping on SIGTTIN during the PATH probe.detach_from_client_sessionbriefly rejoins the parent group and retriessetsidbefore session-bus restore or any child spawn.--selftest-secretsstill skips detach so that diagnostic path keeps its old terminal behavior. A Unix subprocess test launches the binary withprocess_group(0)and asserts it becomes its own session.Reviewed by Cursor Bugbot for commit 31bb5e5. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix gateway stall by robustly detaching from client terminal session on Unix
setsid()call with a newdetach_from_client_session()function in toolport-gateway.rs that handles the case where the gateway is already a process-group leader: it temporarily reattaches to the parent's group viasetpgid(0, parent_group)then callssetsid()again.--selftest-secrets.Macroscope summarized 31bb5e5.