fix: follow-up for salvaged PR #10854

- Extract duplicated activity-callback polling into shared
  touch_activity_if_due() helper in tools/environments/base.py
- Use helper from both base.py _wait_for_process and
  code_execution_tool.py local polling loop (DRY)
- Add test assertion that timeout output field contains the
  timeout message and emoji (#10807)
- Add stream_consumer test for tool-boundary fallback scenario
  where continuation is empty but final_text differs from
  visible prefix (#10807)
This commit is contained in:
kshitijk4poor 2026-04-16 19:01:56 +05:30 committed by kshitij
parent 3e3ec35a5e
commit a6142a8e08
5 changed files with 105 additions and 42 deletions

View file

@ -1128,8 +1128,10 @@ def execute_code(
stderr_reader.start()
status = "success"
_last_activity_touch = time.monotonic()
_ACTIVITY_INTERVAL = 10.0
_activity_state = {
"last_touch": time.monotonic(),
"start": exec_start,
}
while proc.poll() is None:
if _is_interrupted():
_kill_process_group(proc)
@ -1141,17 +1143,11 @@ def execute_code(
break
# Periodic activity touch so the gateway's inactivity timeout
# doesn't kill the agent during long code execution (#10807).
_now = time.monotonic()
if _now - _last_activity_touch >= _ACTIVITY_INTERVAL:
_last_activity_touch = _now
try:
from tools.environments.base import _get_activity_callback
_cb = _get_activity_callback()
if _cb:
_elapsed = int(_now - exec_start)
_cb(f"execute_code running ({_elapsed}s elapsed)")
except Exception:
pass
try:
from tools.environments.base import touch_activity_if_due
touch_activity_if_due(_activity_state, "execute_code running")
except Exception:
pass
time.sleep(0.2)
# Wait for readers to finish draining