Bound ordinary runs with attributable operation timeouts

This commit is contained in:
2026-11-14 17:37:25 +00:00
parent 2066579e09
commit d42b131de2
6 changed files with 144 additions and 3 deletions

View File

@@ -514,8 +514,14 @@ func (e *Engine) PrepareExecution(ctx context.Context, req RunRequest) (*Prepare
// result on error.
func (e *Engine) Run(ctx context.Context, req RunRequest) (*RunResult, error) {
ctx = observation.WithoutExecutionState(ctx)
scope := usecase.NewOperationScope(ctx, req.OperationTimeout)
defer scope.Close()
ctx = scope.Context
if req.Observer == nil {
return e.run(ctx, req)
result, err := e.run(ctx, req)
err = mapPublicError(scope.Finalize(err))
scope.Close()
return result, err
}
recorder, idErr := observation.New(func(event domain.ExecutionEvent) { req.Observer(fromDomainExecutionEvent(event)) })
if req.ContinueFrom != nil && req.ContinueFrom.internal != nil {
@@ -523,12 +529,15 @@ func (e *Engine) Run(ctx context.Context, req RunRequest) (*RunResult, error) {
}
recorder.Start()
if idErr != nil {
err := fmt.Errorf("failed to create run id: %w", idErr)
err := mapPublicError(scope.Finalize(fmt.Errorf("failed to create run id: %w", idErr)))
scope.Close()
terminal := observedFinish(nil, err)
recorder.Finish(observation.FinishData{Outcome: terminal.Outcome, Failure: terminal.Failure})
return nil, err
}
result, err := e.run(observation.WithRecorder(ctx, recorder), req)
err = mapPublicError(scope.Finalize(err))
scope.Close()
terminal := observedFinish(result, err)
recorder.Finish(observation.FinishData{Outcome: terminal.Outcome, Failure: terminal.Failure,
StatusCode: terminal.StatusCode, RetriesExhausted: terminal.RetriesExhausted})
@@ -547,7 +556,7 @@ func (e *Engine) run(ctx context.Context, req RunRequest) (*RunResult, error) {
result, err := e.internal.Run(ctx, domainReq)
if err != nil {
return nil, mapPublicError(err)
return nil, err
}
return fromDomainRunResult(result), nil
}