monad-developers / monad-developers/ultrafuzz
Decompose Smithers OpenRouter recovery into an explicit state machine
Nobody has claimed this yet.
- 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.
-
withOpenRouterRecoveryfalls 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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