恢复前复核当前证据和原错误并保留并发预算
This commit is contained in:
parent
00e4e451e7
commit
c19e3134a7
@ -537,28 +537,41 @@ export class Engine {
|
||||
return { accepted: true };
|
||||
}
|
||||
async retireUnpublished(t: Task, r: Run, comments: any[]) {
|
||||
if (r.status !== "recovery_required" || r.dispatchPhase !== "unstarted" ||
|
||||
r.revision !== t.revision || r.pid !== null || r.sessionId !== null ||
|
||||
r.startedAt !== null || r.result || comments.length ||
|
||||
!existsSync(dirname(r.cwd)) || readdirSync(dirname(r.cwd)).length) return false;
|
||||
if (this.store.runs(t.id).some((other) => other.id !== r.id &&
|
||||
["running", "queued", "recovery_required"].includes(other.status))) return false;
|
||||
const related = (e: any) => e.taskId === t.id || marker(e.body)?.run_id === r.id;
|
||||
if (this.store.pending().some(related) || this.store.published(t.id).some((e) =>
|
||||
e.number === r.issueNumber || marker(e.body)?.run_id === r.id)) return false;
|
||||
const binding = (task: Task, run: Run) => JSON.stringify([
|
||||
task.id, task.repository, task.revision, task.baseSha, task.headSha,
|
||||
run.id, run.taskId, run.revision, run.issueNumber, run.issueUrl, run.cwd,
|
||||
run.role, run.runtime, run.branch, run.baseSha, run.headSha,
|
||||
]);
|
||||
const originalBinding = binding(t, r);
|
||||
const safe = (task: Task, run: Run) => {
|
||||
const expectedErrors = ["分派尚未完成,禁止盲目重派", "未找到已确认发布的分派,不能恢复执行"];
|
||||
if (task.status !== "recovery_required" || run.status !== "recovery_required" ||
|
||||
!expectedErrors.includes(run.error ?? "") ||
|
||||
![...expectedErrors, "分派正文协议校验失败"].includes(task.error ?? "") ||
|
||||
binding(task, run) !== originalBinding || run.dispatchPhase !== "unstarted" ||
|
||||
run.revision !== task.revision || run.pid !== null || run.sessionId !== null ||
|
||||
run.startedAt !== null || run.result || !existsSync(dirname(run.cwd)) ||
|
||||
readdirSync(dirname(run.cwd)).length) return false;
|
||||
if (this.store.runs(task.id).some((other) => other.id !== run.id &&
|
||||
["running", "queued", "recovery_required"].includes(other.status))) return false;
|
||||
return !this.store.pending().some((e) => e.taskId === task.id || marker(e.body)?.run_id === run.id) &&
|
||||
!this.store.published(task.id).some((e) => e.number === run.issueNumber || marker(e.body)?.run_id === run.id);
|
||||
};
|
||||
if (comments.length || !safe(t, r)) return false;
|
||||
const g = this.g(t);
|
||||
let issue;
|
||||
try { issue = await this.g(t).api(`/issues/${r.issueNumber}`); }
|
||||
catch { return false; }
|
||||
try {
|
||||
issue = await g.api(`/issues/${r.issueNumber}`);
|
||||
// Re-read every comments page after the Issue lookup; prior absence is stale evidence.
|
||||
if ((await g.pages(`/issues/${r.issueNumber}/comments`)).length) return false;
|
||||
} catch { return false; }
|
||||
if (typeof issue.body !== "string" ||
|
||||
!issue.body.endsWith(`<!-- ppanel-issue:${r.id} -->`) ||
|
||||
!issue.body.includes("<!-- ppanel:")) return false;
|
||||
// This narrowly identifies the old validation-before-enqueue failure, not arbitrary orphans.
|
||||
const currentTask = this.store.task(t.id);
|
||||
if (currentTask.revision !== t.revision || currentTask.status !== "recovery_required") return false;
|
||||
const latest = this.store.run(r.id);
|
||||
if (latest.status !== r.status || latest.pid !== null || latest.sessionId !== null ||
|
||||
latest.dispatchPhase !== "unstarted" || latest.startedAt !== null ||
|
||||
readdirSync(dirname(r.cwd)).length || this.store.pending().some(related)) return false;
|
||||
// No await from final local checks through writes. Preserve current budgets and evidence.
|
||||
t = this.store.task(t.id);
|
||||
r = this.store.run(r.id);
|
||||
if (!safe(t, r)) return false;
|
||||
r.status = "cancelled";
|
||||
r.endedAt = now();
|
||||
r.error = "旧分派正文校验失败;已核对无远端评论、outbox及启动痕迹,作废分派但保留证据";
|
||||
|
||||
@ -377,6 +377,8 @@ test("old unpublished validation orphan retires only with complete negative evid
|
||||
Object.assign(r, { status: "recovery_required", dispatchPhase: "unstarted",
|
||||
pid: null, sessionId: null, startedAt: null, cwd: join(dir, "repo") });
|
||||
t.status = "recovery_required"; t.corrections = 2;
|
||||
t.error = "分派尚未完成,禁止盲目重派";
|
||||
r.error = t.error;
|
||||
if (mode === "pid") r.pid = 123;
|
||||
if (mode === "session") r.sessionId = "existing";
|
||||
store.save(t); store.saveRun(r);
|
||||
@ -384,7 +386,7 @@ test("old unpublished validation orphan retires only with complete negative evid
|
||||
store.enqueue({ id: "out", taskId: t.id, number: r.issueNumber, body: "正文" });
|
||||
if (mode === "published") { store.confirmPublished("out", "https://example.test/3"); store.ack("out"); }
|
||||
}
|
||||
engine.g = () => ({ api: async () => {
|
||||
engine.g = () => ({ pages: async () => [], api: async () => {
|
||||
if (mode === "unknown") throw new Error("network unavailable");
|
||||
return { body: (mode === "valid-body" ? "合法正文" : "返工<!-- ppanel:{} -->") + `\n\n<!-- ppanel-issue:${r.id} -->` };
|
||||
} }) as any;
|
||||
|
||||
@ -105,3 +105,13 @@ P2:tick 继续观测 failed/cancelled/blocked 根任务的未收敛运行。
|
||||
升级操作:独立维护者核对新版本、停止旧控制面并保留原数据库/数据目录,启动新控制面;不重发任务、不改数据库。tick会核对recovery_required/unstarted孤立分派:本run无PID/session/startedAt/result、运行根目录存在且为空、没有其他活跃或未知运行、完整远端评论为空、该任务无待发布outbox且该run无published记录、原Issue含绑定run的issue标记和导致旧校验失败的协议文本。全部满足才作废旧run并保留Issue和历史,唤醒真实编排模型重新决定,不直接启动或伪造报告。任何不确定项保留recovery_required;核对完成后的旧run为cancelled,不重复作废。原执行/修正次数和根任务总时限不重置;若已超限将按原规则失败,不能承诺任意历史任务都能继续。
|
||||
|
||||
验证:typecheck/build、22项测试、原样8dcf3a4控制面20场景通过。受控回归覆盖无效正文零副作用、合法一次分派,以及评论/pending/published/未知远端/PID/session拒绝清理。没有访问4498或修改原任务;真实升级后的远端核对、模型返工与运行生命周期须由#35重验,开发者不声称线上已恢复。
|
||||
|
||||
## #47 恢复竞态复审修复
|
||||
|
||||
固定独立程序 d025195686b91f30093b4c3229e5d5f0c759e0c7:evidence/issue-47/independent.mjs 原样运行,修复前25/32,修复后32/32。七个失败反例分别为原错误不匹配,以及await期间新增published、活跃run、result、Issue绑定、预算和评论。完整前后输出保留本clone .ppanel/review47;程序自行输出要求的evidence目录仅临时建立,结果移入运行证据目录,不提交独立程序或改其断言。
|
||||
|
||||
恢复现在要求已知旧错误匹配;Issue查询后再次完整分页读评论,之后重新读取当前task/run,复查绑定、预算之外的安全字段、目录、pending/published及其他运行,再无await写入。保存当前记录,预算/模型调用和新证据不被旧快照覆盖。未知错误继续recovery_required。原恢复目标保留,仍不重置年龄/预算。
|
||||
|
||||
远端Gitea不提供跨SQLite原子快照;已知未启动的run没有合法worker发布方,控制面tick串行,最后本地核对至保存无异步间隔。检查后外部新增的任意普通评论不能成为可信assignment;遇到查询失败或查询时已有评论一律不清理。升级仍需独立CR及原任务维护者实际核验,本轮未访问4498或操作原任务。
|
||||
|
||||
实际typecheck/build通过、原22项测试通过、原样20故障场景通过、独立32场景通过。原单测只补齐新增必需的历史错误与分页适配器,不删除断言。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user