Repository navigation
fix(runtime): bound list_drafts verdict work by a count cap and a time budget - #39012
Conversation
…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>
Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 30 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # 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
|
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ Final green head · 2026-12-02T00:45Z · zone osa-ai
|
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm L1 review · PR #39012 (#38965) · head 55d173f · 2026-12-02T00:47ZVERDICT: ACCEPT. No must-fix and no should-fix.
Next: zone landing. The merge closes #38965. #39001 carries the per-verdict cost. |
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ 落地
State change: ready for review + auto-merge, by zone osa-ai (2026-12-02T00:48Z); |
Requested by Yibo Wang · project thread
Fixes #38965
Claim for this branch: #38965 comment 7324088602
Clause-②: no
Metadata-protocol: none
维护者速读
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: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).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 readsDate.now(), so the test spends it with a spy and no sleep.updatedAtdescending). 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 (noORDER BY), so judging in list order would pick an arbitrary set.verdict: nullwithverdictWithheld: { 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.judged(always) and, when some drafts were not judged,notJudged, one sentence that says how many and to passpackage. Both come ahead ofdrafts, so a reply cut short still carries them.judgedcounts them, the rest answerverdict: nullwithverdictWithheld, andpackagenarrows the list.No input parameter is added (no paging, no
offset), so the input schema is unchanged. That keeps the claim'sClause-②: 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 countsgetMetaItemanddraftPublishJudgement:judged= the cap. The judged set is exactly the 50 most recently saved drafts. Every other row hasverdict: nullwithverdictWithheldMAX_RECORDS_EXCEEDED/ 400, and that object parses underDraftReviewVerdictRefusalSchema.Date.nowspy advances 3 s on each strict read. Exactlyceil(20000 / 3000)= 7 verdicts start, which is below the cap; the rest are withheld.judged= 3, and there is nonotJudged.Red on today's code, ablations, restore
mcp-authoring.ts(base38ab473c3e, blob3d9009bbfa) against the new test: 3 failed (expected 500 to be undefinedon the read count;expected { Object (count, drafts) } to match object { count: 3, judged: 3 }).node scripts/ablation-replace.mjs, anchor 1 to 0, blob01bb9c7693to49d566da17): case 1 red,expected 500 to be 50. Restored: blob equals HEAD andgit diff HEADis empty.if (false)(blob01bb9c7693to03662ccd29): case 2 red,expected 50 to be 7. Restored: blob equals HEAD andgit diff HEADis empty.git checkout HEAD -- packages/runtime/src/domains/mcp-authoring.ts,git hash-object= HEAD blob01bb9c7693,git diff HEADempty.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).@objectstack/runtimesuite did not finish within the container's foreground limit and was stopped: NOT MEASURED locally. CI'sTest Coreowns it.Acceptance notes
_diagnostics, collecting the package closure again without the door's shared map. That cost lives inmetadata-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.maxExecutionTimeSec600 did not cut the hung call). That is cloudservice-ai's, out of scope here.skills/objectstack-mcp-build/SKILL.mdsayslist_draftslists "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).DraftReviewItemSchema.verdictWithheldreads "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.list_draftsentry "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:
packages/runtime/src/domains/mcp-authoring.ts, thecase 'list_drafts'branch: the order, the two guards, and the withheld row.packages/runtime/src/domains/mcp-authoring-38965-list-drafts-bound.test.ts..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.tsshould report 3 passed.Local gate subset at 55d173f
node scripts/pm/dispatch-gates.mjs --commandsderived 68 families. 66 exited 0, among themcheck: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/mainandcheck-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) andcheck:dual-build-cjs-loads(it reads dist output for packages this worktree did not build).--ranreconciliation:68 derived, 66 run, 2 NOT-MEASURED, 0 UNRUN.overlap-check.mjswas clean before each push (origin/main, and #39006, which sharesmcp-authoring.ts: merges cleanly).Generated by Claude Code