Skip to content

Commit 270d160

Browse files
fix(runtime): bound list_drafts verdict work by a count cap and a time budget (#39012)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBG4YD4RMAt72Ga5PdYYZDAQ)_ Fixes #38965 Claim for this branch: #38965 comment 7324088602 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:环境里草稿很多时,助手调用「列出草稿」会在几十秒内答复。草稿仍然全部列出,但一次只给最近保存的最多 50 个草稿做发布检查,超过 20 秒就不再开始新的检查,其余草稿注明「未检查」,并提示按应用包缩小范围。 - 为什么做:云端搭建能力上线前的第二阶段修复,替积累了大量草稿的客户解决「一问就卡死、数据库被持续占用」的问题。 - 出错会怎样:最坏情况是部分草稿没有检查结论,助手会如实说明,不会误称可发布;改动只在服务端,回滚这个提交即可恢复原样。 - 要你做什么:无。 ## What changes `list_drafts` (the MCP draft door, and the in-process authoring tools built from it) judged every pending draft one after another: one strict draft read plus one publish judgement each, with no count bound and no deadline. Measured on the real protocol over SQLite, one verdict costs about 25 + P queries, where P is the number of drafts in its package (P = 10 / 50 / 100 gave 35 / 75 / 125 queries per verdict). So a whole list of verdicts costs P × (P + 25) queries. At 500 drafts that is about 262k queries, or about 44 minutes at the roughly 100 queries a second the card measured on sqld. The card saw the call still running after 29 minutes. Now, in `packages/runtime/src/domains/mcp-authoring.ts`: - **Every draft is still listed**, in the protocol's order, with the same fields. The list is one read. - **Count cap:** at most `LIST_DRAFTS_VERDICT_CAP` = 50 drafts are judged per call. This matches the console draft review card's per-turn maximum (`DRAFT_REVIEW_MAX`), so the drafts one turn saved fit under the cap. On a local database 50 verdicts at P = 50 cost about 3,750 queries (about 5 s measured). - **Time budget:** no verdict is started once `LIST_DRAFTS_VERDICT_BUDGET_MS` = 20,000 ms have passed since the call began (the list read counts). The cap alone is no time bound on a remote database. The verdict that is running when the time runs out finishes; at P = 500 on sqld that is about 5 s. So the answer lands well inside the MCP SDK's default 60 s request timeout. The budget reads `Date.now()`, so the test spends it with a spy and no sleep. - **Sequential:** verdicts still run one at a time. They share the per-package closure map, and each one reads the database O(P) times, so running them side by side would multiply the load on the database that the card saw saturated. - **Order:** the most recently saved drafts are judged first (`updatedAt` descending). Drafts without a timestamp come last, and ties keep the list's order. The drafts a caller most likely wants verdicts for are the ones it just saved. The protocol's list has no defined order (no `ORDER BY`), so judging in list order would pick an arbitrary set. - **A draft past the bound** answers `verdict: null` with `verdictWithheld: { code: 'MAX_RECORDS_EXCEEDED', message, status: 400 }`. This is the shape a withheld verdict already has, and the console's draft review row (`DraftReviewVerdictRefusalSchema`) accepts it (pinned). The code is the registered standard caller-side limit (the request asked for more verdicts than one call reads), and its remedy is the request's own: a narrower list. One code covers both bounds, and each row's message says which one stopped it. - **The answer** gains `judged` (always) and, when some drafts were not judged, `notJudged`, one sentence that says how many and to pass `package`. Both come ahead of `drafts`, so a reply cut short still carries them. - **The tool description** gains one sentence: verdicts are bounded, `judged` counts them, the rest answer `verdict: null` with `verdictWithheld`, and `package` narrows the list. No input parameter is added (no paging, no `offset`), so the input schema is unchanged. That keeps the claim's `Clause-②: no`. A package with more than 50 drafts still gets only its 50 most recent judged; paging verdicts would widen the input schema and is left out. ## Tests `packages/runtime/src/domains/mcp-authoring-38965-list-drafts-bound.test.ts` (new). The stand-in protocol lists 500 flow drafts and counts `getMetaItem` and `draftPublishJudgement`: 1. At 500 drafts: all 500 rows are listed in order; reads = judgements = `judged` = the cap. The judged set is exactly the 50 most recently saved drafts. Every other row has `verdict: null` with `verdictWithheld` `MAX_RECORDS_EXCEEDED` / 400, and that object parses under `DraftReviewVerdictRefusalSchema`. 2. Time budget: a `Date.now` spy advances 3 s on each strict read. Exactly `ceil(20000 / 3000)` = 7 verdicts start, which is below the cap; the rest are withheld. 3. Under the bound (3 drafts): every draft is judged, `judged` = 3, and there is no `notJudged`. <details><summary>Red on today's code, ablations, restore</summary> - Today's `mcp-authoring.ts` (base `38ab473c3e`, blob `3d9009bbfa`) against the new test: **3 failed** (`expected 500 to be undefined` on the read count; `expected { Object (count, drafts) } to match object { count: 3, judged: 3 }`). - Ablation 1, cap guard deleted (`node scripts/ablation-replace.mjs`, anchor 1 to 0, blob `01bb9c7693` to `49d566da17`): case 1 red, `expected 500 to be 50`. Restored: blob equals HEAD and `git diff HEAD` is empty. - Ablation 2, budget guard replaced by `if (false)` (blob `01bb9c7693` to `03662ccd29`): case 2 red, `expected 50 to be 7`. Restored: blob equals HEAD and `git diff HEAD` is empty. - Restore after the base run: `git checkout HEAD -- packages/runtime/src/domains/mcp-authoring.ts`, `git hash-object` = HEAD blob `01bb9c7693`, `git diff HEAD` empty. </details> <details><summary>Local runs at 55d173f</summary> - `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/mcp-authoring-38965-list-drafts-bound.test.ts src/domains/mcp-authoring.test.ts` (under the verify lock): `Test Files 2 passed (2)`, `Tests 80 passed (80)`, VERDICT command-exit 0. - `pnpm --filter @objectstack/runtime typecheck`: VERDICT command-exit 0 (`tsc --noEmit`, then check:test-typecheck OK). - The whole `@objectstack/runtime` suite did not finish within the container's foreground limit and was stopped: NOT MEASURED locally. CI's `Test Core` owns it. - The baseline cost measurement (P = 10 / 50 / 100: 352 / 3,752 / 12,502 queries, 565 / 4,928 / 15,004 ms) came from a scratch test that was never committed. </details> ## Acceptance notes - The per-verdict cost that makes the whole list quadratic is the strict draft read: it folds its own publish verdict into `_diagnostics`, collecting the package closure again without the door's shared map. That cost lives in `metadata-protocol`, outside this card's fence, and is filed as #39001. With this bound, about 3 verdicts fit the budget at P = 500 on sqld. That is honest but thin, and #39001 widens it. - The cloud agent loop's turn deadline does not interrupt a running tool (`maxExecutionTimeSec` 600 did not cut the hung call). That is cloud `service-ai`'s, out of scope here. - `skills/objectstack-mcp-build/SKILL.md` says `list_drafts` lists "every pending draft in the environment, each with its verdict". That is now true only up to the bound. This is a follow-up for the skill (not edited here: `skills/**` is outside the fence). - The spec prose of `DraftReviewItemSchema.verdictWithheld` reads "why the person may not read a verdict". A not-judged row uses the same field, as the claim prescribes; the closed schema accepts it, but the prose is permission-only. Spec is not changed here. - The module's header docblock still says each `list_drafts` entry "carries its publish verdict". The bound is documented at the branch and in the tool description. The header lies outside this card's file fence, so it is not edited. ## Verification Files to read first, by risk: 1. `packages/runtime/src/domains/mcp-authoring.ts`, the `case 'list_drafts'` branch: the order, the two guards, and the withheld row. 2. `packages/runtime/src/domains/mcp-authoring-38965-list-drafts-bound.test.ts`. 3. `.changeset/38965-list-drafts-bound.md`. Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run src/domains/mcp-authoring-38965-list-drafts-bound.test.ts` should report 3 passed. <details><summary>Local gate subset at 55d173f</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 68 families. 66 exited 0, among them `check:nul-bytes`, `check:engine-double-contract`, `check:cross-package-test-inputs`, `check:doc-authoring`, `check:issue-citations`, `check:durability-log-level`, `check:test-source-alias`, `check-adr-0087-registration --base origin/main` and `check-changeset-no-major --base origin/main`. Two exited 3 with PREREQUISITE NOT MET and are NOT MEASURED locally, so CI owns them: `check-plugin-teardown-shape.mjs --self-test` (its positive control is pinned to a commit this shallow clone cannot reach) and `check:dual-build-cjs-loads` (it reads dist output for packages this worktree did not build). `--ran` reconciliation: `68 derived, 66 run, 2 NOT-MEASURED, 0 UNRUN`. `overlap-check.mjs` was clean before each push (origin/main, and #39006, which shares `mcp-authoring.ts`: merges cleanly). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ)_ <!-- signed: repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ce0d0da commit 270d160

3 files changed

Lines changed: 251 additions & 4 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): `list_drafts` answers in bounded time when many drafts are pending
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`list_drafts` on the MCP draft door (and on the in-process authoring tools that share it) used to judge every pending draft, one after another. Each verdict is a strict draft read and a publish judgement, and its cost grows with the size of the draft's package. With 500 drafts on a remote database the call never answered. Now:
11+
12+
- Every pending draft is still listed, in the same order, with the same fields.
13+
- One call judges at most 50 drafts, most recently saved first, and starts no new verdict once 20 seconds have passed since the call began. The verdict that is running when the time runs out still finishes.
14+
- A draft that was not judged answers `verdict: null` with `verdictWithheld: { code: 'MAX_RECORDS_EXCEEDED', message, status: 400 }`. A withheld verdict already had this shape, and the console's draft review card shows it as "Verdict withheld".
15+
- The answer gains `judged`, the number of drafts that were judged. When some were not, it also gains `notJudged`, a sentence that says how many were left out and to pass `package` to list fewer.
16+
- The tool description says that verdicts are bounded and how to narrow the list.
17+
18+
Nothing else changes: the input schema is the same, and a list under the bound answers as before, plus `judged`.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#38965] `list_drafts` bounds its verdict work. With 500 pending drafts the
5+
* door judged every one, one after another (a strict draft read and a publish
6+
* judgement each), and on a remote database the call never answered. Every
7+
* draft is still listed; at most `LIST_DRAFTS_VERDICT_CAP` are judged, most
8+
* recently saved first, and none is started once
9+
* `LIST_DRAFTS_VERDICT_BUDGET_MS` has passed. A draft past the bound answers
10+
* `verdict: null` with a `verdictWithheld` reason, the shape the console's
11+
* draft review row reads (`DraftReviewVerdictRefusalSchema`).
12+
*
13+
* The protocol is a stand-in that counts the two per-draft calls; the clock is
14+
* `Date.now`, advanced by the stand-in, so no case sleeps.
15+
*/
16+
17+
import { afterEach, describe, expect, it, vi } from 'vitest';
18+
import { DraftReviewVerdictRefusalSchema } from '@objectstack/spec/ai';
19+
import {
20+
LIST_DRAFTS_VERDICT_BUDGET_MS,
21+
LIST_DRAFTS_VERDICT_CAP,
22+
createOpenAuthoringRegistry,
23+
type OpenAuthoringProtocol,
24+
type OpenAuthoringReadGateSources,
25+
} from './mcp-authoring.js';
26+
27+
const CONTEXT = { door: 'mcp' as const, principal: { userId: 'u1' }, environmentId: 'env_1' };
28+
29+
const AUTHOR_READ_GATE: OpenAuthoringReadGateSources = (protocol) => ({
30+
resolveCaller: async () => ({ userId: 'u1', systemPermissions: ['manage_metadata'], mayWriteItem: true }),
31+
resolveSecurityService: async () => undefined,
32+
listMetaItems: (type) => protocol.getMetaItems?.({ type }),
33+
serviceProbe: () => null,
34+
navPruneLogged: new Set<string>(),
35+
});
36+
37+
/** Draft `i` was saved at minute `i`: the last listed is the most recent. */
38+
const savedAt = (i: number) => new Date(Date.UTC(2026, 11, 1, 0, i)).toISOString();
39+
40+
/**
41+
* `count` flow drafts, listed oldest first. `onRead` runs on every strict
42+
* draft read, before it answers (the fake clock's tick).
43+
*/
44+
function standIn(count: number, onRead: () => void = () => {}) {
45+
const reads: string[] = [];
46+
const judgements: string[] = [];
47+
const protocol: OpenAuthoringProtocol = {
48+
async getMetaTypes() {
49+
return { types: ['flow'] } as any;
50+
},
51+
async listDrafts() {
52+
return {
53+
drafts: Array.from({ length: count }, (_, i) => ({
54+
type: 'flow', name: `flow_${i}`, label: `Flow ${i}`, packageId: 'com.acme.crm', updatedAt: savedAt(i), updatedBy: 'u1',
55+
})),
56+
} as any;
57+
},
58+
async getMetaItem(request: any) {
59+
reads.push(request.name);
60+
onRead();
61+
return { type: 'flow', name: request.name, item: { name: request.name, label: request.name, _draft: true } } as any;
62+
},
63+
async draftPublishJudgement(draft: any) {
64+
judgements.push(draft.name);
65+
return { refusals: [], advisories: [] };
66+
},
67+
};
68+
return { protocol, reads, judgements };
69+
}
70+
71+
async function listDrafts(protocol: OpenAuthoringProtocol, input: unknown = {}) {
72+
const registry = createOpenAuthoringRegistry({
73+
admitted: true,
74+
userId: 'u1',
75+
getProtocol: async () => protocol,
76+
readGate: AUTHOR_READ_GATE,
77+
logger: { warn: () => {} },
78+
});
79+
const result = await registry.execute({ toolCallId: 't', toolName: 'list_drafts', input }, CONTEXT);
80+
return { isError: result.isError === true, body: JSON.parse(result.output.value) };
81+
}
82+
83+
afterEach(() => {
84+
vi.restoreAllMocks();
85+
});
86+
87+
describe('[#38965] list_drafts bounds its verdict work and lists every draft', () => {
88+
it('at 500 drafts it judges at most the cap, most recently saved first, and every other row says it was not judged', async () => {
89+
const { protocol, reads, judgements } = standIn(500);
90+
const listed = await listDrafts(protocol);
91+
92+
expect(listed.isError).toBe(false);
93+
// Every draft is listed, in the list's own order.
94+
expect(listed.body.count).toBe(500);
95+
expect(listed.body.drafts.map((d: any) => d.name)).toEqual(Array.from({ length: 500 }, (_, i) => `flow_${i}`));
96+
// The verdict work is bounded: one strict read and one judgement per judged draft.
97+
expect(reads.length).toBe(LIST_DRAFTS_VERDICT_CAP);
98+
expect(judgements.length).toBe(LIST_DRAFTS_VERDICT_CAP);
99+
expect(listed.body.judged).toBe(LIST_DRAFTS_VERDICT_CAP);
100+
expect(typeof listed.body.notJudged).toBe('string');
101+
102+
// The most recent drafts carry verdicts; the older ones do not.
103+
const recent = new Set(Array.from({ length: LIST_DRAFTS_VERDICT_CAP }, (_, i) => `flow_${499 - i}`));
104+
expect(new Set(reads)).toEqual(recent);
105+
for (const row of listed.body.drafts) {
106+
if (recent.has(row.name)) {
107+
expect(row.verdict, row.name).toEqual({ publishable: true, refusals: [], advisories: [] });
108+
expect('verdictWithheld' in row, row.name).toBe(false);
109+
} else {
110+
expect(row.verdict, row.name).toBeNull();
111+
expect(row.verdictWithheld, row.name).toMatchObject({ code: 'MAX_RECORDS_EXCEEDED', status: 400 });
112+
}
113+
}
114+
// A withheld row is one the console's draft review row accepts.
115+
const withheld = listed.body.drafts.find((d: any) => d.verdict === null).verdictWithheld;
116+
expect(DraftReviewVerdictRefusalSchema.safeParse(withheld).success).toBe(true);
117+
});
118+
119+
it('starts no verdict once the time budget is spent, though the cap is not reached', async () => {
120+
let now = 1_000_000;
121+
vi.spyOn(Date, 'now').mockImplementation(() => now);
122+
const tick = 3_000;
123+
const { protocol, reads, judgements } = standIn(500, () => { now += tick; });
124+
const listed = await listDrafts(protocol);
125+
126+
// Verdicts start at 0, 3, …, 18 s; at 21 s the budget is spent.
127+
const started = Math.ceil(LIST_DRAFTS_VERDICT_BUDGET_MS / tick);
128+
expect(started).toBeLessThan(LIST_DRAFTS_VERDICT_CAP);
129+
expect(reads.length).toBe(started);
130+
expect(judgements.length).toBe(started);
131+
expect(listed.body.judged).toBe(started);
132+
expect(listed.body.count).toBe(500);
133+
expect(listed.body.drafts.filter((d: any) => d.verdict === null)).toHaveLength(500 - started);
134+
for (const row of listed.body.drafts.filter((d: any) => d.verdict === null)) {
135+
expect(row.verdictWithheld).toMatchObject({ code: 'MAX_RECORDS_EXCEEDED', status: 400 });
136+
}
137+
expect(typeof listed.body.notJudged).toBe('string');
138+
});
139+
140+
it('under the bound every draft is judged and the answer carries no notJudged sentence', async () => {
141+
const { protocol, reads } = standIn(3);
142+
const listed = await listDrafts(protocol);
143+
expect(listed.body).toMatchObject({ count: 3, judged: 3 });
144+
expect('notJudged' in listed.body).toBe(false);
145+
expect(reads).toHaveLength(3);
146+
expect(listed.body.drafts.every((d: any) => d.verdict !== null && !('verdictWithheld' in d))).toBe(true);
147+
});
148+
});

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

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@ const VALIDATION_ERROR: ErrorCode = 'VALIDATION_ERROR';
197197
const RESOURCE_NOT_FOUND: ErrorCode = 'RESOURCE_NOT_FOUND';
198198
const SERVICE_UNAVAILABLE: ErrorCode = 'SERVICE_UNAVAILABLE';
199199
const INTERNAL_ERROR: ErrorCode = 'INTERNAL_ERROR';
200+
/**
201+
* [#38965] A listed draft `list_drafts` did not judge: the standard caller-side
202+
* limit (the call asked for more verdicts than one call reads), whose remedy is
203+
* the request's, a narrower list.
204+
*/
205+
const MAX_RECORDS_EXCEEDED: ErrorCode = 'MAX_RECORDS_EXCEEDED';
206+
207+
/**
208+
* [#38965] The most drafts one `list_drafts` call judges. A verdict costs one
209+
* strict draft read and one publish judgement, about 25 queries plus one per
210+
* closure-relevant draft in its package (the strict read collects the package
211+
* closure for its own `_diagnostics`), so the work of a whole list grows with
212+
* the square of a package's size. The console's draft review card lists at
213+
* most this many drafts a turn (`DRAFT_REVIEW_MAX`), so the drafts one turn
214+
* saved fit under it, judged most recently saved first.
215+
*/
216+
export const LIST_DRAFTS_VERDICT_CAP = 50;
217+
218+
/**
219+
* [#38965] Once this many milliseconds have passed since the call began,
220+
* `list_drafts` starts no new verdict. The cap alone is not a time bound: on a
221+
* remote database a verdict in a large package takes seconds. The draft being
222+
* judged when it runs out finishes, so the answer lands well inside an MCP
223+
* client's default 60-second request timeout.
224+
*/
225+
export const LIST_DRAFTS_VERDICT_BUDGET_MS = 20_000;
200226

201227
/** [#34774] The `@objectstack/spec` this process resolves (the version `initialize` states). */
202228
const SERVER_SPEC_VERSION: string | undefined = (() => {
@@ -329,7 +355,10 @@ const READ_TOOLS: readonly AIToolDefinition[] = Object.freeze([
329355
'List the pending metadata drafts in this environment: what was saved as a draft and is not '
330356
+ 'published yet. A person reviews and publishes drafts in Studio. Each draft carries its publish '
331357
+ 'verdict: `verdict.refusals` lists what a publish would refuse it on (rule id, path, hint), empty '
332-
+ 'when it would publish. Pass `package` to list one package\'s drafts.',
358+
+ 'when it would publish. Pass `package` to list one package\'s drafts. '
359+
+ `Every draft is listed, but one call judges at most ${LIST_DRAFTS_VERDICT_CAP} drafts, most recently `
360+
+ `saved first, and starts none after ${LIST_DRAFTS_VERDICT_BUDGET_MS / 1000} seconds: \`judged\` counts them, `
361+
+ 'and the rest answer `verdict: null` with `verdictWithheld`, so pass `package` to judge fewer.',
333362
parameters: {
334363
type: 'object',
335364
properties: {
@@ -899,6 +928,8 @@ export function createOpenAuthoringRegistry(opts: {
899928
if (typeof protocol.draftPublishJudgement !== 'function' || typeof protocol.getMetaItem !== 'function') {
900929
return unavailable();
901930
}
931+
// [#38965] The verdict budget runs from here: the list read spends it too.
932+
const began = Date.now();
902933
const listed = await protocol.listDrafts(pkg ? { packageId: pkg } : {});
903934
const drafts = Array.isArray(listed?.drafts) ? listed.drafts : [];
904935
// The list itself runs no item gate, as `/meta/_drafts` runs
@@ -913,9 +944,59 @@ export function createOpenAuthoringRegistry(opts: {
913944
// The closure a draft is judged against is its package's alone,
914945
// so one map collects it once per package for the judgements.
915946
const packageClosures = new Map<string, Promise<unknown>>();
916-
const judged = [];
917-
for (const draft of drafts) judged.push({ ...draft, ...(await gatedDraftVerdict(protocol, draft, packageClosures)) });
918-
return answer({ count: judged.length, drafts: judged });
947+
// [#38965] That cost grows with a package's size, so a whole
948+
// list of verdicts is bounded twice: at most
949+
// LIST_DRAFTS_VERDICT_CAP drafts are judged, and none is
950+
// started once LIST_DRAFTS_VERDICT_BUDGET_MS has passed. The
951+
// most recently saved drafts are judged first (the ones the
952+
// caller most likely just saved); a draft with no timestamp
953+
// comes after every dated one, and ties keep the list's order.
954+
// Verdicts run one after another: each reads the database,
955+
// and running them side by side would multiply that load.
956+
// Every draft is still listed, in the list's own order.
957+
const recency = (draft: { updatedAt?: string | null }) => {
958+
const at = typeof draft.updatedAt === 'string' ? Date.parse(draft.updatedAt) : Number.NaN;
959+
return Number.isNaN(at) ? Number.NEGATIVE_INFINITY : at;
960+
};
961+
const order = drafts.map((_, index) => index)
962+
.sort((a, b) => (recency(drafts[b]!) - recency(drafts[a]!)) || a - b);
963+
const verdicts: Array<Awaited<ReturnType<typeof gatedDraftVerdict>> | undefined> = [];
964+
let judged = 0;
965+
let budgetSpent = false;
966+
for (const index of order) {
967+
if (judged >= LIST_DRAFTS_VERDICT_CAP) break;
968+
if (Date.now() - began >= LIST_DRAFTS_VERDICT_BUDGET_MS) {
969+
budgetSpent = true;
970+
break;
971+
}
972+
verdicts[index] = await gatedDraftVerdict(protocol, drafts[index]!, packageClosures);
973+
judged += 1;
974+
}
975+
const unjudged = drafts.length - judged;
976+
// A short reason on each row; the sentence that says how to
977+
// get the rest is the answer's own, said once.
978+
const notJudged = {
979+
code: MAX_RECORDS_EXCEEDED,
980+
message: budgetSpent
981+
? `Not judged: this call stopped starting verdicts after ${LIST_DRAFTS_VERDICT_BUDGET_MS / 1000} seconds.`
982+
: `Not judged: one call judges at most ${LIST_DRAFTS_VERDICT_CAP} drafts.`,
983+
status: 400,
984+
};
985+
const rows = drafts.map((draft, index) => ({ ...draft, ...(verdicts[index] ?? { verdict: null, verdictWithheld: notJudged }) }));
986+
// The counts ride ahead of the rows, so a reply cut short still says them.
987+
return answer({
988+
count: rows.length,
989+
judged,
990+
...(unjudged > 0
991+
? {
992+
notJudged: `${unjudged} of ${rows.length} drafts were not judged (${budgetSpent
993+
? `this call starts no verdict after ${LIST_DRAFTS_VERDICT_BUDGET_MS / 1000} seconds`
994+
: `one call judges at most ${LIST_DRAFTS_VERDICT_CAP} drafts`}, most recently saved first): `
995+
+ 'they answer `verdict: null` with `verdictWithheld`. Pass `package` to list fewer drafts and judge those.',
996+
}
997+
: {}),
998+
drafts: rows,
999+
});
9191000
}
9201001
case 'save_metadata_draft': {
9211002
if (typeof protocol?.saveMetaItem !== 'function' || typeof protocol.draftPublishJudgement !== 'function') {

0 commit comments

Comments
 (0)