Workflow RequestInput: an answer that leaves out optional fields gets None instead of the schema defaults, and resume crashes
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Lỗi nằm ở _validate_resume_response trong src/google/adk/workflow/utils/_rehydration_utils.py, hàm này dựng lại mô hình response_schema và gán giá trị mặc định None cho các trường không bắt buộc. Hãy bắt đầu bằng cách chạy bước tái hiện trong issue để thấy ba ValidationError, sau đó đọc cách hàm này xây dựng mô hình từ JSON schema. Hoàn thành khi phản hồi một phần được giải quyết về các giá trị mặc định đã khai báo và bài kiểm thử hồi quy trong tests/unittests/workflow/utils/test_rehydration_utils.py chạy thành công cùng với các bài kiểm thử rehydration và HITL hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When a Workflow node pauses with RequestInput(response_schema=SomeModel) and the answer leaves out optional fields, the resumed answer has None for those fields instead of the defaults the model declares. A field such as priority: int = 3 or tags: list[str] = [] arrives as None, so the next node, typed with the same model, fails validation. A valid partial answer crashes the workflow on resume, and a nullable field with a non-None default silently loses its default.
This is the human-in-the-loop pattern from the request_input_advanced sample. Workflow is exported at the top level, and nothing marks this path as experimental.
Reproduction
Run on current main (4e3aff79):
import asyncio
from google.adk import Workflow
from google.adk.events import RequestInput
from google.adk.runners import Runner
from google.adk.sessions.in_memory_session_service import InMemorySessionService
from google.genai import types
from pydantic import BaseModel
class Decision(BaseModel):
approved: bool
priority: int = 3
tags: list[str] = []
reviewer: str = "manager"
def ask(node_input: str):
return RequestInput(interrupt_id="q", message="decide", response_schema=Decision)
def after(node_input: Decision):
return f"approved={node_input.approved} priority={node_input.priority} tags={node_input.tags} reviewer={node_input.reviewer}"
async def main():
ss = InMemorySessionService()
wf = Workflow(name="wf", edges=[("START", ask, after)])
async def turn(msg):
r = Runner(app_name="app", node=wf, session_service=ss, auto_create_session=True)
return [e async for e in r.run_async(user_id="u", session_id="s1", new_message=msg)]
await turn(types.Content(role="user", parts=[types.Part(text="hi")]))
answer = types.FunctionResponse(id="q", name="adk_request_input", response={"approved": True})
for e in await turn(types.Content(role="user", parts=[types.Part(function_response=answer)])):
print(e.author, "output=", e.output)
asyncio.run(main())
Actual
pydantic_core._pydantic_core.ValidationError: 3 validation errors for dynamic node 'after'
priority
Input should be a valid integer [type=int_type, input_value=None, input_type=NoneType]
tags
Input should be a valid list [type=list_type, input_value=None, input_type=NoneType]
reviewer
Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
Expected
after output= approved=True priority=3 tags=[] reviewer=manager
Cause
_validate_resume_response in src/google/adk/workflow/utils/_rehydration_utils.py rebuilds an object response_schema with pydantic.create_model. Every field that is not required gets the default None, and the default in the JSON schema is ignored.
Proposed fix
For fields that are not required, use prop_schema.get("default") as the default. Required fields behave as now: a missing one still raises, and a given one is still coerced.
I checked mutable defaults ([], {}): they are not shared between answers, because each call builds a new model and model_dump() returns copies. One case stays open: Field(default_factory=list) puts no default into the JSON schema, so such a field still comes back as None. That would need a different approach and is not part of this change.
There is a regression test in tests/unittests/workflow/utils/test_rehydration_utils.py. It fails on main and passes with the fix; the rehydration and HITL workflow tests pass.
I used an AI coding assistant (Claude) to find and analyse this; I reproduced it and checked the fix myself.
I've tested a fix with a regression test: https://github.com/chaitanya0305/adk-python/compare/main...chaitanya0305:adk-python:fix/resume-response-schema-defaults. If this is accepted, I'll open the PR straight away.
- Ngôn ngữ chính
- Python
- Star
- 22.3k
- Fork
- 4.4k
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/adk-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/adk-python#8360 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Can pin to litellm version be changed?Có thể đã có người làm @llalitkumarrr đã nhận 9 ngày trước. Đang mởmodels
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
google/adk-python#8129 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
OpenAPI tools ignore operation- and path-level server overridesCó thể đã có người làm @sanketpatil06 đã nhận 13 ngày trước. Đang mởtools
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
google/adk-python#8064 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Two docstrings in openapi_tool document parameters the signatures do not acceptCó thể đã có người làm @surajksharma07 đã nhận 16 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
google/adk-python#8024 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
`adk run` does not support arrow keys or input historyCó thể đã có người làm @llalitkumarrr đã nhận 16 ngày trước. Đang mởcli
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
google/adk-python#8022 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của google/adk-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
vllm-project/vllm#70030 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TigreGotico/tugaphone#408 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
t: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
needs-triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Azure/azure-sdk-for-python#50155 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày