refactor(adk): extract model timeout middleware - #1095
Merged
Conversation
Change-Id: I2f796eb73bb811e1c3224e457e5bf0eb77ec9b81
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## alpha/10 #1095 +/- ##
===========================================
Coverage ? 81.56%
===========================================
Files ? 187
Lines ? 30545
Branches ? 0
===========================================
Hits ? 24915
Misses ? 3839
Partials ? 1791 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Change-Id: I0930b9d49ae447cd099000435dcb579eeaaf5a6a
shentongmartin
added a commit
that referenced
this pull request
Jun 26, 2026
shentongmartin
added a commit
that referenced
this pull request
Jun 29, 2026
shentongmartin
added a commit
that referenced
this pull request
Jul 21, 2026
shentongmartin
added a commit
that referenced
this pull request
Jul 21, 2026
shentongmartin
added a commit
that referenced
this pull request
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Model Timeout Middleware and Session Event Cleanup
Problem
TypedChatModelAgentcarried model timeout as a first-class config, which made timeout behavior harder to compose with other model wrappers. The stream timeout wrapper also proxied the upstream stream through its own goroutine, so it consumed stream data independently of wrappers such aseventSenderModelWrapper.The ADK test layout also had several narrow extra test files that duplicated helpers and made related behavior harder to scan.
Solution
Model timeout is now a standalone
adk/middlewares/modeltimeoutpackage. Users opt in withmodeltimeout.Newormodeltimeout.NewTyped, and the timeout package ownsConfig,Error, andPhase.Stream timeout enforcement now uses
schema.StreamReaderWithConvert, so timeout checks run on the normal downstreamRecvpath instead of a separate draining goroutine. The ADK package observes timeout retry/span metadata through small error interfaces, so it does not import the middleware package back.Session event cleanup also renames the user interrupt event to
cancel, verifies tool span end emission, and folds scattered ADK tests into their canonical test files.Key Insight
Timeout middleware should be a normal model wrapper, not a special agent config. For streaming, a timeout wrapper that consumes the stream in its own goroutine changes wrapper ordering semantics; attaching timeout checks to
StreamReaderWithConvertkeeps stream ownership with the caller and allows wrappers to compose predictably.Summary
TypedChatModelAgentadk/middlewares/modeltimeoutStreamReaderWithConverton the downstream read pathModel Timeout 中间件与 Session Event 清理
Problem
TypedChatModelAgent将 model timeout 作为一等配置,导致 timeout 行为难以像普通 middleware 一样与其他 model wrapper 组合。原先的 stream timeout wrapper 还会通过独立 goroutine 代理 upstream stream,因此会独立消费 stream 数据,影响eventSenderModelWrapper这类 wrapper 的组合语义。ADK 测试文件也存在多个细分 extra test 文件,部分 helper 重复,相关行为不够集中。
Solution
Model timeout 现在迁移到独立的
adk/middlewares/modeltimeoutpackage。用户通过modeltimeout.New或modeltimeout.NewTyped显式启用,Config、Error、Phase也由该 package 持有。Stream timeout 现在基于
schema.StreamReaderWithConvert实现,timeout 检查发生在正常的 downstreamRecv路径上,不再使用额外 goroutine 主动 drain stream。adkpackage 通过小型 error interface 读取 retry/span 所需的 timeout 信息,避免反向 import middleware package。同时将 user interrupt event 名称改为
cancel,补充 tool span end emission 验证,并把分散的 ADK 测试合并到对应的 canonical test 文件中。Key Insight
Timeout middleware 应该是普通 model wrapper,而不是 agent 的特殊配置。对于 streaming,如果 timeout wrapper 自己用 goroutine 消费 stream,会改变 wrapper 的组合语义;把 timeout 检查挂到
StreamReaderWithConvert的 downstream read path 上,可以保持 stream ownership 清晰,让多个 wrapper 可预测地组合。Summary
TypedChatModelAgentadk/middlewares/modeltimeoutStreamReaderWithConvert的 downstream read pathadk若直接识别 timeout concrete error 会产生 import cycle