monad-developers / monad-developers/ultrafuzz

Decompose Smithers OpenRouter recovery into an explicit state machine

Open
#999 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
85
Forks
18
Avg merge
11h 10m
Merged PRs (30d)
194

Description

Context

The metric ratchet added by #997 identifies withOpenRouterRecovery in packages/runtime/src/templates/smithers/agents/openrouter.tsx as the largest cognitive-complexity hotspot in the repository:

  • cognitive complexity: 148 (template target: 20)
  • cyclomatic complexity: 82 (template target: 20)

This is generated runner code at a sensitive provider/retry boundary, so refactoring must preserve quota detection, retry deadlines, session continuation, error classification, and usage accounting.

Proposed work

  • Model recovery phases and terminal outcomes explicitly rather than through nested conditional control flow.
  • Extract pure transition/classification functions with table-driven tests.
  • Keep provider command execution and filesystem effects at a narrow adapter boundary.
  • Preserve generated-template compatibility under both Node and Bun.

Acceptance criteria

  • The recovery transition core has exhaustive state/outcome handling.
  • withOpenRouterRecovery falls below cyclomatic and cognitive complexity 40 as an intermediate ceiling.
  • Existing OpenRouter recovery, timeout, quota, resume, and usage tests remain green.
  • The metric baseline is lowered in the same PR.

Follow-up to #997.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/runtime/src/templates/smithers/agents/openrouter.tsx and inspect the existing OpenRouter recovery, timeout, quota, resume, and usage tests. Done means the recovery core has exhaustive state and outcome handling, the function is below the stated complexity ceiling, the tests stay green under Node and Bun, and the metric baseline is lowered.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.