Repository navigation
test(mcp): drive the worker CPU-budget case from a stepping thread clock - #34853
Conversation
The worker case raced real time: a 30 ms budget makes the pool's wall-clock ceiling 150 ms, and a loaded runner's worker was cut there before page 1, answering "after page 0 of 120" with no text. The case now starts its worker with a data-URL preload that replaces process.threadCpuUsage in the worker thread with a stepping clock (the worker twin of steppingCpuClock), so the read stops at an exact checkpoint: page 3 of 120, and 12,800 Word paragraphs (past the length cap, which still cuts the text). The 3000 ms budget keeps the real-time ceiling (15 s) out of reach. No shipped file changes. Claude-Session: https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C Co-authored-by: Claude <noreply@anthropic.com>
…p-worker-cpu-budget
📓 Docs Drift CheckNothing in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 0 changed package(s)), so this run has no opinion about the docs. What this run could not see
Coarse fallback — 0 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): |
|
repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C 席位核对 · L1 ACCEPT · Head-sha: a5821d8 · 2026-11-17T14:00ZCard #34758, claim 6948552137, dev report 6950149326. The seat read the diff itself. Self-review of record: one test file, +46 −17,
|
|
repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C Landing · Head-sha: a5821d8 · 2026-11-17T14:20Z
State: ready + auto-merge now (L1 ACCEPT 6950219903). #34758 closes on merge. |
Fixes #34758
Clause-②: no
Metadata-protocol: none
维护者速读
packages/mcp/src/mcp-file-tools.test.ts里 worker 的 CPU 预算用例),让它用"每读一次前进固定毫秒"的假线程时钟,不再和真实 CPU 赛跑;没有改任何会发布的代码。packages/mcp/src/mcp-file-tools.test.ts的steppingThreadCpuWorker辅助函数(注入点),以及紧随其后的用例里 3000 ms 预算与步长的取值说明。pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2 src/mcp-file-tools.test.ts -t 'out of CPU budget on the worker',预期 1 passed,且无论机器多忙,PDF 恒停在第 3 页、Word 恒停在 12800 段。What changes
The worker CPU-budget case in
packages/mcp/src/mcp-file-tools.test.tsraced real time. It is now deterministic at the root, by a test-only seam that crosses the thread boundary, with no shipped file touched.content: "none"at the case's first assertion) reproduces locally under synthetic load, and an instrumented run printed the answer:Reading stopped at the CPU-time budget for one file (30 ms) after page 0 of 120, so the text is partial.That is the pool's wall-clock ceiling (5 budgets of real time = 150 ms) cutting the read before page 1, not the CPU budget: a read stopped by the budget always carries page 1. So making the CPU clock controllable alone, at 30 ms, would leave the failure in place.steppingThreadCpuWorker(stepMs)starts the source worker with one more--import: adata:URL preload that replacesprocess.threadCpuUsageinside the worker thread with a clock that advancesstepMson every read. It is the worker's twin of the in-processsteppingCpuClock, which spies the request thread'sprocess.cpuUsageand cannot reach a worker.file-extraction-worker.tsis unchanged and reads the clock it always reads. The preload is set per case through the existingconfigureExtractionWorkerEntry, which restarts the pool, andafterEachrestores the built entry.(3000 ms) after page 3 of 120.No changeset: the only changed file is a
*.test.ts. It is not a tsup entry and is excluded from the build tsconfig, and@objectstack/mcpshipsfiles: ["dist", "README.md", "CHANGELOG.md"].skip-changesetis declared on create.Tests
Package suite and typecheck (head a5821d8)
pnpm --filter @objectstack/mcp test(under the verify lock):Test Files 68 passed (68),Tests 1237 passed (1237), VERDICT command-exit 0.pnpm --filter @objectstack/mcp typecheck: exit 0,check:test-typecheck: OK — ... 6 file(s) / 53 error(s) / 8 pinned signature(s) held(the ledger is unchanged).Stress proof: 32 busy loops on a 4-core box
The same harness ran both legs: 32
node -e 'for(;;){}'loops, then the case alone (-t 'out of CPU budget on the worker') N times.content: "none", wherecontent: "text"was expected.Tests 1 passed | 46 skipped.Ablation: remove the seam wiring, then restore it
node scripts/ablation-replace.mjsreplaced the helper'sexecArgvline with one that drops the--importof the clock preload.anchor 1 -> 0, blob 58c2867c7929 -> 98321a40db56.Tests 1 failed. The expectednote: ...after page 3 of 120...andtruncated: truewere missing: on the real clock, a 3000 ms budget reads all 120 pages.blob == HEAD (58c2867c7929) and git diff HEAD is empty.dist/is involved: vitest runs the test from source, and the worker runsfile-extraction-worker.tsfrom source throughtsx.Acceptance notes
read_fileanswerscontent: "none". Its reason is the budget sentence, which says "after page 0 of N, so the text is partial", but no text comes back. SeestoppedExtractionAnswer, thenpdfAnswer([], ...), infile-content.ts. Measured throughread_filein this suite, under load.git diff origin/main -- packages/mcp/src/file-extraction-worker.ts packages/mcp/src/file-content.ts packages/mcp/src/file-extraction-pool.tsis empty. The CONTROL is the rest of the worker describe block, which runs on the real thread clock.Verification
Local gate subset (derived by dispatch-gates --commands at a5821d8)
node scripts/check-closing-keyword-parity.mjs,node scripts/check-closing-keyword-parity.mjs --self-test,node scripts/check-comment-mask-adoption.mjs,node scripts/check-comment-mask-adoption.mjs --self-test,node scripts/check-comment-mask-corpus.mjs,node scripts/check-dts-emitted.mjs --self-test,node scripts/check-issue-citations.mjs,node scripts/check-plugin-teardown-shape.mjs,node scripts/check-plugin-teardown-shape.mjs --self-test,node scripts/ci/assert-turbo-remote-cache.mjs --self-test,node scripts/ci/plan-test-core-shards.mjs --self-test,node scripts/ci/prune-turbo-cache.mjs --self-test,node scripts/docs-audit/check-affected-docs.mjs,node scripts/docs-audit/check-drift-comment.mjs,pnpm --filter @objectstack/spec run check:duration-unit-keys,pnpm check:adr-anchors,pnpm check:ci-filter-parity,pnpm check:closed-ceremony-text,pnpm check:cross-package-test-inputs,pnpm check:doc-authoring,pnpm check:driver-memory-census,pnpm check:dts-closure,pnpm check:engine-double-contract,pnpm check:gitlink-declared,pnpm check:issue-citations,pnpm check:keyed-text-bounds,pnpm check:lean-entry-closure,pnpm check:logger-receiver-detach,pnpm check:nul-bytes,pnpm check:objectql-double-limit,pnpm check:org-identifier,pnpm check:page-declaration-shape,pnpm check:platform-object-tenancy-census,pnpm check:published-files,pnpm check:query-options-erasure,pnpm check:refd-timer-probe,pnpm check:registry-log-declared,pnpm check:rest-log-spy-declared,pnpm check:slot-lookup,pnpm check:sourcemap-no-sources-content,pnpm check:system-context-census,pnpm check:test-source-alias,pnpm check:tier-file-adoption,pnpm check:type-check-coverage,pnpm check:type-check-debt,pnpm check:undeclared-dep-imports,pnpm check:vouch-for-reference-callers,pnpm check:watch-hint-literal,pnpm check:where-matcher.pnpm check:dual-build-cjs-loads: NOT MEASURED. It exited 3 withPREREQUISITE NOT MET — this gate reads built output, and some package has no dist/(78 packages unbuilt in this worktree). This is a declared narrowing: the gate reads built output of every package, and this diff changes no built file. CI'sLint & Repo Gatesruns it.dispatch-gates --ranreconciliation:50 derived, 49 run, 0 NOT-MEASURED, 1 UNRUN(the one above).node scripts/pm/overlap-check.mjs:VERDICT clean exit 0(merges cleanly into origin/main e9f65a3).Generated by Claude Code