Skip to content

longPoll: cut cognitive complexity via retry/recover helpers - #1359

Merged
yagop merged 3 commits into
masterfrom
refactor/longpoll-complexity
Sep 6, 2026
Merged

longPoll: cut cognitive complexity via retry/recover helpers#1359
yagop merged 3 commits into
masterfrom
refactor/longpoll-complexity

Conversation

@yagop

@yagop yagop commented Sep 6, 2026

Copy link
Copy Markdown
Owner

What

Refactors the longPoll async generator in src/core/longpoll.ts to reduce its cognitive complexity (Biome noExcessiveCognitiveComplexity, 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 the delay, returning "stop" or the new conflict count.
  • Resolved options moved into a RetryConfig object instead of six locals.

The generator's catch block is now a few lines; all retry limits, delays, cancellation, and offset handling are preserved.

Testing

  • npm run typecheck clean
  • npm run lint:core clean
  • All 235 unit tests pass (bun test test/unit)

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 planRetry to centralize throw-vs-retry decisions, conflict streak accounting, and wait time calculation.
  • Introduced recover to 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 RetryConfig object.
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.

yagop and others added 2 commits September 6, 2026 18:52
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yagop
yagop merged commit e3f5fac into master Sep 6, 2026
8 checks passed
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