Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Fixed BulkChunkOperationResult interface to match actual API response
  • Fixed TypeError when bulk enabling/disabling chunks (was accessing non-existent results property)

Type of Change

  • Bug fix

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 Jan 20, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 20, 2026 8:18am

Request Review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 20, 2026

Greptile Summary

Fixed TypeError in bulk chunk operations by aligning the BulkChunkOperationResult interface with the actual API response structure. The API returns { operation, successCount, errorCount, processed, errors }, but the interface incorrectly defined failedCount and a nested results array, causing runtime errors when accessing non-existent properties.

  • Updated type definition to match API response fields exactly
  • Fixed consumer code to use correct response properties (errorCount instead of failedCount)
  • Simplified local state update logic to iterate over the chunks array directly instead of trying to access results
  • Added refresh on partial failures (errorCount > 0) to ensure UI consistency

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The fix correctly aligns the TypeScript interface with the actual API response structure, eliminating the TypeError when accessing properties. The changes are minimal, focused, and the logic improvements (refreshing on partial failures) enhance robustness.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/hooks/queries/knowledge.ts Fixed BulkChunkOperationResult interface to match API response structure - replaced non-existent results array with correct operation, errorCount, processed, and errors fields
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/document.tsx Updated bulk chunk operation handler to use correct API response properties and refresh on errors instead of attempting to access non-existent results array

Sequence Diagram

sequenceDiagram
    participant UI as Document Component
    participant Hook as useBulkChunkOperation
    participant API as PATCH /api/knowledge/.../chunks
    participant Service as batchChunkOperation
    participant Cache as Query Client

    UI->>Hook: bulkChunkMutation({ operation, chunkIds })
    Hook->>API: PATCH request with operation & chunkIds
    API->>Service: batchChunkOperation(documentId, operation, chunkIds)
    Service-->>API: { processed, errors }
    API-->>Hook: { operation, successCount, errorCount, processed, errors }
    Hook->>UI: onSuccess(result)
    
    alt operation is delete OR errorCount > 0
        UI->>Cache: refreshChunks() - full invalidation
    else successful enable/disable
        UI->>Cache: updateChunk() for each chunk - optimistic update
    end
    
    UI->>UI: Clear selected chunks
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1 waleedlatif1 merged commit e4ad31b into staging Jan 20, 2026
8 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/kb branch January 20, 2026 08:24
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.

2 participants