zed
zed copied to clipboard
GitHub avatars: support enterprise avatars with GITHUB_TOKEN, handle failure better
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
Zed made multiple unsuccessful attempts to retrieve the avatar from my private GH enterprise account. I believe it would be better if the retry attempts were limited, and having a default avatar type, such as using the first characters of the first and last names as a fallback, would be ideal.
Zed log:
My avatar is blank:
Environment
Zed: v0.156.1 (Zed) OS: macOS 14.6.0 Memory: 16 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
If applicable, attach your Zed.log file to this issue.
Zed.log
Yeah, I ran into this previously and just dug up the slack conversation. It appears that when a user is inside a GitHub hosted Enterprise (not surely exactly which plans/settings trigger this) the GitHub API behaves very differently for these users.
For example to fetch my avatar, we would hit: https://api.github.com/users/notpeter which returns a nice json object including an avatar_url of https://avatars.githubusercontent.com/u/145113?v=4.
Where as for a random gh hosted enterprise user it just straight 404s. Similarly, if you hit the profile link it redirects you to an enterprise login. Wild.
We absolutely should handle this better:
- stop retrying so much
- have a fallback icon
- (potentially) use GITHUB_TOKEN to make it work
Do you use the gh cli and potentially have a token which could be made available via export GITHUB_TOKEN="$(gh auth token)"?
export GITHUB_TOKEN="$(gh auth token)"
Indeed, I do have it. I successfully tested the calling profile API on terminal, using that GH token and receive the same response data structure like public GH account could have.
A user reported a similar issue (repeated failed attempts to load an avatar) for a deleted/renamed github user here:
- https://github.com/zed-industries/zed/issues/19460
We should fail gracefully in that situation as well.
Two things to do here:
- Take GITHUB_TOKEN into account for GHE
- If image fails to load, show placeholder avatar and do not try to re-render (or at least backoff and try to slowly reload)
I am no longer able to reproduce the spamming GitHub issue. It has likely been fixed with the image cache: https://github.com/zed-industries/zed/pull/27774
I hardcoded all avatars to load a specific url I knew would fail, and it is only logging once (I am only seeing one when it fails the first time)
I will keep digging into how we can actually support enterprise images though.
@benbrandt I believe the solution would likely be to use a GITHUB_TOKEN for requests:
- https://github.com/zed-industries/zed/issues/9483
#32164 would allow for using a GitHub token if provided, however this has a few potential concerns:
- The user can only do this if they set an env variable and launch Zed from the CLI
- If the token is expired, we may cause more issues throughout the app, which that PR doesn't handle currently
We could do some form of oauth/refresh token route for the user, but this would be a larger change.
It seems like, no matter what having fallback avatars would be a better experience in the app, because there are other reasons we might fail to load the image.
We will circle back with @iamnbutler and @danilo-leal on their previous work here and see if we can manage to get some form of avatar fallbacks in the app.
I discovered if you have the github user id (not just the username) you can directly retrieve the avatar image by-id which (1) saves a 302 http redirect (2) works for github enterprise users.
# curl -I 'https://github.com/notpeter.png?size=128' |grep location
location: https://avatars.githubusercontent.com/u/145113?s=128&v=4
hi @notpeter, the link actually only works if I request within the browser that I have a live session of that GitHub account, it's failed in another browser profile OR just 404 in Zed.
Here is the log I have in Zed.
2025-11-03T11:02:44+07:00 ERROR [gpui::asset_cache] Failed to load asset: unexpected http status for https://github.com/your_enterprise_gh_username.png?size=128: 404 Not Found, body: Not Found