Skip to content

[Bug] literature_fulltext returns an empty success for arXiv e-prints that are not tar archives #266

Closed

Description

@tyh99

Package: @eduwork/dsh-literature 0.1.4
Location: packages/dsh-literature (verified on main, not just the published tarball)
Severity: medium — silent data loss, no error surfaced to the model

Summary

For arXiv submissions whose e-print is a bare (single-file) TeX document rather than a tar archive, literature_fulltext() resolves successfully and returns zero files and an empty summary. The HTML and PDF fallbacks already in the chain never run, even though both of them can extract the full text of the same paper.

This hits a specific, identifiable population: older arXiv submissions (mostly math/…, cond-mat/…, and other pre-2000 categories) uploaded as a single TeX file. arXiv still serves them gzipped, but the payload is the TeX source itself, not a tarball.

Reproduction

await ctx.literature.fulltext('math/9201234')   // "Analytic Disks in Fibers over the Unit Ball of a Banach Space"

Observed: files: [], summary: '' — no exception, no error code. Same for cond-mat/9301001.

What actually happens

GET https://arxiv.org/e-print/math/9201234 returns 200, application/gzip, 19,012 bytes. Gunzipped, the first bytes are:

%&amstex

% prevent warn

i.e. a raw amstex/plain-TeX document. In untarSource() (src/core/extract.ts):

const parser = new Parser()
parser.on('entry', (entry: ReadEntry) => { /* … */ })
parser.on('end', () => { resolve(files) })
Readable.from(decompressed).on('error', reject).pipe(parser)

node:tar's Parser does not reject a buffer that is not a tar archive. It emits no entries and ends cleanly, so the promise resolves with an empty Map instead of throwing LITERATURE_EXTRACTION_FAILED.

That feeds fulltext() (src/core/index.ts):

for (const kind of ['source', 'html', 'pdf'] as const) {
  const bytes = await arxiv.downloadFulltext(record.arxivId, kind, signal)
  if (bytes === null) continue
  try {
    return await this.extractArtifact(kind, bytes, record.id)   // <-- returns an empty success here
  } catch (error) {
    if (!isLiteratureError(error) || error.code !== 'LITERATURE_EXTRACTION_FAILED') throw error
  }
}

extractArtifact('source', …) returns { files: [], summary: '' }, the loop exits at the first iteration, and the html / pdf kinds are never attempted.

Worth noting: commit 3111ff8 ("fix: fall back from PDF-only arXiv e-print to HTML/PDF") already establishes this pattern — a 200 response that is not the expected artifact kind must fall through. This is the same class of problem from the other side: the artifact kind is accepted despite containing nothing.

The fallbacks would have worked

Measured on the same paper, using this package's own extractors:

kind fetched result
source /e-print/ 200, 19,012 B 0 files, 0 chars (the bug)
html /html/ 200, 435,262 B htmlToMarkdown → 60,499 chars, real body text
pdf /pdf/ 200, 204,673 B extractPdfText → 50,951 chars, arXiv:math/9201234v1 [math.FA] 11 Oct 1991 …

The content is reachable; it is only unreachable through the kind that wins the race.

Suggested fix

The minimal change treats an empty source extraction as an extraction failure, which lets the existing loop do its job:

// src/core/extract.ts — extractSource()
if (files.size === 0) {
  throw new LiteratureError('the downloaded source is not a readable archive', 'LITERATURE_EXTRACTION_FAILED')
}

Equivalently at the call site in extractArtifact(). Either way the html fallback then recovers these papers.

Two optional hardening steps, if you want the diagnosis to survive rather than degrade quietly:

  1. Detect the bare-TeX case explicitly. After gunzipSync, if the first 512 bytes contain no NULs and match /^%&[a-z]+/ or /\s*\\(documentstyle|documentclass|input\b)/, this is a single-file submission: return it as one tex file rather than failing. Many of these old papers have no faithful HTML rendition upstream, so the PDF path is the only other option, and PDF text mangles their math harder than the TeX source would.
  2. Distinguish "nothing extracted" from null in fulltext()'s loop, so a future extractor returning an empty result cannot short-circuit the chain the same way.

Activity

  1. freedomkk-qfeng commented on Nov 5, 2026

    @freedomkk-qfeng
    Member

    Thanks for the clear report. I reproduced the empty-success path in the published 0.1.5 package using a synthetic gzipped single-TeX response, and the fix is in #274.

    The extractor now recognizes standalone TeX sources. Empty, unsupported, or malformed source archives raise an extraction error so the existing HTML/PDF fallback can run instead of returning an empty success. Normal tar archives and output limits are preserved.

    Type checking, the build, all 256 package tests, and the DSH 0.2.2-rc.1 tool/runtime probe passed. These checks used synthetic fixtures, not live arXiv downloads. The PR's Windows/macOS CI checks are also green.

    The published 0.1.5 package does not contain the fix yet; we are preparing a new npm release and its integration into EduWork 0.4.11.

  2. freedomkk-qfeng commented on Nov 5, 2026

    @freedomkk-qfeng
    Member

    The fix is now published in @eduwork/[email protected] (npm), via #274. We verified that the registry tarball matches the CI artifact and its provenance points to the reviewed source commit.

    If you installed the plugin separately, please update it to 0.1.6. The fix is also being prepared for the next EduWork desktop release, 0.4.11; that desktop release is not out yet.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions