Skip to content

Commit 28c602d

Browse files
Fix gh auth status false negative detection (#704)
- 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.
1 parent b28caa3 commit 28c602d

File tree

1 file changed

+63
-17
lines changed

1 file changed

+63
-17
lines changed

lib/LinearSolveAutotune/src/telemetry.jl

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ function setup_github_authentication(; auto_login::Bool = true)
2929

3030
# First check if already authenticated
3131
try
32-
# Suppress output of gh auth status check
33-
if success(pipeline(`$gh_cmd auth status`; stdout=devnull, stderr=devnull))
34-
# Check if logged in to github.com
35-
auth_status_output = read(`$gh_cmd auth status`, String)
36-
if contains(auth_status_output, "Logged in to github.com")
37-
println("✅ Found active `gh` CLI session. Will use it for upload.")
38-
return (:gh_cli, "GitHub CLI")
39-
end
32+
# gh auth status outputs to stderr, not stdout
33+
io = IOBuffer()
34+
run(pipeline(`$gh_cmd auth status`; stderr=io, stdout=devnull))
35+
seekstart(io)
36+
auth_status_output = read(io, String)
37+
38+
if contains(auth_status_output, "Logged in to github.com")
39+
println("✅ Found active `gh` CLI session. Will use it for upload.")
40+
return (:gh_cli, "GitHub CLI")
4041
end
4142
catch e
4243
@debug "gh CLI auth status check failed: $e"
@@ -64,21 +65,66 @@ function setup_github_authentication(; auto_login::Bool = true)
6465
println(" This will open your browser to authenticate with GitHub.")
6566
println(" Please follow the prompts to complete authentication.\n")
6667

68+
# Run gh auth login - it may fail to open browser but still succeed
69+
auth_login_success = false
6770
try
68-
# Run gh auth login interactively (using system gh or JLL)
6971
run(`$gh_cmd auth login`)
72+
auth_login_success = true
73+
catch e
74+
# gh auth login might fail (e.g., can't open browser) but auth might still work
75+
println("\n⚠️ gh auth login reported an issue: $e")
76+
println(" Checking if authentication succeeded anyway...")
77+
end
78+
79+
# Always check auth status, even if gh auth login appeared to fail
80+
# This handles cases where browser opening failed but user completed auth manually
81+
try
82+
# Small delay to ensure auth is fully processed
83+
sleep(0.5)
7084

71-
# Check if authentication succeeded
72-
if success(pipeline(`$gh_cmd auth status`; stdout=devnull, stderr=devnull))
73-
auth_status_output = read(`$gh_cmd auth status`, String)
74-
if contains(auth_status_output, "Logged in to github.com")
75-
println("\n✅ Authentication successful! You can now share results.")
76-
return (:gh_cli, "GitHub CLI")
85+
# Check current authentication status
86+
auth_status_output = ""
87+
try
88+
# gh auth status outputs to stderr, not stdout
89+
io = IOBuffer()
90+
run(pipeline(`$gh_cmd auth status`; stderr=io, stdout=devnull))
91+
seekstart(io)
92+
auth_status_output = read(io, String)
93+
catch
94+
# If that fails, try capturing both streams
95+
try
96+
io = IOBuffer()
97+
run(pipeline(`$gh_cmd auth status`; stderr=io, stdout=io))
98+
seekstart(io)
99+
auth_status_output = read(io, String)
100+
catch
101+
# Last resort - assume failure
102+
auth_status_output = ""
77103
end
78104
end
105+
106+
if contains(auth_status_output, "Logged in to github.com")
107+
println("\n✅ Authentication successful! You can now share results.")
108+
return (:gh_cli, "GitHub CLI")
109+
elseif auth_login_success
110+
# gh auth login succeeded but we can't verify the status
111+
println("\n⚠️ Authentication may have succeeded but couldn't verify status.")
112+
println(" Attempting to use gh CLI anyway...")
113+
return (:gh_cli, "GitHub CLI")
114+
else
115+
println("\n❌ Authentication verification failed.")
116+
println(" Output: ", auth_status_output)
117+
end
79118
catch e
80-
println("\n❌ Authentication failed: $e")
81-
println(" You can try again later or use a GitHub token instead.")
119+
if auth_login_success
120+
# gh auth login succeeded but status check failed - try anyway
121+
println("\n⚠️ Couldn't verify authentication status: $e")
122+
println(" gh auth login appeared successful, attempting to proceed...")
123+
return (:gh_cli, "GitHub CLI")
124+
else
125+
println("\n❌ Authentication failed: $e")
126+
println(" You can try again later or use a GitHub token instead.")
127+
end
82128
end
83129
else
84130
println("\n📝 Skipping authentication. You can authenticate later by:")

0 commit comments

Comments
 (0)