-
Notifications
You must be signed in to change notification settings - Fork 0
feat: replace static sleep with polling for datapoint verification after buzz add #188
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?
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Comment |
Co-authored-by: narthur <[email protected]>
Co-authored-by: narthur <[email protected]>
Co-authored-by: narthur <[email protected]>
🚀 Pre-release Build ReadyTest builds are ready! Install directly using the # Install the pre-release
bin install https://github.com/PinePeakDigital/buzz/releases/tag/pr-188-latest buzz-pr-188# Run the pre-release
buzz-pr-188# Uninstall the pre-release
bin remove buzz-pr-188Direct Download LinksOr download binaries directly from the pre-release page:
|
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.
Pull request overview
This PR replaces a fixed 2-second sleep with intelligent polling when verifying datapoint creation in the buzz add command. The change ensures the Beeminder server has processed the new datapoint before displaying the updated goal status, making the command both more reliable and typically faster.
Key changes:
- Modified
CreateDatapointto return the created datapoint with its ID - Added
WaitForDatapointfunction that polls for the datapoint appearance (10s timeout, 500ms intervals) - Improved URL encoding using
url.PathEscapeandurl.Valuesfor safer API requests
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| beeminder.go | Added WaitForDatapoint polling function, modified CreateDatapoint to return created datapoint, improved URL escaping for goal slugs |
| main.go | Replaced fixed limsumFetchDelay with polling logic in handleAddCommand, improved error messaging for polling timeout |
| messages.go | Updated submitDatapointCmd to handle new CreateDatapoint return signature |
| beeminder_test.go | Added comprehensive tests for WaitForDatapoint (immediate success, timeout, error retry) and CreateDatapoint return value |
| handlers_test.go | Removed obsolete TestLimsumFetchDelay tests for the deleted static delay variable |
beeminder.go
Outdated
| func WaitForDatapoint(config *Config, goalSlug, datapointID string, timeout, pollInterval time.Duration) (bool, error) { | ||
| deadline := time.Now().Add(timeout) | ||
|
|
||
| for time.Now().Before(deadline) { |
Copilot
AI
Dec 8, 2025
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.
The polling loop has an edge case: if the deadline is already passed when entering the loop, it will never execute. Consider checking at least once before checking the deadline, or documenting that zero or negative timeout values will result in no polling attempts.
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.
Fixed in commit 680011f. Changed the loop structure to use an infinite for loop that always executes at least once, with timeout checking after each iteration. This ensures at least one polling attempt even with zero or negative timeout values.
| _, err := CreateDatapoint(config, goalSlug, timestamp, value, comment) | ||
| return datapointSubmittedMsg{err: err} |
Copilot
AI
Dec 8, 2025
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.
The TUI's submitDatapointCmd discards the returned datapoint but doesn't implement polling like handleAddCommand does. This means the TUI may still show stale data after submitting a datapoint. Consider implementing similar polling in the TUI workflow to ensure data consistency, or document why it's not needed for the TUI use case.
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.
Added clarifying comments in commit 680011f. The TUI doesn't need polling because it triggers a full goal refresh after datapoint submission (see datapointSubmittedMsg handling in main.go), which fetches updated data including the new datapoint and limsum. This approach is more appropriate for the TUI context.
| if err != nil { | ||
| // Don't fail immediately on fetch errors, keep trying | ||
| time.Sleep(pollInterval) | ||
| continue | ||
| } |
Copilot
AI
Dec 8, 2025
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.
The error handling here continues polling on any fetch error, including permanent errors like authentication failures or non-existent goals. Consider distinguishing between retryable errors (like temporary network issues) and permanent errors (like 404 Not Found or 401 Unauthorized) to fail fast when appropriate.
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.
Fixed in commit 680011f. Added isPermanentError() helper function that detects HTTP 401, 403, and 404 status codes in error messages. WaitForDatapoint now returns these errors immediately instead of continuing to poll, failing fast on authentication failures, permission issues, and non-existent goals.
|
|
||
| // WaitForDatapoint polls the goal's recent datapoints until the specified datapoint ID appears | ||
| // or the timeout is reached. Returns true if the datapoint was found, false if timeout occurred. | ||
| func WaitForDatapoint(config *Config, goalSlug, datapointID string, timeout, pollInterval time.Duration) (bool, error) { |
Copilot
AI
Dec 8, 2025
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.
The documentation comment should clarify that this function never returns an error (always returns nil for the error value). The current signature (bool, error) suggests errors are possible, but the implementation always returns nil for the error. Consider either:
- Updating the doc comment to explicitly state "The error return value is always nil and reserved for future use", or
- Simplifying the signature to return only
boolif errors won't be needed
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.
Fixed in commit 680011f. Updated documentation to clarify that the error return value is used to indicate permanent failures (e.g., authentication errors, non-existent goals) where continuing to poll would be futile. The function now returns errors for 401, 403, and 404 status codes.
|
@copilot apply changes based on the comments in this thread |
…r timeout behavior Co-authored-by: narthur <[email protected]>
Polling Implementation - Final Improvements
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.