@@ -58,6 +58,7 @@ func (h *TaskHook) OnStateChange(ctx context.Context, id uuid.UUID, from, to con
5858
5959func (h * TaskHook ) withError (ctx context.Context , id , uid uuid.UUID , fn func () error ) {
6060 if err := fn (); err != nil {
61+ h .logger .With ("error" , err , "task_id" , id ).ErrorContext (ctx , "failed to handle processing" )
6162 if err := h .taskLifecycle .Transition (ctx , id , consts .TaskStatusError , TaskMetadata {
6263 TaskID : id ,
6364 UserID : uid ,
@@ -78,6 +79,16 @@ func (h *TaskHook) handleError(ctx context.Context, id, uid uuid.UUID) error {
7879
7980func (h * TaskHook ) handleProcessing (ctx context.Context , id uuid.UUID , metadata TaskMetadata ) error {
8081 h .withError (ctx , id , metadata .UserID , func () error {
82+ // 从 DB 查询当前任务状态,如果已经是 processing 说明是 Agent 重连触发的重复 vm-ready,跳过
83+ t , err := h .repo .GetByID (ctx , id )
84+ if err != nil {
85+ return fmt .Errorf ("failed to get task: %w" , err )
86+ }
87+ if t .Status == consts .TaskStatusProcessing {
88+ h .logger .With ("task_id" , id ).InfoContext (ctx , "task already processing, skipping (likely agent reconnect)" )
89+ return nil
90+ }
91+
8192 reqKey := fmt .Sprintf ("task:create_req:%s" , id .String ())
8293 val , err := h .redis .Get (ctx , reqKey ).Result ()
8394 if err != nil {
0 commit comments