Skip to content

fix(runtime): bound list_drafts verdict work by a count cap and a time budget - #39012

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-38965-list-drafts-bound
Dec 2, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-38965-list-drafts-bound

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Yibo Wang · project thread

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.
Red on today's code, ablations, restore
  • 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.
Local runs at 55d173f
  • 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.

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 metadata-protocol: each strict draft read re-collects its package closure, so list_drafts verdicts cost P×(P+25) queries #39001. With this bound, about 3 verdicts fit the budget at P = 500 on sqld. That is honest but thin, and metadata-protocol: each strict draft read re-collects its package closure, so list_drafts verdicts cost P×(P+25) queries #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.

Local gate subset at 55d173f

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).


Generated by Claude Code

…e budget

Every pending draft is still listed. At most LIST_DRAFTS_VERDICT_CAP drafts are judged, most recently saved first, and no verdict starts once LIST_DRAFTS_VERDICT_BUDGET_MS has passed; the rest answer verdict: null with a verdictWithheld reason, and the answer says how many were judged.

Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ
Co-authored-by: Claude <noreply@anthropic.com>
A stand-in protocol counts the strict draft reads and publish judgements; a Date.now spy spends the time budget with no sleep.

Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/runtime, touching 5 documentable anchor(s).

2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/api/data-api.mdx (via MAX_RECORDS_EXCEEDED (symbol, a top-level const object), MAX_RECORDS_EXCEEDED (literal, a string literal in MAX_RECORDS_EXCEEDED))
  • content/docs/api/error-catalog.mdx (via MAX_RECORDS_EXCEEDED (symbol, a top-level const object), MAX_RECORDS_EXCEEDED (literal, a string literal in MAX_RECORDS_EXCEEDED))
What this run could not see
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 71 of 254 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 30 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 571b4947b15598bc338feb8625c449faf6555473 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 66a94f56d6403b564eda2fff8492050da74ee27c — the merge of head 55d173ffd9605b766a7fae5127ea67ba68c83b9f into base 571b4947b15598bc338feb8625c449faf6555473, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 66a94f56d6403b564eda2fff8492050da74ee27c && git checkout 66a94f56d6403b564eda2fff8492050da74ee27c
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 571b4947b15598bc338feb8625c449faf6555473 55d173ffd9605b766a7fae5127ea67ba68c83b9f && git checkout -B drift-repro 571b4947b15598bc338feb8625c449faf6555473 && git merge --no-ff 55d173ffd9605b766a7fae5127ea67ba68c83b9f

node scripts/docs-audit/affected-docs.mjs --json 571b4947b15598bc338feb8625c449faf6555473

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 571b4947b15598bc338feb8625c449faf6555473 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ

Final green head · 2026-12-02T00:45Z · zone osa-ai
Head-sha: 55d173f

  • CI at this head: 39 success, 18 skipped, 0 failure, 0 running; mergeable_state clean.
  • Diff: 3 files, +251 / −4. list_drafts in packages/runtime/src/domains/mcp-authoring.ts still lists every pending draft, but judges at most LIST_DRAFTS_VERDICT_CAP = 50 per call, most recently saved first, and starts no verdict after LIST_DRAFTS_VERDICT_BUDGET_MS = 20000 ms. An unjudged row answers verdict: null with verdictWithheld { code: MAX_RECORDS_EXCEEDED, message, status: 400 }. The answer gains judged, plus notJudged (a sentence naming package) when some were left out. The tool description gains one sentence. Fixes #38965.
  • Readings (dev): one verdict measured at about 25 + P queries (P = drafts in its package), so a whole list is P×(P+25), about 262k queries at 500 drafts. The cap matches the console card's DRAFT_REVIEW_MAX; the budget keeps the answer inside the MCP SDK's 60 s default. Verdicts stay sequential. New test (500 drafts; budget driven by a Date.now spy, no sleep) red on the base blob, 3 of 3 failing; cap and budget each ablated red, restored blob == HEAD with git diff HEAD empty. 80 of 80 in the two runtime test files; 66 of 68 derived gates exit 0, 2 NOT MEASURED (CI ran them).
  • Readers: the console's DraftReviewVerdictRefusalSchema accepts the withheld object (pinned). Whether the cloud producer parses the whole answer strictly is NOT MEASURED (no list_drafts found in cloud by code search).
  • Governed check (check-governed-merges --pr 39012): NOT governed, 255 changed lines. Clause-②: no (no input parameter added; no spec change).
  • Follow-ups named by the dev: skills/objectstack-mcp-build/SKILL.md line 83 ("every pending draft … each with its verdict") is now true only up to the bound; the per-verdict quadratic cost is metadata-protocol: each strict draft read re-collects its package closure, so list_drafts verdicts cost P×(P+25) queries #39001; the cloud turn deadline not cutting a running tool is cloud's.
  • Dev report: 搭建草稿多时「列出草稿」卡死:回合不结束、不受 600 秒上限约束,用户收不到回复 #38965 comment 7330481546. L1 asked of osa-L1-a; the zone lands on ACCEPT.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm

L1 review · PR #39012 (#38965) · head 55d173f · 2026-12-02T00:47Z

VERDICT: ACCEPT. No must-fix and no should-fix.

  • Face. l1-face is CLEAN at 55d173f, with 13 items read and none flagged. Checks are 39 success, 18 expected skip, 0 failed and 0 pending, and mergeable_state is clean. The zone reads it as NOT governed, so no L2 is owed. Fixes is right. The card's acceptance asks for a bounded answer at 500 drafts, said so in the answer, plus a pin. The turn deadline in its 速读 is cloud service-ai's, as the card itself says. The three module consts sit beside the branch and are named as a deviation, which is accepted.
  • Zone point 1: new top-level keys judged / notJudged against a strict reader.
    • In this repo, nothing reads the list_drafts answer as a whole. in-process-authoring.ts passes it through.
    • The one schema built on it, the draft review card (DraftReviewListSchema, closed), is fed by a producer that builds its OWN rows from each draft's verdict / verdictWithheld. It does not take this answer's top level.
    • The row shape is unchanged: verdict: null plus verdictWithheld was already a row the door answered.
    • So no strict reader here moves. The cloud producer is NOT MEASURED, as the body says. Before cloud bumps, someone should check that it takes rows and not the envelope. I note this for the seat. It is not a defect of this PR.
  • Zone point 2: reusing verdictWithheld with MAX_RECORDS_EXCEEDED.
    • Its shape is the closed DraftReviewVerdictRefusalSchema, and the new test pins that it parses. code there is any non-empty string.
    • The console card draws it as "Verdict withheld" with the row's message, and the message says which bound stopped it.
    • The published skill reads it as intended. After docs(skills): mcp-build says a rename repair leaves the old-name draft #39005 (merged 00:38Z), its verdict: null row says "not judged; verdictWithheld or verdictError says why. Say so", and step 5 forbids calling such a draft publishable. That also settles the body's skill follow-up: the "every pending draft… each with its verdict" gloss it names was cut by docs(skills): mcp-build says a rename repair leaves the old-name draft #39005, so nothing is left to do there.
    • What stays is the spec prose on DraftReviewItemSchema.verdictWithheld ("Why the person may not read a verdict"), which now reads too narrow. It is a one-line describe edit and worth a small follow-up card. It is not a blocker, because the closed schema already accepts the row.
  • Zone point 3: arithmetic.
    • began is taken before listDrafts, so the list read spends the budget. The guard is checked before each verdict starts, so the overshoot is at most one verdict. The body measures about 5 s at P = 500 on sqld, so about 25 s plus the list read, inside a 60 s client timeout.
    • The test's 3 s per strict read starts verdicts at 0, 3, … 18 s, which is exactly 7 (ceil(20000 / 3000)).
    • The cap of 50 equals DRAFT_REVIEW_MAX. With recency-first order, a turn's own saves (at most 50) are the ones judged. The sort is total, because undated drafts sort last and ties go by index. Rows keep the list's order.
  • Tests. The tests ran red on base. Each guard has its own ablation (cap 500 → 50, budget 50 → 7), each restored. The under-bound case pins that notJudged is absent.
  • Sentence read (changeset). It is true of this head.
  • Nits, accepted.
    • The tool description still opens "Each draft carries its publish verdict" before the new bound sentence qualifies it, and the module header says the same.
    • notJudged tells the caller to "pass package", but a package with more than 50 drafts still gets only its 50 newest judged. The body says so, and paging is out of scope by design (no input-schema change).

Next: zone landing. The merge closes #38965. #39001 carries the per-verdict cost.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ

落地

reading value
check-governed-merges.mjs --pr 39012 (head fetched) NOT governed — 0 of 3 paths hit the register; 255 changed lines ≤ 3000
reviews on 55d173ff L1 ACCEPT 7330972609 (osa-L1-a), no must-fix or should-fix; no contract face owed (Clause-②: no, not governed)
check-runs on 55d173ff 39 success · 18 expected skip · 0 failed · 0 pending; mergeable_state clean
K landing-k.mjs --pr 39012: K = 1 < 15, no new locale pack, no shared book moved

State change: ready for review + auto-merge, by zone osa-ai (2026-12-02T00:48Z); Fixes #38965. Carried: #39001 (per-verdict cost); the spec describe on DraftReviewItemSchema.verdictWithheld reads permission-only (L1 note, a small follow-up); the cloud producer's reading of the answer envelope is NOT MEASURED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

搭建草稿多时「列出草稿」卡死:回合不结束、不受 600 秒上限约束,用户收不到回复

2 participants