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 { 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 { ablationOutcome, verificationOutcome } from "../submissions/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 {
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) {
const next = step.status === "skip" ? skipNext(stageIdOf(round, step.id), step.reason, view) : roundStepNext(step.id, round, view, frozen);
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。 */
function roundStepNext(step: RoundStepId, round: number, view: View, frozen: Frozen): Next | null {
switch (step) {