From 2ae60e097707eabde1773a426504017cb4ea1653 Mon Sep 17 00:00:00 2001 From: d-robotics Date: Wed, 18 Nov 2026 16:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Resume=20confirmed=20rework=20af?= =?UTF-8?q?ter=20reassignment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/annotation-workbench.js | 16 +++++++++ src/pages/AnnotationOperations.tsx | 29 ++++++--------- .../annotation-history-recovery.test.mjs | 35 +++++++++++++++++++ 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/lib/annotation-workbench.js b/src/lib/annotation-workbench.js index 9cbdfb69..f2894ba8 100644 --- a/src/lib/annotation-workbench.js +++ b/src/lib/annotation-workbench.js @@ -509,6 +509,22 @@ export function annotationRecoverableWorkspaceFromHumanItem(item) { return annotationSavedDraftFromHumanItem(item) || annotationDraftFromHumanItem(item); } +export function annotationWorkspaceForAssignee(item, userId) { + if (!userId || item?.assignedUserId !== userId || !["claimed", "in_progress"].includes(item.status)) return null; + const workspace = annotationRecoverableWorkspaceFromHumanItem(item); + if (workspace?.userId === userId) return workspace; + // A confirmed rework workspace follows the task when the assignee changes. + // The historical fallback to annotationDraft still requires the draft owner. + if ( + item.currentStageId === "annotation_combined" && + item.reviewRound > 0 && + item.subject?.payload?.annotationWorkspace != null + ) { + return workspace; + } + return null; +} + export function validateSliceFullCoverage(slice, segments = [], tolerance = 0.005) { if (!slice) return { complete: false, reason: "slice_missing" }; const sliceSegments = annotationSegmentsForSlice(slice, segments).sort( diff --git a/src/pages/AnnotationOperations.tsx b/src/pages/AnnotationOperations.tsx index 78b82ab8..83ad9aa0 100644 --- a/src/pages/AnnotationOperations.tsx +++ b/src/pages/AnnotationOperations.tsx @@ -156,7 +156,7 @@ import { } from "../lib/annotation-operations.js"; import { annotationDraftFromHumanItem, - annotationRecoverableWorkspaceFromHumanItem, + annotationWorkspaceForAssignee, annotationOrphanSegments, applySliceStatuses, deriveSliceStatuses, @@ -1848,37 +1848,30 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: next.humanItem.version < detailRef.current.humanItem.version ) return; - const storedDraft = annotationRecoverableWorkspaceFromHumanItem(next.humanItem); + const savedWorkspace = annotationWorkspaceForAssignee(next.humanItem, currentUser?.id); const discardedWorkspace = Boolean( (next.humanItem?.subject?.payload?.sliceWorkflow as { discardedWorkspace?: boolean } | undefined) ?.discardedWorkspace, ); - const restoreDraft = Boolean( - storedDraft && - storedDraft.userId === currentUser?.id && - next.humanItem?.assignedUserId === currentUser?.id && - ["claimed", "in_progress"].includes(next.humanItem.status), - ); - let nextAnnotations = restoreDraft - ? storedDraft.segments + let nextAnnotations = savedWorkspace + ? savedWorkspace.segments : discardedWorkspace ? [] : humanEditableAnnotationSegments(next.revisions); const nextSlices = initialCaptureSlices( next.task, discardedWorkspace ? [] : next.sliceRevisions, - restoreDraft ? storedDraft.sliceSegments : undefined, + savedWorkspace?.sliceSegments, ).map((slice) => ({ ...slice, name: slice.deliveryDisposition === "discard" ? "" : slice.name?.trim() || "", ...(next.task.templateVersion >= 6 ? { taskLabelId: undefined, taskLabel: undefined } : {}), })); - const nextOperations = restoreDraft ? storedDraft.operations : []; - let nextStatuses = deriveSliceStatuses( - nextSlices, - nextAnnotations, - restoreDraft ? storedDraft.statuses : {}, - ) as Record>; + const nextOperations = savedWorkspace?.operations ?? []; + let nextStatuses = deriveSliceStatuses(nextSlices, nextAnnotations, savedWorkspace?.statuses ?? {}) as Record< + string, + NonNullable + >; const sliceWorkflow = next.humanItem?.subject?.payload?.sliceWorkflow as | { status?: string; phase?: string; error?: string } | undefined; @@ -1964,7 +1957,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: void loadFrameTimeline( next.task, nextSlices, - !restoreDraft && + !savedWorkspace && !next.sliceRevisions.some( (revision) => revision.segments?.length && !(revision.revision === 0 && revision.authorUserId === "system"), diff --git a/tests/frontend/annotation-history-recovery.test.mjs b/tests/frontend/annotation-history-recovery.test.mjs index 5993d01e..7dd83e65 100644 --- a/tests/frontend/annotation-history-recovery.test.mjs +++ b/tests/frontend/annotation-history-recovery.test.mjs @@ -31,6 +31,41 @@ test("valid newer autosave restores without replacing confirmed baseline", () => draft.savedAt = "2026-10-15T01:00:00Z"; assert.equal(workbench.annotationSavedDraftFromHumanItem(item), null); }); + +test("the current rework assignee resumes confirmed progress from the former assignee", () => { + const annotationWorkspace = { + sliceSegments: [{ id: "merged", start: 0, end: 3 }], + segments: [{ id: "a", start: 0, end: 3, description: "confirmed rework" }], + userId: "former", + confirmedAt: "2026-10-16T01:00:00Z", + }; + const annotationDraft = { + ...annotationWorkspace, + segments: [{ id: "a", start: 0, end: 3, description: "private draft" }], + savedAt: "2026-10-16T02:00:00Z", + }; + const item = { + assignedUserId: "current", + currentStageId: "annotation_combined", + status: "claimed", + reviewRound: 1, + subject: { payload: { annotationWorkspace, annotationDraft } }, + }; + const restored = workbench.annotationWorkspaceForAssignee(item, "current"); + assert.deepEqual(restored.sliceSegments, annotationWorkspace.sliceSegments); + assert.deepEqual(restored.segments, annotationWorkspace.segments); + assert.equal(restored.userId, "former"); + assert.equal(workbench.annotationWorkspaceForAssignee(item, "former"), null); + assert.equal(workbench.annotationWorkspaceForAssignee({ ...item, reviewRound: 0 }, "current"), null); + assert.equal(workbench.annotationWorkspaceForAssignee({ ...item, status: "ready" }, "current"), null); + assert.equal( + workbench.annotationWorkspaceForAssignee({ ...item, subject: { payload: { annotationDraft } } }, "current"), + null, + ); + annotationDraft.userId = "current"; + assert.equal(workbench.annotationWorkspaceForAssignee(item, "current").segments[0].description, "private draft"); +}); + test("semantic reconciliation tolerates compressed proof but still detects content changes", () => { const original = { sliceSegments: [{ id: "a", start: 0, end: 1 }], -- 2.47.2