Merge pull request 'fix: server-authoritative review claim eligibility + dev movi loader (round12)' (#42) from release/fanyu into dev

This commit is contained in:
zhanghongming 2026-10-12 19:22:02 +08:00
commit 5b58c36f41
5 changed files with 82 additions and 18 deletions

View File

@ -391,7 +391,14 @@ func (server *server) handleHumanItemsList(writer http.ResponseWriter, request *
continue
}
}
if principal != nil && principal.User.Role == domain.UserRoleAcceptanceReviewer {
// Server-side claim eligibility is authoritative for both review
// roles. Quality reviewers previously relied on a client-side
// membership guess in the project-scoped workspace; when the member
// fan-out is skipped or its load fails, that guess silently emptied
// the random-claim candidates while the pool count stayed non-zero
// (可见可领取数量却提示无可领取任务). Annotators keep the blind-pool
// contract and never receive candidate-level flags.
if principal != nil && (principal.User.Role == domain.UserRoleAcceptanceReviewer || principal.User.Role == domain.UserRoleQualityReviewer) {
claimable := item.AssignedUserID == "" && (item.Status == domain.HumanItemReady || item.Status == domain.HumanItemRework || item.Status == domain.HumanItemSubmitted) && server.canClaimHumanItem(request.Context(), request, item, annotationRoleForHumanStage(stage))
item.CanClaim = &claimable
}
@ -860,14 +867,19 @@ func (server *server) canClaimHumanItem(ctx context.Context, request *http.Reque
if err != nil {
return false
}
// Resolve the batch through the request-scoped list-read cache: inside a
// pool listing the batches are bulk-prefetched, so per-item claim checks
// must not fall back to one store read per item (N+1 permission reads).
batch, batchErr := server.humanBatchForListRead(ctx, item.BatchID)
if batchErr != nil || batch == nil {
batch = nil
}
profile := item.ProcessingProfile
if profile == "" {
if batch, e := server.store.GetHumanBatch(ctx, item.BatchID); e == nil && batch != nil && batch.ProcessingProfile == domain.ProcessingProfileRawHuman && domain.IsFanyuV58ThreeRoleHumanLoop(batch.Stages) {
profile = domain.ProcessingProfileRawHuman
}
if profile == "" && batch != nil && batch.ProcessingProfile == domain.ProcessingProfileRawHuman && domain.IsFanyuV58ThreeRoleHumanLoop(batch.Stages) {
profile = domain.ProcessingProfileRawHuman
}
legacy := domain.AnnotationTaskRecord{ID: item.LegacyTaskID, ProjectID: item.ProjectID, SupplierID: item.SupplierID, ProcessingScope: item.ProcessingScope, ProcessingProfile: profile, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID}
if batch, e := server.store.GetHumanBatch(ctx, item.BatchID); e == nil && batch != nil {
if batch != nil {
legacy.SupplierPool = batch.ProcessingProfile == domain.ProcessingProfileRawHuman && domain.IsFanyuV58ThreeRoleHumanLoop(batch.Stages)
}
legacy.SupplierPoolClosed = item.Status == domain.HumanItemAccepted || item.Status == domain.HumanItemRejected || item.Status == domain.HumanItemCancelled

View File

@ -43,6 +43,18 @@ func TestReviewerPoolSingleTaskClaim(t *testing.T) {
fmt.Printf("pool item: id=%s stage=%s status=%s version=%d canClaim=%v\n",
poolItem.ID, poolItem.CurrentStageID, poolItem.Status, poolItem.Version, poolItem.CanClaim)
// The pool must carry authoritative claim eligibility for quality
// reviewers too (not only acceptance reviewers): the project-scoped
// workspace skips the member fan-out, so a client-side membership guess
// can go stale and empty the random-claim candidates while the pool
// count stays non-zero.
if poolItem.CanClaim == nil || !*poolItem.CanClaim {
t.Fatalf("expected canClaim=true for quality reviewer pool item, got %v", poolItem.CanClaim)
}
if !jsonContains(list.Body.String(), `"canClaim":true`) {
t.Fatalf("canClaim flag missing from serialized pool payload: %s", list.Body.String())
}
// Reviewer claims that single item.
claim := f.request(http.MethodPost, "/api/human-items/"+poolItem.ID+"/claim", f.reviewer, map[string]any{"version": poolItem.Version})
if claim.Code != 200 {

View File

@ -19,7 +19,16 @@ const MOVI_BASE = `/vendor/movi-player-${MOVI_VERSION}`;
// browsers would otherwise keep the immutable year-long cached copy and never
// receive the patch. Current marker: the 2026-10-12 rate-cap 2→4 patch
// (getMaxAllowedRate, see the vendor README).
export const MOVI_ELEMENT_JS_URL = `${MOVI_BASE}/element.slim.js?v=rate-cap-4-20261012`;
//
// The marker is appended only for the built deployment. Vite's dev server
// resolves public-dir assets by exact path; a query string defeats that
// resolver and trips the transform middleware ("should not be imported from
// source code"), which breaks every page in dev with an error overlay. Dev
// responses carry no immutable cache headers, so the marker buys nothing there.
export const MOVI_ELEMENT_CACHE_BUST = "rate-cap-4-20261012";
export const MOVI_ELEMENT_JS_URL = import.meta.env.DEV
? `${MOVI_BASE}/element.slim.js`
: `${MOVI_BASE}/element.slim.js?v=${MOVI_ELEMENT_CACHE_BUST}`;
export const MOVI_WASM_URL = `${MOVI_BASE}/movi.wasm`;
export type MoviRuntimeMode = "movi" | "native";
@ -73,13 +82,31 @@ export function loadMoviPlayer(): Promise<void> {
}
if (customElements.get("movi-player")) return Promise.resolve();
if (!loadPromise) {
loadPromise = import(/* @vite-ignore */ MOVI_ELEMENT_JS_URL)
.then(() => undefined)
.catch((error) => {
// Reset so a later mount can retry (e.g. transient network failure).
loadPromise = null;
throw error;
});
loadPromise = (
import.meta.env.DEV
? new Promise<void>((resolve, reject) => {
// Vite's dev server refuses to serve /public assets through the
// module pipeline (`?import` → "should not be imported from source
// code"), which hard-blocks the whole page with an error overlay.
// A module script tag fetches the same static file outside that
// pipeline; dev responses carry no immutable cache headers, so the
// bust marker is unnecessary there.
const script = document.createElement("script");
script.type = "module";
script.src = MOVI_ELEMENT_JS_URL;
script.onload = () => resolve();
script.onerror = () => {
script.remove();
reject(new Error(`movi element load failed: ${script.src}`));
};
document.head.appendChild(script);
})
: import(/* @vite-ignore */ MOVI_ELEMENT_JS_URL).then(() => undefined)
).catch((error) => {
// Reset so a later mount can retry (e.g. transient network failure).
loadPromise = null;
throw error;
});
}
return loadPromise;
}

View File

@ -3983,7 +3983,11 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
!item.assignedUserId && ["ready", "submitted", "rework"].includes(item.status) && canCurrentUserClaimItem(item),
);
if (!candidates.length) {
setRandomClaimNotice("当前没有可领取的最终验收任务。");
setRandomClaimNotice(
claimablePrepackageAcceptanceItems.length
? `可领取池中有 ${claimablePrepackageAcceptanceItems.length} 条验收任务,但当前账号在其项目/供应商下没有领取权限,请联系管理员核对配置。`
: "当前没有可领取的最终验收任务。",
);
return;
}
const item = candidates[Math.floor(Math.random() * candidates.length)];
@ -4013,7 +4017,11 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
);
const candidate = candidates[Math.floor(Math.random() * candidates.length)];
if (!candidate) {
setRandomClaimNotice("当前暂无可领取的审核任务。");
setRandomClaimNotice(
availableClaimableItems.length
? `可领取池中有 ${availableClaimableItems.length} 条审核任务,但当前账号在其项目/供应商下没有领取权限,请联系管理员核对配置。`
: "当前暂无可领取的审核任务。",
);
return;
}
setRandomClaimBusy(true);

View File

@ -38,8 +38,13 @@ test("module declares vendored version, asset paths, and endpoint", () => {
assert.match(moduleSource, /MOVI_VERSION = "0\.4\.1"/);
assert.match(moduleSource, /element\.slim\.js/);
// The vendored dist is served immutable for a year, so every local patch to
// element.slim.js must ship with a bumped ?v= marker (cache-busting contract).
assert.match(moduleSource, /element\.slim\.js\?v=rate-cap-4-20261012/);
// element.slim.js must ship with a bumped ?v= marker (cache-busting
// contract). The marker lives in MOVI_ELEMENT_CACHE_BUST and is appended to
// the built-deployment URL only; Vite dev must keep the query-less path
// (public-dir assets cannot go through the dev module pipeline).
assert.match(moduleSource, /MOVI_ELEMENT_CACHE_BUST = "rate-cap-4-20261012"/);
assert.match(moduleSource, /`\$\{MOVI_BASE\}\/element\.slim\.js\?v=\$\{MOVI_ELEMENT_CACHE_BUST\}`/);
assert.match(moduleSource, /import\.meta\.env\.DEV/);
assert.match(moduleSource, /movi\.wasm/);
assert.match(moduleSource, /\/api\/client\/movi-stats/);
assert.match(moduleSource, /droboticflow\.movi\.force/);