Skip to content

Commit 1def14b

Browse files
GWealecopybara-github
authored andcommitted
fix(core): stop the unsafe local code executor waiting forever
Co-authored-by: George Weale <[email protected]> PiperOrigin-RevId: 1002699849
1 parent 486ef30 commit 1def14b

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/google/adk/code_executors/unsafe_local_code_executor.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ class UnsafeLocalCodeExecutor(BaseCodeExecutor):
127127
# optimize_data_file.
128128
optimize_data_file: bool = Field(default=False, frozen=True, exclude=True)
129129

130+
# Overrides the BaseCodeExecutor attribute: the base default of None waits
131+
# for the execution forever, which non-terminating generated code turns into
132+
# a hung agent.
133+
timeout_seconds: int | None = 300
134+
"""The wall-clock timeout in seconds for a single code execution.
135+
136+
Defaults to 300, matching ``ContainerCodeExecutor`` and ``GkeCodeExecutor``.
137+
None waits for the execution indefinitely.
138+
"""
139+
130140
def __init__(self, **data: Any) -> None:
131141
"""Initializes the UnsafeLocalCodeExecutor."""
132142
if 'stateful' in data and data['stateful']:

‎tests/unittests/code_executors/test_unsafe_local_code_executor.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ def test_init_default(self):
9494
executor = UnsafeLocalCodeExecutor()
9595
assert not executor.stateful
9696
assert not executor.optimize_data_file
97+
# Bounded by default, so generated code that never terminates cannot hang
98+
# the agent waiting on it.
99+
assert executor.timeout_seconds == 300
100+
101+
def test_init_accepts_timeout_seconds_none(self):
102+
"""Asking for no timeout at all is still allowed, as on the base class."""
103+
executor = UnsafeLocalCodeExecutor(timeout_seconds=None)
104+
assert executor.timeout_seconds is None
97105

98106
def test_init_stateful_raises_error(self):
99107
with pytest.raises(

0 commit comments

Comments
 (0)