Repository navigation
feat(core): export the bounded document text extractor as @objectstack/core/document-text - #39016
Conversation
…/core/document-text The extractor read_file reads PDF and Word text with (its caps, the CPU budget, the worker pool and the cap on reads in flight) moves out of @objectstack/mcp into a Node-only subpath of @objectstack/core, so an AI service can hand a model a document's text without depending on the MCP package. read_file reads through it and answers exactly as before. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzegtzKWMxkohs9dHSd
…xtractor; changeset Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzegtzKWMxkohs9dHSd
…s the new document-text subpath first Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzegtzKWMxkohs9dHSd
📓 Docs Drift CheckThis PR changes 11 package(s): 15 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 6 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 77 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 6cd5f5533f5f07360e119b4491f39ff64f75f55f && git checkout 6cd5f5533f5f07360e119b4491f39ff64f75f55f
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 2f9a68cfa184eaa7e77616df03654233ddd9f9f9 b2b49cb98a8ade7562d94c760668fd1a487b655e && git checkout -B drift-repro 2f9a68cfa184eaa7e77616df03654233ddd9f9f9 && git merge --no-ff b2b49cb98a8ade7562d94c760668fd1a487b655e
node scripts/docs-audit/affected-docs.mjs --json 2f9a68cfa184eaa7e77616df03654233ddd9f9f9
|
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzegtzKWMxkohs9dHSd Contract reviewServed-tier: ① Derived judgmentsPR #39016, card #39008. Read: the card and its three comments, the PR body and its 26 files, the net diff
S1 (should-fix) — The single process-wide count is not single when the subpath is loaded in both formats. S2 (should-fix) — The published surface is wider than the card asks and wider than the PR body lists. The public entry is the implementation module, so every name the worker and the tests import is now a semver-held export of
The PR body's "New exports" names only N1 (nit) — The operator-visible fallback line changed from N2 (nit) — ② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzegtzKWMxkohs9dHSd The brief the card thread handed its isolated reviewer sub-agent (model run at the contract-review tier; the record's face is the Contract review brief — PR #39016 @
|
…y, Buffer-safe worker hand-off Review findings on the pull request: - S1: the bounds, the count of extractions in flight and the worker pool now live under a registered symbol on globalThis (document-text-state.ts), so an ESM import and a CJS require of @objectstack/core/document-text (or two installed versions) share one cap instead of one each; a busy refusal from any copy answers instanceof for every copy's class. - S2: the implementation moves to document-text-extract.ts; document-text.ts is the curated public entry (the extractor, its caps and bounds, the busy refusal, configureExtractionWorkerEntry). Platform checklist anchors follow the declaring file. - The worker hand-off copies the caller's bytes into a fresh Uint8Array instead of slice(): a Node Buffer's slice is a view over Node's shared, untransferable pool (DataCloneError) or over memory the transfer would detach from the caller. - Changeset and connect-mcp say the one-time warn line changed. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzegtzKWMxkohs9dHSd
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzegtzKWMxkohs9dHSd
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzegtzKWMxkohs9dHSd Contract reviewServed-tier: ① Derived judgmentsDelta read of PR #39016 (card #39008):
N3 (nit) — The Buffer fix changes what N4 (nit) — Two installed versions of core now share the idle workers as well as the count, so a job from one version can run on a worker started from the other version's entry. The ② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm Contract-review-claim: session_01WGufzhGA3zoCFquQgku4pm · head 7e4f966 · 2026-12-02T02:13Z |
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm Contract reviewServed-tier: PR #39016 for card #39008 (acceptance item 1). No path of the diff is on the governed register; the seat asked for a contract-tier read because the PR adds a public subpath to a published package, and the twelve files above are read as ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment(a) The main entry stays free of (b) One cap and one pool across copies, and S3 (should-fix) — (c) Every bound of
(d) The Buffer hand-off: holds. (e) The public surface: holds for a first consumer, with two notes. N5 (nit) — Two knobs are wider than any consumer in the diff needs. N6 (nit) — The changeset says the extractor "keeps every bound N7 (nit) — The changeset tells a bundling host to point the pool at "the worker entry it ships", but The MCP side: holds. S3 is the one open finding, and its fix comes back for a delta read. The three notes numbered N5 to N7 end with this round. Implemented-by: VERDICT: PASS |
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm L1 — PR #39016 @
|
The built worker entry is found beside each copy's own import.meta.url, so whether it exists is a fact about that copy, not the process. The verdict now lives in a module variable of document-text-pool.ts instead of the shared state: a bundled copy that finds no worker no longer sends every other copy (read_file's included) to the request thread. An idle worker serves any copy, so it is taken before the copy's own verdict is consulted. Two-copy pin added. The changeset says the input byte cap stays the caller's, and that the worker file is addressed by path (no exports entry). Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzegtzKWMxkohs9dHSd
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm Contract-review-claim: session_01WGufzhGA3zoCFquQgku4pm · head b2b49cb · 2026-12-02T02:54Z |
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm Contract reviewServed-tier: Delta read of PR #39016 (card #39008): ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentS3: closed The fix, against the scenario it was raised on: holds. Does a reset leave another copy inconsistent: no. Is key N8 (nit) — A copy's verdict can now outlive the entry it was reached on. N9 (nit) — The changeset names the file to ship as S3 is closed and this delta raises no finding above a nit. The notes numbered N5 to N9 end with this round. Implemented-by: VERDICT: PASS |
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm L1 delta · PR #39016 (#39008) · head b2b49cb · 2026-12-02T02:57ZACCEPT, on head
Landing rule B: Next: landing. |
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhPdWmTd47Fi2bKYZS 席位核对ACCEPT — PR #39016 @
落地
State change: ready for review + auto-merge, by the owning seat. #39008 stays open for its cloud acceptance. |
Requested by Yibo Wang · project thread
Part of #39008 (this PR is its first acceptance item; the second, the cloud card that switches PDF input to the extracted text, is filed by the seat when this lands)
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
What changes
The bounded document text extractor MCP
read_fileused (until now private to@objectstack/mcp) moves to@objectstack/coreand is exported from a new Node-only subpath,@objectstack/core/document-text. The last public manifest of@objectstack/service-ai(npm 10.3.0) depends on@objectstack/core,formula,specandtypes, never on@objectstack/mcp, so the AI service can use it without a new dependency (the cloud tree is not readable from here: the cloud follow-up card re-reads its manifest).@objectstack/core/egress, kept off the main entry, so a host that never reads a document never loadsunpdf.unpdf1.9.1 moves from@objectstack/mcpdependencies to@objectstack/core(still a dynamic import on the first PDF; it stays an@objectstack/mcpdevDependency for the suite'svi.mock('unpdf'))..docxbody, 5 MiB image), the CPU budget per extraction and its wall-clock ceiling, the process-wide cap on extractions in flight and its refusal (ReadFileExtractionBusyError, 503, retryable), the worker pool and the worker entry (packages/mcp/src/file-extraction-{pool,worker}.ts→packages/core/src/document-text-{pool,worker}.ts, git renames; the extractor itself topackages/core/src/document-text-extract.ts). Names and the two host variables (OS_MCP_READ_FILE_*) are unchanged.packages/core/src/document-text.tsre-exports exactlyextractFileContentandExtractedContent,ReadFileExtractionBusyError, the caps and bound constants (READ_FILE_*),resolveReadFileExtractionLimits/configureReadFileExtraction/activeReadFileExtractionLimitsandReadFileExtractionLimits, andconfigureExtractionWorkerEntry/ExtractionWorkerEntry. New beside the moved names:activeReadFileExtractionLimits()(the bounds now, failing on a malformed variable;renderReadFilecalls it where it called the private one) andconfigureExtractionWorkerEntry, so a host that bundles core into one file can point the pool at the worker entry it ships. The rest (the document-onlyextractDocument, the worker protocol, the pool's stats and reset) stays internal.globalThis(packages/core/src/document-text-state.ts, keyobjectstack.core.documentText.state.v1, the pattern ofsecurity/credential-use-client.ts), so an ESMimportand a CJSrequireof the subpath, or two installed versions, share one cap instead of admitting it once each. One fact stays per copy: whether a worker entry can be found beside that copy's ownimport.meta.url(the pool'sunavailableReason), so a bundled copy that finds no worker never sends another copy,read_file's included, to the request thread; an idle worker serves any copy first.ReadFileExtractionBusyErroranswersinstanceoffor a refusal from any copy (a symbol brand). A worker thread has its ownglobalThisand counts nothing.new Uint8Array(bytes)instead ofbytes.slice(). A NodeBufferis aUint8Arraywhosesliceis a view over the same memory: a small one sits in Node's shared pool, which cannot be transferred (DataCloneError, the read rejects), and a large one would have its memory detached from the caller. Today'sread_filebridge hands aUint8Array; a public caller would naturally hand aBuffer.packages/core/tsup.config.tsbuildsdocument-textas an entry anddocument-text-workerbeside it in both formats, withshims: trueso the CJS build'simport.meta.urlfinds the worker (nothing else in core readsimport.meta,__dirnameor__filename).packages/mcp/tsup.config.tsdrops its worker entry.read_file:packages/mcp/src/file-content.tskeepsREAD_FILE_MAX_BYTES, the file bridge types andrenderReadFile, and imports the extractor;plugin.tsandmcp-http-tools.tsimportconfigureReadFileExtraction/ReadFileExtractionBusyErrorfrom the subpath. One process, one pool and one count, whoever asks.content/docs/ai/connect-mcp.mdxsays the two bounds cover every caller in the process; the platform checklist itemai.mcp-read-file-pdf-word-extractionrepoints its anchors (revision 4, no clause changed).@objectstack/coreto its source by prefix now maps@objectstack/core/document-textfirst (mcp,runtime,metadata,driver-memory,driver-sql,knowledge-memory,knowledge-pgvector,knowledge-turso,plugin-dev,plugin-hono-server);check:test-source-aliasfound them, andruntimewas a live ENOTDIR (its tests reach@objectstack/mcp).Read first (by risk)
packages/core/src/document-text-state.ts: the shared state and its key; the suffix must change whenever the state's shape or the worker protocol does.packages/core/tsup.config.ts: the worker entry andshims; a CJS build that cannot find the worker silently reads in-process (still bounded).shimschanges no other entry:dist/logger.{js,cjs},dist/index.jsanddist/egress.cjscarry no shim, onlydist/document-text.cjsdoes.packages/core/src/document-text-pool.ts: the worker URL is now./document-text-worker.(c)jsbesidedocument-text.(c)js.packages/core/src/document-text.worker-pool.test.ts: the worker pins, moved from the MCP suite and re-asserted on the extractor's answer.Tests
At
b2b49cb9:pnpm --filter @objectstack/core test: 161 files, 3,839 passed.pnpm --filter @objectstack/mcp exec vitest run: 89 files, 1,659 passed.packages/runtime(ata48aefc4; nothing it reaches changed since)src/mcp-record-file-bridge.test.tsandsrc/domains/mcp-object-schema-mask.test.ts(after the alias fix): 2 files, 87 passed.pnpm --filter @objectstack/core typecheckandpnpm --filter @objectstack/mcp typecheck: clean, test-typecheck ledgers held.read_file extracts PDF and Word text on a worker pool…and…stopped at its wall-clock ceiling before the first page…) moved frompackages/mcp/src/mcp-file-tools.test.tstopackages/core/src/document-text.worker-pool.test.ts: same cases, same inputs, asserting the extractor'sExtractedContent(or its rejection) instead of theread_fileblocks. Howread_filerenders each shape (facts, note, the coded busy refusal, the could-not-read sentence for a rejected read) stays pinned in-process in the MCP suite, which keeps its other 44 tests andautomated.ref.packages/core/src/document-text.shared-state.test.ts(5 tests) loads two module copies of the public entry and pins that bounds set through one bind the other, an extraction in flight through one is refused by the other at a cap of 1, and a refusal from either isinstanceofboth classes (and a look-alike error is not). With the state key swapped for a plainSymbol(), 3 of the first 4 fail. The fifth pins that one copy's "cannot start" is its own: a second copy looks for its own entry, and a copy that recorded one still takes an idle worker another copy started; with the verdict back in the shared state it fails. New in the worker suite: a pooled and a non-pooledBuffereach read on a worker and are left unchanged; withslice()restored it fails withDataCloneError.import('@objectstack/core/document-text')andrequire('@objectstack/core/document-text')are distinct modules; bounds set through the ESM copy are what the CJS copy reads; with a cap of 1, a read held through the ESM copy makes the CJS copy refuse withSERVICE_UNAVAILABLE,instanceofboth classes; each then reads a one-page PDF on a real worker with no fallback warning. The ESM export list is exactly the 15 curated runtime names (the three curated types beside them have no runtime form).@objectstack/mcp's builtdist/index.{js,cjs}carries no copy of the extractor (getDocumentProxy0 hits) and imports the subpath; core's maindist/index.jscarries none either.Gates
Local, re-run in full at
e1cb87d2after the review fixes:dispatch-gates --commandsderived 127 commands over this change set; 126 green, includingcheck:dual-build-cjs-loads,check:published-readme-exports,@objectstack/spec check:skill-examples,check:query-options-erasure,check:test-source-aliasandcheck:platform-checklist(each unmeasured or red in the first round: the first four lacked a full build or were killed with the container, and the alias tables fixed the fifth). NOT MEASURED, prerequisite not met (exit 3):check-plugin-teardown-shape --self-test, whose fixture is pinned to a commit a shallow clone cannot reach; CI runs it.check-platform-checklist --changed-from origin/main: 30 anchors judged, 0 lost. After the S3 fix (b2b49cb9): core tests and typecheck, the MCP suite,check:test-source-aliasandcheck-platform-checklist --changed-from origin/mainre-run green, and the built ESM-plus-CJS smoke repeated. CI onb2b49cb9: 75 check-runs, 64 success and 11 skipped, none failed; mergeable state clean.Acceptance notes
The Buffer hand-off fix changes one
read_fileanswer: on a built worker, a NodeBuffersmall enough to sit in Node's shared pool used to fail the transfer and answer the could-not-read sentence; it now reads. The changeset names it.Two installed versions of core with the same state key share idle workers too, so one version's job can run on the other's worker. The
.v1suffix guards the worker protocol; bumping it when the protocol changes is a comment indocument-text-state.tswith no pin yet (contract review N4, accepted; a pin belongs on a follow-up card).The extractor's
kind: 'none'sentences were written forread_file: two name the tool and all say "Download it with the link instead". A caller that hands them to a model with no link (the cloud follow-up) should know; changing them changesread_file's answers, so they are left as they are.carrier: cloud(the follow-up card).The constant names keep the
READ_FILE_prefix and the host variables keepOS_MCP_READ_FILE_*, now bounding every caller. Renaming them is a separate change through the deprecation helper, not this PR.Two copies of
@objectstack/corein one process (ESM and CJS, or two installed versions) now share one pool and one count, as long as they carry the same state key suffix.One operator-visible change: the one-time
warnwhen no worker can start now reads[document-text] PDF and Word text (read_file and every other caller) is extracted on the request thread, not on a worker: …(was[MCP] read_file extracts PDF and Word text on the request thread, not on a worker: …). The changeset andconnect-mcp.mdxsay so; a log alert on the old text needs the new one.Found while smoking, not changed here (since mcp read_file: move PDF and Word text extraction off the request thread onto a worker pool (#31100 ruling B, phase 2) #31828, moved verbatim): a short-lived script that reads a PDF or Word file on a worker does not exit by itself afterwards, because the pool pipes each worker's stdout to the parent's stderr and a piped worker stream holds the event loop open even after
worker.unref()(reproduced with a bareWorker; adatalistener does the same). A server never notices; a CLI or batch script calling the extractor would. Follow-up card for the seat to file.unpdf(2.1 MB unpacked, no dependencies) now installs with@objectstack/core. Every server install already had it through@objectstack/runtime→@objectstack/mcp.Follow-ups
.v1key; contract-review nits N5 (validate thelimitsargument), N8 (a reset clears only the calling copy's verdict) and N9 (a docs sentence on the worker file's extension).Verification
node -e "import('@objectstack/core/document-text').then(m => console.log(Object.keys(m).includes('extractFileContent')))"frompackages/coreafterpnpm --filter @objectstack/core build: printstrue.🤖 Generated with Claude Code
https://claude.ai/code/session_01WGufzegtzKWMxkohs9dHSd