Skip to content

Fix stale GitHub repo avatars after owner changes - #6507

Merged
nwparker merged 5 commits into
stablyai:mainfrom
ParkerRex:fix/github-avatar-live-refresh
Jul 3, 2026
Merged

nwparker merged 5 commits into
stablyai:mainfrom
ParkerRex:fix/github-avatar-live-refresh

Conversation

@ParkerRex

@ParkerRex ParkerRex commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Takeover (validated + polished by maintainer). Original author work by @ParkerRex, validated, extended with a regression fix, and merged. Original notes preserved below.

Description

When a GitHub repo's owner changes (org → personal or vice-versa, i.e. a transfer), the stored repo avatar went stale forever. Once repo.upstream was backfilled, the settings backfill effect returned early on every subsequent open, and even the manual "Use GitHub avatar" button preferred the cached upstream — so nothing ever re-resolved the live owner.

This change refreshes GitHub-avatar identity lazily when a repo's icon settings open (and on explicit Reset / Use-GitHub-Avatar), by forcing a live resolve that ignores the stale persisted metadata. buildRepositoryGitHubAvatarUpdate computes a minimal diff so nothing is written when the identity is unchanged.

Maintainer changes on top of the original PR:

  • Fork-identity regression fix (the important one). Repo.upstream is tri-state: undefined = fork status unprobed, null = confirmed not-a-fork, {owner,repo} = fork parent. The original forced-live path, when the live upstream lookup returned null, fell through to the origin slug. For a fork opened while offline/unauthed (where resolving the parent needs a network gh repo view), that null is ambiguous and would clobber the stored fork parent with the fork's own origin owner — flipping the avatar and, worse, writing a sticky null that permanently disables fork default-branch auto-sync (the backfill retry gate skips anything not === undefined). Fixed at the resolution layer: a known fork identity is preserved when the live upstream lookup is inconclusive; the origin-slug refresh only applies to non-fork repos (which always store null). Locked with unit + component regression tests.
  • Removed a now-dead exported wrapper (resolveRepositoryGitHubAvatarIcon) and two no-op ?? {...} update fallbacks; simplified the effect dependency array.
  • Corrected two of the original tests that encoded the buggy fork-downgrade behavior to the real non-fork transfer scenario.

Evidence

  • Reproduced on main first: a unit test against the pre-fix resolver shows the cached upstream returns the stale owner's avatar and never consults the live origin (repoSlug/repoUpstream not called).
  • Fixed: the same transfer scenario now resolves the new owner's avatar; the fork-offline scenario preserves the parent and writes nothing.
  • pnpm vitest run (repo config) — 6/6 pass across repository-icon-github.test.ts and RepositoryIconPicker.github-avatar-refresh.test.tsx (non-fork transfer refresh, fork-preservation, passive no-clobber, default-usage).
  • oxlint (+ react-doctor) clean on all four touched files.
  • pnpm run typecheck — exit 0.

ELI5

Your project's little picture comes from whoever owns the repo on GitHub. If the repo moves to a new owner, the picture used to get stuck on the old owner forever. Now, when you open that project's icon settings, Orca quietly asks GitHub who owns it today and updates the picture. And if your project is a fork, we're careful: if GitHub can't be reached at that moment, we keep the parent's picture instead of guessing wrong and breaking fork syncing.

Trade-offs

  • Lazy, not eager: a stale avatar self-heals when you open that repo's icon settings (or hit Reset / Use GitHub Avatar), not the instant .git/config changes behind Orca's back. Deliberate — a startup/background sweep would pay network/gh cost on every launch for every repo to fix a rare transfer.
  • Cost per open: opening icon settings for a GitHub-avatar repo triggers one best-effort live origin/upstream check (routed through the existing per-repo runtime target, so SSH/remote parity holds). It's user-initiated, deduped per mount, and bounded by the existing gh concurrency limiter — no polling, no per-render churn.
  • Fork un-fork edge: if a repo genuinely stops being a fork, the passive refresh conservatively keeps the last-known parent avatar (can't distinguish from a transient failure); the user can correct it via Reset. Chosen to never silently destroy fork identity.
  • No new IPC channels, dependencies, auth scopes, or path handling. GitLab/other providers unchanged.

Original author notes (@ParkerRex)

Hey it's Parker - super random edge case I ran into. If you change repo location from Org -> Personal or vice-versa, the image goes stale.

This keeps the fix lazy instead of checking every repo on startup. Orca only refreshes the GitHub avatar identity when the repo icon settings are opened for a repo already using the GitHub avatar, or when the user explicitly hits Reset / GitHub Avatar.

Decision/tradeoff: rejected a startup-wide refresh (every launch would inspect repo remotes; remote/SSH repos add network round trips; forks spend gh/API budget) and a background sweep (touches unrelated repos, adds scheduling/cache-invalidation complexity) in favor of the lazy settings refresh (zero repo-list/startup cost, only runs for repos already using a GitHub avatar, reuses existing gh.repoUpstream / gh.repoSlug calls).

@ParkerRex
ParkerRex marked this pull request as ready for review June 27, 2026 17:22
@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

repository-icon-github.ts gains two new exported types (ResolveRepositoryGitHubAvatarOptions, RepositoryGitHubAvatarResolution), a resolveRepositorySlugLive helper, a unified resolveRepositoryGitHubAvatar resolver that handles both live upstream lookup and slug fallback, and a buildRepositoryGitHubAvatarUpdate function that computes a Partial<Repo> diff. RepositoryIconPicker.tsx is updated to use these new APIs in handleUseGitHubAvatar, handleResetToDefault, and a rewritten useEffect that performs a one-time identity refresh per repo. Tests are added for both the resolver logic and the picker's refresh effect.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is substantive, but it does not follow the required template and omits Screenshots, Testing, AI Review Report, Security Audit, and Notes. Add the missing template sections with screenshot status, test results, AI review/cross-platform checks, security audit, and platform-specific notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: fixing stale GitHub repo avatars after owner changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/renderer/src/components/settings/repository-icon-github.ts (1)

104-109: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add the clearMissingIcon rationale inline.

This guard carries the PR’s “passive refresh must not clear an existing GitHub avatar” rule, but that policy is only implicit here. A short Why: comment would make the opt-in clear behavior much easier to preserve.

As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Suggested comment
   if (
+    // Why: passive refresh preserves the current GitHub avatar when live
+    // identity cannot be resolved; explicit reset opts into clearing it.
     (resolution.repoIcon || options.clearMissingIcon) &&
     !sameRepoIcon(repo.repoIcon, resolution.repoIcon)
   ) {

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6db9e2ea-a0ac-4b8d-b47b-92103bcc409f

📥 Commits

Reviewing files that changed from the base of the PR and between 867c57b and c45a044.

📒 Files selected for processing (4)
  • src/renderer/src/components/settings/RepositoryIconPicker.github-avatar-refresh.test.tsx
  • src/renderer/src/components/settings/RepositoryIconPicker.tsx
  • src/renderer/src/components/settings/repository-icon-github.test.ts
  • src/renderer/src/components/settings/repository-icon-github.ts

Comment on lines 48 to +56
const upstream =
repo.upstream !== undefined
!options.forceLive && repo.upstream !== undefined
? repo.upstream
: await resolveRepositoryUpstreamLive(runtimeTarget, repo).catch(() => null)
if (upstream) {
return githubAvatarIcon(upstream)
}
const slug =
runtimeTarget.kind === 'environment'
? await callRuntimeRpc<{ owner: string; repo: string } | null>(
runtimeTarget,
'github.repoSlug',
{ repo: repo.id },
{ timeoutMs: 30_000 }
)
: await window.api.gh.repoSlug({ repoPath: repo.path, repoId: repo.id })
return slug ? githubAvatarIcon(slug) : null
return { repoIcon: githubAvatarIcon(upstream), upstream }
}
const slug = await resolveRepositorySlugLive(runtimeTarget, repo)
return { repoIcon: slug ? githubAvatarIcon(slug) : null, upstream: null }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Don't collapse upstream lookup errors into null.

Line 51 swallows every resolveRepositoryUpstreamLive() failure and then Lines 55-56 fall back to repoSlug. If repoSlug succeeds, buildRepositoryGitHubAvatarUpdate() can persist upstream: null, which rewrites a still-forked repo as “not a fork” after a transient RPC/IPC failure. Let the error abort the refresh (or preserve the existing upstream) and only slug-fallback on an actual null upstream result.

Proposed fix
 export async function resolveRepositoryGitHubAvatar(
   runtimeTarget: RuntimeTarget,
   repo: Repo,
   options: ResolveRepositoryGitHubAvatarOptions = {}
 ): Promise<RepositoryGitHubAvatarResolution> {
   const upstream =
     !options.forceLive && repo.upstream !== undefined
       ? repo.upstream
-      : await resolveRepositoryUpstreamLive(runtimeTarget, repo).catch(() => null)
+      : await resolveRepositoryUpstreamLive(runtimeTarget, repo)
   if (upstream) {
     return { repoIcon: githubAvatarIcon(upstream), upstream }
   }
   const slug = await resolveRepositorySlugLive(runtimeTarget, repo)
   return { repoIcon: slug ? githubAvatarIcon(slug) : null, upstream: null }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const upstream =
repo.upstream !== undefined
!options.forceLive && repo.upstream !== undefined
? repo.upstream
: await resolveRepositoryUpstreamLive(runtimeTarget, repo).catch(() => null)
if (upstream) {
return githubAvatarIcon(upstream)
}
const slug =
runtimeTarget.kind === 'environment'
? await callRuntimeRpc<{ owner: string; repo: string } | null>(
runtimeTarget,
'github.repoSlug',
{ repo: repo.id },
{ timeoutMs: 30_000 }
)
: await window.api.gh.repoSlug({ repoPath: repo.path, repoId: repo.id })
return slug ? githubAvatarIcon(slug) : null
return { repoIcon: githubAvatarIcon(upstream), upstream }
}
const slug = await resolveRepositorySlugLive(runtimeTarget, repo)
return { repoIcon: slug ? githubAvatarIcon(slug) : null, upstream: null }
export async function resolveRepositoryGitHubAvatar(
runtimeTarget: RuntimeTarget,
repo: Repo,
options: ResolveRepositoryGitHubAvatarOptions = {}
): Promise<RepositoryGitHubAvatarResolution> {
const upstream =
!options.forceLive && repo.upstream !== undefined
? repo.upstream
: await resolveRepositoryUpstreamLive(runtimeTarget, repo)
if (upstream) {
return { repoIcon: githubAvatarIcon(upstream), upstream }
}
const slug = await resolveRepositorySlugLive(runtimeTarget, repo)
return { repoIcon: slug ? githubAvatarIcon(slug) : null, upstream: null }
}

Comment on lines +30 to +31
// @ts-expect-error test window mock
globalThis.window = { api: { gh: apiMocks } }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Preserve happy-dom’s real window object.

Lines 30-31 replace globalThis.window with a plain object, which strips the real happy-dom window of document, timers, constructors, and other DOM state. That makes this test run against a broken browser global and can hide future regressions. Patch window.api instead of replacing window.

Proposed fix
-// `@ts-expect-error` test window mock
-globalThis.window = { api: { gh: apiMocks } }
+Object.defineProperty(window, 'api', {
+  value: { gh: apiMocks },
+  configurable: true
+})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// @ts-expect-error test window mock
globalThis.window = { api: { gh: apiMocks } }
Object.defineProperty(window, 'api', {
value: { gh: apiMocks },
configurable: true
})

@nwparker

nwparker commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Maintainer takeover — validated, extended, and verified this PR end-to-end.

Security screen: clean. No new IPC/deps/postinstall/network hosts. Avatar URLs are host-pinned (https://github.com/<encodeURIComponent(owner)>.png) and re-validated by sanitizeRepoIcon (host must equal github.com, path ^/[^/?#]+\.png$), so a crafted repo owner can't redirect the fetch to an internal host — no SSRF.

Reproduced first on main: a unit test against the pre-fix resolver confirms the cached upstream returns the stale owner's avatar and never consults the live origin.

One real regression found and fixed before merge: the original forced-live path could clobber a fork's parent identity with the fork's own origin owner when the live upstream lookup returned null offline/unauthed — flipping the avatar and writing a sticky null that silently disables fork default-branch auto-sync. Fixed at the resolution layer (preserve a known fork identity when the live lookup is inconclusive; origin-slug refresh only applies to non-fork repos, which always store null). Added unit + component regression tests.

Verification: vitest 6/6 pass, oxlint (+react-doctor) clean on all four files, typecheck exit 0.

Thanks @ParkerRex — the lazy-refresh design and the explicit cost/benefit write-up were exactly right; that made the takeover fast.

@nwparker
nwparker merged commit 332490e into stablyai:main Jul 3, 2026
1 check passed
@nwparker

nwparker commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Merged (squash) — this passed the full quality bar. Thanks again @ParkerRex: your lazy-refresh design and the explicit cost/benefit reasoning were spot on, and the only thing needed on top was hardening the fork-identity path against transient offline lookups (plus tests for it). Appreciate the clean, well-scoped contribution.

@nwparker

nwparker commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Thank you, @ParkerRex. Avatars getting stuck on the previous owner after a repo transfer is a subtle one to notice, and the lazy self-heal on settings-open is a nice cost/benefit call rather than sweeping on every launch. Thanks for the thoughtful fix — merged!

@nwparker

nwparker commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Thanks Parker! 🙏 Stale avatars after a repo transfer is a small thing that just looks wrong every time you glance at the sidebar. Nice pragmatic lazy-refresh call. Appreciate you polishing the rough edge. 🐋

nwparker added a commit that referenced this pull request Jul 4, 2026
…fix garbled comments (#7322)

Quality pass on renderer/shared PRs merged 2026-07-03:

- WorktreeTitleInlineRename: skip the truncation measure + ResizeObserver in `wrapTitle`
  mode, where wrapped titles never truncate — it could only churn unused state (#7307).
- editor slice: reuse the `removeEditorStateForReplacedPreview` helper this PR added
  instead of a hand-rolled copy of the same six-field eviction (drops ~50 lines) (#6476).
- useFileExplorerTree: extract `readWorktreeDirectory` so the connectionId/settings
  assembly for `readRuntimeDirectory` lives in one place, not three (#6321).
- comment-markdown-github-attachment-media: extract a shared `AttachmentFallbackLink`
  for the image/video error-fallback link (#6759).
- repository-icon-github: fold the two near-identical live resolvers into one
  parameterized `resolveRepositoryIdentityLive`; trim a 3-line comment to 2 (#6507).
- resource-usage-open-slices: delete the `shouldReadPopoverSlices` identity wrapper and
  inline `open` at the four call sites (#7275).
- BrowserPane: drop the pointerEvents assignment already applied inside
  `ensureBrowserPageWebview` for the reused-webview path (#6958).
- github slice: fix two garbled "…a commit main confirmed…" comments (#7277).
- runtime-file-client: trim the binary-file fallback comment to its whys (#6606).
- composer-branch-selection: drop the inline comment that restated the JSDoc (#6748).
- TabBarQuickCommandsButton: correct the stale "+ Command" comment (button shows no +).

No behavior change (the editor-helper reuse is behavior-equivalent, only more
conservative on an edge case); typecheck, oxlint, react-doctor, oxfmt, and touched
unit suites all pass.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Fix stale GitHub repo avatars after owner changes

* Simplify avatar-refresh effect deps (repo covers its fields)

Co-authored-by: Orca <[email protected]>

* Preserve known fork identity when live upstream lookup is inconclusive

Co-authored-by: Orca <[email protected]>

* Remove dead avatar-icon wrapper; drop no-op update fallbacks

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Neil <[email protected]>
Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…fix garbled comments (stablyai#7322)

Quality pass on renderer/shared PRs merged 2026-07-03:

- WorktreeTitleInlineRename: skip the truncation measure + ResizeObserver in `wrapTitle`
  mode, where wrapped titles never truncate — it could only churn unused state (stablyai#7307).
- editor slice: reuse the `removeEditorStateForReplacedPreview` helper this PR added
  instead of a hand-rolled copy of the same six-field eviction (drops ~50 lines) (stablyai#6476).
- useFileExplorerTree: extract `readWorktreeDirectory` so the connectionId/settings
  assembly for `readRuntimeDirectory` lives in one place, not three (stablyai#6321).
- comment-markdown-github-attachment-media: extract a shared `AttachmentFallbackLink`
  for the image/video error-fallback link (stablyai#6759).
- repository-icon-github: fold the two near-identical live resolvers into one
  parameterized `resolveRepositoryIdentityLive`; trim a 3-line comment to 2 (stablyai#6507).
- resource-usage-open-slices: delete the `shouldReadPopoverSlices` identity wrapper and
  inline `open` at the four call sites (stablyai#7275).
- BrowserPane: drop the pointerEvents assignment already applied inside
  `ensureBrowserPageWebview` for the reused-webview path (stablyai#6958).
- github slice: fix two garbled "…a commit main confirmed…" comments (stablyai#7277).
- runtime-file-client: trim the binary-file fallback comment to its whys (stablyai#6606).
- composer-branch-selection: drop the inline comment that restated the JSDoc (stablyai#6748).
- TabBarQuickCommandsButton: correct the stale "+ Command" comment (button shows no +).

No behavior change (the editor-helper reuse is behavior-equivalent, only more
conservative on an edge case); typecheck, oxlint, react-doctor, oxfmt, and touched
unit suites all pass.
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.

3 participants