Skip to content

fix(random): optimized kb connector sync engine, rerenders in tables, files, editors, chat#3513

Merged
waleedlatif1 merged 3 commits intofeat/mothership-copilotfrom
fix/general
Mar 11, 2026
Merged

fix(random): optimized kb connector sync engine, rerenders in tables, files, editors, chat#3513
waleedlatif1 merged 3 commits intofeat/mothership-copilotfrom
fix/general

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Mar 11, 2026

Summary

  • optimized kb connector sync engine, rerenders in tables, files, editors, chat

Type of Change

  • Performance

Testing

Tested manually

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
Copy link

vercel bot commented Mar 11, 2026

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Mar 11, 2026 4:45am

Request Review

@waleedlatif1 waleedlatif1 marked this pull request as ready for review March 11, 2026 04:28
@cursor
Copy link

cursor bot commented Mar 11, 2026

PR Summary

Medium Risk
Sync-engine changes alter connector/document reconciliation and failure handling (including deletions), which could affect data consistency and scheduling if buggy. UI changes are mostly memoization/refactors but touch core navigation and input submission flows.

Overview
Knowledge connector sync is optimized and hardened. The sync engine now batches add/update operations (with partial failure logging), parallelizes DB reads, bulk-marks removed docs, centralizes sync-log completion + next-sync jitter calculation, and prevents syncing/updating deleted connectors (including a cleanup path if a connector is deleted mid-sync).

Workspace UI rerenders and layout positioning are reduced. Multiple components (ResourceHeader, ResourceOptionsBar, table header/row controls, tokenizer toggle, sidebar nav/task items, Checkbox/Switch) are wrapped/extracted with memo and handlers/props are memoized; several overlays (modals/search/action bar) are re-centered to left: 50%. Chat UserInput becomes internally controlled with defaultValue and onSubmit(text, files); Home is updated to seed the initial prompt without keeping input state in the parent.

Written by Cursor Bugbot for commit 5e6f696. Configure here.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR applies performance optimizations and reliability improvements across the workspace UI and the knowledge-base connector sync engine:

Frontend optimizations: Memoization via React.memo, useCallback, and useMemo is applied throughout high-churn components (table, document editor, files, sidebar, resource header/options-bar, and shared Checkbox/Switch primitives) to reduce unnecessary re-renders. The UserInput component is refactored to manage its own state with a defaultValue prop and simplified onSubmit API. Modal and action-bar centering is corrected by replacing sidebar-offset calc() expressions with left: 50%.

Backend improvements: The executeSync function in the KB connector sync engine is refactored to use parallel DB queries, batch document processing (5 documents per batch), dedicated helper functions (completeSyncLog, calculateNextSyncTime, isConnectorDeleted), and a ConnectorDeletedException guard for detecting mid-sync deletions. A bulk UPDATE replaces a per-document loop for deletion reconciliation, reducing DB round-trips.

Key considerations: The refactoring is sound overall, with one operational transparency concern—per-document batch failures during sync are logged but not counted in the sync result, making partial failures difficult for operators to detect without digging into logs.

Confidence Score: 4/5

  • Safe to merge with minor operational visibility enhancement; no critical data-loss or runtime-crash risks.
  • The changes are primarily optimizations (memoization, batch processing) and a visual centering fix with no breaking API or data-schema changes. The per-document batch-failure tracking concern is the only finding—failures are logged but not counted in result metrics, which makes partial syncs harder for operators to detect without reviewing logs. Adding a counter is a straightforward enhancement that would improve observability without blocking merge.
  • apps/sim/lib/knowledge/connectors/sync-engine.ts — consider adding a docsFailed counter to the SyncResult to make partial failures observable in sync metrics.

Sequence Diagram

sequenceDiagram
    participant Home
    participant UserInput
    participant useAnimatedPlaceholder

    Home->>UserInput: defaultValue={initialPrompt}
    Note over UserInput: useState(defaultValue) initializes value
    UserInput->>useAnimatedPlaceholder: useAnimatedPlaceholder(isInitialView)
    useAnimatedPlaceholder-->>UserInput: animated text (or PLACEHOLDER_PREFIX if disabled)
    Note over Home: LandingPromptStorage.consume() → setInitialPrompt(prompt)
    Home->>UserInput: re-render with new defaultValue
    Note over UserInput: useEffect fires → setValue(defaultValue) if truthy
    UserInput->>Home: onSubmit(text, fileAttachments)
    Note over UserInput: setValue('') clears internal state
    Note over Home: handleSubmit receives text directly — no inputValue state
Loading

Last reviewed commit: 5e6f696

@waleedlatif1 waleedlatif1 merged commit 89dafb3 into feat/mothership-copilot Mar 11, 2026
2 of 3 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/general branch March 11, 2026 04:42
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