-
Notifications
You must be signed in to change notification settings - Fork 120
Fix : Repo Indexing Stuck in Pending State (#228) #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix : Repo Indexing Stuck in Pending State (#228) #232
Conversation
📝 WalkthroughWalkthroughAdds server-side cleanup of expired verification tokens before creating sessions, makes pending repository indexing retryable (reset to pending, clear errors, retrigger), and adds timezone-aware verification token expiry checks plus updated Discord messaging. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DiscordCog
participant AuthService
participant DB
participant RepoService
participant Analyzer
User->>DiscordCog: Request to index repo / verify
DiscordCog->>AuthService: Check verification_token and expires_at
AuthService->>DB: cleanup_expired_tokens()
AuthService-->>DiscordCog: token valid? (yes/no)
alt token valid
DiscordCog-->>User: "Verification Pending"
else token expired or none
DiscordCog->>AuthService: create_verification_session()
AuthService->>DB: create session record
AuthService-->>DiscordCog: session created
end
User->>RepoService: index_repo(repo)
RepoService->>DB: fetch repo record
alt record not found
RepoService->>DB: insert record (pending)
RepoService->>Analyzer: trigger /analyze_repo
else record found & completed
RepoService-->>User: error (already indexed)
else record found & not completed (pending/failed)
RepoService->>DB: set indexing_status = pending, clear last_error, touch timestamp
RepoService->>Analyzer: retrigger /analyze_repo
RepoService-->>User: indexing restarted
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (4)
✏️ Tip: You can disable this entire section by setting 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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @backend/app/services/codegraph/repo_service.py:
- Around line 71-83: Fix the typo in the comment message ("faild" → "failed")
where the restart log is emitted; update the logged string near the logger.info
call that says "Restarting indexing for {repo_info['full_name']} (previous
status: {status})" or any adjacent inline comment in RepoService to use "failed"
instead of "faild" so the log and comments are spelled correctly; verify the
change around the logger.info and the subsequent
supabase.table("indexed_repositories").update(...) block for consistency.
In @backend/integrations/discord/cogs.py:
- Around line 221-222: The two adjacent string literals used in the Discord
embed are concatenated without a separating space/newline, producing "...30-35
minutes.Please wait..."; update the embed text in cogs.py so the sentences are
separated (e.g., add a trailing space to the first literal, insert "\n" between
them, or combine into one string with proper spacing) where the embed message
for "⏳ Note: For large repositories..." is defined.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
backend/app/services/auth/verification.pybackend/app/services/codegraph/repo_service.pybackend/integrations/discord/cogs.py
🧰 Additional context used
🧬 Code graph analysis (1)
backend/app/services/auth/verification.py (1)
backend/integrations/discord/cogs.py (1)
cleanup_expired_tokens(39-46)
🔇 Additional comments (4)
backend/app/services/auth/verification.py (1)
39-40: LGTM - Good addition of token cleanup before session creation.This ensures expired tokens are cleaned from the database before creating new verification sessions, preventing stale data accumulation. The ordering (DB cleanup first, then in-memory cleanup) is appropriate.
backend/app/services/codegraph/repo_service.py (1)
84-93: LGTM - New repository insertion path.The insertion logic for new repositories is unchanged and correctly sets initial state to pending with no error.
backend/integrations/discord/cogs.py (2)
132-162: LGTM - Timezone-aware expiry validation.The logic correctly handles both string and datetime types for
expires_at, makes naive datetimes timezone-aware (assuming UTC storage convention), and allows users to retry verification when their previous token has expired.
271-293: LGTM - Error handling and messaging.The updated error embed and tip logic appropriately handles different failure scenarios. The removal of the obsolete "pending" tip aligns with the new restart behavior where pending states are now recoverable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@backend/integrations/discord/cogs.py`:
- Around line 133-148: The code currently leaves a token valid if
verification_token exists but verification_token_expires_at is None; update the
expiry check around expires_at/verification_token_expires_at so that if
expires_at is falsy (None) you mark is_expired = True (i.e., treat missing
expiry as expired) instead of leaving is_expired False — modify the block
handling expires_at/expires_at_dt (variables: expires_at, expires_at_dt,
is_expired, verification_token/verification_token_expires_at) to include an else
branch that sets is_expired = True.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
backend/app/services/codegraph/repo_service.pybackend/integrations/discord/cogs.py
🚧 Files skipped from review as they are similar to previous changes (1)
- backend/app/services/codegraph/repo_service.py
🔇 Additional comments (2)
backend/integrations/discord/cogs.py (2)
221-222: LGTM - Concatenation issue resolved.The newline character at the end of line 221 properly separates the sentences in the Discord embed. This addresses the PR objective of informing users about the 30-35 minute indexing time.
273-276: LGTM - Improved error messaging.The updated description "Indexing did not complete" is more accurate than "Could not index" given the new retry-from-pending behavior, where indexing may have started but not finished.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
Closes #228
📝 Description
This PR improves the repository indexing flow to prevent repositories from getting stuck indefinitely in a pending state and allows safe recovery from failures or backend crashes.
The change ensures that indexing can always be retried unless a repository has already been successfully indexed.
🔧 Problem Solved
Previously, repositories could remain stuck in pending state if :
/analyze_repo.In such cases, subsequent
/index_repositoryrequests would only show “indexing in progress” and never restart indexing, leaving users blocked.🔧 Solution
The indexing flow is updated to treat pending and failed states as recoverable, while keeping completed as a terminal state.
Key changes made :
completed --> indexing is blocked (no re-index)
failed --> indexing is restarted
pending --> indexing is restarted (covers slow jobs and backend crashes)
User is clearly informed that indexing may take 30–35 minutes.
FINAL INDEXING FLOW :
Case 1: New repository (never indexed before) :
/index_repositorystatus = pending./analyze_repoIf indexing succeeds :
DB -->
status = completed, user sees “Repository Indexed”.If indexing fails :
DB -->
status = failed, user sees “Indexing Failed”.Case 2: Repository already indexed (completed)
/index_repository.Case 3: Repository in failed state
/index_repository.status = failed.status = pending,last_error = null./analyze_repois called again and user sees “Indexing started again. This can take 30–35 minutes.”Case 4: Repository in pending state (including backend crash)
/index_repository.status = pendingThis could mean : Indexing is slow OR backend crashed earlier.
User sees : “Indexing started again. Please wait 30–35 minutes.”
✅ Checklist
Summary by CodeRabbit
Bug Fixes
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.