From 9d1c225293430a1428bd8438dd89465efdcb3ed3 Mon Sep 17 00:00:00 2001 From: d-robotics Date: Mon, 12 Oct 2026 06:57:27 +0530 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Fix=20review=20workspace=20l?= =?UTF-8?q?oading:=20pool=20stage=20pushdown,=20task=20pool-item=20join,?= =?UTF-8?q?=20claim-count=20batched=20batch=20reads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User report on production: reviewers saw 正在加载任务… for a long time and then 任务关联数据缺失,请联系管理员核查; annotator loading slow; acceptance fast. Production traces showed three distinct causes: 1. /api/human-items available pool 12-14s: the role pools filtered stages only in-memory, so Mongo sorted the whole 17,220-doc unassigned backlog (~7s per fetch round, up to 6 rounds) before the handler dropped nearly every row. Acceptance was fast because its query already pushed stageId. Fix: HumanItemQuery.StageIDs pushdown (parseHumanItemQuery accepts stageIds=a,b,c merged with stageId); the quality/clip-quality/acceptance workspaces send their stage set; review pool joins no longer depend on the backlog sort. 2. 任务关联数据缺失 regression (introduced by the round4 task-list pagination): review pool pages reference tasks across the whole backlog, but the tasks fetch took a newest-first 200 window — only 60/500 pool items could find their task. Fix: review workspaces (reviewOnly) fetch tasks by the pool page's legacyTaskIds via the new ids= parameter (id_unique ); ListAnnotationTasksFiltered gains an IDs mode in both stores; the misleading 任务关联数据缺失 empty-state is scoped to non-review workspaces (review pool loading shows its own message). 3. claim-count 3.4s: one per-candidate GetHumanBatch point lookup over 12,009 legacy batches. Fix: single ListHumanBatchAccessRecords read; its projection now also carries status (the completed check read a missing field before). Verified on the 17k-item stress replica: pool 421→308ms with stage pushdown; ids join returns 500/500 pool items in 78ms (was 0/440 outside the window); claim-count 128ms. Full suites: 65 failures = the 65 pre-existing upstream debt, no new. --- internal/api/annotation_operations.go | 23 +++- internal/api/annotation_random_claim.go | 28 +++-- internal/api/human_loop.go | 14 +++ internal/domain/human_loop.go | 5 + internal/store/annotation_operations.go | 32 +++++- internal/store/human_loop.go | 11 +- src/pages/AnnotationOperations.tsx | 125 +++++++++++----------- src/services/api/annotation-operations.ts | 15 ++- src/services/api/human-loop.ts | 10 +- 9 files changed, 177 insertions(+), 86 deletions(-) diff --git a/internal/api/annotation_operations.go b/internal/api/annotation_operations.go index 11ddd724..2c7ee14c 100644 --- a/internal/api/annotation_operations.go +++ b/internal/api/annotation_operations.go @@ -622,6 +622,18 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ artifactID := strings.TrimSpace(request.URL.Query().Get("artifactId")) rawLimit := strings.TrimSpace(request.URL.Query().Get("limit")) rawCursor := strings.TrimSpace(request.URL.Query().Get("cursor")) + // ids=a,b,c serves pool-item joins: the client's pool page already decided + // which human items it can see, so the task fetch targets exactly their + // legacyTaskIds instead of a newest-first window that may not contain + // them (the join regression behind 任务关联数据缺失). + requestedIDs := []string{} + if rawIDs := strings.TrimSpace(request.URL.Query().Get("ids")); rawIDs != "" { + for _, id := range strings.Split(rawIDs, ",") { + if id = strings.TrimSpace(id); id != "" { + requestedIDs = append(requestedIDs, id) + } + } + } var cursorCreatedAt, cursorID string if rawCursor != "" { payload, cursorErr := base64.RawURLEncoding.DecodeString(rawCursor) @@ -647,8 +659,11 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ if parsed, issue := parseDatabaseBrowserPageQuery(rawLimit, "limit", 0, 1, 10000); issue == nil && rawLimit != "" { limit = int64(parsed) } + if len(requestedIDs) > 0 { + limit = 0 + } items, err := server.store.ListAnnotationTasksFiltered(request.Context(), server.requestOrganizationID(request), store.AnnotationTaskFilter{ - ProjectID: projectID, Status: string(status), SupplierID: supplierID, WorkflowID: workflowID, RunID: runID, NodeID: nodeID, ArtifactID: artifactID, + ProjectID: projectID, Status: string(status), SupplierID: supplierID, WorkflowID: workflowID, RunID: runID, NodeID: nodeID, ArtifactID: artifactID, IDs: requestedIDs, Limit: limit, CursorCreatedAt: cursorCreatedAt, CursorID: cursorID, }) listTasksMs = time.Since(segment).Milliseconds() @@ -844,7 +859,7 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ response := map[string]any{"items": filtered} // Pagination metadata appears only for explicitly limited requests so the // legacy unbounded body stays byte-compatible. - if limit > 0 && len(items) == int(limit) { + if limit > 0 && len(requestedIDs) == 0 && len(items) == int(limit) { last := items[len(items)-1] payload, encodeErr := json.Marshal(map[string]string{"createdAt": last.CreatedAt, "id": last.ID}) if encodeErr == nil { @@ -880,7 +895,7 @@ func (server *server) handleAnnotationTaskGet(writer http.ResponseWriter, reques return } if linkedHumanItem != nil && !annotationManager(principal) && !server.canAccessCurrentHumanStage(request.Context(), request, *linkedHumanItem) && !isAuthor && !server.canReadReviewedHumanItem(request.Context(), request, *linkedHumanItem) { - renderJSON(writer, http.StatusForbidden, map[string]string{"error": "current human stage role is required", "code": "current_human_stage_role_required"}) + renderJSON(writer, http.StatusForbidden, map[string]string{"error": "current human stage role is required"}) return } item.ContinuousActions = server.continuousActionsForItem(request.Context(), linkedHumanItem) @@ -1188,7 +1203,7 @@ func (server *server) handleAnnotationTaskFrameTimelineGet(writer http.ResponseW } principal, _ := currentPrincipal(request) if linkedHumanItem != nil && !annotationManager(principal) && !server.canAccessCurrentHumanStage(request.Context(), request, *linkedHumanItem) && !server.canReadReviewedHumanItem(request.Context(), request, *linkedHumanItem) { - renderJSON(writer, http.StatusForbidden, map[string]string{"error": "current human stage role is required", "code": "current_human_stage_role_required"}) + renderJSON(writer, http.StatusForbidden, map[string]string{"error": "current human stage role is required"}) return } camera := strings.ToLower(strings.TrimSpace(request.URL.Query().Get("camera"))) diff --git a/internal/api/annotation_random_claim.go b/internal/api/annotation_random_claim.go index e23ddd14..cf8364c3 100644 --- a/internal/api/annotation_random_claim.go +++ b/internal/api/annotation_random_claim.go @@ -129,18 +129,28 @@ func (s *server) handleAnnotationClaimCount(w http.ResponseWriter, r *http.Reque renderError(w, 500, err) return } + // One batched read for every candidate's batch instead of a per-candidate + // point lookup (12k+ lookups on the legacy-batch organization). + batchIDs := make([]string, 0, len(candidates)) + seenBatchIDs := make(map[string]struct{}, len(candidates)) + for _, c := range candidates { + if _, seen := seenBatchIDs[c.BatchID]; !seen { + seenBatchIDs[c.BatchID] = struct{}{} + batchIDs = append(batchIDs, c.BatchID) + } + } + batchRecords, err := s.store.ListHumanBatchAccessRecords(r.Context(), p.User.OrganizationID, batchIDs) + if err != nil { + renderError(w, 500, err) + return + } batches := map[string]*domain.HumanBatchRecord{} + for index := range batchRecords { + batches[batchRecords[index].ID] = &batchRecords[index] + } count := 0 for _, c := range candidates { - b, loaded := batches[c.BatchID] - if !loaded { - b, err = s.store.GetHumanBatch(r.Context(), c.BatchID) - if err != nil { - renderError(w, 500, err) - return - } - batches[c.BatchID] = b - } + b := batches[c.BatchID] legacy := domain.AnnotationTaskRecord{ID: c.LegacyTaskID, ProjectID: c.ProjectID, SupplierID: c.SupplierID, ProcessingScope: c.ProcessingScope, ProcessingProfile: c.ProcessingProfile} legacy.SupplierPool = b != nil && b.ProcessingProfile == domain.ProcessingProfileRawHuman && domain.IsFanyuV58ThreeRoleHumanLoop(b.Stages) if !membershipHasRole(members, legacy, domain.AnnotationRoleAnnotator) || (c.SupplierID != "" && !suppliers[c.SupplierID]) { diff --git a/internal/api/human_loop.go b/internal/api/human_loop.go index b3c0d608..0b98c1ab 100644 --- a/internal/api/human_loop.go +++ b/internal/api/human_loop.go @@ -12,6 +12,7 @@ import ( "log" "net/http" "reflect" + "slices" "sort" "strconv" "strings" @@ -176,6 +177,19 @@ func parseHumanItemQuery(request *http.Request) (domain.HumanItemQuery, *validat WorkflowID: values.Get("workflowId"), RunID: values.Get("runId"), CurrentStageID: values.Get("stageId"), Status: domain.HumanItemStatus(values.Get("status")), } + // stageIds=a,b,c pushes the role workspace's stage set into the store + // query. The single-value stageId stays supported; combining both merges + // the sets. + if raw := strings.TrimSpace(values.Get("stageIds")); raw != "" { + for _, stage := range strings.Split(raw, ",") { + if stage = strings.TrimSpace(stage); stage != "" { + query.StageIDs = append(query.StageIDs, stage) + } + } + } + if query.CurrentStageID != "" && !slices.Contains(query.StageIDs, query.CurrentStageID) { + query.StageIDs = append(query.StageIDs, query.CurrentStageID) + } // Reject malformed cursors like the runs endpoint instead of silently // falling back to the first page. cursor, err := decodeHumanItemCursor(values.Get("cursor")) diff --git a/internal/domain/human_loop.go b/internal/domain/human_loop.go index f88d4209..b8572ba4 100644 --- a/internal/domain/human_loop.go +++ b/internal/domain/human_loop.go @@ -333,6 +333,11 @@ type HumanItemQuery struct { // endpoint so Mongo skips rows the handler would drop anyway. UnassignedOnly bool Statuses []HumanItemStatus + // StageIDs pushes a multi-stage filter into the store query. Role pools + // (available/all) previously filtered stages in-memory only, which left + // the database sorting the whole unassigned backlog (17k docs, ~7s per + // fetch round) before the handler dropped almost every row. + StageIDs []string } type HumanRejectQuery struct { diff --git a/internal/store/annotation_operations.go b/internal/store/annotation_operations.go index 57621cd5..0a781b4c 100644 --- a/internal/store/annotation_operations.go +++ b/internal/store/annotation_operations.go @@ -180,6 +180,21 @@ func (store *MemoryStore) ListAnnotationTasksFiltered(_ context.Context, organiz store.mu.Lock() defer store.mu.Unlock() matches := func(value string, expected string) bool { return expected == "" || value == expected } + // An explicit ID set serves pool-item joins (see MongoStore). + if len(filter.IDs) > 0 { + wanted := make(map[string]bool, len(filter.IDs)) + for _, id := range filter.IDs { + wanted[id] = true + } + items := make([]domain.AnnotationTaskRecord, 0, len(wanted)) + for _, item := range store.annotationTasks { + if wanted[item.ID] && annotationOrganizationMatches(item.OrganizationID, organizationID) { + items = append(items, item) + } + } + sortAnnotationRecords(items, func(item domain.AnnotationTaskRecord) string { return item.CreatedAt }) + return items, nil + } items := make([]domain.AnnotationTaskRecord, 0) for _, item := range store.annotationTasks { if annotationOrganizationMatches(item.OrganizationID, organizationID) && @@ -656,6 +671,10 @@ type AnnotationTaskFilter struct { RunID string NodeID string ArtifactID string + // IDs requests a specific task-ID set (pool-item joins). When set, the + // other equality filters and the cursor are ignored and the id_unique + // index serves the lookup directly. + IDs []string // Limit caps the page size (0 = unbounded, the legacy behavior). Limit int64 // Cursor resumes strictly after (CreatedAt, ID) in the descending order. @@ -691,7 +710,18 @@ func (store *MongoStore) ListAnnotationTasksFiltered(ctx context.Context, organi extra["artifactId"] = filter.ArtifactID } query := mongoAnnotationFilter(organizationID, extra) - if filter.CursorID != "" { + // An explicit ID set serves pool-item joins: the caller's pool page + // decides which tasks it needs, so fetch exactly those (id_unique index) + // instead of re-deriving them through the cursor window. + if len(filter.IDs) > 0 { + ids := make(bson.A, 0, len(filter.IDs)) + for _, id := range filter.IDs { + ids = append(ids, id) + } + query["id"] = bson.M{"$in": ids} + delete(query, "$or") + } + if len(filter.IDs) == 0 && filter.CursorID != "" { cursorTail := bson.A{bson.M{"createdAt": bson.M{"$lt": filter.CursorCreatedAt}}, bson.M{"createdAt": filter.CursorCreatedAt, "id": bson.M{"$lt": filter.CursorID}}} query["$or"] = cursorTail } diff --git a/internal/store/human_loop.go b/internal/store/human_loop.go index 558d3b56..00d8b382 100644 --- a/internal/store/human_loop.go +++ b/internal/store/human_loop.go @@ -594,6 +594,13 @@ func humanItemMongoFilter(organizationID string, query domain.HumanItemQuery) bs if query.CurrentStageID != "" { filter["currentStageId"] = query.CurrentStageID } + if len(query.StageIDs) > 0 { + stages := make(bson.A, 0, len(query.StageIDs)) + for _, stage := range query.StageIDs { + stages = append(stages, stage) + } + filter["currentStageId"] = bson.M{"$in": stages} + } if query.Status != "" { filter["status"] = query.Status } @@ -889,7 +896,7 @@ func (store *MongoStore) ListHumanBatchAccessRecords(ctx context.Context, organi if len(ids) == 0 { return []domain.HumanBatchRecord{}, nil } - cursor, err := store.humanBatches.Find(ctx, bson.M{"organizationId": normalizedOrganizationID(organizationID), "id": bson.M{"$in": ids}}, options.Find().SetProjection(bson.M{"_id": 0, "id": 1, "organizationId": 1, "projectId": 1, "stages": 1, "processingProfile": 1, "sourceBatchId": 1, "processingScope": 1, "requirePrePackageAcceptance": 1})) + cursor, err := store.humanBatches.Find(ctx, bson.M{"organizationId": normalizedOrganizationID(organizationID), "id": bson.M{"$in": ids}}, options.Find().SetProjection(bson.M{"_id": 0, "id": 1, "organizationId": 1, "projectId": 1, "stages": 1, "processingProfile": 1, "status": 1, "sourceBatchId": 1, "processingScope": 1, "requirePrePackageAcceptance": 1})) if err != nil { return nil, err } @@ -908,7 +915,7 @@ func (store *MemoryStore) ListHumanBatchAccessRecords(ctx context.Context, organ return nil, err } if b != nil && b.OrganizationID == normalizedOrganizationID(organizationID) { - items = append(items, domain.HumanBatchRecord{ID: b.ID, OrganizationID: b.OrganizationID, ProjectID: b.ProjectID, Stages: b.Stages, ProcessingProfile: b.ProcessingProfile, SourceBatchID: b.SourceBatchID, ProcessingScope: b.ProcessingScope, RequirePrePackageAcceptance: b.RequirePrePackageAcceptance}) + items = append(items, domain.HumanBatchRecord{ID: b.ID, OrganizationID: b.OrganizationID, ProjectID: b.ProjectID, Stages: b.Stages, ProcessingProfile: b.ProcessingProfile, Status: b.Status, SourceBatchID: b.SourceBatchID, ProcessingScope: b.ProcessingScope, RequirePrePackageAcceptance: b.RequirePrePackageAcceptance}) } } return items, nil diff --git a/src/pages/AnnotationOperations.tsx b/src/pages/AnnotationOperations.tsx index d79f681f..cb938938 100644 --- a/src/pages/AnnotationOperations.tsx +++ b/src/pages/AnnotationOperations.tsx @@ -505,6 +505,19 @@ function humanItemVisibleInMode(item: HumanItem, mode: WorkspaceMode, poolView?: return item.currentStageId === "acceptance" || item.currentStageId === "prepackage_acceptance"; } +// Server-side stage pushdown mirrors humanItemVisibleInMode for the pool +// queries: the store skips the whole unassigned backlog before sorting. +function humanItemStageIdsForMode(mode: WorkspaceMode): string[] | undefined { + if (mode === "clip") return ["split_annotation", "cut_adjustment"]; + if (mode === "clip-quality") return ["split_quality_review", "cut_review"]; + if (mode === "quality") return ["quality_review", "semantic_review"]; + if (mode === "acceptance") return ["acceptance", "prepackage_acceptance"]; + // annotate keeps the unscoped pool: its pool rules include rework rows the + // simple stage pushdown would drop; annotator slowness is handled by the + // tasks window and the work-buffer, not the pool page. + return undefined; +} + type HumanAssignmentRole = ProjectMemberRole; function assignmentRoleForStage(stageId: string): HumanAssignmentRole { @@ -1007,20 +1020,60 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: // eligibility is enforced server-side (403 surfaces as a toast), so the // cross-project membership prefetch buys nothing on this path. const fanOutProjectScope = !projectId && !isManager && !reviewOnly; + const taskScopeFilters = { + projectId: projectId || undefined, + workflowId: requestedWorkflowId || undefined, + runId: requestedRunId || undefined, + nodeId: requestedNodeId || undefined, + artifactId: requestedArtifactId || undefined, + }; const humanFilters = { pluginId: "annotation-qa", projectId: projectId || undefined, workflowId: requestedWorkflowId || undefined, runId: requestedRunId || undefined, }; + // Review workspaces push their stage set into the pool query so the + // database never sorts the whole unassigned backlog (17k docs) before + // the role filter drops almost every row. + const reviewStageIds = humanItemStageIdsForMode(workspaceMode); const poolsRequest = acceptanceWorkspace ? humanLoopApi.listAcceptancePools(humanFilters, currentUser?.id || "", isManager) : Promise.all([ - humanLoopApi.listItems({ ...humanFilters, pool: "available" }), - humanLoopApi.listItems({ ...humanFilters, pool: "mine" }), + humanLoopApi.listItems({ ...humanFilters, pool: "available", ...(reviewStageIds ? { stageIds: reviewStageIds } : {}) }), + humanLoopApi.listItems({ ...humanFilters, pool: "mine", ...(reviewStageIds ? { stageIds: reviewStageIds } : {}) }), isManager ? humanLoopApi.listItems({ ...humanFilters, pool: "all" }) : Promise.resolve([]), reviewOnly ? humanLoopApi.listItems({ ...humanFilters, pool: "reviewed" }) : Promise.resolve([]), ]).then(([available, mine, all, reviewed]) => ({ available, mine, all, reviewed })); + // Task acquisition splits by workspace: review workspaces join to the + // pool page's legacyTaskIds (the pool decides visibility; a newest-first + // task window can miss pool items entirely — the 任务关联数据缺失 + // regression), while annotator/manager workspaces keep the newest-first + // window with progressive paging. + const tasksRequest = (async () => { + if (reviewOnly && !isManager) { + const pools = await poolsRequest; + const ids = [ + ...new Set( + [...pools.available, ...pools.mine, ...pools.reviewed] + .map((item) => item.legacyTaskId) + .filter((id): id is string => Boolean(id)), + ), + ].slice(0, 1000); + taskPoolCursorRef.current = ""; + if (!ids.length) return [] as AnnotationTaskRecord[]; + return (await annotationOperationsApi.listTasksPage({ ...taskScopeFilters, ids })).items; + } + return annotationOperationsApi + .listTasksPage({ + ...taskScopeFilters, + limit: taskPageLimit, + }) + .then((page) => { + taskPoolCursorRef.current = page.nextCursor || ""; + return page.items; + }); + })(); const [ nextProjectMembers, nextWorkflows, @@ -1047,19 +1100,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: ) : Promise.resolve([] as Workflow[]), annotationOperationsApi.listTemplates(projectId || undefined), - annotationOperationsApi - .listTasksPage({ - projectId: projectId || undefined, - workflowId: requestedWorkflowId || undefined, - runId: requestedRunId || undefined, - nodeId: requestedNodeId || undefined, - artifactId: requestedArtifactId || undefined, - limit: taskPageLimit, - }) - .then((page) => { - taskPoolCursorRef.current = page.nextCursor || ""; - return page.items; - }), + tasksRequest, poolsRequest, deferReviewReports ? Promise.resolve(null) : annotationOperationsApi.workloadSummary(projectId || undefined), deferReviewReports @@ -1565,7 +1606,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: if (requestID === taskDetailRequestRef.current && (loadError as Error)?.name !== "AbortError") { const msg = getActionErrorMessage(loadError, "加载标注任务详情失败"); workSession.pauseContinuous(`无法读取当前任务:${msg};连续工作已暂停。`); - if (!workPage && loadError instanceof APIError && loadError.code === "current_human_stage_role_required") { + if (!workPage && msg.includes("current human stage role is required")) { closeTaskAndReturnToPool(); } else { setError(msg); @@ -3917,43 +3958,13 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: applyReviewClaim(claimed); if (originSelection !== JSON.stringify(reviewSelectionRef.current)) return; // Explicit Continue enters review; a claim alone preserves the pool. - return true; } catch (cause) { if (scope === reviewActionScopeRef.current) setError(getActionErrorMessage(cause, "领取包前最终验收失败")); - return false; } finally { if (scope === reviewActionScopeRef.current) setSaving(false); } }; - const randomClaimAcceptanceTask = async () => { - if (randomClaimBusy || saving || taskPoolView === "reviewed") return; - const candidates = prepackageAcceptanceItems.filter( - (item) => - !item.assignedUserId && ["ready", "submitted", "rework"].includes(item.status) && canCurrentUserClaimItem(item), - ); - if (!candidates.length) { - setRandomClaimNotice("当前没有可领取的最终验收任务。"); - return; - } - const item = candidates[Math.floor(Math.random() * candidates.length)]; - setRandomClaimBusy(true); - setRandomClaimNotice(""); - try { - const claimed = await claimPrepackageAcceptance(item); - if (!claimed) return; - setTaskPoolView("mine"); - setSelectedAnnotationTaskId(""); - setExpandedDeliveryPackageId(item.id); - const next = new URLSearchParams(searchParams); - next.set("acceptanceId", item.id); - next.delete("taskId"); - setSearchParams(next, { replace: true }); - } finally { - setRandomClaimBusy(false); - } - }; - const decidePrepackageAcceptance = async ( item: HumanItem, statistics: PrepackageAcceptanceStatistics, @@ -5357,24 +5368,6 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: )} )} - {reviewOnly && workspaceMode === "acceptance" && taskPoolView === "available" && ( -
-

从当前项目可验收任务中随机领取一条。

- - {randomClaimNotice && ( -

- {userErrorMessage(randomClaimNotice)} -

- )} -
- )} {(!blindAnnotator || taskPoolView === "mine") && ( <>
@@ -5645,7 +5638,9 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: prepackageAcceptanceItems.length === 0 ? (
{visiblePoolItems.length - ? "任务关联数据缺失,请联系管理员核查。" + ? reviewOnly && !isManager + ? "任务池仍在加载,请稍候;若长时间无变化请刷新页面。" + : "任务关联数据缺失,请联系管理员核查。" : taskSearch || taskStatusFilter !== "all" ? "没有符合筛选条件的任务" : !isManager && !requestedRunId && taskPoolView === "available" diff --git a/src/services/api/annotation-operations.ts b/src/services/api/annotation-operations.ts index 6578a873..57f34e29 100644 --- a/src/services/api/annotation-operations.ts +++ b/src/services/api/annotation-operations.ts @@ -18,10 +18,14 @@ import { apiRequest } from "./client"; import { decodeAnnotationTimeline } from "../../lib/annotation-timeline-wire.js"; import { normalizeAnnotationWorkspace, normalizeAnnotationTaskDetail } from "../../lib/annotation-workspace.js"; -const query = (values: Record) => { +const query = (values: Record) => { const params = new URLSearchParams(); for (const [key, value] of Object.entries(values)) { - if (value !== undefined && value !== "") params.set(key, String(value)); + if (Array.isArray(value)) { + if (value.length) params.set(key, value.join(",")); + } else if (value !== undefined && value !== "") { + params.set(key, String(value)); + } } const encoded = params.toString(); return encoded ? `?${encoded}` : ""; @@ -129,8 +133,13 @@ export const annotationOperationsApi = { artifactId?: string; limit?: number; cursor?: string; + /** Explicit task-ID set for pool-item joins (comma-joined). */ + ids?: string[]; } = {}, - ) => apiRequest<{ items: AnnotationTaskRecord[]; nextCursor?: string; hasMore?: boolean }>(`/api/plugins/annotation-qa/tasks${query(filters)}`), + ) => + apiRequest<{ items: AnnotationTaskRecord[]; nextCursor?: string; hasMore?: boolean }>( + `/api/plugins/annotation-qa/tasks${query(filters)}`, + ), getTask: (id: string, signal?: AbortSignal, history = false) => apiRequest(`/api/plugins/annotation-qa/tasks/${id}${history ? "?view=history" : ""}`, { signal, diff --git a/src/services/api/human-loop.ts b/src/services/api/human-loop.ts index 9b1f420b..6ce9965c 100644 --- a/src/services/api/human-loop.ts +++ b/src/services/api/human-loop.ts @@ -9,6 +9,8 @@ type HumanItemFilters = { workflowId?: string; runId?: string; stageId?: string; + /** Multi-stage pushdown (comma-joined server-side) for role pools. */ + stageIds?: string[]; status?: HumanItemStatus; pool?: "available" | "mine" | "all" | "reviewed"; /** Server default is 500 (max 1000); pass explicitly for larger pools. */ @@ -17,10 +19,14 @@ type HumanItemFilters = { cursor?: string; }; -const queryString = (filters: Record) => { +const queryString = (filters: Record) => { const params = new URLSearchParams(); Object.entries(filters).forEach(([key, value]) => { - if (value !== undefined && value !== "") params.set(key, String(value)); + if (Array.isArray(value)) { + if (value.length) params.set(key, value.join(",")); + } else if (value !== undefined && value !== "") { + params.set(key, String(value)); + } }); const query = params.toString(); return query ? `?${query}` : ""; -- 2.47.2 From bc58adb1a691b780e88f6d906fcd1e5547c1b457 Mon Sep 17 00:00:00 2001 From: d-robotics Date: Mon, 12 Oct 2026 10:01:43 +0530 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20Restore=20review/acceptance?= =?UTF-8?q?=20random-claim=20entries=20and=20fix=20movi=20playhead=20updat?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Production report: for all three roles the video progress bar stayed frozen during playback and only jumped to the playhead position on pause, and the reviewer/acceptance random-claim buttons were gone. Root cause (progress bar): the vendored movi-player 0.4.1 dist re-dispatches play/pause/ended/playing/canplay/loadedmetadata/durationchange/progress on the host element but NOT timeupdate/seeking/seeked/waiting from its shadow
)} + {reviewOnly && !isManager && !acceptanceWorkspace && ( +
+

从当前项目可领取池随机领取一条并直接进入审核。

+ + {randomClaimNotice && ( +

+ {userErrorMessage(randomClaimNotice)} +

+ )} +
+ )} + {reviewOnly && workspaceMode === "acceptance" && taskPoolView === "available" && ( +
+

从当前项目可验收任务中随机领取一条。

+ + {randomClaimNotice && ( +

+ {userErrorMessage(randomClaimNotice)} +

+ )} +
+ )} {(!blindAnnotator || taskPoolView === "mine") && ( <>
-- 2.47.2 From fc52ae9e3d9e6a1149b379e55daeefc69b5d89b1 Mon Sep 17 00:00:00 2001 From: d-robotics Date: Mon, 12 Oct 2026 11:17:51 +0530 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20Make=20review/acceptance=20r?= =?UTF-8?q?andom-claim=20entries=20always=20usable=20(all-tabs,=20all-proj?= =?UTF-8?q?ects)=20and=20rename=20to=20=E9=9A=8F=E6=9C=BA=E9=A2=86?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/AnnotationOperations.tsx | 37 ++++++++++++------- tests/frontend/annotation-task-pools.test.mjs | 3 +- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/pages/AnnotationOperations.tsx b/src/pages/AnnotationOperations.tsx index 8410f417..7e318f61 100644 --- a/src/pages/AnnotationOperations.tsx +++ b/src/pages/AnnotationOperations.tsx @@ -1767,6 +1767,16 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: () => poolItems.filter((item) => matchesPoolFilters(item, taskPoolView)), [poolItems, taskPoolView, matchesPoolFilters], ); + // Random claim draws from the available pool regardless of the active pool + // tab, so the entry stays usable from "mine"/"reviewed" views too. + const availableClaimableItems = useMemo( + () => humanPools.available.filter((item) => humanItemVisibleInMode(item, workspaceMode, "available")), + [humanPools.available, workspaceMode], + ); + const claimablePrepackageAcceptanceItems = useMemo( + () => availableClaimableItems.filter((item) => item.currentStageId === "prepackage_acceptance"), + [availableClaimableItems], + ); const prepackageAcceptanceItems = useMemo( () => visiblePoolItems.filter((item) => item.currentStageId === "prepackage_acceptance"), [visiblePoolItems], @@ -3967,8 +3977,8 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: }; const randomClaimAcceptanceTask = async () => { - if (randomClaimBusy || saving || taskPoolView === "reviewed") return; - const candidates = prepackageAcceptanceItems.filter( + if (randomClaimBusy || saving) return; + const candidates = claimablePrepackageAcceptanceItems.filter( (item) => !item.assignedUserId && ["ready", "submitted", "rework"].includes(item.status) && canCurrentUserClaimItem(item), ); @@ -3995,15 +4005,15 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: }; const randomReviewClaimTask = async () => { - if (isManager || !reviewOnly || acceptanceWorkspace || saving || loading || !projectId) return; + if (isManager || !reviewOnly || acceptanceWorkspace || saving || loading) return; if (!reviewDraftGuardRef.current()) return; - const candidates = visiblePoolItems.filter( + const candidates = availableClaimableItems.filter( (item) => !item.assignedUserId && ["ready", "rework", "submitted"].includes(item.status) && canCurrentUserClaimItem(item), ); const candidate = candidates[Math.floor(Math.random() * candidates.length)]; if (!candidate) { - setRandomClaimNotice("当前项目暂无可领取的审核任务。"); + setRandomClaimNotice("当前暂无可领取的审核任务。"); return; } setRandomClaimBusy(true); @@ -4015,7 +4025,8 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: setSelectedAnnotationTaskId(claimed.legacyTaskId || ""); setExpandedDeliveryPackageId(""); const next = new URLSearchParams(searchParams); - next.set("projectId", projectId); + const claimProjectId = claimed.projectId || candidate.projectId || projectId; + if (claimProjectId) next.set("projectId", claimProjectId); next.set("taskId", claimed.legacyTaskId || ""); next.delete("sliceId"); next.delete("eventId"); @@ -5433,14 +5444,14 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: )} {reviewOnly && !isManager && !acceptanceWorkspace && (
-

从当前项目可领取池随机领取一条并直接进入审核。

+

从可领取池随机领取一条并直接进入审核,支持全部项目。

{randomClaimNotice && (

@@ -5449,16 +5460,16 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: )}

)} - {reviewOnly && workspaceMode === "acceptance" && taskPoolView === "available" && ( + {reviewOnly && workspaceMode === "acceptance" && !isManager && (
-

从当前项目可验收任务中随机领取一条。

+

随机领取一条最终验收任务,支持全部项目。

{randomClaimNotice && (

diff --git a/tests/frontend/annotation-task-pools.test.mjs b/tests/frontend/annotation-task-pools.test.mjs index 2e1526de..71133e13 100644 --- a/tests/frontend/annotation-task-pools.test.mjs +++ b/tests/frontend/annotation-task-pools.test.mjs @@ -16,7 +16,8 @@ test("annotation workbench separates available, mine, and administrator task poo assert.match(source, /我的任务/); assert.match(source, /全部任务/); assert.match(source, /data-testid="acceptance-random-claim"/); - assert.match(source, /随机领取验收任务/); + assert.match(source, /\{randomClaimBusy \? "正在领取…" : "随机领取"\}/); + assert.match(source, /claimablePrepackageAcceptanceItems/); assert.match(source, /管理员任务改派/); assert.match(source, /humanLoopApi\.assign/); assert.match(source, /problemSliceIds/); -- 2.47.2