Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions workers/shared/workflow/destination_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ def _check_and_handle_hitl(
file_hash=file_ctx.file_hash,
workflow=file_ctx.workflow,
api_client=exec_ctx.api_client,
tool_execution_result=result.tool_execution_result,
error=file_ctx.execution_error,
)

Expand Down Expand Up @@ -1423,9 +1424,6 @@ def _should_handle_hitl(
f"{file_name}: Skipping HITL validation as we're not using file_history"
)
return False
if not file_hash.is_manualreview_required:
logger.info(f"{file_name}: File is not marked for manual review")
return False

# Use class-level manual review service
manual_review_service = self._ensure_manual_review_service(api_client)
Expand All @@ -1434,8 +1432,40 @@ def _should_handle_hitl(
return False

workflow_util = manual_review_service.get_workflow_util()

# Don't skip rule evaluation just because file wasn't pre-selected by percentage
# validate_db_rule will check both percentage selection AND rules with OR/AND logic
if not file_hash.is_manualreview_required:
logger.info(
f"{file_name}: File not pre-selected by percentage, "
f"but checking if rules match..."
)

# Wrap tool_execution_result in the expected structure for rule evaluation
# validate_db_rule expects: {"output": {...}, "metadata": {...}}
wrapped_result = None
if tool_execution_result:
if isinstance(tool_execution_result, dict):
# Check if tool_execution_result already has the correct structure
if "output" in tool_execution_result:
# Already in correct format, use as-is
wrapped_result = tool_execution_result
logger.debug(
f"{file_name}: tool_execution_result already has 'output' key, using as-is"
)
else:
# Wrap it in the expected structure
wrapped_result = {"output": tool_execution_result, "metadata": {}}
logger.debug(
f"{file_name}: Wrapped tool_execution_result in output/metadata structure"
)
else:
logger.warning(
f"{file_name}: tool_execution_result is not a dict: {type(tool_execution_result)}"
)

is_to_hitl = workflow_util.validate_db_rule(
tool_execution_result,
wrapped_result,
workflow,
file_hash.file_destination,
file_hash.is_manualreview_required,
Expand Down