Skip to content

Comments

fix(providers): enable graceful termination during SSO browser authentication#151

Open
8nevil8 wants to merge 2 commits intomainfrom
fix/sso-auth-graceful-termination
Open

fix(providers): enable graceful termination during SSO browser authentication#151
8nevil8 wants to merge 2 commits intomainfrom
fix/sso-auth-graceful-termination

Conversation

@8nevil8
Copy link
Collaborator

@8nevil8 8nevil8 commented Feb 16, 2026

Summary

Fixes issue where SSO authentication flow cannot be interrupted with Ctrl+C when waiting for browser callback. Previously, the process would hang indefinitely, requiring manual termination (kill -9).

Changes

  • Added AbortController support to enable external cancellation of authentication flow
  • Registered SIGINT/SIGTERM handlers following the pattern from agent.ts:486-496 for consistent signal handling across the codebase
  • Replaced recursive polling in waitForCallback with non-recursive setInterval to prevent uninterruptible wait loops
  • Enhanced cleanup() method to force-close HTTP server connections immediately using closeAllConnections()
  • Added proper error handling for user cancellation with clear error messages
  • Implemented proper resource cleanup including timer cleanup and state reset

Impact

Before:

1. Browser opens for SSO authentication
2. User presses Ctrl+C
3. ❌ Process hangs indefinitely
4. ❌ Requires manual kill -9

After:

1. Browser opens for SSO authentication
2. User presses Ctrl+C
3. ✅ Shows "⚠️  Authentication cancelled by user"
4. ✅ Server closes immediately
5. ✅ Process terminates gracefully

Checklist

  • Self-reviewed
  • Manual testing performed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)

8nevil8 and others added 2 commits February 16, 2026 10:29
Fixes race condition in date-based log rotation that caused crashes when
Claude sessions crossed midnight. The async rotation fired but writeToLogFile
continued to write to the stream being closed, causing stream write-after-end errors.

Changes:
- Add defensive checks in writeToLogFile() to skip writes during rotation
- Check isRotating flag and stream.writable property before writing
- Enhance close() method to wait for in-progress rotation (max 5 seconds)
- Add detailed comments explaining the race condition scenario

Impact: Prevents application crashes in long-running sessions that span midnight.
Trade-off: May skip 1-2 log entries during rotation (acceptable vs crash).

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
…tication

Fixes issue where SSO authentication flow cannot be interrupted when
waiting for browser callback, requiring manual process termination.

Changes:
- Add AbortController for cancellation support
- Register SIGINT/SIGTERM handlers for graceful shutdown
- Replace recursive polling with setInterval in waitForCallback
- Enhance cleanup() to force-close server connections
- Add proper error handling for user cancellation

Pattern follows agent.ts signal handling implementation for consistency
across the codebase.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
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.

2 participants