Skip to content

Conversation

@mbburch
Copy link

@mbburch mbburch commented Jul 24, 2025

This PR adds retry logic to the Validate function.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of the validation process by adding automatic retry logic.
    • Simplified error messages in grant and revoke operations for clearer feedback.

@coderabbitai
Copy link

coderabbitai bot commented Jul 24, 2025

Walkthrough

The Validate method in the connector builder was updated to implement indefinite retry logic using a retryer with no maximum attempts and a 1-second initial delay. Additionally, the Grant and Revoke methods had their error logging removed and error message formatting simplified.

Changes

Cohort / File(s) Change Summary
Connector Builder Logic
pkg/connectorbuilder/connectorbuilder.go
Added indefinite retry logic to Validate; removed error logging and simplified error messages in Grant and Revoke methods.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • laurenleach
  • ggreer

Poem

A bunny hops through code so neat,
With retries now that can't be beat!
Errors trimmed, logs swept away,
Validation tries all day.
Grant and Revoke, now less verbose—
This change, dear friends, deserves a toast!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 aa341f0 and 5be86e0.

📒 Files selected for processing (1)
  • pkg/connectorbuilder/connectorbuilder.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/connectorbuilder/connectorbuilder.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Cursor Bugbot
  • GitHub Check: go-test (1.23.x, windows-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mbburch/bb-1181-retry-validate

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 generate unit tests to generate unit tests for 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.

if retryer.ShouldWaitAndRetry(ctx, err) {
continue
}
l.Error("error: validate failed", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this log can be removed, as the error will be logged by the caller. Also you can remove error: from the fmt.Errorf().

Copy link
Author

Choose a reason for hiding this comment

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

@ggreer Thanks! I was trying to keep it consistent with Grant and Revoke, but sounds like I can just update all three to remove the log and error:. 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. I guess try granting or revoking to see how the error message differs.

Copy link
Author

Choose a reason for hiding this comment

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

@ggreer I'm going to update this in all three functions.... agreed we don't need it after looking at logs.

@mbburch mbburch force-pushed the mbburch/bb-1181-retry-validate branch from 2336af6 to aa341f0 Compare July 30, 2025 19:12
cursor[bot]

This comment was marked as outdated.

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: 1

🔭 Outside diff range comments (1)
pkg/connectorbuilder/connectorbuilder.go (1)

976-1003: Add metrics recording for consistency.

The Validate method is missing the task timing and metrics recording that other methods in this file use. This makes monitoring and debugging more difficult.

Add metrics recording similar to other methods:

 func (b *builderImpl) Validate(ctx context.Context, request *v2.ConnectorServiceValidateRequest) (*v2.ConnectorServiceValidateResponse, error) {
 	ctx, span := tracer.Start(ctx, "builderImpl.Validate")
 	defer span.End()
 
+	start := b.nowFunc()
+	tt := tasks.ValidateType
 	l := ctxzap.Extract(ctx)
 
 	retryer := retry.NewRetryer(ctx, retry.RetryConfig{
 		MaxAttempts:  0, // 0 means no limit - retry indefinitely
 		InitialDelay: 1 * time.Second,
 		MaxDelay:     0,
 	})
 
 	for {
 		annos, err := b.cb.Validate(ctx)
 		if err == nil {
 			l.Debug("validation successful")
+			b.m.RecordTaskSuccess(ctx, tt, b.nowFunc().Sub(start))
 			return &v2.ConnectorServiceValidateResponse{Annotations: annos}, nil
 		}
 
 		if retryer.ShouldWaitAndRetry(ctx, err) {
 			l.Debug("retrying validation", zap.Error(err), zap.String("status_code", status.Code(err).String()))
 			continue
 		}
 
 		l.Error("error: validate failed", zap.Error(err), zap.String("status_code", status.Code(err).String()))
+		b.m.RecordTaskFailure(ctx, tt, b.nowFunc().Sub(start))
 		return nil, fmt.Errorf("error: validate failed: %w", err)
 	}
 }
♻️ Duplicate comments (1)
pkg/connectorbuilder/connectorbuilder.go (1)

1000-1001: Remove "error:" prefix from error message for consistency.

Based on past review feedback, the "error:" prefix should be removed from error messages as the error will be logged by the caller.

Apply this diff:

-	l.Error("error: validate failed", zap.Error(err), zap.String("status_code", status.Code(err).String()))
-	return nil, fmt.Errorf("error: validate failed: %w", err)
+	l.Error("validate failed", zap.Error(err), zap.String("status_code", status.Code(err).String()))
+	return nil, fmt.Errorf("validate failed: %w", err)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2336af6 and aa341f0.

📒 Files selected for processing (1)
  • pkg/connectorbuilder/connectorbuilder.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
pkg/connectorbuilder/connectorbuilder.go (4)

Learnt from: MarcusGoldschmidt
PR: #393
File: pkg/test/integration_wrapper.go:54-54
Timestamp: 2025-06-02T21:28:25.367Z
Learning: The connectorbuilder.NewConnector function in the baton-sdk already validates the connector parameter using a type switch and returns appropriate errors for nil or invalid connectors in the default case, so additional nil checks are not needed before calling this function.

Learnt from: MarcusGoldschmidt
PR: #393
File: pkg/test/integration_wrapper.go:54-54
Timestamp: 2025-06-02T21:28:25.367Z
Learning: The connectorbuilder.NewConnector function in the baton-sdk already validates the connector parameter and returns appropriate errors for nil or invalid connectors, so additional nil checks are not needed before calling this function.

Learnt from: ggreer
PR: #194
File: pkg/uhttp/gocache.go:125-132
Timestamp: 2024-07-30T19:21:37.891Z
Learning: Errors when clearing the cache in the GoCache struct are logged later in the process, so additional logging in the Clear method is unnecessary and would cause log spam.

Learnt from: ggreer
PR: #194
File: pkg/uhttp/gocache.go:125-132
Timestamp: 2024-10-08T21:29:30.695Z
Learning: Errors when clearing the cache in the GoCache struct are logged later in the process, so additional logging in the Clear method is unnecessary and would cause log spam.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Cursor Bugbot
  • GitHub Check: go-test (1.23.x, ubuntu-latest)
  • GitHub Check: go-test (1.23.x, windows-latest)

Comment on lines +982 to +986
retryer := retry.NewRetryer(ctx, retry.RetryConfig{
MaxAttempts: 0, // 0 means no limit - retry indefinitely
InitialDelay: 1 * time.Second,
MaxDelay: 0,
})
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reconsider infinite retry configuration.

Setting MaxAttempts: 0 creates infinite retries, which could cause the validation to hang indefinitely if there's a persistent configuration issue. This differs from the Grant and Revoke methods which use MaxAttempts: 3.

Consider using a reasonable maximum attempt limit:

 retryer := retry.NewRetryer(ctx, retry.RetryConfig{
-	MaxAttempts:  0, // 0 means no limit - retry indefinitely
+	MaxAttempts:  3,
 	InitialDelay: 1 * time.Second,
-	MaxDelay:     0,
+	MaxDelay:     60 * time.Second,
 })
📝 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
retryer := retry.NewRetryer(ctx, retry.RetryConfig{
MaxAttempts: 0, // 0 means no limit - retry indefinitely
InitialDelay: 1 * time.Second,
MaxDelay: 0,
})
retryer := retry.NewRetryer(ctx, retry.RetryConfig{
MaxAttempts: 3,
InitialDelay: 1 * time.Second,
MaxDelay: 60 * time.Second,
})
🤖 Prompt for AI Agents
In pkg/connectorbuilder/connectorbuilder.go around lines 982 to 986, the retry
configuration uses MaxAttempts: 0, causing infinite retries that may hang
validation indefinitely. Change MaxAttempts to a finite number, such as 3, to
limit retry attempts similarly to the Grant and Revoke methods, preventing
potential endless loops while still allowing retries.

@mbburch mbburch merged commit 60e0808 into main Jul 30, 2025
6 checks passed
@mbburch mbburch deleted the mbburch/bb-1181-retry-validate branch July 30, 2025 20:31
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.

4 participants