Skip to content

fix(connectors): treat a zero-byte source file as nothing to index - #6848

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/connector-empty-source-file
Aug 19, 2026
Merged

fix(connectors): treat a zero-byte source file as nothing to index#6848
waleedlatif1 merged 1 commit into
stagingfrom
fix/connector-empty-source-file

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • A zero-byte source file is no longer treated as something to index
  • The emptiness rule now lives in one place, hasIndexablePayload, shared by the sync engine's classify and hydrate gates and both connectors' getDocument

Why

Found by auditing production after connectors began delivering source files. A zero-byte PDF was stored and sent to OCR, which answered 400 Bad Request:

OCR failed: 400 Bad Request - {"success":false,"error":"Mistral API error: Bad Request"}
file_size: 0

Two problems in one. It bills an external API call to discover the file was empty, and it reports the result as a provider fault rather than as an empty file, so the row gives no one a reason they can act on.

This was a regression. Before source files existed, an empty file produced empty extracted text and was dropped at the empty-content check.

The rule also existed in two places that disagreed: the connectors asked whether a source file was present, the sync engine asked the same question a second way, and a source file with no bytes satisfied both. One definition now, so the two gates cannot drift.

Scope

This is the only unexplained failure class in the fleet since the source-file change deployed. Everything else post-deploy is legitimate and correctly reported: image-only decks, password-protected workbooks, files over the 100MB cap, and archives caught by the decompression guard.

Testing

  • vitest run connectors/ lib/knowledge/ lib/uploads/ lib/file-parsers/ app/api/knowledge/2,007 passed (129 files)
  • New cases cover a source file with bytes, extracted text, blank text, and the zero-byte file; verified the zero-byte case fails when the guard is weakened
  • bun run check:audits — 29/29
  • tsgo --noEmit — no errors in changed files (pre-existing mssql and @c15t/nextjs resolution errors unrelated)

Checklist

  • Self-reviewed
  • No secrets or customer data introduced

Observed in production after connectors began delivering source files: a
zero-byte PDF was stored and shipped to OCR, which answered `400 Bad Request`.
That bills an external call to discover the file was empty and reports it as an
API fault rather than as what it is. Before source files existed, an empty file
produced empty extracted text and was dropped at the empty-content check, so
this was a regression.

The emptiness rule now lives in one place, `hasIndexablePayload`, used by the
sync engine's classify and hydrate gates and by both connectors' `getDocument`.
It previously existed twice — the connectors asked whether a source file was
present while the sync engine asked the same question a second way — and a
source file with no bytes satisfied both.
@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 19, 2026 5:18pm

Request Review

@cursor

cursor Bot commented Aug 19, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Focused connector sync guard with no auth or billing changes; risk is limited to dropping empty source files instead of indexing them and triggering OCR failures.

Overview
Fixes a regression where zero-byte source files (e.g. empty PDFs) were treated as indexable once connectors started shipping sourceFile bytes. Those files were stored and sent to OCR, which failed with opaque 400 errors and billed an external call to learn the file was empty.

hasIndexablePayload in connectors/utils centralizes the rule: a sourceFile must have bytes.length > 0; otherwise non-blank extracted content is required. The sync engine’s classify/hydrate gates and OneDrive/SharePoint getDocument now use this helper instead of duplicating checks (sourceFile presence vs content.trim()), so the two paths cannot disagree again.

Tests cover bytes, text, blank text, and the zero-byte rejection case.

Reviewed by Cursor Bugbot for commit eabfba7. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR centralizes connector payload eligibility in hasIndexablePayload, rejecting zero-byte source files before storage or OCR while preserving nonempty source files and extracted text.

  • Applies the shared predicate to OneDrive and SharePoint hydration.
  • Uses the same rule during sync classification and post-hydration validation.
  • Adds focused coverage for byte-bearing files, extracted text, blank text, and zero-byte files.

Confidence Score: 5/5

The PR appears safe to merge, with zero-byte source files consistently rejected before indexing and no actionable regression identified.

The changed connector and sync-engine gates share one predicate, current producers satisfy its source-file-versus-text assumptions, and existing indexed documents remain preserved when a refreshed payload is empty.

Important Files Changed

Filename Overview
apps/sim/connectors/utils.ts Introduces the shared payload predicate that rejects zero-byte source files and blank extracted content.
apps/sim/connectors/onedrive/onedrive.ts Applies the shared predicate before returning hydrated OneDrive documents.
apps/sim/connectors/sharepoint/sharepoint.ts Applies the shared predicate before returning hydrated SharePoint documents.
apps/sim/lib/knowledge/connectors/sync-engine.ts Reuses the centralized payload rule at classification and hydration gates while retaining existing documents as last-known-good when refreshes are empty.
apps/sim/connectors/utils.test.ts Adds focused tests for valid source bytes, extracted text, blank text, and zero-byte source files.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Connector document] --> B{Source file present?}
  B -->|Yes| C{Contains bytes?}
  B -->|No| D{Nonblank extracted text?}
  C -->|Yes| E[Index payload]
  C -->|No| F[Drop empty document]
  D -->|Yes| E
  D -->|No| F
Loading

Reviews (1): Last reviewed commit: "fix(connectors): treat a zero-byte sourc..." | Re-trigger Greptile

@waleedlatif1
waleedlatif1 merged commit 10ff622 into staging Aug 19, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/connector-empty-source-file branch August 19, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant