From b6165e56e53e8a5e4239e00bfb001722b11841f6 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 15 Apr 2026 20:09:08 -0400 Subject: [PATCH] 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 --- .../services/generation_task.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/fabledassistant/services/generation_task.py b/src/fabledassistant/services/generation_task.py index dfe50f7..d3e90dd 100644 --- a/src/fabledassistant/services/generation_task.py +++ b/src/fabledassistant/services/generation_task.py @@ -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