Skip to content

Conversation

ChrisRackauckas
Copy link
Member

Summary

Fixes false negative authentication detection when gh auth login appears to fail but authentication actually succeeds.

Problem

As reported, when using gh auth login in LinearSolveAutotune:

  • The browser might fail to open (e.g., on headless systems)
  • User manually enters the URL and completes authentication
  • gh auth login returns non-zero exit code due to browser failure
  • Authentication actually succeeded but the code doesn't detect it
  • Results are saved locally instead of being uploaded

Root Cause

  1. gh auth status outputs to stderr, not stdout
  2. The code was trying to read from stdout, getting empty output
  3. When gh auth login failed (even if auth succeeded), the code gave up

Solution

1. Properly Capture stderr

# Before: reading from stdout (wrong)
auth_status_output = read(`$gh_cmd auth status`, String)

# After: reading from stderr (correct)
io = IOBuffer()
run(pipeline(`$gh_cmd auth status`; stderr=io, stdout=devnull))
seekstart(io)
auth_status_output = read(io, String)

2. Always Check Auth Status

  • Even if gh auth login returns non-zero exit, still check auth status
  • User might have completed authentication manually
  • Added recovery logic to detect successful auth despite command failure

3. Improved Feedback

  • Clear messages when browser fails but auth might still work
  • Fallback detection with multiple attempts
  • Better error handling and user guidance

Testing

Tested scenarios:

  • Normal authentication flow
  • Browser fails to open but manual URL entry works
  • Already authenticated user
  • Various error conditions

Example

Before fix:

\! Failed opening a web browser at https://github.com/login/device
✓ Authentication complete. Press Enter to continue...
[ Info: 📁 Results saved locally to autotune_results_2025-08-09T19-47-13.639.md

After fix:

⚠️  gh auth login reported an issue: failed to open browser
   Checking if authentication succeeded anyway...
✅ Authentication successful\! You can now share results.
[ Info: 📤 Uploading benchmark results to GitHub...

This ensures authentication is properly detected even when the browser opening fails.

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

- gh auth status outputs to stderr, not stdout
- Fixed auth detection to properly capture stderr output
- Added fallback detection when gh auth login fails but auth succeeds
- Always check auth status even if gh auth login returns non-zero exit
- Add delay to ensure auth is fully processed before checking
- Provide better feedback when browser fails to open but auth might work

This fixes the issue where authentication succeeds (e.g., via manual URL entry
when browser fails to open) but the autotune system fails to detect it.
@ChrisRackauckas ChrisRackauckas merged commit 28c602d into SciML:main Aug 10, 2025
99 of 118 checks passed
@ChrisRackauckas ChrisRackauckas deleted the fix-auth-false-negative branch August 10, 2025 00:17
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