Skip to content

fix(knowledge): bound source titles and tag values so an oversized index row cannot fail a connector sync - #8123

Merged
waleedlatif1 merged 5 commits into
stagingfrom
fix/connector-oversized-title
Sep 22, 2026
Merged

waleedlatif1 merged 5 commits into
stagingfrom
fix/connector-oversized-title

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • a document's filename and text tag columns carry btree indexes, and Postgres refuses an index row past 2704 bytes (SQLSTATE 54000). Reproduced on the real schema: an incompressible 2,700-character filename fails with index row size 2712 exceeds btree version 4 maximum 2704 for index "doc_filename_idx", a 3,200-character tag fails on doc_kb_tag1_lower_idx, 2,600 characters insert. Connector syncs wrote source titles and mapped metadata straight into those columns, and the failure-recording path re-inserts the same title, so one such document escalates to a connector-level failure on every sync and ten of those disable the connector
  • one shared bound, MAX_DOCUMENT_INDEXED_TEXT_LENGTH (512 characters, under the ceiling even at four bytes per character) in lib/knowledge/constants.ts
  • connector ingress truncates to it (source titles and mapped tag values are machine input with no caller to refuse), cutting by code point so a value never ends in half a surrogate pair
  • the document APIs reject over-long input instead: .max() on filename (create, upsert, update) and on tag1..tag7 (create, update), and the upload-metadata tag bound (previously 1000 characters, which still overflows at four bytes per character) now uses the same constant
  • not in this PR: doc_filename_idx itself looks close to unused in production (338 scans against millions on the tag indexes); dropping it is a separate, evidence-gated migration

Type of Change

  • Bug fix

Testing

  • sync-persistence.test.ts: bounded filename on the placeholder path, bounded and intact mapped tag values, code-point cut on a 600-emoji title
  • documents.test.ts: at-limit accepted; over-limit filename rejected on create/upsert/update and over-limit tag rejected on create/update, with the descriptive messages
  • upload-metadata.test.ts: over-limit tag rejected
  • all five new tests fail with the bound neutralized (mutation-checked); 60 tests pass across the three files
  • bun run type-check and bun run check:api-validation pass; the mechanism was reproduced on a local database with the real indexes inside rolled-back transactions

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 22, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 22, 2026 3:35am UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with the previous findings resolved and no new actionable defects identified.

Summary

This PR prevents oversized document filenames and tag values from repeatedly failing knowledge connector synchronization.

  • Introduces a shared 512-code-unit bound for indexed document text.
  • Truncates connector-supplied titles and mapped tags without splitting surrogate pairs.
  • Rejects oversized API and document-service inputs with descriptive validation errors.
  • Adds boundary, exact-result, and Unicode coverage for connector and API paths.
  • Preserves values already within the accepted limit, addressing the remaining previous-review concern.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Connector source metadata] --> B[Bound title and mapped tags]
  B --> C[Document persistence]
  D[Document API input] --> E[Reject values over shared limit]
  E --> C
  C --> F[PostgreSQL filename and tag indexes]
Loading

Reviews (5) · Last reviewed commit: "fix(knowledge): leave values at the limi..."

Comment thread apps/sim/lib/knowledge/connectors/sync-persistence.test.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

…reject oversized filenames and tags at the document APIs
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/knowledge/upload-metadata.ts Outdated
Comment thread apps/sim/lib/knowledge/connectors/sync-persistence.ts Outdated
Comment thread apps/sim/lib/api/contracts/knowledge/documents.ts Outdated
Comment thread apps/sim/lib/knowledge/upload-metadata.ts Outdated
Comment thread apps/sim/lib/knowledge/connectors/sync-persistence.ts Outdated
…inside the limit and leave stored upload metadata untouched
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/api/contracts/knowledge/documents.ts
Comment thread apps/sim/lib/knowledge/connectors/sync-persistence.ts
…ong tag values on the tag-data and tag-update paths
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 11 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit fe7d6d3 into staging Sep 22, 2026
37 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/connector-oversized-title branch September 22, 2026 03:41

This branch was previously deployed

1 inactive deployment
Preview 95960d55 Deployed Sep 22, 2026 by vercel[bot]
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