fix: handle bare numeric and negative durations in Wait action handler#412
Open
nankingjing wants to merge 2 commits into
Open
fix: handle bare numeric and negative durations in Wait action handler#412nankingjing wants to merge 2 commits into
nankingjing wants to merge 2 commits 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 bug in
ActionHandler._handle_waitwhere theWaitaction silently failed when the model returned a bare numeric duration (int/float) instead of a string like"3 seconds".Root cause
_handle_waitalways calls.replace("seconds", "")onaction.get("duration"). When a model emitsdo(action="Wait", duration=3),ast.literal_evalreturns the integer3. Calling.replace()on anintraisesAttributeError, which theexcept ValueErrorclause does not catch, so the action falls through toexecute()'s generic handler and reportssuccess=FalsewithAction failed: 'int' object has no attribute 'replace'— no actual wait happens. A negative duration string (e.g."-5 seconds") is a second latent defect: it parses to-5.0andtime.sleep(-5.0)raisesValueError.Fix (
phone_agent/actions/handler.py)isinstance(duration_raw, (int, float))before calling string methods; convert numeric input tofloatdirectly.except (ValueError, TypeError).1.0sotime.sleepcannot raise.The documented happy path
duration="N seconds"is unchanged.Test (
tests/test_wait_action.py)Seven deterministic tests driving
ActionHandler.execute, covering: string with unit, string without unit, missing key (default), bareint(the bug), barefloat, unparseable fallback, and negative clamp.time.sleepis patched — no device or network access.Verification
_handle_wait(checked 修复parse_action函数:移除</answer>标签导致的语法解析错误 #347, fix: prevent IndexError in Type action parser and fix screenshot temp file leak #394, fix: fail malformed model actions #402, Adding log snapshot and action record features #385).tests/test_handler.py.Generated with Claude Code