chore(generation): add CTX_DIAG logs for silent-round investigation

Log num_ctx, message count, prompt/output tokens, headroom, and a
silent flag per round so we can correlate silent generations against
context pressure on the dev instance.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-15 20:09:08 -04:00
parent 5e281c534a
commit b6165e56e5
@@ -412,8 +412,14 @@ async def run_generation(
round_content_start = len(buf.content_so_far)
round_tokens_start = timing.get("output_tokens") or 0
round_prompt_tokens_start = timing.get("prompt_tokens") or 0
approx_msg_chars = sum(len(str(m.get("content", ""))) for m in messages)
effective_think = think
retried_with_think = False
logger.info(
"CTX_DIAG round_start conv=%d round=%d num_ctx=%d msgs=%d approx_chars=%d think=%s",
conv_id, _round, num_ctx, len(messages), approx_msg_chars, effective_think,
)
while True:
async for chunk in _stream_with_retry(messages, model, tools, effective_think, num_ctx=num_ctx):
@@ -519,6 +525,18 @@ async def run_generation(
round_content_added = len(buf.content_so_far) - round_content_start
round_tokens_added = (timing.get("output_tokens") or 0) - round_tokens_start
round_prompt_tokens = (timing.get("prompt_tokens") or 0) - round_prompt_tokens_start
headroom = num_ctx - round_prompt_tokens if round_prompt_tokens else None
is_silent = (
not round_tool_calls
and round_content_added == 0
and round_tokens_added > 0
)
logger.info(
"CTX_DIAG round_end conv=%d round=%d think=%s prompt_tokens=%d output_tokens=%d headroom=%s content_added=%d tool_calls=%d silent=%s",
conv_id, _round, effective_think, round_prompt_tokens, round_tokens_added,
headroom, round_content_added, len(round_tool_calls), is_silent,
)
if (
not round_tool_calls
and round_content_added == 0