Repository navigation
fix(skills): decode bytes stdout on shell script TimeoutExpired - #8482
Open
1828703450qqcom-ux wants to merge 1 commit into
Open
1828703450qqcom-ux wants to merge 1 commit into
1828703450qqcom-ux wants to merge 1 commit into
Conversation
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
Fixes a
TypeError: Object of type bytes is not JSON serializablecrash in_SkillScriptCodeExecutor._WRAPPER_SHELL_TEMPLATEwhen a skill shell script exceedsscript_timeout.Root Cause
In
_SkillScriptCodeExecutor._WRAPPER_SHELL_TEMPLATE,subprocess.run(..., capture_output=True, text=True, encoding='utf-8', errors='replace', timeout=...)raisessubprocess.TimeoutExpiredwhen a shell script times out. Even whentext=True/encodingare specified, CPython'ssubprocess.TimeoutExpired.stdout(.output) is documented to still bebytesrather thanstron timeout before decoding completes. Passing_e.stdout or ''directly to_json.dumps(...)fails withTypeError: Object of type bytes is not JSON serializable, losing the partial stdout and structured timeout envelope.Fix
_e.stdoutwith.decode('utf-8', errors='replace')whenisinstance(_e.stdout, bytes)before serializing the__shell_result__JSON payload in_SkillScriptCodeExecutor._WRAPPER_SHELL_TEMPLATE.test_shell_wrapper_timeout_decodes_bytes_stdoutintests/unittests/tools/test_skill_toolset.pycoveringbytesoutput containing invalid UTF-8 sequences, emptybytes, andNone.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_argsandtest_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-existingvar-annotatederrors 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.