diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index b27c869ab..f0ceecc40 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -27590,6 +27590,7 @@ - 没有写成的个人报告写「这份报告没有写成,点数已退回」,「重新生成」走同一个开始弹窗。 - 验证与防复发:`frontend/tests/report-start-progress-2046.test.tsx` 覆盖开始卡的内容和价格来源、出生时间那一句的条件、已有报告那一行、拒绝时的说明、弹窗的关闭方式、任务阶段到步骤的对应、进度卡、三种报告三种状态的列表行;「不扣」「已退回」两句话的依据(失败前先释放预留点数)也钉在测试里。钉住旧写法的七个测试文件按原值、新值、原因更新。`frontend/DESIGN.md` 的「报告生成等待态」一节改写为现在的规定。本机没有数据库,登录后的页面无法实际渲染,没有做页面截图核对。 - 关联记录:BUG-1630、BUG-1665、BUG-1941、BUG-1950、BUG-2037。 +- 补修(2026-11-20,合并前):进度回调原先无条件 `await`,没有回调时模型调用也晚一拍,`report-reading-20261027` 里用假时钟的测试一直等下去,整套前端测试停在那个文件上;算星盘那一步的回调抛错还会让整份报告失败。现在有回调才等,并且统一经 `settleProgress`:抛错丢掉,最多等 5 秒就继续写。另有三条旧测试跟着 BUG-2046 的有意改动更新:个人报告页生成中改用和年运同款的进度卡,不再有画星盘的动效;生成中的状态多带 `createdAt`;合盘失败标题的测试改为定位到它自己的分支。验证:`report-reading-20261027` 新增一条「回调抛错、拒绝、永不返回都不影响也不卡住正文」。 - 修复版本:`claude/report-start-progress-2046`。 ## BUG-2054 | 格式骨架收尾:「时间」一节标题不固定;单一主题段首不加粗 diff --git a/frontend/src/lib/personal-report-longform-generate.ts b/frontend/src/lib/personal-report-longform-generate.ts index 41a1f5d97..75cf0de8e 100644 --- a/frontend/src/lib/personal-report-longform-generate.ts +++ b/frontend/src/lib/personal-report-longform-generate.ts @@ -7,7 +7,7 @@ import { acceptEnglishEdition, type EnglishOutcome } from "./personal-report-eng import { hashLongformMarkdown } from "./personal-report-longform-appendix"; import { annotateUnreliableChartSections } from "./personal-report-chart-caveats"; import { asRecord as record } from "@/lib/guards"; -import { writeReportReading, type ReportReadingWriter } from "./personal-report-reading"; +import { settleProgress, writeReportReading, type ReportReadingWriter } from "./personal-report-reading"; import { LONGFORM_APPENDIX_TABLE, @@ -249,7 +249,7 @@ export async function generatePersonalReportLongform( // BUG-1978: the opaque subject of the reading facts' snapshot (占星师 2026-11-18 §二.2). ...(deps.writeReading && reportSubjectRef ? { subject_ref: reportSubjectRef } : {}), }; - await deps.onProgress?.({ phase: "computing_report", completed: 0, total: 3 }); + if (deps.onProgress) await settleProgress(() => deps.onProgress?.({ phase: "computing_report", completed: 0, total: 3 })); const generated = await fetchLongformMarkdown({ payload: reportInput, apiBase: deps.apiBase ?? process.env.JYOTISH_API_BASE ?? DEFAULT_API_BASE, diff --git a/frontend/src/lib/personal-report-reading.ts b/frontend/src/lib/personal-report-reading.ts index e736d95f9..180f07deb 100644 --- a/frontend/src/lib/personal-report-reading.ts +++ b/frontend/src/lib/personal-report-reading.ts @@ -839,6 +839,27 @@ function repairInstruction(reason: ReadingRejection, conflicts: RefConflict[] | * Allow two draft attempts and a single section repair after a usable draft. * The job's remaining lease applies to all extra calls. */ +/** How long a progress write may hold the run up before the run goes on without it. */ +export const PROGRESS_WAIT_MS = 5_000; + +/** + * BUG-2046 follow-up: runs one progress callback so that it can never fail or stall the report. + * A throw is dropped; a callback that has not settled within `waitMs` is left behind. + */ +export async function settleProgress(run: () => Promise | void, waitMs = PROGRESS_WAIT_MS): Promise { + let timer: ReturnType | undefined; + try { + const pending = Promise.resolve().then(run); + // A late rejection after the wait ran out must not surface as an unhandled rejection. + pending.catch(() => undefined); + await Promise.race([pending, new Promise((resolve) => { timer = setTimeout(resolve, waitMs); })]); + } catch { + // Progress is extra; the run goes on without it. + } finally { + if (timer !== undefined) clearTimeout(timer); + } +} + export async function writeReportReading(input: Readonly<{ facts: unknown; birthTimeConfirmed: boolean; @@ -883,10 +904,12 @@ export async function writeReportReading(input: Readonly<{ attempts.push({ attempt: attempt + 1, status: "skipped", reason, sections: [] }); break; } - try { - await input.onStep?.(repairSections && repair ? "repair" : "draft"); - } catch { - // Progress is extra; the reading goes on without it. + // Awaited only when a caller gave one: an unconditional `await` moved the model call one + // microtask later even with no listener, so a caller that advances time right after starting + // the reading (the fake-timer tests) ticked before the call's own timer existed and waited forever. + if (input.onStep) { + const step = repairSections && repair ? "repair" : "draft"; + await settleProgress(() => input.onStep?.(step)); } const timed = timedSignal(input.signal, timeoutMs); try { diff --git a/frontend/tests/page-curtain-20261105.test.tsx b/frontend/tests/page-curtain-20261105.test.tsx index 29f3514d6..8097f7fe5 100644 --- a/frontend/tests/page-curtain-20261105.test.tsx +++ b/frontend/tests/page-curtain-20261105.test.tsx @@ -80,7 +80,14 @@ test("the remaining in-page waits use the same chart-drawing motion", () => { assert.match(read("../src/components/orbit-waiting.tsx"), //); assert.match(read("../src/components/app-loading-indicator.tsx"), //); assert.match(read("../src/components/synastry/synastry-wait.tsx"), //); - assert.match(read("../src/components/personal-report/personal-report-page.tsx"), //); + // 原值:个人报告页生成中是 加一句话 + // 新值:个人报告页生成中是和年运同一张进度卡(ReportRunCard,`.annual-progress`),卡片里没有画星盘的动效 + // 原因:BUG-2046,产品负责人 2026-11-20 走查后定的原型:报告写作时显示三步进度、当前在做什么和已用时间, + // 与年运的进度卡同款;年运的进度卡本来就不带这个动效,也不在这条测试里。 + const reportPage = read("../src/components/personal-report/personal-report-page.tsx"); + assert.doesNotMatch(reportPage, /ChartDrawLoader/); + assert.match(reportPage, / { + const write = Object.assign(async () => ({ body: draft(), inputTokens: 0, outputTokens: 0 }), { prompt: PROMPT }); + const steps: string[] = []; + const base = { reportInput: {}, facts: FACTS, birthTimeConfirmed: true, write }; + assert.ok((await writeReportReading({ ...base, onStep: (step) => { steps.push(step); throw new Error("progress down"); } })).reading); + assert.ok((await writeReportReading({ ...base, onStep: async () => { throw new Error("progress down"); } })).reading); + assert.deepEqual(steps, ["draft"]); + + await settleProgress(() => { throw new Error("progress down"); }); + const started = Date.now(); + await settleProgress(() => new Promise(() => {}), 30); + assert.ok(Date.now() - started < 2_000, "a callback that never settles is left behind after the wait"); + // One that rejects after the wait ran out does not surface later. + await settleProgress(() => new Promise((_, reject) => setTimeout(() => reject(new Error("late")), 40)), 10); + await new Promise((resolve) => setTimeout(resolve, 60)); + assert.equal(PROGRESS_WAIT_MS, 5_000); +}); + test("a report reading that takes 200 seconds finishes before the default timeout", async (t) => { t.mock.timers.enable({ apis: ["setTimeout", "Date"] }); const write = Object.assign(async () => { diff --git a/frontend/tests/report-start-progress-2046.test.tsx b/frontend/tests/report-start-progress-2046.test.tsx index 8a5d7fbc4..6231f03ee 100644 --- a/frontend/tests/report-start-progress-2046.test.tsx +++ b/frontend/tests/report-start-progress-2046.test.tsx @@ -190,12 +190,19 @@ test("「写到一半断掉不扣」 and 「点数已退回」 are true: credits test("the long-form report reports its real steps; every phase fits the job's phase column", () => { const generate = read("../src/lib/personal-report-longform-generate.ts"); - assert.match(generate, /await deps\.onProgress\?\.\(\{ phase: "computing_report", completed: 0, total: 3 \}\);\n\s+const generated = await fetchLongformMarkdown\(/); + // 原值: `await deps.onProgress?.(…)`,回调抛错会让整份报告失败。 + // 新值: 经 settleProgress 调用,抛错丢掉、最多等 5 秒。 + // 原因: BUG-2046 补修。进度是附带的,不能让报告失败或卡住。 + assert.match(generate, /if \(deps\.onProgress\) await settleProgress\(\(\) => deps\.onProgress\?\.\(\{ phase: "computing_report", completed: 0, total: 3 \}\)\);\n\s+const generated = await fetchLongformMarkdown\(/); assert.match(generate, /phase: step === "repair" \? "checking_reading" : "writing_reading"/); assert.match(read("../src/lib/personal-report-worker.ts"), /readingRetryDeadlineMs: context\.readingRetryDeadlineMs,\n\s+onProgress: context\.onProgress,/); // The reading says which call it is about to make, and a failed progress write never stops it. const reading = read("../src/lib/personal-report-reading.ts"); - assert.match(reading, /try \{\n\s+await input\.onStep\?\.\(repairSections && repair \? "repair" : "draft"\);\n\s+\} catch \{/); + // 原值: 不管有没有人听,都 `await input.onStep?.(…)`。 + // 新值: 有人听才等,而且经 settleProgress:抛错丢掉、最多等 5 秒。 + // 原因: BUG-2046 补修。无条件的 await 让模型调用晚一拍,`report-reading-20261027` 里用假时钟的测试 + // 在定时器建好之前就拨了时间,一直等下去,整套前端测试停在那个文件上。 + assert.match(reading, /if \(input\.onStep\) \{\n\s+const step = repairSections && repair \? "repair" : "draft";\n\s+await settleProgress\(\(\) => input\.onStep\?\.\(step\)\);/); for (const phase of ["computing_report", "writing_reading", "checking_reading"]) { assert.ok(isValidPersonalReportJobProgressPhase(phase), phase); assert.match(phase, /^[a-z][a-z0-9_]{0,63}$/, "the database check on progress_phase"); diff --git a/frontend/tests/synastry-gate-repair-20261115.test.ts b/frontend/tests/synastry-gate-repair-20261115.test.ts index 63c0e809f..2ac3fbd78 100644 --- a/frontend/tests/synastry-gate-repair-20261115.test.ts +++ b/frontend/tests/synastry-gate-repair-20261115.test.ts @@ -37,7 +37,12 @@ test("the ten-section prompt requires exactly one evidence string", () => { test("a failed synastry run keeps the synastry page title", () => { const page = readFileSync(new URL("../src/components/personal-report/personal-report-page.tsx", import.meta.url), "utf8"); - const failed = page.slice(page.indexOf('state.phase === "failed"')); + // 原值: 从第一处 `state.phase === "failed"` 往后取。 + // 新值: 从 `if (state.phase === "failed") {` 这个分支往后取。 + // 原因: BUG-2046 在它前面加了一个只管个人报告的失败分支(排除合盘和年运);合盘失败仍走这个分支,标题没有变。 + const start = page.indexOf('if (state.phase === "failed") {'); + assert.ok(start > 0); + const failed = page.slice(start); assert.match(failed.slice(0, 400), /state\.reportType === "synastry_full" \? "婚恋合盘" : "个人报告"/); });