longPoll: cut cognitive complexity via retry/recover helpers - #1359
Merged
Conversation
Split the getUpdates error-handling out of the longPoll generator into two helpers - planRetry (throw-vs-retry decision, conflict counter, wait) and recover (abort-before/during-wait plus the delay) - and move the resolved options into a RetryConfig object. Behavior is unchanged; this drops the generator's cognitive complexity from 33 to under 15. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The refactor preserves the existing retry/abort/conflict-handling logic while reducing complexity, and the changes are localized to longPoll with no apparent behavioral regressions.
Pull request overview
Refactors the core longPoll async generator to reduce Biome cognitive complexity by extracting retry/abort decision-making into dedicated helpers, while preserving long-polling behavior (offset handling, retry policy, and abort semantics).
Changes:
- Introduced
planRetryto centralize throw-vs-retry decisions, conflict streak accounting, and wait time calculation. - Introduced
recoverto unify abort-aware waiting and to return a simple"stop"/updated-conflicts outcome to the polling loop. - Consolidated resolved retry-related options into a single
RetryConfigobject.
File summaries
| File | Description |
|---|---|
| src/core/longpoll.ts | Extracts retry/recover helpers and groups retry options to simplify the polling loop without changing behavior. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Refactors the
longPollasync generator insrc/core/longpoll.tsto reduce its cognitive complexity (BiomenoExcessiveCognitiveComplexity, max 15) from 33 to under 15, with no behavior change.How
planRetry— the throw-vs-retry decision, the consecutive-conflict counter, and the wait computation.recover— abort-before/during-wait handling plus thedelay, returning"stop"or the new conflict count.RetryConfigobject instead of six locals.The generator's
catchblock is now a few lines; all retry limits, delays, cancellation, and offset handling are preserved.Testing
npm run typecheckcleannpm run lint:corecleanbun test test/unit)🤖 Generated with Claude Code