mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-08 01:09:44 +08:00
feat: add action timeout for StartToGoal
This commit is contained in:
@@ -18,7 +18,17 @@ import (
|
|||||||
|
|
||||||
func (dExt *XTDriver) StartToGoal(ctx context.Context, prompt string, opts ...option.ActionOption) ([]*PlanningExecutionResult, error) {
|
func (dExt *XTDriver) StartToGoal(ctx context.Context, prompt string, opts ...option.ActionOption) ([]*PlanningExecutionResult, error) {
|
||||||
options := option.NewActionOptions(opts...)
|
options := option.NewActionOptions(opts...)
|
||||||
log.Info().Int("max_retry_times", options.MaxRetryTimes).Msg("StartToGoal")
|
log.Info().Int("max_retry_times", options.MaxRetryTimes).
|
||||||
|
Int("timeout_seconds", options.Timeout).
|
||||||
|
Msg("StartToGoal")
|
||||||
|
|
||||||
|
// Create timeout context for entire StartToGoal process if Timeout is specified
|
||||||
|
if options.Timeout > 0 {
|
||||||
|
var cancel context.CancelFunc
|
||||||
|
ctx, cancel = context.WithTimeout(ctx, time.Duration(options.Timeout)*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
log.Info().Int("timeout_seconds", options.Timeout).Msg("StartToGoal timeout configured for entire process")
|
||||||
|
}
|
||||||
|
|
||||||
var allPlannings []*PlanningExecutionResult
|
var allPlannings []*PlanningExecutionResult
|
||||||
var attempt int
|
var attempt int
|
||||||
@@ -119,25 +129,11 @@ func (dExt *XTDriver) StartToGoal(ctx context.Context, prompt string, opts ...op
|
|||||||
planningResult.SubActions = append(planningResult.SubActions, subActionResult)
|
planningResult.SubActions = append(planningResult.SubActions, subActionResult)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Create action context with timeout if specified
|
if err := dExt.invokeToolCall(ctx, toolCall, opts...); err != nil {
|
||||||
actionCtx := ctx
|
log.Warn().
|
||||||
if options.Timeout > 0 {
|
Str("action", toolCall.Function.Name).
|
||||||
var cancel context.CancelFunc
|
Err(err).
|
||||||
actionCtx, cancel = context.WithTimeout(ctx, time.Duration(options.Timeout)*time.Second)
|
Msg("invoke tool call failed")
|
||||||
defer cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the tool call with timeout
|
|
||||||
if err := dExt.invokeToolCall(actionCtx, toolCall, opts...); err != nil {
|
|
||||||
// Check if the error is due to timeout
|
|
||||||
if errors.Is(err, context.DeadlineExceeded) {
|
|
||||||
log.Warn().
|
|
||||||
Str("action", toolCall.Function.Name).
|
|
||||||
Int("timeout_seconds", options.Timeout).
|
|
||||||
Msg("action timeout exceeded, continuing to next action")
|
|
||||||
subActionResult.Error = errors.New("action timeout exceeded")
|
|
||||||
return nil // Continue to next action instead of failing the entire StartToGoal
|
|
||||||
}
|
|
||||||
subActionResult.Error = err
|
subActionResult.Error = err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ type ActionOptions struct {
|
|||||||
PressDuration float64 `json:"press_duration,omitempty" yaml:"press_duration,omitempty" desc:"Press duration in seconds"`
|
PressDuration float64 `json:"press_duration,omitempty" yaml:"press_duration,omitempty" desc:"Press duration in seconds"`
|
||||||
Steps int `json:"steps,omitempty" yaml:"steps,omitempty" desc:"Number of steps for action"`
|
Steps int `json:"steps,omitempty" yaml:"steps,omitempty" desc:"Number of steps for action"`
|
||||||
Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty" desc:"Direction for swipe operations or custom coordinates"`
|
Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty" desc:"Direction for swipe operations or custom coordinates"`
|
||||||
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty" desc:"Timeout in seconds"`
|
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty" desc:"Timeout in seconds for action execution"`
|
||||||
Frequency int `json:"frequency,omitempty" yaml:"frequency,omitempty" desc:"Action frequency"`
|
Frequency int `json:"frequency,omitempty" yaml:"frequency,omitempty" desc:"Action frequency"`
|
||||||
|
|
||||||
ScreenOptions
|
ScreenOptions
|
||||||
@@ -533,9 +533,9 @@ func WithMaxRetryTimes(maxRetryTimes int) ActionOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithTimeout(timeout int) ActionOption {
|
func WithTimeout(seconds int) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.Timeout = timeout
|
o.Timeout = seconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user