Skip to content

UN-2801 [FIX] Fix file batch distribution algorithm to respect configured batch limits#1537

Merged
jaseemjaskp merged 2 commits into
mainfrom
v0.134.2-hotfix
Sep 16, 2025
Merged

UN-2801 [FIX] Fix file batch distribution algorithm to respect configured batch limits#1537
jaseemjaskp merged 2 commits into
mainfrom
v0.134.2-hotfix

Conversation

@muhammad-ali-e

Copy link
Copy Markdown
Contributor

Fixed an issue where the file batching algorithm was creating fewer batches than configured (16 instead of 30), causing uneven distribution of files across parallel workers. The new implementation ensures files are distributed as evenly as possible across the target number of batches.

🤖 Generated with Claude Code

What

Why

How

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

Database Migrations

Env Config

Relevant Docs

Related Issues or PRs

Dependencies Versions

Notes on Testing

Screenshots

Checklist

I have read and understood the Contribution Guidelines.

…ured batch limits

Fixed an issue where the file batching algorithm was creating fewer batches than configured (16 instead of 30), causing uneven distribution of files across parallel workers. The new implementation ensures files are distributed as evenly as possible across the target number of batches.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 16, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

Failed to post review comments.

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between bb1aee0 and 7b09100.

📒 Files selected for processing (1)
  • backend/workflow_manager/workflow_v2/workflow_helper.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build

Summary by CodeRabbit

  • Bug Fixes
    • Prevented empty batches and ensured batch count never exceeds available files during workflow processing.
  • Refactor
    • Implemented deterministic, evenly distributed batching for more predictable performance and load balancing.
  • Documentation
    • Expanded and clarified the description of the batching behavior.
  • Chores
    • Removed an unused dependency to reduce overhead.

Walkthrough

Refactors get_file_batches in workflow_helper.py to remove math usage, update docstring, and implement deterministic, even distribution of files into batches using remainder-based allocation while preventing empty batches.

Changes

Cohort / File(s) Summary of changes
Batching logic refactor
backend/workflow_manager/workflow_v2/workflow_helper.py
Removed unused math import; expanded get_file_batches docstring; replaced ceil-based batching with even distribution using base size + remainder; iterates to create exactly num_batches, assigns first remainder batches one extra item; ensures non-empty batches; uses start_index slicing.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Helper as WorkflowHelper.get_file_batches

  Caller->>Helper: get_file_batches(file_items, BATCH_SIZE)
  activate Helper
  Note over Helper: Compute num_files, num_batches = min(BATCH_SIZE, num_files)
  Helper->>Helper: base = num_files // num_batches<br/>rem = num_files % num_batches
  loop Build batches (i = 0..num_batches-1)
    alt i < rem
      Note over Helper: batch_size = base + 1
    else
      Note over Helper: batch_size = base
    end
    Helper->>Helper: slice file_items[start:start+batch_size]
    Note over Helper: Append non-empty batch
  end
  Helper-->>Caller: list[list[file_item]]
  deactivate Helper
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR contains a brief top-line summary describing the bug and fix but leaves the repository's required template sections (What, Why, How, "Can this PR break any existing features", Database Migrations, Env Config, Relevant Docs, Related Issues/PRs, Dependencies Versions, and Notes on Testing) as empty placeholders, so the description does not meet the repository's template requirements. Please complete the template before merging by filling the What/Why/How sections, explicitly state any potential breakages and list database migrations or env config changes, add testing steps and related issues/PRs and dependency/version notes, then update the PR description accordingly.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title concisely and accurately summarizes the main change by referencing UN-2801, marking the PR as a fix, and stating that the file batch distribution algorithm will be updated to respect configured batch limits.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v0.134.2-hotfix
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v0.134.2-hotfix

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor
filepath function $$\textcolor{#23d18b}{\tt{passed}}$$ SUBTOTAL
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_logs}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_cleanup}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_cleanup\_skip}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_client\_init}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image\_exists}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_container\_run\_config}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_container\_run\_config\_without\_mount}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_run\_container}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image\_for\_sidecar}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_sidecar\_container}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{TOTAL}}$$ $$\textcolor{#23d18b}{\tt{11}}$$ $$\textcolor{#23d18b}{\tt{11}}$$

@sonarqubecloud

Copy link
Copy Markdown

@jaseemjaskp jaseemjaskp merged commit b2170d1 into main Sep 16, 2025
6 checks passed
@jaseemjaskp jaseemjaskp deleted the v0.134.2-hotfix branch September 16, 2025 07:33
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