fix: increase branch_detail max_tokens to 8192 and add response logging

Truncated output at 4096 tokens produces invalid JSON mid-generation.
Also logs stop_reason and output_tokens per attempt to diagnose failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-02-21 04:01:58 -05:00
parent 950f6750e0
commit 2e65e65afd

View File

@@ -202,14 +202,23 @@ async def generate_branch_detail(
for attempt in range(2):
response = await client.messages.create(
model=settings.AI_MODEL,
max_tokens=4096,
max_tokens=8192,
system=BRANCH_DETAIL_SYSTEM_PROMPT,
messages=messages,
)
raw_text = _strip_markdown_fences(response.content[0].text)
total_input += response.usage.input_tokens
total_output += response.usage.output_tokens
logger.debug(
"branch_detail attempt=%d stop_reason=%s content_blocks=%d output_tokens=%d",
attempt,
response.stop_reason,
len(response.content),
response.usage.output_tokens,
)
raw_text = _strip_markdown_fences(response.content[0].text) if response.content else ""
if not raw_text:
logger.warning("branch_detail attempt=%d returned empty text, stop_reason=%s", attempt, response.stop_reason)
try:
branch_tree = json.loads(raw_text)