Skip to content

Commit 4a3b532

Browse files
fix(runtime): get_metadata_item without state answers the version a following save takes (#39022)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwB9eZJyiNVzkieFuPufqwCKz)_ Fixes #38982 Clause-②: no (the tool answer gains the `version` it already carries on a read with `state`; no input parameter added, no package export moved) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:助手通过连接读取一个已有配置时,即使没说读哪个状态,返回里也带上版本号,紧接着保存修改不再因为猜错版本号被拒。 - 为什么做:属于「助手直接在环境里搭应用」这条主线第二阶段,替改现有对象、视图的助手省掉一轮失败重来。 - 出错会怎样:最坏是读的过程中配置恰好被别人改了,这时不给版本号或给旧版本号,保存会被拒并提示重读,不会覆盖别人的改动;可直接撤回本改动。 - 要你做什么:无。 ## What changes `get_metadata_item` read without `state` serves the pending draft where one exists and the published item otherwise, through the protocol's `previewDrafts` read, which answers no `version` on purpose (no single lifecycle's token describes it; it is the render path). The door therefore answered no token, and an agent that saved after such a read guessed `ifMatch` and was refused. The door now reads each lifecycle's token by the strict read a `state` read makes (`state: 'draft'` first; on `NO_DRAFT`, the plain read), BEFORE the served read, and answers the token of the lifecycle the served item came from: the draft's when the answer says `draft: true`, the published item's otherwise. A read with `state` is unchanged, and so is the protocol (`packages/metadata-protocol/**` untouched; the `previewDrafts` read keeps omitting `version`). Why before and not after: a change landing between the token read and the served read leaves the token OLDER than what was served, and a save pinned to it is refused (409, naming the current version). Read after, the token could be NEWER than what was served and would pin a save to content the caller never saw. A draft published, discarded or first saved in between leaves no token of the served lifecycle, and the answer carries no `version` then (PM mechanism assumption 3: no version rather than a wrong one). The tool description's sentence "a read without `state` answers none" now says what the answer carries, and that `version: null` means save without `ifMatch` (the save refuses `ifMatch: null` with `VALIDATION_ERROR`; a read with `state: 'active'` of an item with no stored row already answered `null`). Seat rulings D1 to D4 and ruling 5856774816 quoted in the file are untouched. Read first, by risk: 1. `packages/runtime/src/domains/mcp-authoring.ts`, the `get_metadata_item` branch: the token reads ahead of the `previewDrafts` read, and the `version` selection after the gate. 2. `packages/runtime/src/domains/mcp-authoring-38982-read-version.test.ts`, the second `describe` (a writer landing between the token reads and the served read). 3. `packages/runtime/src/domains/mcp-authoring.test.ts`, the one pin whose recorded protocol calls gain the leading `state: 'draft'` read. ## Tests New file, real metadata protocol over a SQLite file; every token is one a read answered and every save is the protocol's own judgement, no token built by hand: - no pending draft: the stateless read answers the published item's version, equal to a `state: 'active'` read's; a save pinned to it is written; - a pending draft: it answers the draft's version, equal to a `state: 'draft'` read's and different from the published one; the published version is refused `409 METADATA_CONFLICT` (the card's case) and the answered one is written; - a never-published item: the first draft's version, and a save pinned to it is written; - the draft saved again between the token read and the served read: the answered token is the older draft's, and a save pinned to it is refused, leaving the newer draft in place; - the draft discarded in between: the published item is served with no `version`; - a first draft saved in between: the draft is served with no `version`. <details><summary>Runs at head 8d6f9b4 (the merge of origin/main; 4ab29f3 after it is an empty trailer-carrying commit, same tree)</summary> - `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2` over the four files that import the authoring registry plus `src/domains/mcp*`: `Test Files 15 passed (15)`, `Tests 451 passed (451)`, lock verdict `command-exit 0`. - `pnpm --filter @objectstack/runtime typecheck`: exit 0, `check:test-typecheck: OK — @objectstack/runtime's test layer compiles under packages/runtime/tsconfig.test.json`. - The full `@objectstack/runtime` suite did not finish inside the container's foreground cap: NOT MEASURED locally, left to CI's `Test Core`. </details> <details><summary>Ablations (on-disk mutation through scripts/ablation-replace.mjs, restored to the HEAD blob, git diff HEAD empty after each)</summary> - A: the stateless read answers only the protocol's own `version` (the old behaviour): 4 of 6 new cases red (the three version cases and the re-saved-draft race); the two no-version race cases stay green, as they should. - B: the lifecycle match dropped (`servedTokens.draft ?? servedTokens.active`): the two no-version race cases red, the other four green. </details> ## Acceptance notes - Cost: a stateless read now makes two protocol reads where a draft is pending (the strict draft read, which also folds the draft's publish verdict, then the served read), and three where none is (the draft read's 404, the plain read, the served read). A read with `state` still makes one. - Boundary, not filed: the preview read considers a declared override's pending draft (`servedOverride`), the strict draft read does not. Where both an override draft and another draft of the name exist, the token answered is the one a `state: 'draft'` read answers, which may describe a different row from the one served. That is the existing `state: 'draft'` read's address, unchanged here. - AGENTS.md says a new pin for a component with a shared harness file goes into that file as a top-level `describe` (ruling record 6583487846). The dispatch's file surface names a new file and limits `mcp-authoring.test.ts` to pins reading a changed node, so the new pins are in their own file; raised in the report. - The card's other half (a skill line stating the read that does answer the token) is in `skills/**`, outside this card's surface. ## Verification `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/mcp-authoring-38982-read-version.test.ts` (after building the runtime package's dependencies) prints `Tests 6 passed (6)`. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzivFXq32jQSCUnECPj)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ff491c4 commit 4a3b532

4 files changed

Lines changed: 306 additions & 3 deletions

File tree

‎.changeset/38982-read-version.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): `get_metadata_item` without `state` answers the `version` a following save takes
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The MCP authoring door's `get_metadata_item`, read without `state`, serves the pending draft where one exists and the published item otherwise, and answered no `version`. An agent that then saved the item had no token for `save_metadata_draft`'s `ifMatch`: it guessed, and the save was refused (`VALIDATION_ERROR` on `ifMatch`, or `409 METADATA_CONFLICT`) until it read again with `state`.
11+
12+
The answer now carries the `version` of what it served: the pending draft's when it says `draft: true`, the published item's otherwise, the same token a read with that `state` answers. A save pinned to it is written. The tokens are read before the item is served, so a change made while the item is read leaves the token older than what was served, and a save pinned to it is refused naming the current version rather than written over a change the caller never saw. A draft published, discarded or first saved while the item is read leaves the answer with no `version`; read it again. `version: null` means save without `ifMatch`. A read with `state` answers as before, and the protocol's `previewDrafts` read is unchanged.
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#38982] `get_metadata_item` without `state` answers the `version` a
5+
* following `save_metadata_draft` takes as `ifMatch`. The protocol's
6+
* `previewDrafts` read, which serves a pending draft in place of the published
7+
* item, answers no `version` (no single lifecycle's token describes it), so an
8+
* agent that read an item that way and then saved it guessed `ifMatch` and was
9+
* refused. The door now answers the token of the lifecycle it served: the
10+
* draft's when the answer says `draft: true`, the published item's otherwise.
11+
*
12+
* Every case runs the real metadata protocol over a SQLite file: each token is
13+
* one a read answered, and each save is the protocol's own judgement of it.
14+
* No token is built by hand.
15+
*/
16+
17+
import { afterEach, describe, expect, it } from 'vitest';
18+
import { mkdtempSync, rmSync } from 'node:fs';
19+
import { tmpdir } from 'node:os';
20+
import { join } from 'node:path';
21+
import { ObjectQL } from '@objectstack/objectql';
22+
import { SqlDriver } from '@objectstack/driver-sql';
23+
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
24+
import {
25+
SysMetadataObject,
26+
SysMetadataHistoryObject,
27+
SysMetadataAuditObject,
28+
SysMetadataCommitObject,
29+
} from '@objectstack/metadata-core';
30+
import {
31+
createOpenAuthoringRegistry,
32+
type OpenAuthoringProtocol,
33+
type OpenAuthoringReadGateSources,
34+
type OpenAuthoringWriter,
35+
} from './mcp-authoring.js';
36+
37+
const CONTEXT = { door: 'mcp' as const, principal: { userId: 'u1' }, environmentId: 'env_1' };
38+
const PKG = 'com.example.crm_studio';
39+
const FLOW = 'crm_opportunity_followup';
40+
41+
const AUTHOR_READ_GATE: OpenAuthoringReadGateSources = (protocol) => ({
42+
resolveCaller: async () => ({ userId: 'u1', systemPermissions: ['manage_metadata'], mayWriteItem: true }),
43+
resolveSecurityService: async () => undefined,
44+
listMetaItems: (type) => protocol.getMetaItems?.({ type }),
45+
serviceProbe: () => null,
46+
navPruneLogged: new Set<string>(),
47+
});
48+
49+
const WRITER: OpenAuthoringWriter = {
50+
userTextLocales: ['en-US'],
51+
writeVerdict: async () => ({ allowed: true }),
52+
itemSaveRefusal: async () => undefined,
53+
};
54+
55+
/** An autolaunched flow, labelled so each save differs. */
56+
const flow = (label: string) => ({
57+
name: FLOW,
58+
label,
59+
type: 'autolaunched',
60+
nodes: [
61+
{ id: 'start', type: 'start', label: 'Start' },
62+
{ id: 'end', type: 'end', label: 'End' },
63+
],
64+
edges: [{ id: 'e1', source: 'start', target: 'end' }],
65+
});
66+
67+
let cleanup: Array<() => void> = [];
68+
afterEach(() => {
69+
for (const c of cleanup.reverse()) c();
70+
cleanup = [];
71+
});
72+
73+
async function realProtocol(): Promise<OpenAuthoringProtocol> {
74+
const dir = mkdtempSync(join(tmpdir(), 'os-38982-'));
75+
cleanup.push(() => rmSync(dir, { recursive: true, force: true }));
76+
const driver = new SqlDriver({ client: 'better-sqlite3', connection: { filename: join(dir, 'data.sqlite') }, useNullAsDefault: true });
77+
const platform = [SysMetadataObject, SysMetadataHistoryObject, SysMetadataAuditObject, SysMetadataCommitObject] as any[];
78+
await driver.initObjects(platform);
79+
const engine = new ObjectQL();
80+
engine.registerDriver(driver as any, true);
81+
await engine.init();
82+
for (const o of platform) engine.registry.registerObject(o, '@objectstack/platform-objects');
83+
engine.registry.registerObject({
84+
name: 'crm_opportunity',
85+
label: 'Opportunity',
86+
sharingModel: 'private',
87+
fields: { name: { type: 'text', label: 'Name' } },
88+
} as any, 'com.example.crm');
89+
engine.registry.installPackage({ id: 'com.example.crm', name: 'CRM', version: '1.0.0', type: 'app', scope: 'project' } as any, 'code' as never);
90+
engine.registry.installPackage({ id: PKG, name: 'CRM Studio', version: '1.0.0', type: 'app' } as any, 'authored');
91+
cleanup.push(() => { void engine.destroy(); });
92+
return new ObjectStackProtocolImplementation(engine as any) as unknown as OpenAuthoringProtocol;
93+
}
94+
95+
function door(protocol: OpenAuthoringProtocol) {
96+
const registry = createOpenAuthoringRegistry({
97+
admitted: true,
98+
userId: 'u1',
99+
getProtocol: async () => protocol,
100+
readGate: AUTHOR_READ_GATE,
101+
writer: WRITER,
102+
logger: { warn: () => {} },
103+
});
104+
return async (toolName: string, input: Record<string, unknown>) => {
105+
const result = await registry.execute({ toolCallId: `t-${toolName}`, toolName, input }, CONTEXT);
106+
return { isError: result.isError === true, body: JSON.parse(result.output.value) };
107+
};
108+
}
109+
110+
/** The item published at `PKG`, with no pending draft. */
111+
async function published(protocol: OpenAuthoringProtocol, label = 'Published') {
112+
await protocol.saveMetaItem!({ type: 'flow', name: FLOW, item: flow(label), packageId: PKG, mode: 'publish', actor: 'u1' } as any);
113+
}
114+
115+
const save = (call: ReturnType<typeof door>, label: string, ifMatch: unknown) =>
116+
call('save_metadata_draft', { type: 'flow', name: FLOW, item: flow(label), package: PKG, ifMatch });
117+
118+
describe('[#38982] get_metadata_item without state answers the version a following save takes', () => {
119+
it('no pending draft: it answers the published item\'s version, the one a state: active read answers, and a save pinned to it is written', async () => {
120+
const protocol = await realProtocol();
121+
await published(protocol);
122+
const call = door(protocol);
123+
124+
const read = await call('get_metadata_item', { type: 'flow', name: FLOW });
125+
expect(read.isError, JSON.stringify(read.body)).toBe(false);
126+
expect(read.body.draft).toBe(false);
127+
expect(typeof read.body.version).toBe('string');
128+
const active = await call('get_metadata_item', { type: 'flow', name: FLOW, state: 'active' });
129+
expect(read.body.version).toBe(active.body.version);
130+
// The answer's key order is unchanged: the version rides ahead of the item.
131+
expect(Object.keys(read.body)).toEqual(['type', 'name', 'draft', 'version', 'item']);
132+
133+
const saved = await save(call, 'First edit', read.body.version);
134+
expect(saved.isError, JSON.stringify(saved.body)).toBe(false);
135+
expect(saved.body.saved).toMatchObject({ state: 'draft', version: expect.any(String) });
136+
});
137+
138+
it('a pending draft: it answers the draft\'s version, the one a state: draft read answers, and a save pinned to it is written', async () => {
139+
const protocol = await realProtocol();
140+
await published(protocol);
141+
const call = door(protocol);
142+
const activeVersion = (await call('get_metadata_item', { type: 'flow', name: FLOW })).body.version;
143+
expect((await save(call, 'First edit', activeVersion)).isError).toBe(false);
144+
145+
const read = await call('get_metadata_item', { type: 'flow', name: FLOW });
146+
expect(read.isError, JSON.stringify(read.body)).toBe(false);
147+
expect(read.body.draft).toBe(true);
148+
expect(read.body.item.label).toBe('First edit');
149+
const pending = await call('get_metadata_item', { type: 'flow', name: FLOW, state: 'draft' });
150+
expect(read.body.version).toBe(pending.body.version);
151+
expect(read.body.version).not.toBe(activeVersion);
152+
153+
// The control: the published item's version is not the token this save
154+
// takes once a draft is pending (the card's 409).
155+
const stale = await save(call, 'Second edit', activeVersion);
156+
expect(stale.isError).toBe(true);
157+
expect(stale.body.error).toMatchObject({ code: 'METADATA_CONFLICT', status: 409 });
158+
159+
const saved = await save(call, 'Second edit', read.body.version);
160+
expect(saved.isError, JSON.stringify(saved.body)).toBe(false);
161+
expect((await call('get_metadata_item', { type: 'flow', name: FLOW, state: 'draft' })).body.item.label).toBe('Second edit');
162+
});
163+
164+
it('an item that was never published: the first draft\'s version, and a save pinned to it is written', async () => {
165+
const protocol = await realProtocol();
166+
const call = door(protocol);
167+
expect((await call('save_metadata_draft', { type: 'flow', name: FLOW, item: flow('Draft only'), package: PKG })).isError).toBe(false);
168+
169+
const read = await call('get_metadata_item', { type: 'flow', name: FLOW });
170+
expect(read.body.draft).toBe(true);
171+
expect(typeof read.body.version).toBe('string');
172+
const saved = await save(call, 'Draft edited', read.body.version);
173+
expect(saved.isError, JSON.stringify(saved.body)).toBe(false);
174+
});
175+
});
176+
177+
describe('[#38982] a change while the item is read never answers a token newer than what was served', () => {
178+
/**
179+
* The real protocol, with `change` run once on the served read
180+
* (`previewDrafts`), before it reads: a writer that lands between the
181+
* door's token reads and the served read.
182+
*/
183+
function racing(protocol: OpenAuthoringProtocol, change: () => Promise<unknown>): OpenAuthoringProtocol {
184+
let fired = false;
185+
return new Proxy(protocol, {
186+
get(target, key, receiver) {
187+
const value = Reflect.get(target, key, receiver);
188+
if (key !== 'getMetaItem' || typeof value !== 'function') return typeof value === 'function' ? value.bind(target) : value;
189+
return async (request: { previewDrafts?: boolean }) => {
190+
if (request.previewDrafts && !fired) {
191+
fired = true;
192+
await change();
193+
}
194+
return value.call(target, request);
195+
};
196+
},
197+
});
198+
}
199+
200+
it('the draft saved again in between: the token answered is the older draft\'s, and a save pinned to it is refused, never written over the newer draft', async () => {
201+
const protocol = await realProtocol();
202+
await published(protocol);
203+
const direct = door(protocol);
204+
const activeVersion = (await direct('get_metadata_item', { type: 'flow', name: FLOW })).body.version;
205+
expect((await save(direct, 'First edit', activeVersion)).isError).toBe(false);
206+
const firstDraftVersion = (await direct('get_metadata_item', { type: 'flow', name: FLOW, state: 'draft' })).body.version;
207+
208+
const call = door(racing(protocol, async () => {
209+
expect((await save(direct, 'Someone else', firstDraftVersion)).isError).toBe(false);
210+
}));
211+
const read = await call('get_metadata_item', { type: 'flow', name: FLOW });
212+
expect(read.body.draft).toBe(true);
213+
expect(read.body.item.label).toBe('Someone else');
214+
expect(read.body.version).toBe(firstDraftVersion);
215+
216+
const refused = await save(direct, 'Mine', read.body.version);
217+
expect(refused.body.error).toMatchObject({ code: 'METADATA_CONFLICT', status: 409 });
218+
expect((await direct('get_metadata_item', { type: 'flow', name: FLOW, state: 'draft' })).body.item.label).toBe('Someone else');
219+
});
220+
221+
it('the draft discarded in between: the published item is served with no version, since the token read was the draft\'s', async () => {
222+
const protocol = await realProtocol();
223+
await published(protocol);
224+
const direct = door(protocol);
225+
const activeVersion = (await direct('get_metadata_item', { type: 'flow', name: FLOW })).body.version;
226+
expect((await save(direct, 'First edit', activeVersion)).isError).toBe(false);
227+
228+
const call = door(racing(protocol, async () => {
229+
expect((await direct('delete_metadata_draft', { type: 'flow', name: FLOW, package: PKG })).isError).toBe(false);
230+
}));
231+
const read = await call('get_metadata_item', { type: 'flow', name: FLOW });
232+
expect(read.isError, JSON.stringify(read.body)).toBe(false);
233+
expect(read.body.draft).toBe(false);
234+
expect('version' in read.body).toBe(false);
235+
});
236+
237+
it('a first draft saved in between: the draft is served with no version, since the token read was the published item\'s', async () => {
238+
const protocol = await realProtocol();
239+
await published(protocol);
240+
const direct = door(protocol);
241+
const activeVersion = (await direct('get_metadata_item', { type: 'flow', name: FLOW, state: 'active' })).body.version;
242+
243+
const call = door(racing(protocol, async () => {
244+
expect((await save(direct, 'Someone else', activeVersion)).isError).toBe(false);
245+
}));
246+
const read = await call('get_metadata_item', { type: 'flow', name: FLOW });
247+
expect(read.isError, JSON.stringify(read.body)).toBe(false);
248+
expect(read.body.draft).toBe(true);
249+
expect('version' in read.body).toBe(false);
250+
});
251+
});

‎packages/runtime/src/domains/mcp-authoring.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ describe('the read tools answer from the metadata protocol\'s public reads', ()
462462
await call(authoring, 'get_metadata_item', { type: 'flow', name: 'lead_intake', state: 'draft' });
463463
await call(authoring, 'get_metadata_item', { type: 'flow', name: 'lead_intake', state: 'active' });
464464
expect(calls).toEqual([
465+
// [#38982] The read without `state` reads the pending draft's token first,
466+
// then the item it serves.
467+
['getMetaItem', { type: 'flow', name: 'lead_intake', state: 'draft' }],
465468
['getMetaItem', { type: 'flow', name: 'lead_intake', previewDrafts: true }],
466469
['getMetaItem', { type: 'flow', name: 'lead_intake', state: 'draft' }],
467470
['getMetaItem', { type: 'flow', name: 'lead_intake' }],

‎packages/runtime/src/domains/mcp-authoring.ts‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,10 @@ const READ_TOOLS: readonly AIToolDefinition[] = Object.freeze([
331331
'Read one metadata item\'s full definition. Without `state`, a pending draft is read in place of '
332332
+ 'the published version and the answer says `draft: true`. `state: "draft"` reads the pending '
333333
+ 'draft only and is refused when there is none; `state: "active"` reads the published version. '
334-
+ 'A read with `state` answers that version\'s `version`, the token `save_metadata_draft` takes as '
335-
+ '`ifMatch`; a read without `state` answers none. '
334+
+ 'The answer\'s `version` is the token `save_metadata_draft` takes as `ifMatch`, the one of the '
335+
+ 'version it read: without `state`, the pending draft\'s when it says `draft: true` and the published '
336+
+ 'version\'s otherwise. It carries none when the item changed while it was read: read it again. '
337+
+ '`version: null` means save without `ifMatch`. '
336338
+ 'A flow\'s answer also carries `runtimeState.enabled`: `false` means the flow is switched off and '
337339
+ 'does not run, whatever its `status` reads.',
338340
parameters: {
@@ -883,6 +885,36 @@ export function createOpenAuthoringRegistry(opts: {
883885
if (!type || !name) return refuse(VALIDATION_ERROR, 'Name the item as `type` and `name`.', 400);
884886
const typeRefused = await typeReadRefusal(type);
885887
if (typeRefused) return typeRefused;
888+
// [#38982] A read without `state` serves the pending draft
889+
// where one exists and the published item otherwise, through
890+
// the protocol's `previewDrafts` read, which answers no
891+
// `version`: no one lifecycle's token describes it. So the
892+
// token of each lifecycle is read here, by the strict read a
893+
// `state` read makes, and the answer below carries the one of
894+
// the lifecycle the served item came from. The tokens are read
895+
// BEFORE the served item, never after: a change in between
896+
// leaves the token older than what was served, and a save
897+
// pinned to it is refused naming the current version. Read
898+
// after, a newer token would pin a save to content the caller
899+
// never saw. A draft that is published, discarded or first
900+
// saved in between leaves no token of the served lifecycle,
901+
// and the answer then carries none.
902+
let servedTokens: { draft?: unknown; active?: unknown } | undefined;
903+
if (state === undefined) {
904+
let pending: { item?: unknown; version?: unknown } | undefined;
905+
try {
906+
pending = await protocol.getMetaItem({ type, name, state: 'draft' });
907+
} catch (error) {
908+
// No pending draft: the strict draft read's 404.
909+
if ((error as { code?: unknown } | null)?.code !== 'NO_DRAFT') throw error;
910+
}
911+
if (pending?.item !== undefined && pending.item !== null) {
912+
servedTokens = pending.version !== undefined ? { draft: pending.version } : {};
913+
} else {
914+
const published = await protocol.getMetaItem({ type, name });
915+
servedTokens = published?.version !== undefined ? { active: published.version } : {};
916+
}
917+
}
886918
const read = await protocol.getMetaItem({
887919
type,
888920
name,
@@ -902,6 +934,11 @@ export function createOpenAuthoringRegistry(opts: {
902934
}
903935
const item = verdict.document;
904936
const draft = state === 'draft' || (item as { _draft?: unknown })._draft === true;
937+
// A `state` read's own token; a read without `state`, the
938+
// token read above of the lifecycle served, if one was.
939+
const version = servedTokens === undefined
940+
? read.version
941+
: draft ? servedTokens.draft : servedTokens.active;
905942
// [#36856] A flow's switch is not in its definition: an admin
906943
// who switched it off left `status: 'active'` on the item. The
907944
// engine's reading rides beside the item, ahead of it, so a
@@ -914,7 +951,7 @@ export function createOpenAuthoringRegistry(opts: {
914951
type: read.type ?? type,
915952
name: read.name ?? name,
916953
draft,
917-
...(read.version !== undefined ? { version: read.version } : {}),
954+
...(version !== undefined ? { version } : {}),
918955
...(runtimeState ? { [FLOW_RUNTIME_STATE_KEY]: runtimeState } : {}),
919956
item,
920957
});

0 commit comments

Comments
 (0)