feat: harden repository list against GitHub API failures (#105) - #131
Merged
Conversation
Issue #105 fix slice: the repository list endpoint no longer hard-fails when GitHub momentarily rejects or rate-limits the per-user OAuth call, and the repositories table is now reconciled in the background regardless of user activity. - Extend accessible_repo_ids cache: 10m→1h valid, 1h→24h stale, sync throttle 10m→30m. Cleanup job preserves entries 24h past expiration so they remain usable as stale fallbacks. - Cache layer serves stale on any AccessError (TokenExpired / Upstream), not only RateLimited. - Add github_installation_sync_state table tracking webhook_seen_at / last_sync_* per installation. Webhook handler stamps webhook_seen_at on installation and installation_repositories events. - Worker periodic reconciler (default every 30m) uses GitHub App credentials to list installations + their repositories and upserts into repositories, skipping installations whose webhook is fresh and whose last sync is within the throttle window. - Add (updated_at DESC, github_repository_id DESC) index on repositories for the list endpoint cursor pagination. Configurable via INSTALLATION_SYNC_INTERVAL_SECS, INSTALLATION_SYNC_STALE_AFTER_SECS, INSTALLATION_SYNC_MIN_INTERVAL_SECS, INSTALLATION_SYNC_MAX_PER_SWEEP. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #105 (レポジトリ一覧画面の軽量化) を満たすため、レポジトリ一覧 API が GitHub API の一時失敗で落ちないようにし、
repositoriesテーブルを webhook + worker で背景同期する仕組みを足した。変更内容
crates/api/src/github_access/cached.rs)accessible_repo_idsvalid TTL: 10m → 1hRateLimitedのみだったが、TokenExpired/Upstreamでも stale cache を返す。一覧画面が GitHub session expired で落ちる頻度を下げる(GitHub OAuth token 失効時の401ハンドリングを改善する #104 の症状にも効く)。github_installation_sync_stateテーブル追加 (migrations/20260504000000_add_installation_sync_state.*)webhook_seen_at,last_sync_started_at,last_sync_completed_at,last_sync_status,last_errorwebhook_seen_atを更新installation/installation_repositories両方crates/worker/src/installation_sync.rs)list_installations→list_installation_repositories→repositoriesupsert + 削除レポの installation_id クリアgithub_installation_sync_stateに記録repositories(updated_at DESC, github_repository_id DESC)indexGitHubAppClientにlist_installation_ids/list_installation_repositoriesを追加スコープ外 / 続編候補
list_accessible_repo_idsを完全に外してrepositoriesテーブル直照会へ寄せる変更は別途。今回は「失敗時に落ちない」「背景でrepositoriesが埋まる」までを担保した。設定 (デフォルト)
Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspace(ローカル DB 含む)installation_sync::needs_sync(5 ケース)crates/worker/tests/installation_sync_test.rs):installation/installation_repositoriesがwebhook_seen_atを打刻🤖 Generated with Claude Code