From 27da1b84aee2e138f527a8614e41a10ded916466 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 31 Aug 2026 09:26:25 +0000 Subject: [PATCH] fix(critic): add CriticFeature TypedDict for improved type safety Add TypedDict definition for critic feature structure used in refinement logic. This provides better IDE support and catches potential type mismatches at type-check time. Changes: - Add CriticFeature TypedDict with name, display_name, and probability fields - Update function signatures to use CriticFeature instead of dict[str, Any] - Export CriticFeature from the critic module __init__.py Addresses item from code quality report. Closes #816 Co-authored-by: openhands --- openhands_cli/tui/utils/critic/__init__.py | 2 ++ openhands_cli/tui/utils/critic/refinement.py | 22 +++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/openhands_cli/tui/utils/critic/__init__.py b/openhands_cli/tui/utils/critic/__init__.py index 42a60dd7c..93ef6bdc0 100644 --- a/openhands_cli/tui/utils/critic/__init__.py +++ b/openhands_cli/tui/utils/critic/__init__.py @@ -2,6 +2,7 @@ from openhands_cli.tui.utils.critic.feedback import send_critic_inference_event from openhands_cli.tui.utils.critic.refinement import ( + CriticFeature, build_refinement_message, get_high_probability_issues, should_trigger_refinement, @@ -10,6 +11,7 @@ __all__ = [ + "CriticFeature", "build_refinement_message", "create_critic_collapsible", "get_high_probability_issues", diff --git a/openhands_cli/tui/utils/critic/refinement.py b/openhands_cli/tui/utils/critic/refinement.py index 5f814ef0f..4042a23fb 100644 --- a/openhands_cli/tui/utils/critic/refinement.py +++ b/openhands_cli/tui/utils/critic/refinement.py @@ -12,14 +12,22 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, TypedDict if TYPE_CHECKING: from openhands.sdk.critic.result import CriticResult -def _format_feature_for_prompt(feature: dict[str, Any]) -> str: +class CriticFeature(TypedDict, total=False): + """TypedDict for critic feature structure from metadata.""" + + name: str + display_name: str + probability: float + + +def _format_feature_for_prompt(feature: CriticFeature) -> str: """Format a single feature for display in the refinement prompt. Args: @@ -36,7 +44,7 @@ def _format_feature_for_prompt(feature: dict[str, Any]) -> str: def get_high_probability_issues( critic_result: CriticResult, issue_threshold: float, -) -> list[dict[str, Any]]: +) -> list[CriticFeature]: """Extract issues with probability above the threshold. Looks for agent behavioral issues and other detected issues from the @@ -47,7 +55,7 @@ def get_high_probability_issues( issue_threshold: Minimum probability to consider an issue significant Returns: - List of issue dicts with 'name', 'display_name', and 'probability' + List of CriticFeature dicts with 'name', 'display_name', and 'probability' """ if not critic_result.metadata: return [] @@ -56,7 +64,7 @@ def get_high_probability_issues( if not categorized: return [] - high_prob_issues: list[dict[str, Any]] = [] + high_prob_issues: list[CriticFeature] = [] # Check agent behavioral issues (e.g., insufficient_testing, loop_behavior) for issue in categorized.get("agent_behavioral_issues", []): @@ -75,7 +83,7 @@ def build_refinement_message( max_iterations: int = 3, *, issue_threshold: float = 0.75, - triggered_issues: list[dict[str, Any]] | None = None, + triggered_issues: list[CriticFeature] | None = None, ) -> str: """Build a follow-up message to send to the agent when refinement is needed. @@ -132,7 +140,7 @@ def should_trigger_refinement( threshold: float, *, issue_threshold: float = 0.75, -) -> tuple[bool, list[dict[str, Any]]]: +) -> tuple[bool, list[CriticFeature]]: """Check if iterative refinement should be triggered. Refinement is triggered when: