Skip to content

refactor(assistant): use retry library for backoff loops#144

Merged
omarluq merged 1 commit into
mainfrom
chore/retry
Jun 20, 2026
Merged

refactor(assistant): use retry library for backoff loops#144
omarluq merged 1 commit into
mainfrom
chore/retry

Conversation

@omarluq

@omarluq omarluq commented Jun 20, 2026

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fe723d85-950c-44a4-b8b8-929254324a45

📥 Commits

Reviewing files that changed from the base of the PR and between 40e9f99 and 33b75c0.

📒 Files selected for processing (5)
  • go.mod
  • internal/assistant/retry.go
  • internal/assistant/retry_internal_test.go
  • internal/assistant/runtime_model.go
  • internal/assistant/runtime_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Refactored internal retry mechanism to use exponential backoff with configurable maximum delays, improving reliability during recovery from transient failures and provider errors.
    • Enhanced error handling to better classify and manage retriable errors.
    • Updated test coverage for retry behavior and backoff calculations.

Walkthrough

The PR migrates the assistant retry mechanism from a manual exponential backoff loop to the github.com/sethvargo/go-retry library. It adds retryFailedError and retryableProviderError error types, replaces retryDelay/waitForRetry with retryBackoff, and decomposes completeWithRetry into retryAttempt, completeAttempt, retryError, and retryResultError helpers. go-retry is promoted from indirect to direct dependency.

Changes

Assistant Retry Library Migration

Layer / File(s) Summary
Retry primitives: error types and backoff builder
go.mod, internal/assistant/retry.go, internal/assistant/retry_internal_test.go
Promotes go-retry to a direct dependency. Adds retryFailedError and retryableProviderError wrappers. Replaces retryDelay/waitForRetry with retryBackoff (capped exponential via retrylib) and maxRetryDelays. Updates unit tests from TestRetryDelayIsCapped/TestWaitForRetryRespectsCancellation to TestRetryBackoffUsesCappedExponentialDelays.
Runtime retry orchestration and helper decomposition
internal/assistant/runtime_model.go, internal/assistant/runtime_test.go
Rewrites completeWithRetry to drive retries via retrylib.Do with the backoff callback. Adds retryAttempt (per-attempt execution + retryability gating), completeAttempt (single provider RPC + event emission), retryError (unwraps retry failures), and retryResultError (maps cancellation/deadline to retry_canceled). Updates runtime test to cancel only on StreamEventToolResult.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • omarluq/librecode#42: Shares changes to internal/assistant/retry.go and the TestShouldRetryModelErrorTreatsHTTP2StreamErrorsAsTransient test, which remains present unchanged in this PR's diff.
  • omarluq/librecode#46: Both PRs modify ShouldRetryModelError and the retryable error classification logic in internal/assistant/retry.go, overlapping at the core retry decision point.
  • omarluq/librecode#87: Directly tied to this PR's refactor of completeWithRetry and context-window retryability decisions in runtime_model.go.

Poem

🐇 Hop, hop, the old loop's gone away,
retrylib now schedules each delay,
Exponential caps keep waits in line,
retryAttempt helpers work just fine.
No more manual ticks and timer dread—
The rabbit lets the library lead instead! 🎉

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate whether the description relates to the changeset. Add a pull request description explaining the motivation, implementation details, and any breaking changes or migration notes for this retry library refactoring.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: refactoring the assistant module to use a retry library for backoff loops instead of custom retry logic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/retry

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.09524% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.44%. Comparing base (40e9f99) to head (33b75c0).

Files with missing lines Patch % Lines
internal/assistant/runtime_model.go 90.16% 4 Missing and 2 partials ⚠️
internal/assistant/retry.go 82.60% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #144      +/-   ##
==========================================
+ Coverage   80.40%   80.44%   +0.04%     
==========================================
  Files         277      277              
  Lines       21898    21925      +27     
==========================================
+ Hits        17607    17638      +31     
+ Misses       3079     3075       -4     
  Partials     1212     1212              
Flag Coverage Δ
unittests 80.44% <88.09%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@omarluq omarluq merged commit 651ae84 into main Jun 20, 2026
15 checks passed
@omarluq omarluq deleted the chore/retry branch June 20, 2026 04:28
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant