diff --git a/.scratch/production-quality-dashboard/responsiveness.md b/.scratch/production-quality-dashboard/responsiveness.md new file mode 100644 index 00000000..394545e4 --- /dev/null +++ b/.scratch/production-quality-dashboard/responsiveness.md @@ -0,0 +1,62 @@ +# Responsiveness after the 50 Mbps upgrade + +Status: in progress; first local improvement verified, production capacity not accepted. + +Continue the user's current dashboard work on `codex/production-quality-dashboard`, starting at `6969411b`. The freshness check includes latest fetched `origin/dev` and the live API/annotation processor `005eb934`; the new dashboard is not deployed. Preserve the existing preview on ports 5197/3037. No production data/configuration/index change, push, PR or deployment is part of this increment. + +## Observed baseline + +Read-only production inspection on October 30: four API replicas, each requesting 1 CPU/2 GiB and limited to 2 CPU/4 GiB. An instantaneous sample showed 20–148 millicores and 244–643 MiB per API, which is not evidence of peak capacity or throttling. Four validator replicas each request 6 CPU/4 GiB, limited to 8 CPU/8 GiB; observed active validators used about 1.3–1.7 CPU. Do not infer a validator queue or need for expansion from CPU alone. + +Across bounded 15-minute API log tails, 312 records exceeded the one-second slow-log threshold. Selected successful slow samples: + +| Request | Samples | Median of slow samples | Maximum | +| --- | ---: | ---: | ---: | +| Annotation claim count | 49 | 15.49 s | 23.86 s | +| Human-item lists | 26 | 10.32 s | 16.68 s | +| Random claims | 24 | 6.47 s | 10.72 s | +| Project metadata subroutes | 60 | 2.78 s | 4.30 s | +| Workforce dashboard | 2 | 7.80 s | 7.80 s | + +Five claim-count slow records returned 500. This sample excludes fast requests and cannot yield overall p95/error rate. Long 206 media responses measure streaming duration, not necessarily time to first byte. Identifiers, bodies, query strings and credentials are omitted. + +A later single existing-test-account HTTP count read returned 200 with first byte 52 ms / total 54 ms. Its project/data scope and load differ from the slow-log population; it confirms that the endpoint is not uniformly slow, not that the 15-second cases are resolved. + +Local Mongo checks on the current code: the sparse 1,200-batch fixture examined one candidate and one batch (~9 ms); 12,000 unclaimed tasks counted in ~189 ms. These do not reproduce production's 15-second waits, so a specific database/lock/network root cause remains unproven. No query rewrite, index hint, permission cache or resource increase is justified by these checks alone. + +## Completed increment + +- Project refresh/scope changes cancel obsolete pool, count, task-join and supporting metadata GETs for annotation, quality, acceptance and admin views. Successful review claims also invalidate pending pool reads. A cancelled read cannot publish a count, page or cursor, enter a legacy fallback, or start another task-join batch. +- Pagination has a separate cancellation controller: loading more annotation tasks must not cancel the initial membership/workflow reads or pending count. Keep server eligibility, complete stage merging, row order and pagination rules intact. Save, claim, decision and continuation writes retain their existing recovery behavior. +- The random-claim handler checks the existing directed-rework priority before reading the public candidate inventory. Account/project/supplier checks and receipt replay still happen first; returned task identity, version and ownership do not change. A regression first returned 500 when public inventory was unavailable, then returned the owned rework without querying that inventory. Existing random-claim/replay/concurrency/count/permission tests pass. This only removes unnecessary waiting for already-directed rework, not ordinary new-task claim latency. +- Existing adapters accept an optional cancellation signal; existing callers remain valid. No API response, persisted schema or migration change. No additional page copy or visual elements. +- Read-mix tooling supports explicit annotation/quality/acceptance actor counts (one administrator, maximum 250 total), optionally adds exact claim-count reads every 12 seconds, and checks every actor/endpoint schedule. Default 81-user runs and analysis of old evidence remain supported. Counts are included in result equivalence; missing requests or falsely labelled actor counts fail validation. + +Verification: + +- Three initial cancellation regressions failed on the original implementation, then passed. Targeted loading/pagination regression covers stale scope, refresh, permission errors, cursor ownership, metadata failure and preserving pending metadata during pagination. +- Real browser + isolated local HTTP endpoints: quality cancelled 3 requests, acceptance 6, annotation 5, admin 1; all connections closed, no follow-up reads or stale updates, no page errors. This is a network-cancellation test, not a browser capacity test. +- 121-user read smoke: 90 annotation, 18 quality, 12 acceptance, 1 admin; 5 s warmup + 60 s scheduled measurement; 100 historical items per reviewer, 256 KiB synthetic run payload. All 2,885 scheduled requests completed, zero HTTP errors and zero measured Mongo writes. Slowest endpoint p95 836.6 ms; claim count p95 513.0 ms, buffer p95 561.1 ms. Single-process local handler timing excludes authentication/network/ingress. It does not measure this frontend cancellation change's production speed benefit. +- Existing shared snapshot scale test: 5,000 parts/25,000 work facts, four independent API handlers, cold 223 ms, warm p95 21 ms, one source build and one stored snapshot slot. This is the legacy annotation-output endpoint and sequential warm reads, not the new dashboard's concurrent acceptance. +- Added a warm new-cohort-dashboard burst against the same isolated 5,000-part dataset: 121 concurrent wide-scope administrator reads over four independent handlers, p95 424 ms / max 443 ms. Every response retained the same snapshot ID and 5,000 submitted parts; no handler rebuilt raw history. This stresses report reads only, not distinct worker sessions, cold rebuilding or mixed editing/media load. +- Evidence: `local-data/test-results/responsiveness-121/` (smoke report/resources, browser report, dashboard-scale log, build and full gate results). Frontend gate: 13 known failures, no new failures. Go gate: 68 known failures, no new failures. Baselines are unchanged. +- Type/architecture checks, web build and changed-file formatting pass. Global formatting retains three inherited failures: `ReviewHistorySummary.tsx`, `useAnnotationOutputData.ts`, `useReviewContinuation.ts`; they are unchanged. +- A repeated frontend gate hung in the unchanged `devboot` test while closing Vite with unread asset responses. The owned test child was terminated and that failed invocation retained. The test now consumes both response bodies before closing; its focused run completed in 1.4 s. No failure was added to the known-failure baseline; the complete rerun (`frontend-gate-complete`) passed with only the 13 known failures. + +## Remaining work, ordered by impact + +1. **Production query/claim waiting.** Capture bounded per-stage timings for authority lookup, candidate query, batch metadata, display enrichment, lock acquisition and response encoding on actual slow routes. Compare Mongo execution plans and command counts on representative local fixtures; separate server execution from diagnostic tunnel transfer time. Claim-count 500 responses need a classified error cause before considering the issue fixed. Index changes require their own production plan/approval. +2. **Start-work critical path.** Measure page entry to usable pool, claim to editable task, first video frame and next-task handoff. Check hidden/obsolete history loads and eager all-stage pagination before optimizing. Any summary response is explicit and version-compatible; do not lose timestamps, source identity, server eligibility or task versions. Never hide tasks or turn errors into empty/zero data for speed. +3. **Reporting.** Exercise the new cohort dashboard at production-sized histories, including cold rebuild, expiry, concurrent roles/filters, permission revocation, restart and export. Preserve cohort semantics and shared-snapshot time consistency; avoid refreshing source history on every page request. Existing 120-second refresh is not zero-delay live reporting. +4. **Editing and processing.** Include autosave, version conflict, renewal, claim idempotency, submission, rework, reviewer decisions, reconnect and validator backlog/recovery in an isolated real HTTP/Mongo workload. Saving/claiming must retain confirmed outcomes and unknown-result recovery; lowering timeouts or cancelling writes is not a performance shortcut. +5. **Capacity acceptance.** Start with the provisional 90/18/12 + 1 mix, add a 150-worker burst and simultaneous page entry. Pin dataset/resources/compression and versions. Each final variant needs 5-minute warmup + 30-minute steady state, repeated three times; test cold start/recovery separately. Record p50/p95/p99, errors, actual transferred bytes, Mongo scans/timing, CPU throttling, memory and queue length. Keep a mixed traffic test distinct from focused endpoint tests. + +Working targets: pool/list/report read p95 <= 2 s; warm task metadata entry p95 <= 2 s; save/decision acknowledgement p95 <= 2 s. Improve previously slow pool requests by at least 50% under identical conditions. These are targets, not current guarantees; media startup and asynchronous processing completion require separate measured budgets. Correct ownership, current permissions, complete rows, drafts and final decisions are mandatory throughout. + +## Bandwidth and resources + +50 Mbps is theoretically 6.25 MB/s before overhead, shared by all traffic using that egress. At 121 equal active consumers that is only ~0.413 Mbps each. The 60-second synthetic read schedule compressed to 126,489,366 bytes (~16.9 Mbps per scheduled minute); deliberately large synthetic task payloads mean this is **not** a production traffic forecast. It does identify full pool payloads as a candidate for measured response-summary work. + +The existing preview component already prefers object-storage signed redirects and deliberately avoids a browser-transcode fallback. Measure actual video bitrate, simultaneous streams, seek/range behavior and any other content routes independently; establish which flows consume this IP's egress instead of assuming all video does. For example, 100 concurrent 1 Mbps streams alone exceed 50 Mbps if all use that egress. Do not certify video capacity from small JSON responses. Reserve operational headroom based on actual sustained/peak measurements. + +Keep current Pod sizes/counts while measuring code changes. Expand only against demonstrated CPU throttling, memory pressure, queue saturation or bandwidth limits, so resource changes do not hide query regressions. Prior 81-user long read tests explicitly recorded `capacity_accepted=false`; neither those tests nor this 121-user smoke grants whole-system acceptance. Production load/mutation tests and deployment remain subject to the user's specific authorization. diff --git a/.scratch/production-quality-dashboard/work.md b/.scratch/production-quality-dashboard/work.md index 3041ffe0..3ce315e2 100644 --- a/.scratch/production-quality-dashboard/work.md +++ b/.scratch/production-quality-dashboard/work.md @@ -3,6 +3,6 @@ Goal: Show latest outcomes for part tasks selected by first submission date, with role quality metrics and a clean shared dashboard. Agent: Codex, current dashboard conversation Base: codex/poll-pool-optimization @ b2324c19 (user explicitly approved this unmerged base) -Scope: workforce statistics, output snapshots/API, rework misreport handling, dashboard components, regression tests and contracts +Scope: workforce statistics, output snapshots/API, rework misreport handling, dashboard components, regression tests and contracts; continued responsiveness work for dashboard/pool entry, cancellation of obsolete reads, directed-rework query ordering, and configurable 121-user isolated read validation Out of scope: deployment, production data mutation, claim restrictions, sampling workflow, annotation reset feature Risk: new reporting semantics and reviewer handling permissions; keep legacy report behavior compatible and customer review history unchanged. diff --git a/internal/api/annotation_output_snapshot_scale_test.go b/internal/api/annotation_output_snapshot_scale_test.go index f0eee800..1dc49190 100644 --- a/internal/api/annotation_output_snapshot_scale_test.go +++ b/internal/api/annotation_output_snapshot_scale_test.go @@ -10,8 +10,10 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" + "net/http" "os" "sort" + "sync" "testing" "time" ) @@ -117,4 +119,70 @@ func TestAnnotationOutputSnapshotScale(t *testing.T) { report := map[string]any{"environment": "local isolated Mongo; synthetic metadata; no production performance claim", "parts": n, "historyEvents": n * 5, "apiInstances": 4, "warmRequests": len(samples), "coldMs": coldMS, "warmP50Ms": samples[len(samples)/2], "warmP95Ms": p95, "sourceBuilds": wrapped.loads.Load(), "storedSlots": count, "compressedBytes": len(slot.Data)} encoded, _ := json.Marshal(report) t.Log(string(encoded)) + t.Run("production-quality-concurrent-warm-reads", func(t *testing.T) { + url := fmt.Sprintf("/api/dashboard/production-quality?from=%s&to=%s&timeZone=UTC", time.Now().UTC().AddDate(0, 0, -1).Format("2006-01-02"), time.Now().UTC().AddDate(0, 0, 1).Format("2006-01-02")) + ready := outputReady(t, f, url, f.admin) + var initial struct { + Snapshot struct { + ID string `json:"id"` + } `json:"snapshot"` + } + if err := json.Unmarshal(ready.Body.Bytes(), &initial); err != nil || initial.Snapshot.ID == "" { + t.Fatal("new report snapshot not ready") + } + url += "&snapshotId=" + initial.Snapshot.ID + readers := make([]*countingOutputStore, 4) + handlers := make([]http.Handler, len(readers)) + for i := range readers { + readers[i] = &countingOutputStore{Store: store.NewMongoStore(db)} + handlers[i] = NewHandler(readers[i], nil) + } + const burst = 121 + latencies := make(chan int64, burst) + start := make(chan struct{}) + var wg sync.WaitGroup + for i := 0; i < burst; i++ { + wg.Add(1) + go func(i int) { + defer wg.Done() + local := f + local.handler = handlers[i%len(handlers)] + <-start + at := time.Now() + r := local.request("GET", url, local.admin, nil) + latencies <- time.Since(at).Milliseconds() + var result struct { + Totals struct { + Submitted struct { + Count int `json:"count"` + } `json:"submitted"` + } `json:"totals"` + Snapshot struct { + ID string `json:"id"` + } `json:"snapshot"` + } + if err := json.Unmarshal(r.Body.Bytes(), &result); err != nil || r.Code != 200 || result.Totals.Submitted.Count != n || result.Snapshot.ID != initial.Snapshot.ID { + t.Errorf("cohort read code=%d parts=%d snapshotMatches=%t", r.Code, result.Totals.Submitted.Count, result.Snapshot.ID == initial.Snapshot.ID) + } + }(i) + } + close(start) + wg.Wait() + close(latencies) + samples := make([]int64, 0, burst) + for ms := range latencies { + samples = append(samples, ms) + } + sort.Slice(samples, func(i, j int) bool { return samples[i] < samples[j] }) + for _, reader := range readers { + if reader.loads.Load() != 0 { + t.Error("warm report reloaded source history") + } + } + p95 := samples[(len(samples)*95-1)/100] + t.Logf("local synthetic warm cohort burst: requests=%d apiHandlers=4 parts=%d p95_ms=%d max_ms=%d sourceBuilds=0; not full capacity acceptance", burst, n, p95, samples[len(samples)-1]) + if p95 > 2000 { + t.Errorf("warm concurrent report p95 %dms exceeds 2s target", p95) + } + }) } diff --git a/internal/api/annotation_random_claim.go b/internal/api/annotation_random_claim.go index 20463766..c0d04497 100644 --- a/internal/api/annotation_random_claim.go +++ b/internal/api/annotation_random_claim.go @@ -228,11 +228,6 @@ func (s *server) handleAnnotationRandomClaim(w http.ResponseWriter, r *http.Requ s.renderRandomClaimResult(ctx, w, r, replay.ItemID, true) return } - candidates, e := s.store.ListAnnotationClaimCandidates(ctx, p.User.OrganizationID, project.ID) - if e != nil { - renderError(w, 500, e) - return - } // B03 返工优先(spec §5.4-6,2026-10-12 确认):先清自己的错再领新—— // 定向归属我的返工任务存在时优先原样返回(不改版本、不重复领取)。 // 不设 Limit:列表按 createdAt 倒序分页,老的返工任务会被较新的领取记录 @@ -245,6 +240,11 @@ func (s *server) handleAnnotationRandomClaim(w http.ResponseWriter, r *http.Requ } } } + candidates, e := s.store.ListAnnotationClaimCandidates(ctx, p.User.OrganizationID, project.ID) + if e != nil { + renderError(w, 500, e) + return + } // Shuffle the whole eligible project inventory, not the first UI page. Only // lightweight routing fields were fetched; content is loaded after selection. rand.Shuffle(len(candidates), func(i, j int) { candidates[i], candidates[j] = candidates[j], candidates[i] }) diff --git a/internal/api/poll_pool_load_test.go b/internal/api/poll_pool_load_test.go index a841f534..3f914929 100644 --- a/internal/api/poll_pool_load_test.go +++ b/internal/api/poll_pool_load_test.go @@ -1,6 +1,6 @@ package api -// Local-only read-mix harness. This is NOT the full 81-user capacity acceptance: +// Local-only read-mix harness. This is NOT full concurrent-user capacity acceptance: // it excludes media, editing/submission, continuation writes and ingress shaping. import ( "bytes" @@ -77,6 +77,15 @@ func TestPollPoolReadMixLocal(t *testing.T) { return n } warmup, duration := seconds("POLL_POOL_WARMUP_SECONDS", 5), seconds("POLL_POOL_DURATION_SECONDS", 30) + annotators := seconds("POLL_POOL_ANNOTATORS", 60) + quality := seconds("POLL_POOL_QUALITY_REVIEWERS", 12) + acceptance := seconds("POLL_POOL_ACCEPTANCE_REVIEWERS", 8) + totalActors := annotators + quality + acceptance + 1 + if totalActors > 250 { + t.Fatal("local read mix supports at most 250 actors") + } + claimCounts := os.Getenv("POLL_POOL_CLAIM_COUNTS") == "1" + mode := os.Getenv("POLL_POOL_MODE") if mode == "" { mode = "summary" @@ -171,18 +180,18 @@ func TestPollPoolReadMixLocal(t *testing.T) { must(e) } actors := []pollLoadActor{} - for i := 0; i < 81; i++ { + for i := 0; i < totalActors; i++ { role := domain.UserRoleAnnotator label := "annotation" - if i >= 60 && i < 72 { + if i >= annotators && i < annotators+quality { role = domain.UserRoleQualityReviewer label = "quality" } - if i >= 72 && i < 80 { + if i >= annotators+quality && i < totalActors-1 { role = domain.UserRoleAcceptanceReviewer label = "acceptance" } - if i == 80 { + if i == totalActors-1 { role = domain.UserRoleAdmin label = "admin" } @@ -255,7 +264,11 @@ func TestPollPoolReadMixLocal(t *testing.T) { } for _, p := range projects { for _, s := range suppliers { - for _, stage := range []string{"quality_review", "semantic_review", "acceptance", "prepackage_acceptance"} { + stages := []string{"quality_review", "semantic_review", "acceptance", "prepackage_acceptance"} + if claimCounts { + stages = append(stages, "annotation_combined") + } + for _, stage := range stages { for n := 0; n < 8; n++ { seed(fmt.Sprintf("available-%s-%s-%s-%d", p, s, stage, n), p, s, stage, "", domain.HumanItemReady) } @@ -342,6 +355,7 @@ func TestPollPoolReadMixLocal(t *testing.T) { completedErrors.Add(1) } var body struct { + Count *int `json:"count"` Code string `json:"code"` Error string `json:"error"` Items []struct { @@ -359,12 +373,17 @@ func TestPollPoolReadMixLocal(t *testing.T) { for _, v := range body.Summaries { ids = append(ids, v.ID) } + rowCount := len(ids) + if body.Count != nil { + rowCount = *body.Count + ids = append(ids, fmt.Sprintf("count:%d", *body.Count)) + } sort.Strings(ids) var compressed bytes.Buffer zw := gzip.NewWriter(&compressed) _, _ = zw.Write(response.Body.Bytes()) _ = zw.Close() - sample := pollLoadSample{a.User.ID, key, float64(elapsed.Microseconds()) / 1000, response.Body.Len(), compressed.Len(), len(ids), response.Code, fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(ids, "\n"))))} + sample := pollLoadSample{a.User.ID, key, float64(elapsed.Microseconds()) / 1000, response.Body.Len(), compressed.Len(), rowCount, response.Code, fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(ids, "\n"))))} if response.Code != 200 { class := "unclassified" for _, known := range []string{"context deadline exceeded", "context canceled", "duplicate key", "not found", "conflict", "timeout"} { @@ -396,7 +415,7 @@ func TestPollPoolReadMixLocal(t *testing.T) { } return sample } - paths := func(a pollLoadActor, all bool) map[string]string { + paths := func(a pollLoadActor, all, countCycle bool) map[string]string { scope := "&projectId=" + a.Project scopeName := "project" if all { @@ -408,7 +427,11 @@ func TestPollPoolReadMixLocal(t *testing.T) { if mode == "summary" { path += "&view=summary" } - return map[string]string{"annotation.buffer": path} + result := map[string]string{"annotation.buffer": path} + if claimCounts && countCycle { + result["annotation.claim-count"] = "/api/plugins/annotation-qa/claim-count?projectId=" + a.Project + } + return result } if a.Role == "admin" { return map[string]string{"admin.workforce": "/api/dashboard/workforce?from=2026-10-01T00:00:00Z&to=2026-10-28T00:00:00Z"} @@ -428,7 +451,7 @@ func TestPollPoolReadMixLocal(t *testing.T) { } // Fail before timing if permissions or fixtures accidentally produce empty work. for _, a := range actors { - for key, path := range paths(a, false) { + for key, path := range paths(a, false, true) { result := call(a, key, path, false) if result.Code != 200 { t.Fatalf("preflight %s status=%d", key, result.Code) @@ -461,7 +484,7 @@ func TestPollPoolReadMixLocal(t *testing.T) { default: } var requests sync.WaitGroup - for key, path := range paths(a, cycle%2 == 1) { + for key, path := range paths(a, cycle%2 == 1, cycle%4 == 0) { requests.Add(1) go func(key, path string) { defer requests.Done(); call(a, key, path, record) }(key, path) } @@ -587,7 +610,7 @@ func TestPollPoolReadMixLocal(t *testing.T) { sort.Float64s(lat) metrics[key] = map[string]any{"requests": len(rows), "p95_ms": lat[(len(lat)*95-1)/100], "max_ms": lat[len(lat)-1], "raw_bytes": raw, "gzip_bytes": gz, "min_items": minRows} } - report := map[string]any{"schema": 2, "resource_samples": resourceRows, "process_cpu_seconds": cpuAfter - cpuBefore, "authorization_state": authorizationState, "fixture": "read-mix-v3-released-history", "run_payload_kib": runPayloadKiB, "author_history_per_reviewer": authorHistory, "mode": mode, "revision": os.Getenv("POLL_POOL_REVISION"), "actors": 81, "warmup_seconds": warmup, "scheduled_seconds": duration, "actual_seconds": actual.Seconds(), "errors": failures, "failure_samples": failureSamples, "metrics": metrics, "mongo_breakdown": observations, "mongo_commands": commands.Load(), "mongo_reply_bytes": mongoBytes.Load(), "mongo_command_ms": float64(mongoNS.Load()) / 1e6, "mongo_write_commands": writes.Load(), "go_heap_before": memBefore.HeapAlloc, "go_heap_after": memAfter.HeapAlloc, "go_heap_after_gc": memAfterGC.HeapAlloc, "go_gc_cycles": memAfter.NumGC - memBefore.NumGC, "go_allocated_bytes": memAfter.TotalAlloc - memBefore.TotalAlloc, "limitations": []string{"handler timing excludes ingress/network/authentication", "gzip computed separately with fixed Go default compression", "no continuation renew, media or workflow writes", "synthetic fixture; not capacity acceptance", "CPU covers handler and in-process load harness, not Mongo/Pod throttling", "resource heap includes retained benchmark request samples; not standalone service RSS"}, "samples": samples} + report := map[string]any{"schema": 2, "resource_samples": resourceRows, "process_cpu_seconds": cpuAfter - cpuBefore, "authorization_state": authorizationState, "fixture": "read-mix-v3-released-history", "run_payload_kib": runPayloadKiB, "author_history_per_reviewer": authorHistory, "mode": mode, "revision": os.Getenv("POLL_POOL_REVISION"), "actors": totalActors, "actor_counts": map[string]int{"annotation": annotators, "quality": quality, "acceptance": acceptance, "admin": 1}, "claim_counts": claimCounts, "warmup_seconds": warmup, "scheduled_seconds": duration, "actual_seconds": actual.Seconds(), "errors": failures, "failure_samples": failureSamples, "metrics": metrics, "mongo_breakdown": observations, "mongo_commands": commands.Load(), "mongo_reply_bytes": mongoBytes.Load(), "mongo_command_ms": float64(mongoNS.Load()) / 1e6, "mongo_write_commands": writes.Load(), "go_heap_before": memBefore.HeapAlloc, "go_heap_after": memAfter.HeapAlloc, "go_heap_after_gc": memAfterGC.HeapAlloc, "go_gc_cycles": memAfter.NumGC - memBefore.NumGC, "go_allocated_bytes": memAfter.TotalAlloc - memBefore.TotalAlloc, "limitations": []string{"handler timing excludes ingress/network/authentication", "gzip computed separately with fixed Go default compression", "no continuation renew, media or workflow writes", "synthetic fixture; not capacity acceptance", "CPU covers handler and in-process load harness, not Mongo/Pod throttling", "resource heap includes retained benchmark request samples; not standalone service RSS"}, "samples": samples} encoded, e := json.MarshalIndent(report, "", " ") must(e) must(os.WriteFile(out, encoded, 0600)) diff --git a/internal/api/pool_count_performance_test.go b/internal/api/pool_count_performance_test.go index 60c62b9c..f12669af 100644 --- a/internal/api/pool_count_performance_test.go +++ b/internal/api/pool_count_performance_test.go @@ -55,6 +55,21 @@ func TestPoolPerformanceClaimCountDoesNotMaterializeCandidates(t *testing.T) { } } +func TestDirectedReworkDoesNotWaitForPublicInventory(t *testing.T) { + f := randomClaimFixture(t, 3) + item := f.item + item.ReviewRound = 1 + item.Status = domain.HumanItemRework + if err := f.store.UpsertHumanItem(f.ctx, item); err != nil { + t.Fatal(err) + } + f.handler = NewHandler(&poolCountProbeStore{Store: f.store, rejectCandidateLoad: true}, nil) + got := claimRandom(t, f, "rework-fast-path-0001") + if got.ID != item.ID || got.Version != item.Version || got.AssignedUserID != f.annotator.ID { + t.Fatal("directed rework changed identity, version or ownership") + } +} + func TestPoolPerformanceKeepsLegacyStageExceptionsAndAuthorHistory(t *testing.T) { f := randomClaimFixture(t, 2) batch, err := f.store.GetHumanBatch(f.ctx, f.item.BatchID) diff --git a/scripts/local/analyze-poll-pool-readmix.py b/scripts/local/analyze-poll-pool-readmix.py index e1f70660..a1a4eef8 100644 --- a/scripts/local/analyze-poll-pool-readmix.py +++ b/scripts/local/analyze-poll-pool-readmix.py @@ -22,7 +22,8 @@ def ratio(after, before): def summarize(manifest, reports): rounds = manifest["repetitions"] variants = [v["label"] for v in manifest["variants"] if v["label"] != "baseline"] - result = {"capacity_accepted": False, "duration_complete": manifest["warmup_seconds"] >= 300 and + result = {"capacity_accepted": False, "actor_counts": _readmix.actor_counts(manifest), + "claim_counts": manifest.get("claim_counts", False), "duration_complete": manifest["warmup_seconds"] >= 300 and manifest["duration_seconds"] >= 1800 and rounds >= 3, "limitations": ["handler read workload only; no renew/media/submission/ingress", "CPU includes in-process client and gzip; no Mongo or Pod resource metrics", @@ -47,10 +48,11 @@ def summarize(manifest, reports): for x, y in zip(before, after)] identity = lambda d: {(s["Actor"], s["Key"], s["Hash"], s["Rows"]) for s in d["samples"]} equivalent = all(identity(x) == identity(y) for x, y in zip(before, after)) - expected = 60 * ((manifest["duration_seconds"] + 2) // 3) + 85 * ((manifest["duration_seconds"] + 11) // 12) + schedule = _readmix.expected_schedule(manifest["duration_seconds"], manifest) + expected = sum(schedule.values()) healthy = all(d["errors"] == 0 and d["mongo_write_commands"] == 0 and len(d["samples"]) == expected and all(s["Code"] == 200 for s in d["samples"]) and - Counter((s["Actor"], s["Key"]) for s in d["samples"]) == _readmix.expected_schedule(manifest["duration_seconds"]) for d in before + after) + Counter((s["Actor"], s["Key"]) for s in d["samples"]) == schedule for d in before + after) sustained_cpu = rounds >= 3 and all(x is not None and x > 1.1 for x in cpu) sustained_heap = rounds >= 3 and all(x is not None and x > 1.1 for x in heap) resource_complete = all(x is not None for x in cpu + heap) diff --git a/scripts/local/poll-pool-readmix.py b/scripts/local/poll-pool-readmix.py index 9c00ab70..87a77f57 100644 --- a/scripts/local/poll-pool-readmix.py +++ b/scripts/local/poll-pool-readmix.py @@ -26,13 +26,31 @@ def write_json(path, value): temporary.replace(path) -def expected_schedule(seconds): +DEFAULT_ACTORS = {"annotation": 60, "quality": 12, "acceptance": 8, "admin": 1} + + +def actor_counts(config): + counts = config.get("actor_counts", DEFAULT_ACTORS) + if (set(counts) != set(DEFAULT_ACTORS) or counts.get("admin") != 1 or + any(type(v) is not int or v < 1 for v in counts.values()) or sum(counts.values()) > 250): + raise ValueError("invalid actor counts") + return counts + + +def expected_schedule(seconds, config=None): + config = config or {} + counts = actor_counts(config) + annotation_end = counts["annotation"] + quality_end = annotation_end + counts["quality"] + total = sum(counts.values()) expected = Counter() - for i in range(81): + for i in range(total): actor = f"load-user-{i:02d}" - if i < 60: + if i < annotation_end: expected[(actor, "annotation.buffer")] = (seconds + 2) // 3 - elif i == 80: + if config.get("claim_counts", False): + expected[(actor, "annotation.claim-count")] = (seconds + 11) // 12 + elif i == total - 1: expected[(actor, "admin.workforce")] = (seconds + 11) // 12 else: cycles = (seconds + 11) // 12 @@ -40,7 +58,7 @@ def expected_schedule(seconds): if not count: continue for pool in ("available", "mine", "reviewed"): - if i < 72: + if i < quality_end: expected[(actor, f"quality.{scope}.{pool}")] = count else: for stage in ("acceptance", "prepackage_acceptance"): @@ -49,7 +67,13 @@ def expected_schedule(seconds): def validate_result(data, revision, mode, config): - expected = 60 * ((config["duration_seconds"] + 2) // 3) + 85 * ((config["duration_seconds"] + 11) // 12) + schedule_expected = expected_schedule(config["duration_seconds"], config) + expected = sum(schedule_expected.values()) + if "actor_counts" in config: + if data.get("actor_counts") != actor_counts(config) or data.get("actors") != sum(actor_counts(config).values()): + raise ValueError("result mismatch: actor counts") + if data.get("claim_counts") != config.get("claim_counts", False): + raise ValueError("result mismatch: claim-count workload") for key, value in {"revision": revision, "mode": mode, "authorization_state": config["authorization_state"], "warmup_seconds": config["warmup_seconds"], @@ -61,7 +85,7 @@ def validate_result(data, revision, mode, config): if len(data.get("samples", [])) != expected: raise ValueError(f"incomplete requests; expected {expected}") schedule = Counter((row["Actor"], row["Key"]) for row in data["samples"]) - if schedule != expected_schedule(config["duration_seconds"]): + if schedule != schedule_expected: raise ValueError("actor/endpoint schedule is incomplete or duplicated") if data.get("errors") != 0 or data.get("mongo_write_commands") != 0: raise ValueError("read mix had errors or unexpected writes") @@ -112,19 +136,29 @@ def main(): parser.add_argument("--warmup", type=int, default=5) parser.add_argument("--duration", type=int, default=30) parser.add_argument("--repetitions", type=int, default=1) + parser.add_argument("--annotators", type=int, default=60) + parser.add_argument("--quality-reviewers", type=int, default=12) + parser.add_argument("--acceptance-reviewers", type=int, default=8) + parser.add_argument("--claim-counts", action="store_true", help="also refresh exact annotation counts every 12 seconds") parser.add_argument("--resume", action="store_true") parser.add_argument("--output", type=Path, required=True) args = parser.parse_args() if not (0 <= args.author_history <= 5000 and 0 <= args.run_payload_kib <= 2048 and 1 <= args.warmup <= 7200 and 1 <= args.duration <= 7200 and 1 <= args.repetitions <= 10): parser.error("invalid fixture size, duration or repetitions") + counts = {"annotation": args.annotators, "quality": args.quality_reviewers, + "acceptance": args.acceptance_reviewers, "admin": 1} + try: + actor_counts({"actor_counts": counts}) + except ValueError as error: + parser.error(str(error)) resolve = lambda ref: subprocess.check_output(["git", "rev-parse", "--verify", ref + "^{commit}"], cwd=ROOT, text=True).strip() variants = [{"label": "baseline", "revision": resolve(args.baseline), "mode": args.baseline_mode}] if args.intermediate: variants.append({"label": "stage1", "revision": resolve(args.intermediate), "mode": "summary"}) variants.append({"label": "candidate", "revision": resolve(args.candidate), "mode": "summary"}) harness = (ROOT / HARNESS).read_bytes() - config = {"schema": 2, "variants": variants, "harness_sha256": hashlib.sha256(harness).hexdigest(), + config = {"schema": 3, "actor_counts": counts, "claim_counts": args.claim_counts, "variants": variants, "harness_sha256": hashlib.sha256(harness).hexdigest(), "authorization_state": args.authorization_state, "run_payload_kib": args.run_payload_kib, "author_history_per_reviewer": args.author_history, "warmup_seconds": args.warmup, "duration_seconds": args.duration, "repetitions": args.repetitions} @@ -179,6 +213,8 @@ def main(): write_json(output / "status.json", {"state": "running", "run": name, "revision": revision, "started_unix": time.time(), "completed_pairs": len(summary["pairs"])}) env = dict(os.environ, POLL_POOL_AUTHOR_HISTORY=str(args.author_history), + POLL_POOL_ANNOTATORS=str(args.annotators), POLL_POOL_QUALITY_REVIEWERS=str(args.quality_reviewers), + POLL_POOL_ACCEPTANCE_REVIEWERS=str(args.acceptance_reviewers), POLL_POOL_CLAIM_COUNTS="1" if args.claim_counts else "0", POLL_POOL_RUN_PAYLOAD_KIB=str(args.run_payload_kib), POLL_POOL_AUTHORIZATION_STATE=args.authorization_state, POLL_POOL_LOAD="1", POLL_POOL_MODE=mode, POLL_POOL_REVISION=revision, POLL_POOL_WARMUP_SECONDS=str(args.warmup), POLL_POOL_DURATION_SECONDS=str(args.duration), diff --git a/scripts/local/test_poll_pool_readmix.py b/scripts/local/test_poll_pool_readmix.py index 074b7a2b..e5173336 100644 --- a/scripts/local/test_poll_pool_readmix.py +++ b/scripts/local/test_poll_pool_readmix.py @@ -29,6 +29,32 @@ class ResultValidationTests(unittest.TestCase): def test_complete_matching_result_is_reusable(self): readmix.validate_result(self.result, "fixed", "summary", self.config) + def test_121_actor_schedule_includes_exact_counts_and_all_roles(self): + config = {"actor_counts": {"annotation": 90, "quality": 18, "acceptance": 12, "admin": 1}, "claim_counts": True} + schedule = readmix.expected_schedule(1800, config) + self.assertEqual(len({actor for actor, _ in schedule}), 121) + self.assertEqual(sum(schedule.values()), 86550) + self.assertEqual(schedule[("load-user-89", "annotation.buffer")], 600) + self.assertEqual(schedule[("load-user-89", "annotation.claim-count")], 150) + self.assertEqual(schedule[("load-user-90", "quality.all.available")], 75) + self.assertEqual(schedule[("load-user-108", "acceptance.project.prepackage_acceptance.mine")], 75) + self.assertEqual(schedule[("load-user-120", "admin.workforce")], 150) + + def test_scaled_results_require_correct_actor_counts_and_count_requests(self): + config = {**self.config, "actor_counts": {"annotation": 90, "quality": 18, "acceptance": 12, "admin": 1}, "claim_counts": True} + result = {**self.result, "actors": 121, "actor_counts": config["actor_counts"], "claim_counts": True, + "samples": [{"Actor": actor, "Key": key, "Code": 200} for (actor, key), n in readmix.expected_schedule(3, config).items() for _ in range(n)]} + readmix.validate_result(result, "fixed", "summary", config) + for change in ({"actors": 81}, {"actor_counts": readmix.DEFAULT_ACTORS}, {"claim_counts": False}, + {"samples": [r for r in result["samples"] if r["Key"] != "annotation.claim-count"]}): + with self.subTest(change=next(iter(change))), self.assertRaises(ValueError): + readmix.validate_result({**result, **change}, "fixed", "summary", config) + + def test_invalid_concurrency_cannot_label_a_smaller_run_as_capacity(self): + for invalid in ({"annotation": 0}, {"admin": 2}, {"quality": 1.5}, {"annotation": 250}): + with self.subTest(invalid=invalid), self.assertRaises(ValueError): + readmix.expected_schedule(3, {"actor_counts": {**readmix.DEFAULT_ACTORS, **invalid}}) + def test_invalid_results_cannot_be_silently_reused(self): changes = [{"revision": "other"}, {"mode": "legacy"}, {"errors": 1}, {"mongo_write_commands": 1}, {"samples": self.result["samples"][:-1]}, diff --git a/src/lib/annotation-project-loading.js b/src/lib/annotation-project-loading.js index e0787ac1..0fe4b27e 100644 --- a/src/lib/annotation-project-loading.js +++ b/src/lib/annotation-project-loading.js @@ -1,29 +1,37 @@ // Keep GET joins below proxy request-line limits, with bounded concurrency. -export async function loadAnnotationTaskJoin(annotation, filters, ids) { +export async function loadAnnotationTaskJoin(annotation, filters, ids, signal) { + signal?.throwIfAborted(); const unique = [...new Set(ids)]; const tasks = []; for (let start = 0; start < unique.length; start += 200) { const pages = []; + signal?.throwIfAborted(); for (let offset = start; offset < Math.min(unique.length, start + 200); offset += 50) - pages.push(annotation.listTasksPage({ ...filters, ids: unique.slice(offset, offset + 50) })); + pages.push(annotation.listTasksPage({ ...filters, ids: unique.slice(offset, offset + 50) }, { signal })); for (const page of await Promise.all(pages)) tasks.push(...page.items); + signal?.throwIfAborted(); } return tasks; } // Rolling upgrades may briefly serve an API without this read endpoint. Only // route absence allows the legacy path; permission and server errors propagate. -export async function loadAnnotationSidebar(annotation, human, filters) { +export async function loadAnnotationSidebar(annotation, human, filters, signal) { + signal?.throwIfAborted(); if (annotation.getSidebar) { try { - return await annotation.getSidebar(filters); + const page = await annotation.getSidebar(filters, { signal }); + signal?.throwIfAborted(); + return page; } catch (error) { + signal?.throwIfAborted(); if (error?.status !== 404 && error?.status !== 405) throw error; } } - const page = await human.listItemsPage({ pluginId: "annotation-qa", pool: "mine", ...filters }); + const page = await human.listItemsPage({ pluginId: "annotation-qa", pool: "mine", ...filters }, { signal }); + signal?.throwIfAborted(); const ids = page.items.map((item) => item.legacyTaskId).filter(Boolean); - const tasks = await loadAnnotationTaskJoin(annotation, { projectId: filters.projectId }, ids); + const tasks = await loadAnnotationTaskJoin(annotation, { projectId: filters.projectId }, ids, signal); return { ...page, tasks }; } @@ -41,49 +49,67 @@ export async function loadOwnedAnnotationProject({ runId, onPage, onTasks, + signal, }) { + signal?.throwIfAborted(); + const current = () => !signal?.aborted && isCurrent(); const count = projectId ? Promise.resolve() - .then(() => annotation.claimCount(projectId)) + .then(() => { + signal?.throwIfAborted(); + return annotation.claimCount(projectId, { signal }); + }) .catch(() => null) : Promise.resolve(null); void count.then((result) => { - if (isCurrent()) onCount(result?.count ?? null); + if (current()) onCount(result?.count ?? null); }); // The pool and task join are the sidebar's complete data dependency. Start // them immediately; project metadata still gates the full result and actions. let failed = false; const ownedTasks = Promise.resolve().then(async () => { + signal?.throwIfAborted(); let mine, tasks; if (annotationView) { // Same scope as "load more", which continues from this page's cursor. - const page = await loadAnnotationSidebar(annotation, human, { - projectId: projectId || undefined, - ...(workflowId ? { workflowId } : {}), - ...(runId ? { runId } : {}), - annotationView, - }); - if (!failed && isCurrent()) onPage?.(page); + const page = await loadAnnotationSidebar( + annotation, + human, + { + projectId: projectId || undefined, + ...(workflowId ? { workflowId } : {}), + ...(runId ? { runId } : {}), + annotationView, + }, + signal, + ); + if (!failed && current()) onPage?.(page); mine = page.items; tasks = page.tasks; } else { - mine = await human.listItems({ pluginId: "annotation-qa", projectId: projectId || undefined, pool: "mine" }); + mine = await human.listItems( + { pluginId: "annotation-qa", projectId: projectId || undefined, pool: "mine" }, + { signal }, + ); + signal?.throwIfAborted(); const owned = mine.filter((item) => item.legacyTaskId); - tasks = (await Promise.all(owned.map((item) => annotation.getTaskSummary(item.legacyTaskId)))).map( + tasks = (await Promise.all(owned.map((item) => annotation.getTaskSummary(item.legacyTaskId, { signal })))).map( (detail) => detail.task, ); } const result = { mine, tasks }; - if (!failed && isCurrent()) onTasks?.(result); + signal?.throwIfAborted(); + if (!failed && current()) onTasks?.(result); return result; }); try { const [members, owned, templates, workflows] = await Promise.all([ - projectId ? projects.listMembers(projectId) : Promise.resolve([]), + projectId ? projects.listMembers(projectId, { signal }) : Promise.resolve([]), ownedTasks, - annotation.listTemplates(projectId || undefined), - projectId ? projects.listWorkflows(projectId) : Promise.resolve([]), + annotation.listTemplates(projectId || undefined, { signal }), + projectId ? projects.listWorkflows(projectId, { signal }) : Promise.resolve([]), ]); + signal?.throwIfAborted(); return { members, ...owned, templates, workflows }; } catch (error) { failed = true; @@ -95,8 +121,10 @@ export async function loadOwnedAnnotationProject({ // a failed join or an obsolete request cannot advance the caller's pagination. // `view` selects an existing HTTP contract; it never derives claim eligibility. export async function loadAnnotationPoolPage({ annotation, human, scope, view, cursor = "", signal = undefined }) { + signal?.throwIfAborted(); if (view.kind === "admin") { const page = await annotation.adminPool({ ...view.filters, ...(cursor ? { cursor } : {}) }, { signal }); + signal?.throwIfAborted(); return { tasks: page.tasks, pools: { available: [], mine: [], all: [], reviewed: [], [view.filters.pool]: page.items }, @@ -106,13 +134,18 @@ export async function loadAnnotationPoolPage({ annotation, human, scope, view, c }; } if (view.kind === "sidebar") { - const page = await loadAnnotationSidebar(annotation, human, { - projectId: scope.projectId, - workflowId: scope.workflowId, - runId: scope.runId, - annotationView: view.annotationView, - ...(cursor ? { cursor } : {}), - }); + const page = await loadAnnotationSidebar( + annotation, + human, + { + projectId: scope.projectId, + workflowId: scope.workflowId, + runId: scope.runId, + annotationView: view.annotationView, + ...(cursor ? { cursor } : {}), + }, + signal, + ); return { tasks: page.tasks, pools: { available: [], mine: page.items, all: [], reviewed: [] }, @@ -123,7 +156,8 @@ export async function loadAnnotationPoolPage({ annotation, human, scope, view, c } const taskFilters = { ...scope }; if (cursor) { - const page = await annotation.listTasksPage({ ...taskFilters, limit: view.limit, cursor }); + const page = await annotation.listTasksPage({ ...taskFilters, limit: view.limit, cursor }, { signal }); + signal?.throwIfAborted(); return { tasks: page.items, pools: null, taskCursor: page.nextCursor || "", mineCursor: "", counts: null }; } const humanFilters = { @@ -135,21 +169,27 @@ export async function loadAnnotationPoolPage({ annotation, human, scope, view, c }; let mineCursor = ""; const poolsRequest = view.acceptance - ? human.listAcceptancePools(humanFilters, view.userId, view.isManager) + ? human.listAcceptancePools(humanFilters, view.userId, view.isManager, { signal }) : Promise.all([ - human.listItems({ ...humanFilters, pool: "available", ...(view.stageIds ? { stageIds: view.stageIds } : {}) }), + human.listItems( + { ...humanFilters, pool: "available", ...(view.stageIds ? { stageIds: view.stageIds } : {}) }, + { signal }, + ), human - .listItemsPage({ ...humanFilters, pool: "mine", ...(view.stageIds ? { stageIds: view.stageIds } : {}) }) + .listItemsPage( + { ...humanFilters, pool: "mine", ...(view.stageIds ? { stageIds: view.stageIds } : {}) }, + { signal }, + ) .then((page) => { mineCursor = page.nextCursor || ""; return page.items; }), - view.isManager ? human.listItems({ ...humanFilters, pool: "all" }) : Promise.resolve([]), - view.reviewOnly ? human.listItems({ ...humanFilters, pool: "reviewed" }) : Promise.resolve([]), + view.isManager ? human.listItems({ ...humanFilters, pool: "all" }, { signal }) : Promise.resolve([]), + view.reviewOnly ? human.listItems({ ...humanFilters, pool: "reviewed" }, { signal }) : Promise.resolve([]), ]).then(([available, mine, all, reviewed]) => ({ available, mine, all, reviewed })); let taskCursor = ""; const tasksRequest = view.isManager - ? annotation.listTasksPage({ ...taskFilters, limit: view.limit }).then((page) => { + ? annotation.listTasksPage({ ...taskFilters, limit: view.limit }, { signal }).then((page) => { taskCursor = page.nextCursor || ""; return page.items; }) @@ -162,7 +202,7 @@ export async function loadAnnotationPoolPage({ annotation, human, scope, view, c [...pools.available, ...pools.mine, ...pools.reviewed].map((item) => item.legacyTaskId).filter(Boolean), ), ]; - const tasks = await loadAnnotationTaskJoin(annotation, taskFilters, ids); + const tasks = await loadAnnotationTaskJoin(annotation, taskFilters, ids, signal); // Each HTTP page is sorted separately; restore the global task order // of the former single join before the page applies its render window. return tasks.sort((a, b) => { @@ -175,5 +215,6 @@ export async function loadAnnotationPoolPage({ annotation, human, scope, view, c }); }); const [pools, tasks] = await Promise.all([poolsRequest, tasksRequest]); + signal?.throwIfAborted(); return { pools, tasks, taskCursor, mineCursor, counts: null }; } diff --git a/src/pages/AnnotationOperations.tsx b/src/pages/AnnotationOperations.tsx index 8f758f9e..ebe8e1b9 100644 --- a/src/pages/AnnotationOperations.tsx +++ b/src/pages/AnnotationOperations.tsx @@ -775,11 +775,18 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: const workbenchHostRef = useRef(null); const [taskSearch, setTaskSearch] = useState(""); const [adminSearch, setAdminSearch] = useState(""); - const adminPoolAbortRef = useRef(null); + const projectReadAbortRef = useRef(null); + const poolPageAbortRef = useRef(null); const taskPoolCursorRef = useRef(""); const taskPoolFetchOwnerRef = useRef(null); const [taskPoolFetchBusy, setTaskPoolFetchBusy] = useState(false); - useEffect(() => () => adminPoolAbortRef.current?.abort(), []); + useEffect( + () => () => { + projectReadAbortRef.current?.abort(); + poolPageAbortRef.current?.abort(); + }, + [], + ); const [adminPoolTotals, setAdminPoolTotals] = useState<{ scope: string; counts: { available: number; mine: number; all: number }; @@ -993,10 +1000,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: const projectPoolView = acceptanceWorkspace ? "all" : taskPoolView; const managerAnnotationPool = isManager && workspaceMode === "annotate"; useEffect(() => { - if (!managerAnnotationPool) { - adminPoolAbortRef.current?.abort(); - return; - } + if (!managerAnnotationPool) return; const timer = window.setTimeout(() => setAdminSearch(taskSearch.trim()), 350); return () => window.clearTimeout(timer); }, [managerAnnotationPool, taskSearch]); @@ -1207,20 +1211,24 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: const loadProject = useCallback(async () => { if (reviewActionScopeRef.current !== projectDataScope) return; const requestID = ++projectLoadRequestRef.current; + const controller = new AbortController(); const current = () => - requestID === projectLoadRequestRef.current && reviewActionScopeRef.current === projectDataScope; + !controller.signal.aborted && + requestID === projectLoadRequestRef.current && + reviewActionScopeRef.current === projectDataScope; // A refresh supersedes pagination even when the project ID stays the same. taskPoolFetchOwnerRef.current = null; setTaskPoolFetchBusy(false); taskPoolCursorRef.current = ""; minePoolCursorRef.current = ""; - adminPoolAbortRef.current?.abort(); + projectReadAbortRef.current?.abort(); + poolPageAbortRef.current?.abort(); + projectReadAbortRef.current = controller; const foreground = !deferReviewReports || loadedProjectScope.current !== projectDataScope; setLoading(foreground); setRefreshingProject(!foreground); setProjectLoadError(""); if (managerAnnotationPool) { - adminPoolAbortRef.current = new AbortController(); setHumanPools(emptyHumanPools); setTasks([]); } @@ -1238,6 +1246,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: human: humanLoopApi, annotation: annotationOperationsApi, isCurrent: current, + signal: controller.signal, annotationView: annotatorTaskView, workflowId: requestedWorkflowId, runId: requestedRunId, @@ -1293,35 +1302,40 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: stageIds: humanItemStageIdsForMode(workspaceMode), limit: taskPageLimit, }, - signal: adminPoolAbortRef.current?.signal, + signal: controller.signal, }); const [nextProjectMembers, nextWorkflows, nextTemplates, poolPage, nextWorkload, nextPackages, nextScopedRun] = await Promise.all([ projectId - ? projectsApi.listMembers(projectId) + ? projectsApi.listMembers(projectId, { signal: controller.signal }) : fanOutProjectScope - ? Promise.allSettled(knownProjects.map((p) => projectsApi.listMembers(p.id))).then((results) => - results.flatMap((r) => (r.status === "fulfilled" ? r.value : [])), - ) + ? Promise.allSettled( + knownProjects.map((p) => projectsApi.listMembers(p.id, { signal: controller.signal })), + ).then((results) => results.flatMap((r) => (r.status === "fulfilled" ? r.value : []))) : Promise.resolve([] as ProjectMember[]), projectId - ? projectsApi.listWorkflows(projectId) + ? projectsApi.listWorkflows(projectId, { signal: controller.signal }) : fanOutProjectScope - ? Promise.allSettled(knownProjects.map((p) => projectsApi.listWorkflows(p.id))).then((results) => - results.flatMap((r) => (r.status === "fulfilled" ? r.value : [])), - ) + ? Promise.allSettled( + knownProjects.map((p) => projectsApi.listWorkflows(p.id, { signal: controller.signal })), + ).then((results) => results.flatMap((r) => (r.status === "fulfilled" ? r.value : []))) : Promise.resolve([] as Workflow[]), - annotationOperationsApi.listTemplates(projectId || undefined), + annotationOperationsApi.listTemplates(projectId || undefined, { signal: controller.signal }), poolsRequest, - deferReviewReports ? Promise.resolve(null) : annotationOperationsApi.workloadSummary(projectId || undefined), + deferReviewReports + ? Promise.resolve(null) + : annotationOperationsApi.workloadSummary(projectId || undefined, { signal: controller.signal }), reviewOnly && workspaceMode !== "acceptance" ? Promise.resolve([] as DeliveryPackage[]) - : deliveryPackagesApi.list({ - projectId: projectId || undefined, - workflowId: requestedWorkflowId || undefined, - runId: requestedRunId || undefined, - status: projectPoolView === "all" ? undefined : "pending_acceptance", - }), + : deliveryPackagesApi.list( + { + projectId: projectId || undefined, + workflowId: requestedWorkflowId || undefined, + runId: requestedRunId || undefined, + status: projectPoolView === "all" ? undefined : "pending_acceptance", + }, + { signal: controller.signal }, + ), isManager && requestedRunId ? runsApi.get(requestedRunId) : Promise.resolve(null), ]); if (!current()) return; @@ -1474,6 +1488,8 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: // would compete with detail/evidence requests for browser connections. if (!acceptanceWorkspace && taskPoolView !== "mine") skipClaimPoolReload.current = projectDataScope; ++projectLoadRequestRef.current; + projectReadAbortRef.current?.abort(); + poolPageAbortRef.current?.abort(); setLoading(false); setRefreshingProject(false); setDetail((current) => @@ -2615,19 +2631,19 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: const cursor = sidebar ? minePoolCursorRef.current : taskPoolCursorRef.current; if (taskPoolFetchOwnerRef.current || !cursor) return; const owner = Symbol("pool-page"); + const controller = new AbortController(); taskPoolFetchOwnerRef.current = owner; const scope = projectDataScope; const epoch = projectLoadRequestRef.current; const current = () => + !controller.signal.aborted && taskPoolFetchOwnerRef.current === owner && reviewActionScopeRef.current === scope && projectLoadRequestRef.current === epoch; setTaskPoolFetchBusy(true); try { - if (managerAnnotationPool) { - adminPoolAbortRef.current?.abort(); - adminPoolAbortRef.current = new AbortController(); - } + poolPageAbortRef.current?.abort(); + poolPageAbortRef.current = controller; const page = await loadAnnotationPoolPage({ annotation: annotationOperationsApi, human: humanLoopApi, @@ -2644,7 +2660,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?: ? { kind: "sidebar", annotationView: annotatorTaskView } : { kind: "workspace", limit: taskPageLimit }, cursor, - signal: adminPoolAbortRef.current?.signal, + signal: controller.signal, }); if (!current()) return; taskPoolCursorRef.current = page.taskCursor; diff --git a/src/services/api/annotation-operations.ts b/src/services/api/annotation-operations.ts index adc131c4..cee5c6e9 100644 --- a/src/services/api/annotation-operations.ts +++ b/src/services/api/annotation-operations.ts @@ -95,16 +95,20 @@ export const annotationOperationsApi = { { method: "PUT" }, { capacity }, ), - getSidebar: (filters: { - projectId?: string; - workflowId?: string; - runId?: string; - annotationView: "active" | "submitted"; - cursor?: string; - limit?: number; - }) => + getSidebar: ( + filters: { + projectId?: string; + workflowId?: string; + runId?: string; + annotationView: "active" | "submitted"; + cursor?: string; + limit?: number; + }, + options: { signal?: AbortSignal } = {}, + ) => apiRequest<{ items: HumanItem[]; tasks: AnnotationTaskRecord[]; nextCursor?: string; hasMore?: boolean }>( `/api/plugins/annotation-qa/sidebar${query(filters)}`, + options, ), adminPool: ( filters: { @@ -129,9 +133,10 @@ export const annotationOperationsApi = { nextCursor?: string; hasMore?: boolean; }>(`/api/plugins/annotation-qa/admin-pool${query(filters)}`, options), - claimCount: (projectId: string) => + claimCount: (projectId: string, options: { signal?: AbortSignal } = {}) => apiRequest<{ projectId: string; count: number }>( `/api/plugins/annotation-qa/claim-count?projectId=${encodeURIComponent(projectId)}`, + options, ), setSliceDisposition: ( taskId: string, @@ -174,9 +179,13 @@ export const annotationOperationsApi = { { method: "POST" }, { projectId, requestId, bufferOnly }, ), - listTemplates: async (projectId?: string) => - (await apiRequest<{ items: AnnotationTemplate[] }>(`/api/plugins/annotation-qa/templates${query({ projectId })}`)) - .items, + listTemplates: async (projectId?: string, options: { signal?: AbortSignal } = {}) => + ( + await apiRequest<{ items: AnnotationTemplate[] }>( + `/api/plugins/annotation-qa/templates${query({ projectId })}`, + options, + ) + ).items, createTemplate: (payload: { projectId: string; name: string; @@ -222,16 +231,18 @@ export const annotationOperationsApi = { /** Explicit task-ID set for pool-item joins (comma-joined). */ ids?: string[]; } = {}, + options: { signal?: AbortSignal } = {}, ) => apiRequest<{ items: AnnotationTaskRecord[]; nextCursor?: string; hasMore?: boolean }>( `/api/plugins/annotation-qa/tasks${query(filters)}`, + options, ), getTask: (id: string, signal?: AbortSignal, history = false) => apiRequest(`/api/plugins/annotation-qa/tasks/${id}${history ? "?view=history" : ""}`, { signal, }).then(normalizeAnnotationTaskDetail), - getTaskSummary: (id: string) => - apiRequest<{ task: AnnotationTaskRecord }>(`/api/plugins/annotation-qa/tasks/${id}?view=summary`), + getTaskSummary: (id: string, options: { signal?: AbortSignal } = {}) => + apiRequest<{ task: AnnotationTaskRecord }>(`/api/plugins/annotation-qa/tasks/${id}?view=summary`, options), getTaskStatus: (id: string, signal?: AbortSignal) => apiRequest<{ taskId: string; @@ -473,6 +484,9 @@ export const annotationOperationsApi = { { method: "POST", headers }, payload, ), - workloadSummary: (projectId?: string) => - apiRequest(`/api/plugins/annotation-qa/workload-summary${query({ projectId })}`), + workloadSummary: (projectId?: string, options: { signal?: AbortSignal } = {}) => + apiRequest( + `/api/plugins/annotation-qa/workload-summary${query({ projectId })}`, + options, + ), }; diff --git a/src/services/api/delivery-packages.ts b/src/services/api/delivery-packages.ts index 6ae60fd8..98339ce7 100644 --- a/src/services/api/delivery-packages.ts +++ b/src/services/api/delivery-packages.ts @@ -13,7 +13,9 @@ const packageQuery = (values: Record) => { export const deliveryPackagesApi = { list: async ( filters: { projectId?: string; workflowId?: string; runId?: string; status?: DeliveryPackage["status"] } = {}, - ) => (await apiRequest<{ items: DeliveryPackage[] }>(`/api/delivery-packages${packageQuery(filters)}`)).items, + options: { signal?: AbortSignal } = {}, + ) => + (await apiRequest<{ items: DeliveryPackage[] }>(`/api/delivery-packages${packageQuery(filters)}`, options)).items, get: (id: string) => apiRequest(`/api/delivery-packages/${encodeURIComponent(id)}`), contents: (id: string) => apiRequest(`/api/delivery-packages/${encodeURIComponent(id)}/contents`), diff --git a/src/services/api/human-loop.ts b/src/services/api/human-loop.ts index fd0a4af1..1cc5a42f 100644 --- a/src/services/api/human-loop.ts +++ b/src/services/api/human-loop.ts @@ -41,22 +41,25 @@ type HumanItemPage = { hasMore?: boolean; }; -const listItemsPage = async (filters: HumanItemFilters = {}) => - apiRequest(`/api/human-items${queryString(filters)}`); +const listItemsPage = async (filters: HumanItemFilters = {}, options: { signal?: AbortSignal } = {}) => + apiRequest(`/api/human-items${queryString(filters)}`, options); -const listItems = async (filters: HumanItemFilters = {}) => (await listItemsPage(filters)).items; +const listItems = async (filters: HumanItemFilters = {}, options: { signal?: AbortSignal } = {}) => + (await listItemsPage(filters, options)).items; /** * Fetch every page behind the cursor so pools larger than the server's * default page size (500, max 1000) are not silently truncated. */ -async function listAllItems(filters: HumanItemFilters = {}) { +async function listAllItems(filters: HumanItemFilters = {}, options: { signal?: AbortSignal } = {}) { const items = new Map(); let cursor: string | undefined; // Hard cap: 200 pages × up to 1000 items per page guards against a // server bug looping on the same cursor. for (let page = 0; page < 200; page += 1) { - const result = await listItemsPage({ ...filters, cursor }); + options.signal?.throwIfAborted(); + const result = await listItemsPage({ ...filters, cursor }, options); + options.signal?.throwIfAborted(); for (const item of result.items) { if (!items.has(item.id) || item.version > items.get(item.id)!.version) items.set(item.id, item); } @@ -66,11 +69,11 @@ async function listAllItems(filters: HumanItemFilters = {}) { return [...items.values()]; } -async function listAcceptancePool(filters: HumanItemFilters) { +async function listAcceptancePool(filters: HumanItemFilters, options: { signal?: AbortSignal } = {}) { // Keep the legacy package acceptance stage alongside prepackage acceptance. // Both requests retain the server's actor, project and supplier checks. const pages = await Promise.all( - ["acceptance", "prepackage_acceptance"].map((stageId) => listAllItems({ ...filters, stageId })), + ["acceptance", "prepackage_acceptance"].map((stageId) => listAllItems({ ...filters, stageId }, options)), ); const items = new Map(); for (const item of pages.flat()) { @@ -87,9 +90,10 @@ export const humanLoopApi = { filters: Omit, actorId: string, manager: boolean, + options: { signal?: AbortSignal } = {}, ) => { if (manager) { - const all = await listAcceptancePool({ ...filters, pool: "all" }); + const all = await listAcceptancePool({ ...filters, pool: "all" }, options); return { all, available: all.filter((item) => !item.assignedUserId && ["ready", "submitted", "rework"].includes(item.status)), @@ -98,7 +102,7 @@ export const humanLoopApi = { }; } const [available, mine, reviewed] = await Promise.all( - (["available", "mine", "reviewed"] as const).map((pool) => listAcceptancePool({ ...filters, pool })), + (["available", "mine", "reviewed"] as const).map((pool) => listAcceptancePool({ ...filters, pool }, options)), ); return { available, mine, all: [], reviewed }; }, diff --git a/src/services/api/projects.ts b/src/services/api/projects.ts index 34f69ec9..1d5c761e 100644 --- a/src/services/api/projects.ts +++ b/src/services/api/projects.ts @@ -39,8 +39,8 @@ export const projectsApi = { { method: "PUT" }, { items }, ), - listMembers: async (projectId: string) => - (await apiRequest<{ items: ProjectMember[] }>(`/api/projects/${projectId}/members`)).items, + listMembers: async (projectId: string, options: { signal?: AbortSignal } = {}) => + (await apiRequest<{ items: ProjectMember[] }>(`/api/projects/${projectId}/members`, options)).items, createMember: (projectId: string, payload: { userId: string; supplierId?: string; roles: ProjectMemberRole[] }) => apiRequest(`/api/projects/${projectId}/members`, { method: "POST" }, payload), updateMember: (projectId: string, memberId: string, payload: { supplierId?: string; roles: ProjectMemberRole[] }) => @@ -63,8 +63,8 @@ export const projectsApi = { { method: "POST" }, payload, ), - listWorkflows: async (projectId: string) => - (await apiRequest<{ items: Workflow[] }>(`/api/projects/${projectId}/workflows`)).items, + listWorkflows: async (projectId: string, options: { signal?: AbortSignal } = {}) => + (await apiRequest<{ items: Workflow[] }>(`/api/projects/${projectId}/workflows`, options)).items, createWorkflow: (projectId: string, payload: Partial) => apiRequest(`/api/projects/${projectId}/workflows`, { method: "POST" }, payload), listWorkflowInstances: async (projectId: string) => diff --git a/tests/browser/workspace-read-cancellation.mjs b/tests/browser/workspace-read-cancellation.mjs new file mode 100644 index 00000000..b87b53e7 --- /dev/null +++ b/tests/browser/workspace-read-cancellation.mjs @@ -0,0 +1,127 @@ +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { chromium } from "playwright"; +import { createServer } from "vite"; + +const requests = []; +const server = await createServer({ + cacheDir: "local-data/test-results/responsiveness-121/vite-cache", + server: { host: "127.0.0.1", port: 5198, strictPort: true }, + plugins: [ + { + name: "isolated-cancellation-endpoints", + configureServer(vite) { + vite.middlewares.use((req, res, next) => { + if (req.url === "/__cancellation-test") { + res.setHeader("Content-Type", "text/html"); + res.end("Local cancellation test"); + } else if (req.url.startsWith("/api/")) { + assert.equal(req.method, "GET"); + const record = { path: req.url.split("?")[0], cancelled: false }; + requests.push(record); + res.on("close", () => { + record.cancelled = !res.writableEnded; + }); + } else next(); + }); + }, + }, + ], +}); +const report = { cases: [], errors: [] }; +let browser; +try { + await server.listen(); + browser = await chromium.launch({ + executablePath: process.env.BROWSER_EXECUTABLE || "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge", + headless: true, + args: ["--no-proxy-server"], + }); + const page = await browser.newPage(); + page.on("pageerror", (error) => report.errors.push(error.message)); + await page.route("**/*", (route) => + new URL(route.request().url()).hostname === "127.0.0.1" ? route.continue() : route.abort(), + ); + await page.goto("http://127.0.0.1:5198/__cancellation-test"); + for (const [kind, expected] of [ + ["quality", 3], + ["acceptance", 6], + ["annotation", 5], + ["admin", 1], + ]) { + const start = requests.length; + await page.evaluate(async (kind) => { + const { loadAnnotationPoolPage, loadOwnedAnnotationProject } = + await import("/src/lib/annotation-project-loading.js"); + const { annotationOperationsApi: annotation } = await import("/src/services/api/annotation-operations.ts"); + const { humanLoopApi: human } = await import("/src/services/api/human-loop.ts"); + const { projectsApi: projects } = await import("/src/services/api/projects.ts"); + window.cancelRead = new AbortController(); + window.readResult = null; + window.updates = []; + const signal = window.cancelRead.signal; + const read = + kind === "annotation" + ? loadOwnedAnnotationProject({ + projectId: "synthetic", + projects, + annotation, + human, + signal, + annotationView: "active", + isCurrent: () => true, + onCount: () => window.updates.push("count"), + onTasks: () => window.updates.push("tasks"), + onPage: () => window.updates.push("page"), + }) + : loadAnnotationPoolPage({ + annotation, + human, + signal, + scope: {}, + view: + kind === "admin" + ? { kind: "admin", filters: { pool: "all" } } + : { kind: "workspace", acceptance: kind === "acceptance", reviewOnly: true, userId: "synthetic" }, + }); + void read.then( + () => { + window.readResult = "unexpected-success"; + }, + (error) => { + window.readResult = error.name; + }, + ); + }, kind); + const deadline = Date.now() + 10000; + while (requests.length - start < expected && Date.now() < deadline) + await new Promise((resolve) => setTimeout(resolve, 20)); + assert.equal(requests.length - start, expected, kind); + await page.evaluate(() => window.cancelRead.abort()); + await page.waitForFunction(() => window.readResult !== null); + assert.equal(await page.evaluate(() => window.readResult), "AbortError", kind); + assert.deepEqual(await page.evaluate(() => window.updates), []); + const closedDeadline = Date.now() + 3000; + while (requests.slice(start).some((r) => !r.cancelled) && Date.now() < closedDeadline) + await new Promise((resolve) => setTimeout(resolve, 20)); + assert.ok( + requests.slice(start).every((r) => r.cancelled), + `${kind} left HTTP reads running`, + ); + assert.equal(requests.length - start, expected, "cancelled reads started follow-up queries"); + report.cases.push({ kind, cancelledRequests: expected }); + } + assert.deepEqual(report.errors, []); + report.passed = true; +} catch (error) { + report.failure = error.stack; + process.exitCode = 1; +} finally { + await browser?.close(); + await server.close(); + const out = path.resolve("local-data/test-results/responsiveness-121"); + fs.mkdirSync(out, { recursive: true }); + fs.writeFileSync(path.join(out, "browser-cancellation.json"), JSON.stringify(report, null, 2)); + console.log(JSON.stringify(report)); +} diff --git a/tests/frontend/annotation-pool-loading.test.mjs b/tests/frontend/annotation-pool-loading.test.mjs index be10f4bd..dc0b2323 100644 --- a/tests/frontend/annotation-pool-loading.test.mjs +++ b/tests/frontend/annotation-pool-loading.test.mjs @@ -1,5 +1,88 @@ import assert from "node:assert/strict"; import test from "node:test"; +import { loadAnnotationTaskJoin, loadOwnedAnnotationProject } from "../../src/lib/annotation-project-loading.js"; + +test("obsolete review pool reads are cancelled before task joins start", async () => { + const controller = new AbortController(); + const pending = Promise.withResolvers(); + let joins = 0; + const signals = []; + const read = async (_filters, options) => { + signals.push(options?.signal); + await pending.promise; + return [{ legacyTaskId: "task" }]; + }; + const result = loadAnnotationPoolPage({ + scope: {}, + view: { kind: "workspace", reviewOnly: true }, + signal: controller.signal, + human: { listItems: read, listItemsPage: async (...args) => ({ items: await read(...args) }) }, + annotation: { + listTasksPage: async () => { + joins++; + return { items: [] }; + }, + }, + }); + controller.abort(); + pending.resolve(); + await assert.rejects(result, { name: "AbortError" }); + assert.equal(joins, 0); + assert.equal(signals.length, 3); + assert.ok(signals.every((s) => s === controller.signal)); +}); + +test("cancelled task joins stop before the next bounded batch", async () => { + const controller = new AbortController(); + let calls = 0; + const annotation = { + listTasksPage: async (_filters, options) => { + assert.equal(options?.signal, controller.signal); + if (++calls === 4) controller.abort(); + return { items: [] }; + }, + }; + await assert.rejects( + loadAnnotationTaskJoin( + annotation, + {}, + Array.from({ length: 250 }, (_, i) => String(i)), + controller.signal, + ), + { name: "AbortError" }, + ); + assert.equal(calls, 4); +}); + +test("an obsolete owned-project count cannot publish after cancellation", async () => { + const controller = new AbortController(); + const pending = Promise.withResolvers(); + const updates = []; + const result = loadOwnedAnnotationProject({ + projectId: "p", + annotationView: "active", + signal: controller.signal, + isCurrent: () => true, + onCount: () => updates.push("count"), + onTasks: () => updates.push("tasks"), + onPage: () => updates.push("page"), + projects: { listMembers: async () => [], listWorkflows: async () => [] }, + human: {}, + annotation: { + claimCount: async () => pending.promise, + getSidebar: async () => { + await pending.promise; + return { items: [], tasks: [] }; + }, + listTemplates: async () => [], + }, + }); + await Promise.resolve(); + controller.abort(); + pending.resolve({ count: 1 }); + await assert.rejects(result, { name: "AbortError" }); + assert.deepEqual(updates, []); +}); import { loadAnnotationPoolPage } from "../../src/lib/annotation-project-loading.js"; const scope = { projectId: "p", workflowId: "w", runId: "r", nodeId: "n", artifactId: "a" }; @@ -92,6 +175,7 @@ for (const isManager of [false, true]) { { pluginId: "annotation-qa", projectId: "p", workflowId: "w", runId: "r" }, "reviewer", isManager, + { signal: undefined }, ]); return pools; }; diff --git a/tests/frontend/annotation-pool-pagination.test.mjs b/tests/frontend/annotation-pool-pagination.test.mjs index baee248d..2328c914 100644 --- a/tests/frontend/annotation-pool-pagination.test.mjs +++ b/tests/frontend/annotation-pool-pagination.test.mjs @@ -46,7 +46,8 @@ function fixture(kind) { minePoolCursorRef: { current: kind === "sidebar" ? "old-cursor" : "" }, projectLoadRequestRef: { current: 1 }, reviewActionScopeRef: { current: "scope-a" }, - adminPoolAbortRef: { current: null }, + projectReadAbortRef: { current: null }, + poolPageAbortRef: { current: null }, annotationOperationsApi: { adminPool: read, getSidebar: read, listTasksPage: read }, humanLoopApi: {}, setTaskPoolFetchBusy: (value) => updates.push(["busy", value]), @@ -231,7 +232,7 @@ test("an old captured loader cannot invalidate the new scope before making reque const newerPage = Symbol("new-page"); f.env.taskPoolFetchOwnerRef.current = newerPage; let aborted = false; - f.env.adminPoolAbortRef.current = { + f.env.projectReadAbortRef.current = { abort: () => { aborted = true; }, @@ -244,3 +245,51 @@ test("an old captured loader cannot invalidate the new scope before making reque assert.equal(f.requests(), 0); assert.deepEqual(f.updates, []); }); + +for (const kind of ["admin", "sidebar", "workspace"]) { + test(`${kind} pagination receives a live cancellation signal`, async () => { + const f = fixture(kind); + const pending = f.run(); + assert.ok(f.env.poolPageAbortRef.current instanceof AbortController); + assert.equal(f.env.poolPageAbortRef.current.signal.aborted, false); + f.resolve(); + await pending; + }); +} + +test("refresh cancels obsolete review reads without surfacing an error or pausing work", async () => { + const f = initialFixture(); + f.env.managerAnnotationPool = false; + f.env.isManager = false; + const previous = new AbortController(); + f.env.projectReadAbortRef.current = previous; + const signals = []; + const read = (_filters, options) => { + signals.push(options.signal); + return f.metadata.promise; + }; + f.env.humanLoopApi = { listItems: read, listItemsPage: read }; + const first = f.run(); + const firstSignal = f.env.projectReadAbortRef.current.signal; + assert.equal(previous.signal.aborted, true); + const second = f.run(); + assert.equal(firstSignal.aborted, true); + assert.equal(signals.length, 6); + assert.ok(signals.slice(0, 3).every((s) => s === firstSignal)); + f.env.reviewActionScopeRef.current = "new-scope"; + f.metadata.reject(new DOMException("cancelled", "AbortError")); + await Promise.all([first, second]); + assert.ok(!f.updates.some(([kind]) => kind === "pause" || kind === "error")); +}); + +test("sidebar pagination leaves pending project metadata and claim count running", async () => { + const f = fixture("sidebar"); + const metadataController = new AbortController(); + f.env.projectReadAbortRef.current = metadataController; + const pending = f.run(); + assert.equal(metadataController.signal.aborted, false); + f.resolve(); + await pending; + assert.equal(metadataController.signal.aborted, false); + assert.equal(f.env.minePoolCursorRef.current, "new-cursor"); +}); diff --git a/tests/frontend/devboot.test.mjs b/tests/frontend/devboot.test.mjs index 550d2662..ca2b71e0 100644 --- a/tests/frontend/devboot.test.mjs +++ b/tests/frontend/devboot.test.mjs @@ -37,6 +37,7 @@ test("vite dev boots and keeps the movi loader off the module pipeline", async ( // 3) That DEV URL must be fetchable as a plain static asset (script-tag path). const asset = await fetch(`${origin}${movi.MOVI_ELEMENT_JS_URL}`); assert.equal(asset.status, 200, "dev server must statically serve the movi element script"); + assert.ok((await asset.arrayBuffer()).byteLength > 0, "dev asset response must complete"); // 4) Negative control — the prod-shaped URL is exactly what the module // pipeline rejects; this is why importing /vendor assets from source is @@ -52,6 +53,7 @@ test("vite dev boots and keeps the movi loader off the module pipeline", async ( // 5) The shell page itself still responds. const index = await fetch(`${origin}/`); assert.equal(index.status, 200, "dev server must serve the app shell"); + await index.text(); } finally { await server.close(); }