Skip to content

fix(skills): decode bytes stdout on shell script TimeoutExpired - #8482

Open
1828703450qqcom-ux wants to merge 1 commit into
google:mainfrom
1828703450qqcom-ux:fix/skill-shell-timeout-bytes-stdout
Open

1828703450qqcom-ux wants to merge 1 commit into
google:mainfrom
1828703450qqcom-ux:fix/skill-shell-timeout-bytes-stdout

Conversation

@1828703450qqcom-ux

Copy link
Copy Markdown
Contributor

Summary

Fixes a TypeError: Object of type bytes is not JSON serializable crash in _SkillScriptCodeExecutor._WRAPPER_SHELL_TEMPLATE when a skill shell script exceeds script_timeout.

Root Cause

In _SkillScriptCodeExecutor._WRAPPER_SHELL_TEMPLATE, subprocess.run(..., capture_output=True, text=True, encoding='utf-8', errors='replace', timeout=...) raises subprocess.TimeoutExpired when a shell script times out. Even when text=True / encoding are specified, CPython's subprocess.TimeoutExpired.stdout (.output) is documented to still be bytes rather than str on timeout before decoding completes. Passing _e.stdout or '' directly to _json.dumps(...) fails with TypeError: Object of type bytes is not JSON serializable, losing the partial stdout and structured timeout envelope.

Fix

  • Decode _e.stdout with .decode('utf-8', errors='replace') when isinstance(_e.stdout, bytes) before serializing the __shell_result__ JSON payload in _SkillScriptCodeExecutor._WRAPPER_SHELL_TEMPLATE.
  • Add test_shell_wrapper_timeout_decodes_bytes_stdout in tests/unittests/tools/test_skill_toolset.py covering bytes output containing invalid UTF-8 sequences, empty bytes, and None.

Verification

  • pytest tests/unittests/tools/test_skill_toolset.py -k "test_shell_wrapper_timeout_decodes_bytes_stdout or test_shell_json_envelope_timeout or test_execute_script_shell" -v: 9 passed (including all 3 parametrized timeout cases). (On the broader -k "shell" filter on Windows, 23 passed and 2 pre-existing Windows-environment integration tests failed unrelated to this change: test_run_skill_script_code_executor_shell_coerces_int_positional_args and test_run_skill_script_environment_quotes_shell_metacharacters.)
  • pyink --check src/google/adk/tools/skill_toolset.py tests/unittests/tools/test_skill_toolset.py: passed.
  • isort --check src/google/adk/tools/skill_toolset.py tests/unittests/tools/test_skill_toolset.py: passed.
  • ruff check src/google/adk/tools/skill_toolset.py: passed.
  • mypy src/google/adk/tools/skill_toolset.py: 0 new errors introduced (2 pre-existing var-annotated errors remain on untouched lines 1548–1549).
  • python scripts/compliance_checks.py src/google/adk/tools/skill_toolset.py tests/unittests/tools/test_skill_toolset.py: passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant