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: ..."
Problem
novelforge/routes/generation/chapters.pylines 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_retrypattern — 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: