Skip to content

Commit 491ea82

Browse files
fix(migrate): os migrate meta --stored judges a stored view's bulkActions with the declared actions, and is not green over a row served invalid (#39136)
Fixes #38923 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:运维在升级前跑「存储元数据检查」命令时,数据库里保存的列表视图若还带着已退役的批量操作配置,现在会被正确说明原因并判为不通过;能自动改写的会在应用模式下改写。 - 为什么做:属于 18 升 19 的升级主线,替升级运维解决「检查结果显示全绿、升级后视图却被标为无效」的假绿问题。 - 出错会怎样:最坏情况是检查结果偏严,某个与本次无关的无效存储行也会让检查失败,直到那一行被修好;改动只读判断和一处已有的改写路径,可以直接撤回。 - 要你做什么:确认「任何被运行时判为无效的存储行都让检查不通过」这一范围(席位已按卡片预期裁定,保留你的否决权)。 ## What changes **A stored view's `bulkActions`, judged with the actions the deployment declares.** `os migrate meta --stored` replays the conversion chain over each `sys_metadata` row on its own (`applyConversionsToStoredItem` wraps the row as `{ views: [row] }`). So `view-bulk-actions-to-action-selection` saw no action and told every stored list its actions were "not declared as an action of that object", even where the package declares them. A new sibling module, `packages/metadata-protocol/src/protocol-stored-view-selection.ts`, runs **the same entry** again for such a row. It takes the entry from `ALL_CONVERSIONS`, the pattern `collectDecisionModeReview` uses, so the rule is not restated. This time the row has the deployment's declared objects (name, `actions`, `actionLayout`) and its object-bound standalone actions beside it, read from the registry the way the runtime's action listing reads them. The answer falls into three cases: - **moves**: the actions already carry `selection` and no arm is needed, so the entry writes only `views[0].*`. The row alone is the write: it is listed `pending`, and `--stored --apply` re-saves it through the existing `saveMetaItem` call; - **declared**: the entry would also write `actions[i].locations` or `objects[j].actionLayout.selection`. Those belong to the package, not to the row, so the row stays as stored. Its TODO says the actions ARE declared, names them, and gives both fixes: add `'selection'` in the package source and deploy, or re-save the view without `bulkActions`; - **left**: an action is really undeclared, two lists order the bar differently, or the object already declares an arm. The entry's own reason stands, now given with the actions in view. No `packages/spec/src/**` edit was needed. **Rows the runtime serves invalid, judged by the runtime's own check.** The boot hydration (`loadMetaFromDb`) registers `convertStoredItem(type, body)` and warns `[metadata_spec_invalid]` when `computeMetadataDiagnostics` answers `valid: false`; the reads badge the row with the same verdict. The pass now asks that function, with no second rule, about every row whose body it reads. Not judged: identity skips (a non-canonical stored type, an organization-scoped row) and a row the chain yields no item of. On `--apply` a rewritten row is judged as rewritten. New, additive fields: - `StoredMigrationRow.servedInvalid?: { path, message }`; - `StoredMigrationReport.servedInvalid: number`; - `storedMigrationClean` also requires `servedInvalid === 0`. A report from an older protocol carries no field and reads as 0; - the formatter prints one line per such row with its id, type/name, the refused site and the fix; - `runStored` prints why the run is red and exits 1. `--json` gains `servedInvalid` beside `clean`; nothing is renamed or removed. A row that converts nothing and is served invalid is now listed `skipped` with that reason, where it used to be counted `canonical`. **Cost, stated plainly:** a deployment holding an unrelated invalid stored row now goes non-green (exit 1) until that row is fixed; the line names the row and its fix. This includes a row whose only finding is a TODO no conversion can rewrite, such as a refused `controlled_by_parent` object, which used to be `skipped` and left the run green. The scope was ruled option A by the seat (mailbox PR #38811, comment 7344505672), on the card's Expected 2 and its runtime-predicate pin; the maintainer's veto window is open. **Kept exactly as they were:** ruling C on #15429 (the decision review list), ruling A on #36055 (the View All Fields review list) and option A on stored permission sets. Both lists are still REPORT ONLY and move no count and no verdict, and a test pins the second one. **Files outside the per-card grant, edited because the change forces them** (the seat may veto any of them): - `protocol.stored-migration.test.ts`: two fixtures/pins. The legacy flow fixture lacked `label`/`type`/`edges` and the runtime served it invalid, so I added the declarations. The cbp pin asserted the old "no verdict flips" rule, and it now asserts the ruled one (`servedInvalid: 3`, not clean); - `protocol.migrate-stored-noncanonical-type.test.ts`: a `select` field without `options`, which the runtime serves invalid, gains `options`. It also gets a module-top `import '@objectstack/lint'`, which `check:test-source-alias` asks for now that the pass reaches the diagnostics; - `scripts/engine-double-contract.pinned.json`: the three rows `--write` adds for the new test's double. ## Tests - New `packages/metadata-protocol/src/protocol-stored-view-selection.test.ts` (8 cases), over the stub engine with a registry holding the package's object and actions: - the card's row: TODO names the actions declared plus both fixes, `servedInvalid` at `list.bulkActions`, not clean; - actions carrying `selection`: pending on preview, then rewritten on apply (stored body has no `bulkActions`), then a clean re-run; - an undeclared action keeps the entry's reason; - the formatter line carries the id and the fix; - **agreement**: for every seeded row, `servedInvalid` equals `!computeMetadataDiagnostics(type, convertStoredItem(type, body)).valid`; - the View All Fields list moves no count or verdict; - the module answers `unchanged` with no registry, or with no TODO of the entry. - New `packages/cli/src/commands/migrate/meta.stored-served-invalid.test.ts` (3 cases): exit 1 with the row line and the red line; `--json` carries `clean: false`, `servedInvalid: 1` and the per-row field; a control with the same skipped row served valid stays green (exit 0). <details><summary>Readings (local, on the branch before the main merge; the merge brought no change to these packages)</summary> - `pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2` (whole package): 380 files passed. The 3 failures it showed were the pre-existing pins above, fixed in this PR, and those files then passed (73/73). - metadata-protocol pins: 8/8; CLI stored tests (4 files): 11/11. - `pnpm --filter @objectstack/metadata-protocol typecheck` exit 0; `pnpm --filter @objectstack/cli typecheck` exit 0. - Ablations, each through `scripts/ablation-replace.mjs`, with the mutation shown landed and then restored (blob equal to HEAD, `git diff HEAD` empty): - the re-judgement call site off: 3 of 8 red; - the `servedInvalid` term dropped from `storedMigrationClean`: 3 red; - `servedInvalidVerdict` always answering valid: 6 red; - the CLI red line off: 1 of 3 red. </details> ## Acceptance notes - The reproduction on `origin/main` at `a533126fb4`, before this change: one stored view, reported `skipped` with the "not declared" TODO, `storedMigrationClean` true, while `computeMetadataDiagnostics` answered `valid: false` at `list.bulkActions`. - The registry read takes every declared object and action, not only the view's object. The entry itself groups by object, and a view row may list several objects. ## Verification Gates derived by `node scripts/pm/dispatch-gates.mjs` for this diff: 84 families, 80 run with exit 0, 0 unrun. The 4 NOT MEASURED families exited 3 (`PREREQUISITE NOT MET`: a full `pnpm build` is absent in this container): `check:dual-build-cjs-loads`, `check:i18n`, `check:i18n-coverage`, `check:i18n-walk-parity`. These belong to CI. `check:engine-double-contract`, `check:objectql-double-limit` and `check:test-source-alias` went red once on the new test file; each was fixed and re-run with exit 0. `node scripts/pm/overlap-check.mjs`: clean against `origin/main` and against #39131, which shares `meta.ts`. Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec vitest run src/protocol-stored-view-selection.test.ts`. Expect 8 passed, including the case that says the actions are declared and the run is not clean. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYoSKoNUygbCoMBTbGc)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QSeKYoSKoNUygbCoMBTbGc --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3dfffef commit 491ea82

10 files changed

Lines changed: 855 additions & 11 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
'@objectstack/cli': patch
4+
---
5+
6+
fix(migrate): `os migrate meta --stored` judges a stored view's `bulkActions` with the actions the deployment declares, and is not green over a row the runtime serves invalid
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
**A stored view's `bulkActions`.** The stored pass replays the conversion chain over each `sys_metadata` row on its own, so a Studio-saved list view whose `list` still carried `bulkActions` was told its actions were "not declared as an action of that object", even where the package declares them on that object. The pass now runs the same conversion (`view-bulk-actions-to-action-selection`) again for such a row, with the deployment's declared objects and actions beside it, as the registry holds them:
12+
13+
- the package's actions already carry the `selection` location, and no `actionLayout.selection` is needed: the view row alone is the write, so it is listed as pending and `--stored --apply` rewrites it without `bulkActions`;
14+
- the actions are declared but still lack `selection` (or the bar's order needs the object's `actionLayout.selection`): that write is the package's, not the row's, so the row stays as stored and its TODO says so. It names the actions and both fixes: add `'selection'` to those actions in the package source and deploy it, or re-save the view without `bulkActions`;
15+
- an action really is undeclared, two lists order the bar differently, or the object already declares an arm: the conversion's own reason, now given with the actions in view.
16+
17+
**Rows the runtime serves invalid.** Each row whose body the pass reads is judged with the runtime's own check. That is the body the boot hydration registers for the row (`convertStoredItem`), validated by `computeMetadataDiagnostics`, the check behind the `[metadata_spec_invalid]` boot line and the reads' `_diagnostics` badge. A row that fails it carries `servedInvalid: { path, message }`, and the report counts them in `servedInvalid`. `storedMigrationClean` is false while that count is not zero, so `os migrate meta --stored` exits 1. The output lists each such row with its id, the site the schema refuses and its fix, and says why the run is red. `--json` gains `servedInvalid` (the count, and the per-row field) beside `clean`; no existing field is renamed or removed. Not judged: a row stored under a non-canonical type, an organization-scoped row, and a row the chain yields no item of, because the runtime serves none of them under that type. A row that converts nothing and is served invalid is now listed `skipped` with that reason, where it used to be counted `canonical`.
18+
19+
**Cost.** A deployment holding an unrelated invalid stored row now goes non-green (exit 1) until that row is fixed. The line names the row and its fix. That includes a row whose only finding is a TODO no conversion can rewrite (for example a `controlled_by_parent` object the protocol refuses): those used to be `skipped` and left the run green. The report-only review lists (stored decision nodes, stored permission-set View All / Modify All entries) are unchanged: they still move no count and no verdict.
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #38923 — `os migrate meta --stored` is not green over a stored row the
5+
* runtime serves invalid.
6+
*
7+
* The pass (`migrateStoredMetadata`) judges each row it reads with the
8+
* runtime's own verdict and reports `servedInvalid`; `storedMigrationClean`
9+
* then answers false. This pins the command's half: the exit is non-zero,
10+
* `--json` carries the count and the per-row verdict beside `clean` (added,
11+
* nothing renamed), and the human output names the row and says why the run
12+
* is red — and a report with none stays green.
13+
*
14+
* The boot is replaced, so no database is opened; the command's own control
15+
* flow runs for real, the formatter and the verdict included.
16+
*/
17+
18+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
19+
import { dirname, resolve } from 'node:path';
20+
import { fileURLToPath } from 'node:url';
21+
import { stripVTControlCharacters } from 'node:util';
22+
import MigrateMeta from './meta.js';
23+
// The packages the command reaches through dynamic imports, loaded at module top so the
24+
// first load is paid during collection, never inside a clocked case (`check:test-source-alias`).
25+
import '@objectstack/cloud-connection';
26+
import '@objectstack/driver-sql';
27+
import '@objectstack/driver-turso';
28+
import '@objectstack/metadata';
29+
import '@objectstack/metadata-protocol';
30+
import '@objectstack/platform-objects/plugin';
31+
import '@objectstack/plugin-hono-server';
32+
import '@objectstack/plugin-security';
33+
import '@objectstack/rest';
34+
import '@objectstack/service-automation';
35+
import '@objectstack/service-datasource';
36+
import '@objectstack/service-settings';
37+
import '@objectstack/service-storage';
38+
39+
const boot = vi.hoisted(() => vi.fn());
40+
vi.mock('../../utils/schema-migrate.js', () => ({ bootSchemaStack: boot }));
41+
vi.mock('../../utils/migrate-occupancy-gate.js', () => ({
42+
OCCUPANCY_HINT: 'occupancy hint',
43+
probeMigrationTarget: vi.fn(async () => ({ status: 'free' })),
44+
}));
45+
vi.mock('../../utils/data-migration-plugins.js', () => ({ buildDataMigrationPlugins: vi.fn(async () => []) }));
46+
47+
const HERE = dirname(fileURLToPath(import.meta.url));
48+
const CLI_ROOT = resolve(HERE, '..', '..', '..');
49+
/** oclif builds its whole command table on the first `run()` in a process. */
50+
const RUN_TIMEOUT = 60_000;
51+
52+
/** The stored view of the card: a TODO, nothing to convert, and served invalid. */
53+
const VIEW_ROW = {
54+
id: 'r_7',
55+
type: 'view',
56+
name: 'lead_grid',
57+
organizationId: null,
58+
packageId: 'app.crm',
59+
state: 'active' as const,
60+
outcome: 'skipped' as const,
61+
notices: [],
62+
todos: [{
63+
conversionId: 'view-bulk-actions-to-action-selection',
64+
surface: 'view.list.bulkActions',
65+
from: '["merge_leads"]',
66+
path: 'views[0].list.bulkActions',
67+
reason: 'This stored view still carries the retired `bulkActions`.',
68+
message: 'left as stored',
69+
}],
70+
reason: 'the conversion chain rewrites nothing here',
71+
servedInvalid: { path: 'list.bulkActions', message: '`view.list.bulkActions` was removed in @objectstack/spec 19.0.0' },
72+
};
73+
74+
function reportOf(servedInvalid: boolean) {
75+
return {
76+
apply: false,
77+
protocol: '19.0.0',
78+
scanned: 2,
79+
canonical: 1,
80+
pending: 0,
81+
rewritten: 0,
82+
skipped: 1,
83+
failed: 0,
84+
servedInvalid: servedInvalid ? 1 : 0,
85+
rows: [servedInvalid ? VIEW_ROW : { ...VIEW_ROW, servedInvalid: undefined }],
86+
decisionModeReview: [],
87+
viewAllFieldsReview: [],
88+
};
89+
}
90+
91+
const migrateStoredMetadata = vi.fn();
92+
let written: string[];
93+
let stdout: ReturnType<typeof vi.spyOn>;
94+
let stderr: ReturnType<typeof vi.spyOn>;
95+
let log: ReturnType<typeof vi.spyOn>;
96+
97+
beforeEach(() => {
98+
migrateStoredMetadata.mockReset();
99+
boot.mockReset();
100+
boot.mockResolvedValue({
101+
kernel: { getService: (name: string) => (name === 'protocol' ? { migrateStoredMetadata } : undefined) },
102+
dbLabel: 'file:test.db',
103+
tableAbsent: () => false,
104+
shutdown: vi.fn(async () => {}),
105+
});
106+
written = [];
107+
// `emitJson` awaits the write's DRAIN callback, so the double invokes it.
108+
stdout = vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown, enc?: unknown, cb?: unknown) => {
109+
written.push(String(chunk));
110+
const done = typeof enc === 'function' ? enc : cb;
111+
if (typeof done === 'function') done();
112+
return true;
113+
}) as typeof process.stdout.write);
114+
stderr = vi.spyOn(process.stderr, 'write').mockImplementation((() => true) as typeof process.stderr.write);
115+
log = vi.spyOn(console, 'log').mockImplementation(() => {});
116+
});
117+
afterEach(() => {
118+
stdout.mockRestore();
119+
stderr.mockRestore();
120+
log.mockRestore();
121+
});
122+
123+
/** Run the command over `report`; the printed text, colour stripped, and the exit code it raised. */
124+
async function run(argv: string[], report: ReturnType<typeof reportOf>) {
125+
migrateStoredMetadata.mockResolvedValue(report);
126+
let exit: number | undefined;
127+
try {
128+
await MigrateMeta.run(argv, { root: CLI_ROOT });
129+
} catch (error: any) {
130+
exit = error?.oclif?.exit;
131+
if (exit === undefined) throw error;
132+
}
133+
const text = log.mock.calls.map((call: unknown[]) => stripVTControlCharacters(call.map(String).join(' '))).join('\n');
134+
return { exit, text };
135+
}
136+
137+
describe('os migrate meta --stored — a row the runtime serves invalid makes the run non-green (#38923)', () => {
138+
it('exits 1, names the row by id with its fix, and says why the run is red', async () => {
139+
const { exit, text } = await run(['--stored'], reportOf(true));
140+
141+
expect(exit).toBe(1);
142+
expect(text).toContain('view/lead_grid [env-wide, package=app.crm] id=r_7 — list.bulkActions:');
143+
expect(text).toContain('fix: correct the row (sys_metadata id r_7)');
144+
expect(text).toContain('1 stored row(s) are served INVALID by the runtime on protocol 19.0.0');
145+
expect(text).not.toMatch(/already on protocol/);
146+
}, RUN_TIMEOUT);
147+
148+
it('--json adds `servedInvalid` beside `clean: false`, and the per-row verdict', async () => {
149+
const { exit } = await run(['--stored', '--json'], reportOf(true));
150+
151+
expect(exit).toBe(1);
152+
const out = JSON.parse(written.join(''));
153+
expect(out).toMatchObject({ clean: false, servedInvalid: 1, skipped: 1, pending: 0, failed: 0 });
154+
expect(out.rows[0].servedInvalid).toEqual(VIEW_ROW.servedInvalid);
155+
}, RUN_TIMEOUT);
156+
157+
it('CONTROL — the same skipped row served valid leaves the run green', async () => {
158+
const { exit } = await run(['--stored', '--json'], reportOf(false));
159+
160+
expect(exit).toBeUndefined();
161+
expect(JSON.parse(written.join(''))).toMatchObject({ clean: true, servedInvalid: 0 });
162+
}, RUN_TIMEOUT);
163+
});

‎packages/cli/src/commands/migrate/meta.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,7 @@ export default class MigrateMeta extends Command {
19711971
rewritten: 0,
19721972
skipped: 0,
19731973
failed: 0,
1974+
servedInvalid: 0,
19741975
rows: [],
19751976
decisionModeReview: [],
19761977
viewAllFieldsReview: [],
@@ -2040,12 +2041,23 @@ export default class MigrateMeta extends Command {
20402041
: '')
20412042
+ '.',
20422043
);
2043-
} else {
2044+
} else if (report.pending > 0) {
20442045
printWarning(
20452046
`${report.pending} row(s) carry a pre-protocol shape. They read canonically today (the chain `
20462047
+ 'runs on every load); re-run with --apply to persist it.',
20472048
);
20482049
}
2050+
// [#38923] Beside whichever line above: a row the runtime serves
2051+
// invalid is what a green run must never hide. The report lists each
2052+
// one with its id and fix; this line says it is why the run is red.
2053+
const servedInvalid = report.servedInvalid ?? 0;
2054+
if (servedInvalid > 0) {
2055+
printError(
2056+
`${servedInvalid} stored row(s) are served INVALID by the runtime on protocol ${report.protocol} — `
2057+
+ 'each is listed above with its id, the site the schema refuses and its fix. The run is not clean '
2058+
+ 'until each is fixed.',
2059+
);
2060+
}
20492061
}
20502062
} catch (error: any) {
20512063
exitCode = 1;

‎packages/metadata-protocol/src/protocol-save.ts‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
} from './protocol-translated-echo.js';
4141
import { PROTOCOL_VERSION, stripReadDecorations } from '@objectstack/spec/kernel';
4242
import { collectDecisionModeReview, collectViewAllFieldsReview } from './stored-migration.js';
43+
import { judgeStoredViewBulkActions, servedInvalidOf } from './protocol-stored-view-selection.js';
4344
import type {
4445
StoredFlowCanonicalization,
4546
StoredMigrationNotice,
@@ -2688,6 +2689,7 @@ export class ProtocolSaveFacet {
26882689
rewritten: 0,
26892690
skipped: 0,
26902691
failed: 0,
2692+
servedInvalid: 0,
26912693
rows: [],
26922694
decisionModeReview: [],
26932695
viewAllFieldsReview: [],
@@ -2761,6 +2763,8 @@ export class ProtocolSaveFacet {
27612763
return;
27622764
}
27632765
report[entry.outcome]++;
2766+
// [#38923] The runtime's own verdict, counted whatever the outcome.
2767+
if (entry.servedInvalid) report.servedInvalid++;
27642768
report.rows.push(entry);
27652769
};
27662770

@@ -2886,6 +2890,7 @@ export class ProtocolSaveFacet {
28862890
if (!canonicalizeFlow) {
28872891
record({
28882892
...base,
2893+
...servedInvalidOf(singular, body),
28892894
outcome: 'skipped',
28902895
reason: 'flows canonicalize at AutomationEngine.registerFlow — its registration '
28912896
+ 'checks need the live node registry, and no automation service '
@@ -2901,6 +2906,7 @@ export class ProtocolSaveFacet {
29012906
// already broken at runtime. Report it; never persist a guess.
29022907
record({
29032908
...base,
2909+
...servedInvalidOf(singular, body),
29042910
outcome: 'failed',
29052911
reason: `the flow does not canonicalize: ${e?.message ?? String(e)}`,
29062912
});
@@ -2913,6 +2919,7 @@ export class ProtocolSaveFacet {
29132919
if (!overlayAllowed && !runtimeCreateAllowed) {
29142920
record({
29152921
...base,
2922+
...servedInvalidOf(singular, flowResult ? body : host.convertStoredItemDetailed(singular, body).item),
29162923
outcome: 'skipped',
29172924
reason: `type '${singular}' has no repository write path (allowEnvironmentOverlay and `
29182925
+ 'allowRuntimeCreate are both false), so a rewrite would record no history',
@@ -2942,11 +2949,26 @@ export class ProtocolSaveFacet {
29422949
// [#25279] A stored object's `external` binding is judged against the
29432950
// datasource the save door reads for it, so the listing names the
29442951
// row exactly when that door refuses its next save.
2945-
const { item, notices, todos } = flowResult
2952+
const converted = flowResult
29462953
? { item: flowResult.storable, notices: flowResult.notices, todos: flowResult.todos ?? [] }
29472954
: host.convertStoredItemDetailed(
29482955
singular, body, undefined, await host.storedRowKnownDatasources(singular, body),
29492956
);
2957+
// [#38923] What the runtime serves for this row today (`convertStoredItem`
2958+
// converts every type but `flow`, which is served as stored), judged
2959+
// below by the runtime's own verdict ({@link servedInvalidVerdict}).
2960+
const servedBody = flowResult ? body : converted.item;
2961+
// [#38923] A stored view's `bulkActions`, re-judged by the same entry
2962+
// with the deployment's declared actions beside the row, which the
2963+
// stored seam does not see ({@link judgeStoredViewBulkActions}).
2964+
const judged = !flowResult && singular === 'view'
2965+
? judgeStoredViewBulkActions(converted.item, converted.todos, host.engine.registry)
2966+
: { kind: 'unchanged' as const };
2967+
const { item, notices, todos }: { item: unknown; notices: StoredMigrationNotice[]; todos: StoredMigrationTodo[] } =
2968+
judged.kind === 'moves'
2969+
? { item: judged.item, notices: [...converted.notices, ...judged.notices], todos: judged.todos }
2970+
: judged.kind === 'unchanged' ? converted : { ...converted, todos: judged.todos };
2971+
const asServed = servedBody === undefined ? {} : servedInvalidOf(singular, servedBody);
29502972
// [#29673] …and, for an `object` row, the save door's translated-echo
29512973
// restoration ({@link restoreTranslatedObjectEchoes}), asked of the
29522974
// row against itself and the platform's injected columns: a row a
@@ -2982,10 +3004,23 @@ export class ProtocolSaveFacet {
29823004
message: t.message,
29833005
}));
29843006
if (!changed) {
2985-
if (flattenedTodos.length === 0) {
3007+
if (flattenedTodos.length === 0 && !asServed.servedInvalid) {
29863008
record({ ...base, outcome: 'canonical' });
29873009
continue;
29883010
}
3011+
// [#38923] Nothing to convert, and the runtime serves the row
3012+
// invalid: not on protocol, and outside what this pass can rewrite.
3013+
if (flattenedTodos.length === 0) {
3014+
record({
3015+
...base,
3016+
...asServed,
3017+
outcome: 'skipped',
3018+
reason: 'the conversion chain rewrites nothing here, and the runtime serves the row invalid: '
3019+
+ 'its body fails the current spec schema at the site named below, which no conversion '
3020+
+ 'covers. Correct the row by hand.',
3021+
});
3022+
continue;
3023+
}
29893024
// Nothing to persist, and not on protocol either: every site the
29903025
// chain recognised here is one it has no lossless rewrite for.
29913026
// `skipped` — outside what a body-canonicalization pass can do,
@@ -2995,6 +3030,7 @@ export class ProtocolSaveFacet {
29953030
// `storedMigrationClean`: no run of this pass could ever clear it.
29963031
record({
29973032
...base,
3033+
...asServed,
29983034
todos: flattenedTodos,
29993035
outcome: 'skipped',
30003036
reason: `the conversion chain rewrites nothing here: it left ${flattenedTodos.length} `
@@ -3037,7 +3073,7 @@ export class ProtocolSaveFacet {
30373073
}
30383074

30393075
if (!apply) {
3040-
record({ ...base, notices: flattened, todos: flattenedTodos, outcome: 'pending' });
3076+
record({ ...base, ...asServed, notices: flattened, todos: flattenedTodos, outcome: 'pending' });
30413077
continue;
30423078
}
30433079

@@ -3059,7 +3095,9 @@ export class ProtocolSaveFacet {
30593095
// #4556 default). The pass's name is on `source` above.
30603096
...(request.actor ? { actor: request.actor } : {}),
30613097
});
3062-
const entry: StoredMigrationRow = { ...base, notices: flattened, todos: flattenedTodos, outcome: 'rewritten' };
3098+
const entry: StoredMigrationRow = {
3099+
...base, ...servedInvalidOf(singular, item), notices: flattened, todos: flattenedTodos, outcome: 'rewritten',
3100+
};
30633101
// [#32369] Read back BEFORE the row is recorded rewritten: a read
30643102
// that fails records the row failed alone (the `catch` below).
30653103
if (judging && state === 'active' && organizationId === null && isBatchObjectType(singular)) {
@@ -3106,6 +3144,7 @@ export class ProtocolSaveFacet {
31063144
// below, whole.
31073145
record({
31083146
...base,
3147+
...asServed,
31093148
notices: flattened,
31103149
todos: flattenedTodos,
31113150
outcome: 'failed',

0 commit comments

Comments
 (0)