-
[OPIK-6188] [BE] feat: implement prompt project migration job (D4) (#6808)
发布于
2026-05-21 16:28:03 +00:00 -
[OPIK-6188] [BE] feat: implement prompt project migration job
-
fix(prompt-migration): defer trap when batch is not the workspace tail
Both trap sites in PromptProjectMigrationService.applyClassifications
inherited D1's decision logic, but D4 added a LIMIT :limit cap on
findOrphanPromptIds that D1's experiment-classification query doesn't
have. The trap decisions are therefore made against a partial view of
the workspace, not the whole one — which silently strands the
remaining orphans when the current batch happens to be entirely or
mostly ambiguous.Concrete failure mode (default batch=1000): a workspace with 1500
orphans whose first 1000 are all ambiguous gets trapped after cycle 1
and the other 500 orphans never migrate. No error, no metric anomaly
— it's a silent data-loss path. Same defect on the post-write trap
when a batch contains a partial mix.Fix: gate both trap decisions on
isTailBatch = orphanIds.size() < batchSize. When the current batch isn't the workspace's tail, defer
the trap to a later cycle rather than permanently excluding the
workspace from a partial sample.Known residual: a workspace where every orphan is genuinely ambiguous
keeps returning a full BATCH_SIZE-sized page each cycle, so
isTailBatch stays false and the workspace cycles indefinitely without
ever trapping. The indefinite cycle is observable in metrics / logs
and is strictly better than the silent-data-loss alternative. Closing
it cleanly requires ORDER BY id ASC + cursor-style spillover in
findOrphanPromptIds and is a follow-up.Tests:
- partialBatchAllAmbiguousDoesNotTrap — BATCH_SIZE + 2 ambiguous
prompts; asserts cycle 1 migrates nothing and does NOT trap (the
silent-data-loss path is closed). - partialBatchMixedAmbiguousAndCertainDoesNotTrap — 51 certain + 51
ambiguous prompts (BATCH_SIZE + 2 total); pigeonhole guarantees
cycle 1's batch contains at least 49 of each bucket; asserts cycle
1 migrates at least some certain prompts AND does NOT trap.
下载附件
-