Python: validate functional workflow HITL response types - #8309
Python: validate functional workflow HITL response types#8309CoralGarden52 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Successful coercion and string-to-Content behavior lack functional workflow coverage.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Aligns functional HITL response handling with graph workflows.
Changes:
- Adds response coercion and runtime type validation.
- Converts string responses to
Contentwhile preservingNone. - Adds an incompatible-response regression test.
File summaries
| File | Description |
|---|---|
_functional.py |
Validates and coerces replayed responses. |
test_functional_workflow.py |
Tests type-mismatch rejection. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| if response_type is Content and isinstance(value, str): | ||
| value = Content.from_text(text=value) | ||
| value = try_coerce_to_type(value, response_type) |
There was a problem hiding this comment.
Added functional-workflow resume regression tests covering both successful branches: JSON-like dictionary responses are coerced into the declared dataclass type, and string responses are converted to Content. The existing mismatch-rejection and None compatibility tests remain covered, all relevant tests pass, and the changes are included in commit cd515ac59.
Motivation & Context
Functional workflows currently return the raw value supplied to
run(responses=...)fromRunContext.request_info, even when the request declares a differentresponse_type. On clean upstream commitc47da07e22943d238a94f0a094180c1c2b13d2a7, a workflow declaringresponse_type=intaccepted "not-an-int" and produced ['not-an-int:str'] instead of rejecting the response. The graph workflow path already validates and coerces responses, and the original functional workflow review in #4238 identified this mismatch. Issue #8308 tracks the bug.The existing functional-workflow behavior for an explicit
Noneresponse is preserved: it logs the established warning and returnsNone.Description & Review Guide
Contentforresponse_type=Content, matching the graph workflow path.Noneresponses.Content.NoneHITL responses now fail at the response boundary instead of silently entering workflow code.ValueError: Response type mismatch for request ID typed: expected <class 'int'>, got <class 'str'>.5044 passed, 131 skipped, 2 xfailed; the focused functional workflow, graph workflow, and typing utility tests passed; Ruff format/lint passed; Pyright reported0 errors, 0 warningsfor both changed files._workflow.pyfor coercion and runtime type checking.Nonebehavior is the right compatibility boundary.Contentconversion.Related Issue
Fixes #8308
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.