From 21fcb14c8d481d5644804d7a359bc3b85894f6fb Mon Sep 17 00:00:00 2001 From: digital-garbage <133010426+digital-garbage@users.noreply.github.com> Date: Sat, 16 May 2026 16:47:44 +0300 Subject: [PATCH] Fix diagnostic generation in Full mode: simpler prompt + rule-based fallback Two issues prevented diagnostics from reliably appearing in Full mode: 1. The analysis prompt asked for "root cause of recurring patterns" which is too vague for early sessions with no history. Now adapts: simple per-run analysis when no session history exists, pattern analysis when history is available. 2. When the LLM fails or produces empty output after thinking-token stripping, analysis was silently "" and nothing was stored. Added a rule-based fallback that builds a diagnostic from axis_feedback (regressed/missing/wrong axes) so the history always accumulates even when the LLM produces nothing useful. Co-Authored-By: Claude Sonnet 4.6 --- conditioning.py | 52 ++++++++++++++++++++--------- tests/test_v2_category_alignment.py | 2 +- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/conditioning.py b/conditioning.py index 3aa23f38..3f49fe77 100644 --- a/conditioning.py +++ b/conditioning.py @@ -9252,25 +9252,34 @@ class FunPackVideoRefinerV2(FunPackVideoRefiner): regressed = axis_feedback.get("regressed_axes", []) wrong = axis_feedback.get("wrong_axes", []) - analysis_system = ( - "You are diagnosing a video generation prompt session. " - "Your job is to identify the root cause of recurring issues across runs, not just describe the current problem.\n\n" - "Output exactly one line:\n" - "DIAGNOSTIC: " - ) + has_history = bool(str(feedback_history or "").strip()) + if has_history: + analysis_system = ( + "You are diagnosing a video generation prompt session. " + "Look at the session history and identify the root cause of why the same issues keep returning.\n\n" + "Output exactly one line:\n" + "DIAGNOSTIC: " + ) + else: + analysis_system = ( + "You are analyzing a video generation prompt. " + "Identify what is specifically wrong or missing that caused this rating.\n\n" + "Output exactly one line:\n" + "DIAGNOSTIC: " + ) user_lines = [] - user_lines.append(f"Current rating: {rating_label or 'unrated'}") + user_lines.append(f"Rating: {rating_label or 'unrated'}") if missing: - user_lines.append(f"Still missing: {', '.join(missing)}") + user_lines.append(f"Missing: {', '.join(missing)}") if regressed: - user_lines.append(f"Regressed (was fixed, broke again): {', '.join(regressed)}") + user_lines.append(f"Regressed: {', '.join(regressed)}") if resolved: - user_lines.append(f"Recently resolved: {', '.join(resolved)}") + user_lines.append(f"Resolved: {', '.join(resolved)}") if wrong: - user_lines.append(f"Wrong (present but incorrect): {', '.join(wrong)}") + user_lines.append(f"Wrong: {', '.join(wrong)}") user_lines.append(f"Intent: {self._v2_prompt_key(intent_prompt) or 'same as prompt'}") - user_lines.append(f"Current prompt: {self._v2_prompt_key(prompt)}") + user_lines.append(f"Prompt: {self._v2_prompt_key(prompt)}") if previous_prompt and previous_prompt != self._v2_prompt_key(prompt): user_lines.append(f"Previous prompt: {previous_prompt}") candidates = [ @@ -9278,10 +9287,10 @@ class FunPackVideoRefinerV2(FunPackVideoRefiner): if isinstance(c, dict) and str(c.get("text", "")).strip() ] if candidates: - user_lines.append(f"Memory suggests adding: {', '.join(candidates)}") - if feedback_history: + user_lines.append(f"Memory suggests: {', '.join(candidates)}") + if has_history: user_lines.append(f"Session history:\n{feedback_history}") - user_lines.append("\nWhat is the root cause? One sentence.") + user_lines.append("\nOne sentence.") return analysis_system, "\n".join(user_lines) def _v2_advisor_prompt( @@ -9511,6 +9520,17 @@ class FunPackVideoRefinerV2(FunPackVideoRefiner): analysis, _ = self._v2_parse_advisor_response(analysis_raw, prompt_labels=("ANALYSIS",)) if not analysis and analysis_raw: analysis = re.sub(r"\s+", " ", analysis_raw).strip()[:400] + if not analysis: + # LLM failed or produced empty output - build a rule-based fallback so + # the diagnostic history always grows and future runs have context. + parts = [] + if axis_feedback.get("regressed_axes"): + parts.append(f"{', '.join(axis_feedback['regressed_axes'])} regressing after repair") + if axis_feedback.get("missing_axes"): + parts.append(f"missing {', '.join(axis_feedback['missing_axes'])}") + if axis_feedback.get("wrong_axes"): + parts.append(f"wrong {', '.join(axis_feedback['wrong_axes'])}") + analysis = f"Session note: {'; '.join(parts)}." if parts else f"Rating: {rating_profile.get('label', 'unrated')}." if mode == "Only diagnostics": return current_prompt, f"Advisor: diagnostics only. {analysis or 'No analysis returned.'}", analysis, False, "" diff --git a/tests/test_v2_category_alignment.py b/tests/test_v2_category_alignment.py index be87f37a..33793adf 100644 --- a/tests/test_v2_category_alignment.py +++ b/tests/test_v2_category_alignment.py @@ -1489,7 +1489,7 @@ def test_refiner_v2_advisor_uses_explicit_system_prompt_previous_prompt_thinking assert applied is False assert "diagnostics only" in status assert diagnostic == "add clearer smoke motion." - assert "Current prompt: person smoking" in advisor_prompt + assert "Prompt: person smoking" in advisor_prompt assert "Previous prompt: old encoded prompt" in advisor_prompt assert kwargs["image"] is image assert kwargs["thinking"] is True