Skip to content

fix(knowledge): grant member access as each batch is indexed instead of at the end of the run - #7418

Merged
waleedlatif1 merged 6 commits into
stagingfrom
fix/member-sync-incremental-visibility
Sep 2, 2026
Merged

fix(knowledge): grant member access as each batch is indexed instead of at the end of the run#7418
waleedlatif1 merged 6 commits into
stagingfrom
fix/member-sync-incremental-visibility

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Three fixes to how a large first crawl feels and behaves in members mode, found on staging with a Gmail mailbox whose crawl had every indexed document hidden after fifteen minutes.

Access is granted as each batch is indexed. A members-mode run listed a member's whole source, hydrated every document, and only then wrote the member's observations and materialised ACLs. Until the run ended nothing was searchable, the Knowledge page's document list was empty, and the Sources chip read "Indexing" with nothing behind it for up to the run's 45-minute budget. The hydrate-and-persist loop now reports each batch it wrote (skipped rows included), and the member engine records the observation and materialises the ACL under its lease, best-effort, once the batch has been dispatched for processing. The listing's own pass at the end still records the same observations idempotently and remains the only thing that decides removals.

Deferred mail and chat documents hydrate in batches, under an enforced ceiling. A listing that defers content with no size hint was assumed to be as large as the whole in-flight budget, so every Gmail thread hydrated alone: one thread at a time, roughly 170 a minute on staging. ExternalDocument.estimatedBytes lets a listing say what to expect, and for text a connector assembles itself (a mail thread, a chat transcript) the estimate is now a real bound rather than a guess: CONNECTOR_TEXT_DOCUMENT_MAX_BYTES (12 MiB) is enforced by a shared BoundedLines accumulator in the Gmail, Outlook, and Google Chat formatters, which appends each message whole or not at all and marks the document as truncated. Five such documents fit the 64 MiB in-flight budget, so they hydrate together. Sources with real file sizes are unchanged.

The member-sync scheduler no longer fails on the stale-observation sweep. The sweep's cutoff was written as $now - GREATEST(...) with the bound instant untyped, which Postgres resolves as interval arithmetic and then rejects every timestamp > interval comparison. The instant is now cast, and the sweep runs cleanly against a real database.

Verification

  • persistedDocumentsByObserver is a pure helper tested with a union of two members and a document nobody listed.
  • The byte-budget chunker is tested with unknown deferred documents (one per batch, as before) and estimated ones (batched together).
  • BoundedLines is tested for whole-record refusal, the truncation notice, and byte (not character) accounting.
  • The stale sweep was run end-to-end against a database before and after the cast: the untyped form fails with 42883, the cast form returns.
  • Connector suites, type-check, lint, and check:audits (45 audits) pass.

@vercel

vercel Bot commented Sep 2, 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 2, 2026 10:11pm UTC

Request Review

@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 2, 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 3 files

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

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/knowledge/connectors/sync-primitives.ts Outdated

@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 3 files

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

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/knowledge/connectors/sync-primitives.ts Outdated
@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR makes large member-mode crawls progressively accessible, batches bounded deferred connector content more efficiently, and fixes the stale-observation cutoff query.

  • Reports persisted documents per batch after queue dispatch and grants member observations and ACLs best-effort.
  • Adds byte-bounded transcript formatting and deferred-size estimates for Gmail, Outlook, and Google Chat.
  • Casts the stale-observation cutoff parameter to a timestamp before interval subtraction.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/knowledge/connectors/sync-primitives.ts Reports persisted rows after queue dispatch and treats ordinary batch-grant failures as best-effort while preserving lease-loss termination.
apps/sim/lib/knowledge/connectors/member-sync-engine.ts Groups persisted documents by observing member and incrementally records observations and materializes ACLs under the member lease.
apps/sim/lib/knowledge/connectors/sync-persistence.ts Returns identifiers for newly inserted and replaced skipped-document rows so batch callbacks can grant access.
apps/sim/connectors/utils.ts Introduces a UTF-8 byte-bounded line accumulator used to enforce connector transcript limits.
apps/sim/lib/knowledge/connectors/member-observations.ts Correctly casts the stale-sweep instant before subtracting the interval window.

Sequence Diagram

sequenceDiagram
  participant Sync as Member sync
  participant DB as Document persistence
  participant Queue as Processing queue
  participant ACL as Observation and ACL transaction
  Sync->>DB: Persist hydrated and skipped batch rows
  DB-->>Sync: Return external and document IDs
  Sync->>Queue: Dispatch persisted documents
  Queue-->>Sync: Dispatch completes or is logged
  Sync->>ACL: Record observations and materialize ACLs
  alt Non-lease grant failure
    ACL-->>Sync: Error
    Sync->>Sync: Log and continue
    Sync->>ACL: Retry authoritatively during final listing pass
  else Lease lost
    ACL-->>Sync: SyncLockLostException
    Sync->>Sync: End superseded run
  end
Loading

Reviews (5): Last reviewed commit: "fix(google-chat): report the number of m..." | Re-trigger Greptile

Comment thread apps/sim/lib/knowledge/connectors/sync-primitives.ts Outdated
@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 2, 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.

@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 2, 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 9 files

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

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/connectors/gmail/gmail.ts Outdated
Comment thread apps/sim/connectors/google-chat/google-chat.ts Outdated
@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 2, 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 12 files

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

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/connectors/outlook/outlook.ts
Comment thread apps/sim/connectors/google-chat/google-chat.ts
Comment thread apps/sim/connectors/google-chat/google-chat.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 2, 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 12 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 c77b070 into staging Sep 2, 2026
23 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/member-sync-incremental-visibility branch September 2, 2026 22:15
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