Skip to content

fix: Fixed issue with repositories appearing in the carousel when indexing fails on first sync #305

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

Merged
merged 2 commits into from
May 12, 2025

Conversation

brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented May 12, 2025

Problem: If a repository fails to index on the first sync, it will appear in the repository carousel, even if the repo doesn't have any shards associated with it:

image

Solution: I've changed the behaviour of repoManager to not set the indexedAt field on index job failure. Functionally, this changes the behaviour from:

last time a indexing job completed in either a success or failure state.

To:

late time this repository was successfully indexed

IMO the new behaviour is more expected for the name we are using. To keep things consistent, I've also changed the syncedAt field in connectionManager to have the same behaviour.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue where repositories that failed indexing for the first time could incorrectly appear in the carousel.
  • Documentation

    • Improved descriptions for fields related to last successful indexing and syncing times in the data models.

@brendan-kellam brendan-kellam requested a review from msukkari May 12, 2025 19:02
Copy link

coderabbitai bot commented May 12, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes update backend logic to ensure that the syncedAt and indexedAt timestamps are only updated on successful sync or indexing operations, not on failures. Documentation comments were added to the database schema to clarify the meaning of these fields. The changelog was updated to document the bug fix.

Changes

File(s) Change Summary
CHANGELOG.md Added an entry under "Unreleased" describing the fix for repositories incorrectly appearing after failed indexing.
packages/backend/src/connectionManager.ts Removed updating syncedAt timestamp on sync failure; only updates syncStatus and syncStatusMetadata.
packages/backend/src/repoManager.ts Removed updating indexedAt timestamp on indexing failure; only updates repoIndexingStatus.
packages/db/prisma/schema.prisma Added documentation comments to indexedAt (Repo) and syncedAt (Connection) fields to clarify their meaning.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Backend
    participant Database

    User->>Backend: Trigger repo indexing or connection sync
    Backend->>Database: Start job, set status to IN_PROGRESS

    alt On Success
        Backend->>Database: Update status to SUCCESS
        Backend->>Database: Update indexedAt/syncedAt to now
    else On Failure
        Backend->>Database: Update status to FAILED
        Note right of Database: Do NOT update indexedAt/syncedAt
    end
Loading

Suggested reviewers

  • msukkari

Poem

In the warren of code, a timestamp’s tale,
Now only success lets the clocks set sail.
No more false signals when things go awry,
The schema speaks clear, no need to ask why.
🐇 With bugs now fixed, we hop on with glee,
To a garden of data, neat as can be!

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de1d849 and eab7b23.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • packages/backend/src/connectionManager.ts (0 hunks)
  • packages/backend/src/repoManager.ts (0 hunks)
  • packages/db/prisma/schema.prisma (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
CHANGELOG.md (1)

10-11: Ensure consistent verb tense in changelog entries
Other "Fixed" sections often use present-tense verbs (e.g., "- Fixes bug..."). Consider changing

- Fixed issue with repos appearing in the carousel when they fail indexing for the first time.

to

- Fix issue with repos appearing in the carousel when they fail indexing for the first time.

for stylistic consistency.

🧰 Tools
🪛 LanguageTool

[duplication] ~10-~10: Possible typo: you repeated a word.
Context: ...pec/v2.0.0.html). ## [Unreleased] ### Fixed - Fixed issue with repos appearing in the carou...

(ENGLISH_WORD_REPEAT_RULE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cab9aaa and de1d849.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • packages/backend/src/connectionManager.ts (0 hunks)
  • packages/backend/src/repoManager.ts (0 hunks)
  • packages/db/prisma/schema.prisma (2 hunks)
💤 Files with no reviewable changes (2)
  • packages/backend/src/repoManager.ts
  • packages/backend/src/connectionManager.ts
🧰 Additional context used
🪛 LanguageTool
CHANGELOG.md

[duplication] ~10-~10: Possible typo: you repeated a word.
Context: ...pec/v2.0.0.html). ## [Unreleased] ### Fixed - Fixed issue with repos appearing in the carou...

(ENGLISH_WORD_REPEAT_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (2)
packages/db/prisma/schema.prisma (2)

44-45: Clarify indexedAt semantics with Prisma doc-comment
The added /// When the repo was last indexed successfully. comment correctly documents that indexedAt should only reflect successful indexing events. This aligns with the updated backend logic.


90-91: Clarify syncedAt semantics with Prisma doc-comment
The added /// When the connection was last synced successfully. comment accurately describes that syncedAt now only updates on successful syncs, matching the change in connectionManager.

@brendan-kellam brendan-kellam force-pushed the bkellam/fix_indexedAt branch from de1d849 to eab7b23 Compare May 12, 2025 19:09
@brendan-kellam brendan-kellam merged commit e4e36bd into main May 12, 2025
3 of 4 checks passed
@brendan-kellam brendan-kellam deleted the bkellam/fix_indexedAt branch May 12, 2025 19:10
@msukkari
Copy link
Contributor

/review

Comment on lines +10 to +12
### Fixed
- Fixed issue with repos appearing in the carousel when they fail indexing for the first time. [#305](https://github.com/sourcebot-dev/sourcebot/pull/305)

Choose a reason for hiding this comment

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

The new entry added under the 'Unreleased' section duplicates the same fix already present under the '3.2.0' release. To avoid redundancy, please remove this duplicate changelog entry from 'Unreleased'.

Comment on lines +10 to +12
### Fixed
- Fixed issue with repos appearing in the carousel when they fail indexing for the first time. [#305](https://github.com/sourcebot-dev/sourcebot/pull/305)

Choose a reason for hiding this comment

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

The new changelog entry for the 'Fixed' section should be added under '## [Unreleased]' not above '## [3.1.4] - 2025-05-10'. Please insert the fix description after line 9 and before the '3.1.4' release heading to maintain changelog format consistency.

Comment on lines 336 to 337
syncStatus: ConnectionSyncStatus.FAILED,
syncedAt: new Date(),
syncStatusMetadata: syncStatusMetadata as Prisma.InputJsonValue,

Choose a reason for hiding this comment

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

The previous code was updating the "syncedAt" field when the syncStatus was set to FAILED, but the new code removes this. However, in the onSyncJobFailed method (lines 353-380), after a failure, "syncedAt" is not explicitly updated. Given the PR context where "syncedAt" should reflect the last successful sync, it is correct to remove the update on failure. Just ensure that elsewhere the "syncedAt" field is only updated on success (as onSyncJobCompleted does). No change is required here, just confirm consistency.

@@ -334,7 +334,6 @@ export class ConnectionManager implements IConnectionManager {
},
data: {
syncStatus: ConnectionSyncStatus.FAILED,
syncedAt: new Date(),
syncStatusMetadata: syncStatusMetadata as Prisma.InputJsonValue,

Choose a reason for hiding this comment

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

The removal of setting 'syncedAt: new Date()' on sync failure means the syncedAt field will now only reflect the time of last successful sync, which is intended. However, verify if there are any downstream consumers or UI components relying on syncedAt being updated even on failure, as this change could lead to stale syncedAt values if sync repeatedly fails.

Comment on lines 394 to 395
repoIndexingStatus: RepoIndexingStatus.FAILED,
indexedAt: new Date(),
}

Choose a reason for hiding this comment

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

Removing the update to the 'indexedAt' field on indexing failure changes the timestamp semantics. Ensure that all code depending on 'indexedAt' properly reflects this new meaning (last successful index time) and handle cases where 'indexedAt' may be null. Also verify that this change does not cause unintended consequences where the timestamp is expected to be updated regardless of failure or success.

Comment on lines 393 to 395
data: {
repoIndexingStatus: RepoIndexingStatus.FAILED,
indexedAt: new Date(),
}

Choose a reason for hiding this comment

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

The removal of setting indexedAt on failure can affect downstream logic that relies on this timestamp. Ensure that all consumers of indexedAt can handle it being null or unset in failure cases to avoid unexpected errors or behavior.

@@ -41,6 +41,7 @@ model Repo {
displayName String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
/// When the repo was last indexed successfully.

Choose a reason for hiding this comment

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

The added comment 'When the repo was last indexed successfully.' could be improved for clarity by specifying this corresponds to the last successful indexing time, differentiating it explicitly from previous semantics that could include failed indexing attempts.

@@ -41,6 +41,7 @@ model Repo {
displayName String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
/// When the repo was last indexed successfully.

Choose a reason for hiding this comment

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

The added comment '/// When the repo was last indexed successfully.' for 'indexedAt' is good for clarity. Please ensure the comment for 'syncedAt' in the Connection model is updated similarly to reflect it tracks last successful syncing only, to maintain consistency.

@@ -86,6 +87,7 @@ model Connection {
isDeclarative Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
/// When the connection was last synced successfully.

Choose a reason for hiding this comment

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

Add a newline between the comment and the field 'syncedAt' to improve readability and maintain consistent formatting with other fields that have comments.

@@ -86,6 +87,7 @@ model Connection {
isDeclarative Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
/// When the connection was last synced successfully.

Choose a reason for hiding this comment

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

The added comment "/// When the connection was last synced successfully." duplicates the style of other field comments but to maintain clarity and completeness, please ensure that the comments for similar date tracking fields (e.g., indexedAt on Repo) follow a consistent style and format, including specifying that this timestamp reflects the last successful sync rather than any attempt. Consider updating related documentation to reflect this behavior change.

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.

2 participants