Skip to content

Draft Retry Block Mixes Prompt Construction with Retry Logic #144

@CyberSecDef

Description

@CyberSecDef

Problem

novelforge/routes/generation/chapters.py lines 305-342: The content-rejection retry loop for chapter drafting contains 37 lines mixing prompt assembly with retry logic. Every other pipeline step uses the clean _safe() / _call_with_content_retry pattern — this is the only exception.

Why It Matters

Hard to maintain and test. If the retry strategy changes, this is the one place that doesn't follow the standard pattern.

Recommended Fix

Extract into a helper:

def _draft_with_content_retry(build_prompt_fn, *, action, special_instructions, max_attempts=3):
    content_note = ""
    for attempt in range(max_attempts):
        try:
            instructions = special_instructions
            if content_note:
                instructions = f"{special_instructions}\n\n{content_note}" if special_instructions else content_note
            return call_llm(build_prompt_fn(instructions), action=action)
        except ContentRejectionError:
            if attempt >= max_attempts - 1:
                raise
            content_note = "CONTENT NOTE: ..."

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions