Skip to content

Refactor (packages/opencode/src/session/retry.ts): Function with many returns - #88

Open
faboueln wants to merge 1 commit into
CMU-17313Q:mainfrom
faboueln:p1b-retryable-refactor
Open

faboueln wants to merge 1 commit into
CMU-17313Q:mainfrom
faboueln:p1b-retryable-refactor

Conversation

@faboueln

@faboueln faboueln commented Sep 5, 2026

Copy link
Copy Markdown

P1B: Starter Task: Refactoring PR

1. Issue: Closes #30

Link to the associated GitHub issue:

#30

Full path to the refactored file:

packages/opencode/src/session/retry.ts

What do you think this file does?
(Your answer does not have to be 100% correct; give a reasonable, evidence‑based guess.)

  • This file handles retry behavior for session-related errors. It decides which errors should be retried, how long to wait before retrying, and which errors should stop immediately.

What is the scope of your refactoring within that file?
(Name specific functions/blocks/regions touched.)

  • I refactored the retryable() function by separating parts of its error-handling logic into smaller helper functions, including handling API errors, usage-limit errors, reset-time formatting, and other retryable errors.

Which Qlty‑reported issue did you address?
(Name the rule/metric and include the BEFORE value; e.g., “Cognitive Complexity 18 in render()”.)

  • Qlty reported Function with many returns (count = 14): retryable in packages/opencode/src/session/retry.ts.

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?

  • Having 14 return statements in one function made retryable() harder to read and follow because it was handling many different error cases in one place.

What changes did you make to resolve the issue?

  • I split the logic in retryable() into smaller helper functions so each helper handles a specific type of error while keeping the same behavior.

How do your changes improve maintainability? Did you consider alternatives?

  • The refactor makes the code easier to read, understand, and modify because each helper has a clearer responsibility. I considered keeping everything inside retryable(), but separating the logic reduced the number of returns and made the flow easier to follow.

3. Validation

How did you validate that the change is correct?

  • I ran bun test test/session/retry.test.ts, and all 52 tests passed with 0 failures. I also ran coverage and Qlty again to confirm the changed code was exercised and the original many-returns warning was removed.

Attach a screenshot of the test coverage showing the lines were executed by the tests.

coverage coverage2 coverage_screenshot lint_screenshot bun-lint-passing

Attach a screenshot showing the tests that cover the change passing during CI

Screen Shot 2026-09-06 at 12 09 22 AM

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.ts> showing fewer reported issues after the changes.

qlty

Before QTLY.

beforeQLTY

Bun lint.

bun-lint-passing

Local bun test.

localBunTest

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.

P1B: Refactor (packages/opencode/src/session/retry.ts:77): Function with many returns (count = 14)

1 participant