```
feat(learning): 添加技能学习候选者合成锁定机制 添加了 DraftSynthesisInProgress 和 DraftHasNoChanges 异常来处理并发场景, 确保同一技能学习候选者的合成过程不会重复执行。实现了 claim_learning_candidate_for_synthesis 方法来原子性地锁定候选者进行合成。 fix(web): 为技能草案创建端点添加适当的HTTP状态码 当草案没有变化或正在合成时,现在正确返回409状态码而不是内部错误。 feat(skills): 实现技能修订内容比较以检测无变化情况 添加了 _is_noop_revision 方法来比较基础技能和提议的修订, 如果内容没有实际变化则抛出 NoDraftChanges 异常。 refactor(process): 修复任务证据记录后根运行状态更新逻辑 将任务证据记录事件后的状态从 waiting 更改为 done,并设置 finished_at 时间戳。 feat(tools): 防止在同一运行中重复执行外部写入操作 为邮件发送、日历创建等外部写入工具添加去重机制,避免重复的外部操作。 test: 添加技能学习和工具执行的单元测试 增加测试用例验证并发草案合成、重复外部写入抑制和无变化修订检测等功能。 ```
This commit is contained in:
@ -114,6 +114,52 @@ class SkillLearningStore:
|
||||
)
|
||||
return updated
|
||||
|
||||
def claim_learning_candidate_for_synthesis(
|
||||
self,
|
||||
candidate_id: str,
|
||||
*,
|
||||
force: bool = False,
|
||||
) -> SkillLearningCandidate | None:
|
||||
"""Atomically claim a candidate before the expensive draft synthesis step."""
|
||||
|
||||
with self._locked():
|
||||
candidates = self.list_learning_candidates()
|
||||
claimed: SkillLearningCandidate | None = None
|
||||
for index, candidate in enumerate(candidates):
|
||||
if candidate.candidate_id != candidate_id:
|
||||
continue
|
||||
if candidate.status in {"queued", "synthesizing"}:
|
||||
return None
|
||||
if not force and candidate.draft_skill_name and candidate.draft_id:
|
||||
return None
|
||||
payload = candidate.to_dict()
|
||||
payload.update(
|
||||
{
|
||||
"status": "synthesizing",
|
||||
"last_error": None,
|
||||
"updated_at": _utc_now(),
|
||||
}
|
||||
)
|
||||
claimed = SkillLearningCandidate.from_dict(payload)
|
||||
candidates[index] = claimed
|
||||
break
|
||||
if claimed is None:
|
||||
return None
|
||||
self.candidates_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self.candidates_path.write_text(
|
||||
"".join(
|
||||
json.dumps(candidate.to_dict(), ensure_ascii=False, sort_keys=True) + "\n"
|
||||
for candidate in candidates
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
self.append_audit_event(
|
||||
candidate_id,
|
||||
"draft_synthesis_started",
|
||||
{"status": "synthesizing", "force": force},
|
||||
)
|
||||
return claimed
|
||||
|
||||
def list_learning_candidates(self, status: str | None = None) -> list[SkillLearningCandidate]:
|
||||
results: list[SkillLearningCandidate] = []
|
||||
for payload in self._read_jsonl(self.candidates_path):
|
||||
|
||||
Reference in New Issue
Block a user