Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
Error: tool "knowledge_get_document" returned invalid output: value is not lossless JSON(and the same error inknowledge_read_evidence) that occurs immediately after importing or reindexing documents parsed by the built-in text processor (e.g..md,.txt,.xlsx,.json).Root Cause
ArtifactRepository.saveRevision()(src/knowledge/artifacts.ts) unconditionally assigned optional properties (processorVersion,pageCount,processedPages) ontoDocumentProcessingInfo. WhenparsedTextDocument()omits those optional fields, the in-memorydoc.processingobject retains three own properties with valueundefined.undefinedown properties in memory:composeDocumentEvidence()(src/knowledge/evidence.ts):processing: doc.processingKnowledgeService.reindexDocument()(src/knowledge/index.ts):processing: rebuilt.processed?.processingnormalizeMineruArchive()(src/knowledge/parsed-document.ts):bbox: sourceBox(...)andprocessorVersion: versiontoolOutput()(src/tool-knowledge/tool-schemas.ts) cloned values withstructuredClone(), which preserves ownundefinedproperties (unlikeJSON.stringify). Because DSH's tool runtime validates lossless JSON strictly,knowledge_get_document(both page and context-window modes) andknowledge_read_evidencefailed withINVALID_TOOL_OUTPUTuntil a host restart reloadedknowledge.jsonfrom disk.Changes
src/knowledge/artifacts.ts: Only includeprocessorVersion,pageCount, andprocessedPagesonDocumentProcessingInfowhen defined.src/knowledge/evidence.ts: Only includeprocessingonDocumentEvidencewhen defined.src/knowledge/index.ts: Strip staleprocessingfrom thereindexDocumentcandidate and only attachprocessingwhen defined.src/knowledge/parsed-document.ts: Only attachbboxandprocessorVersionwhen defined innormalizeMineruArchive().src/tool-knowledge/tool-schemas.ts: Strip ownundefinedkeys recursively intoolOutput()afterstructuredClone()as defense-in-depth.tests/tool-contract.spec.ts: Added end-to-end regression test through the real@deepseek-ai/dsh-toolsruntime covering builtin file import,knowledge_get_document(page & context-window modes),knowledge_read_evidence, and liveknowledge_reindex_document(mode: "reparse").tests/processing-lifecycle.spec.ts: Added unit test assertingArtifactRepository.save(),composeDocumentEvidence(), andtoolOutput()omit ownundefinedkeys while keeping clones detached.Verification
All required checks from
CONTRIBUTING.mdpassed locally on Windows (Nodev24.16.0, DSH host SDK commit9c2670d3):npm run verify:workspace— passed (5 explicit decisions)npm run typecheck— passednpm test— passed (59 test files, 738/738 tests; the newtool-contract.spec.tstest reproduced the exactvalue is not lossless JSONfailure prior to the fix)npm run build— passednpm run audit:prod— passed (critical=0, high=0)npm run verify:package— passednode scripts/benchmark-retrieval.mjs— passed (Hit@1 100.0%, MRR 1.000, 0 overruns)node scripts/smoke-worker-protocol.mjs— passed (4/4 bundles)Impact
JSON.stringifyalready droppedundefinedkeys).value is not lossless JSONerrors inknowledge_get_documentandknowledge_read_evidenceafter importing or reindexing files.