fix(adk): add nil checks for execContext in ChatModelAgent Run and Resume#758
Merged
shentongmartin merged 1 commit intoalpha/08from Feb 4, 2026
Merged
fix(adk): add nil checks for execContext in ChatModelAgent Run and Resume#758shentongmartin merged 1 commit intoalpha/08from
shentongmartin merged 1 commit intoalpha/08from
Conversation
…sume - Add early return in getRunFunc when execContext is nil - Guard execContext field access with nil checks in Run method - Guard execContext field access with nil checks in Resume method - Add tests for prepareExecContext error handling edge case This prevents potential nil pointer dereferences when prepareExecContext fails (e.g., when a tool's Info method returns an error).~ Change-Id: I36ef545ff44db57343ceb14c8883380a7c38a243
meguminnnnnnnnn
approved these changes
Feb 4, 2026
hi-pender
pushed a commit
that referenced
this pull request
Feb 14, 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.
Summary
prepareExecContextfailsexecContextingetRunFunc,Run, andResumemethodsKey Insight
When
prepareExecContext()fails (e.g., when a tool'sInfo()method returns an error),a.exeCtxremainsnilwhilea.runis set toerrFunc(err). The original code assumedbc(execContext) would always be non-nil aftergetRunFunc()returned, leading to potential nil pointer dereferences when accessingbc.toolInfos,bc.instruction, etc.The fix adds defensive nil checks at three locations:
getRunFunc(): Early return whenbcis nilRun(): Guardbcfield access with nil checkResume(): Guardbcfield access with nil checkThis ensures the error is properly propagated through the event iterator instead of causing a panic.
Testing
Added
TestChatModelAgent_PrepareExecContextErrorwith two sub-tests:Run_WithToolInfoError_ReturnsError: VerifiesRun()properly returns errorResume_WithToolInfoError_ReturnsError: VerifiesResume()properly returns error摘要
prepareExecContext失败时可能出现空指针解引用getRunFunc、Run和Resume方法中添加 nil 检查关键洞察
当
prepareExecContext()失败时(例如,当工具的Info()方法返回错误时),a.exeCtx保持为nil,而a.run被设置为errFunc(err)。原始代码假设getRunFunc()返回后bc(execContext)始终非空,导致访问bc.toolInfos、bc.instruction等字段时可能出现空指针解引用。修复在三个位置添加了防御性 nil 检查:
getRunFunc():当bc为 nil 时提前返回Run():使用 nil 检查保护bc字段访问Resume():使用 nil 检查保护bc字段访问这确保错误通过事件迭代器正确传播,而不是导致 panic。
测试
添加了
TestChatModelAgent_PrepareExecContextError测试,包含两个子测试:Run_WithToolInfoError_ReturnsError:验证Run()正确返回错误Resume_WithToolInfoError_ReturnsError:验证Resume()正确返回错误