droboticflow/internal/api/rework_assignment.go
2026-11-11 03:51:18 -08:00

57 lines
2.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package api
import (
"context"
"droboticflow/internal/domain"
"os"
"strings"
)
// 新删除交接规则启用时,仍在职的原标注员保持定向返工。
// reworkReturnMode 报告正式退回的路由策略(B01 回退开关):
// - "directed"(默认):退回定向归还原标注员(spec §10 行为变更裁定,2026-10-12 用户确认);
// - "pool":回退开关打开(FANYU_REWORK_RETURN=pool),恢复退回公共池的历史行为。
func reworkReturnMode() string {
if !accountHandoffPolicyEnabled() && strings.EqualFold(strings.TrimSpace(os.Getenv("FANYU_REWORK_RETURN")), "pool") {
return "pool"
}
return "directed"
}
// Resolve before recording a decision: transient lookup failures must not silently
// turn a return-to-author decision into a public-pool assignment.
func (s *server) reworkAuthor(ctx context.Context, item domain.HumanItemRecord) (string, error) {
if item.LatestAuthorUserID == "" || item.ReviewRound+1 > item.MaxReworkRounds {
return "", nil
}
user, err := s.store.GetUser(ctx, item.LatestAuthorUserID)
if err != nil {
return "", err
}
if user == nil || user.OrganizationID != item.OrganizationID || user.Status != domain.UserStatusActive || user.Role != domain.UserRoleAnnotator || user.SupplierID == "" {
return "", nil
}
if item.SupplierID != "" && item.SupplierID != user.SupplierID {
return "", nil
}
supplier, err := s.store.GetSupplier(ctx, user.SupplierID)
if err != nil {
return "", err
}
if supplier == nil || supplier.OrganizationID != item.OrganizationID || !strings.EqualFold(supplier.Status, "active") {
return "", nil
}
members, err := s.annotationMembershipsForUser(ctx, item.OrganizationID, item.ProjectID, user.ID)
if err != nil {
return "", err
}
task := domain.AnnotationTaskRecord{ID: item.LegacyTaskID, ProjectID: item.ProjectID, SupplierID: item.SupplierID, ProcessingScope: item.ProcessingScope, ProcessingProfile: item.ProcessingProfile}
if batch, err := s.store.GetHumanBatch(ctx, item.BatchID); err == nil && batch != nil {
task.SupplierPool = batch.ProcessingProfile == domain.ProcessingProfileRawHuman && domain.IsFanyuV58ThreeRoleHumanLoop(batch.Stages)
}
if !membershipHasRole(members, task, domain.AnnotationRoleAnnotator) {
return "", nil
}
return user.ID, nil
}