fix: guarantee bounded authentication and skill shutdown - #144
Closed
GautamSharma99 wants to merge 1 commit into
Closed
fix: guarantee bounded authentication and skill shutdown#144GautamSharma99 wants to merge 1 commit into
GautamSharma99 wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for working through bounded shutdown for authentication and skills. The corresponding shutdown handling is already implemented on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #131.
Make authentication and skill subprocess cancellation settle within a bounded deadline, even when the immediate child ignores the cooperative termination signal or a descendant keeps inherited output pipes open.
Previously,
CodexLoginHandle.cancel()sentSIGTERMonce andCodexSecurity.close()waited on the login handle without a deadline. The CLI skill path used the same one-signal behavior. A non-cooperative child or inherited pipe could therefore leave SDK or CLI cleanup pending indefinitely.Changes
Bounded login cancellation
Interactive login cancellation now uses a two-stage shutdown:
SIGTERM;SIGKILL;The forced completion remains an unsuccessful canceled login, so the authentication success callback cannot run after cancellation.
Repeated calls to
cancel()reuse the existing deadline instead of creating additional timers.Cross-platform inherited-pipe fallback
The existing post-exit pipe fallback was Windows-only. It now applies on every platform.
After the immediate login child exits, normal pipe draining still receives a one-second grace period. If a descendant continues holding stdout or stderr open after that deadline, the SDK destroys the streams and settles the login using the immediate child's exit status.
This preserves ordinary diagnostic draining while preventing descendants from keeping
login.wait()andCodexSecurity.close()alive forever.Timer and listener cleanup
Login completion and spawn failure now clear both the post-exit fallback and forced-termination timer. Process pipes are released on every terminal path, and late
error,exit, orcloseevents cannot settle the same login twice.Bounded CLI signal forwarding
runCodexSkillCommandnow applies the same one-second termination deadline when forwardingSIGINTorSIGTERM:SIGKILL;SIGINTand 143 forSIGTERM;Explicitly releasing the capture wait is necessary because destroying a stream alone does not reliably settle every parser or inherited-pipe configuration.
Impact
SDK consumers can now rely on
CodexSecurity.close()completing after it cancels an interactive login. CLI skill commands also return after cancellation instead of waiting indefinitely for an uncooperative child or inherited output pipe.The cooperative path is unchanged: children still receive the original signal and have time to clean up normally before forced termination occurs.
Tests
Added and updated regression coverage for:
SIGTERMhandler and refuses to exit;CodexLoginHandle.cancel()completion within a bounded deadline;CodexSecurity.close()completion when its active login ignoresSIGTERM;SIGTERMwhile its skill child ignores the signal;Verification
pnpm run typespnpm run formatpnpm run buildPATH="/opt/homebrew/bin:$PATH" pnpm run testFull test result: