fix: 进行中的轮次不因余额为 0 被跳过(任务书 17 真实运行发现)

full17-b 第 5 轮:两个正向运行把余额用到 0 后,roundsNext 在下一轮'下一步'时对
【正在进行中的这一轮】也判余额 0,采纳决定、收尾阶段、轮末解封全部没写就走到
导出停下。方法.md 第七部分的'余额为 0'只是不开下一轮:最后一次正向用掉全部
余额时,这一轮的采纳(采纳多因子改法则各格记'没测:剩余次数不够')、收尾与
解封照常做。修复:余额检查只对还没开始的轮次(账本里没有这一轮的阶段、跳过
事件或决定)生效。附回归测试(旧代码下断言 adopt、实际得到 halt)。

恢复:受影响的 full17-b 用 eval:study --resume 从出错处续跑,已入账记录照原样用。
npm run check 通过,npm test 477 条通过。
This commit is contained in:
2026-10-04 22:55:53 -04:00
parent 0694303153
commit 3f7de96db3
2 changed files with 29 additions and 2 deletions
+13 -2
View File
@@ -1,6 +1,6 @@
import type { RoundStepId, StudyStepId } from "../config/index.ts"; import type { RoundStepId, StudyStepId } from "../config/index.ts";
import type { Content, LedgerRecord } from "../ledger/index.ts"; import type { Content, LedgerRecord } from "../ledger/index.ts";
import { Board, CELL_NOT_RUN, cellId, experimenterId, factorKey, FORWARD_NOT_RUN, ORIGINAL_BASELINE, researcherId, splitCell, verifierId } from "../materials/index.ts"; import { Board, CELL_NOT_RUN, cellId, DECISION_KINDS, experimenterId, factorKey, FORWARD_NOT_RUN, ORIGINAL_BASELINE, researcherId, splitCell, verifierId } from "../materials/index.ts";
import { compareIds, listCells, runBalance, sharedSettings } from "../rules/index.ts"; import { compareIds, listCells, runBalance, sharedSettings } from "../rules/index.ts";
import { ablationOutcome, verificationOutcome } from "../submissions/index.ts"; import { ablationOutcome, verificationOutcome } from "../submissions/index.ts";
import { SUBMISSION_KINDS, type Stage, type SubmissionKind } from "../vocab/index.ts"; import { SUBMISSION_KINDS, type Stage, type SubmissionKind } from "../vocab/index.ts";
@@ -113,7 +113,10 @@ function studyStepNext(step: Exclude<StudyStepId, "rounds">, view: View, frozen:
*/ */
function roundsNext(view: View, frozen: Frozen): Next | null { function roundsNext(view: View, frozen: Frozen): Next | null {
for (let round = 1; ; round++) { for (let round = 1; ; round++) {
if (runBalance(frozen.config.runs, view.board.runStates()).balance === 0) return null; // 余额为 0 不开【下一轮】;已经开始的轮次照常走完——最后一次正向用掉全部余额时,这一轮的采纳、
// 消融(各格记“没测:剩余次数不够”)、收尾与解封照样做(方法.md 第七部分“什么时候开下一轮”)。
// 一轮在账本里留下的第一处痕迹是阶段记录(或按配置跳过事件、决定记录),此前这一轮还不算开始。
if (!roundStarted(view, round) && runBalance(frozen.config.runs, view.board.runStates()).balance === 0) return null;
for (const step of frozen.steps.round) { for (const step of frozen.steps.round) {
const next = step.status === "skip" ? skipNext(stageIdOf(round, step.id), step.reason, view) : roundStepNext(step.id, round, view, frozen); const next = step.status === "skip" ? skipNext(stageIdOf(round, step.id), step.reason, view) : roundStepNext(step.id, round, view, frozen);
if (next !== null) return next; if (next !== null) return next;
@@ -121,6 +124,14 @@ function roundsNext(view: View, frozen: Frozen): Next | null {
} }
} }
/** 第 round 轮开始了没有:看账本里有没有这一轮的阶段、跳过事件或决定。 */
function roundStarted(view: View, round: number): boolean {
const prefix = `r${round}-`;
if ([...view.board.stages.keys()].some((id) => id.startsWith(prefix))) return true;
if (DECISION_KINDS.some((kind) => view.board.decision(kind, round) !== undefined)) return true;
return view.events(EVENTS.skipped).some((e) => typeof e.objects[0] === "string" && e.objects[0].startsWith(prefix));
}
/** 第 round 轮的一个要执行的步骤还要做什么;做完了交回 null。 */ /** 第 round 轮的一个要执行的步骤还要做什么;做完了交回 null。 */
function roundStepNext(step: RoundStepId, round: number, view: View, frozen: Frozen): Next | null { function roundStepNext(step: RoundStepId, round: number, view: View, frozen: Frozen): Next | null {
switch (step) { switch (step) {
+16
View File
@@ -652,6 +652,22 @@ test("结算和押的因子写完:开收尾;收尾关闭后解封本轮选
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r2-proposal", stage: "proposal", round: 2, roster: R }); assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r2-proposal", stage: "proposal", round: 2, roster: R });
}); });
test("最后一次正向用掉全部余额:进行中的这一轮照常走完采纳与收尾,不开下一轮", () => {
// 复现 full17-b 第 5 轮的缺陷:两个正向运行把余额用到 0 后,采纳决定、收尾和解封被整轮跳过,
// 直接走到导出停下。余额为 0 只是不开【下一轮】(方法.md 第七部分“什么时候开下一轮”)。
const book = firstVerification(batchTwo(1), true, true);
for (const c of C) recordForward(book, c, 1, "valid");
// 已扣 3 次(基线 1、正向 2):把冻结配置的运行次数改成 3,余额为 0。
const record = book.records.find((r) => r.kind === "config")!;
const study = record.content as unknown as StudyRecord;
study.config = { ...fullConfig(), runs: 3 } as unknown as Json;
// 这一轮已经开始(r1- 的阶段都在账上):下一步是写采纳决定,不是停下。
assert.deepEqual(nextStep(book.records), { do: "adopt", round: 1 });
book.add("decision", { decision: "adopt", round: 1, rule: "adopt", ruleVersion: 1, params: null, seed: null, input: null, output: { adopted: null } });
// 没有采纳:不做消融,照样开收尾阶段。
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-wrapUp", stage: "wrapUp", round: 1, roster: R });
});
test("余额为 0:不开下一轮,走到导出停下,原因写明", () => { test("余额为 0:不开下一轮,走到导出停下,原因写明", () => {
const book = afterWrapUp(); const book = afterWrapUp();
book.add("unseal", { candidate: "r1-c1", seals: [1] }); book.add("unseal", { candidate: "r1-c1", seals: [1] });