Skip to content

Gate full clone by repository size - #58

Merged
prathamdby merged 3 commits into
mainfrom
pd/large-repo-sparse-checkout-6885
Jun 4, 2026
Merged

Gate full clone by repository size#58
prathamdby merged 3 commits into
mainfrom
pd/large-repo-sparse-checkout-6885

Conversation

@prathamdby

@prathamdby prathamdby commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Adds an event-time repository size threshold for local PR workspace setup. Repositories at or below the cap keep the full checkout path; repositories above the cap use a sparse checkout containing changed, non-deleted PR files. Threads repository.size through webhook intake and durable work payloads, documents the new workspace configuration knob, and covers the missing-size full-checkout fallback in tests.

Open in Web Open in Cursor 

PR Agent Description

PR Type

Enhancement, Tests

Description

  • Capture repository.size from GitHub webhooks and thread it through intake, job payloads, and executors
  • Add LocalPrWorkspaceCheckoutMode type and selectLocalPrWorkspaceCheckoutMode to choose "full" vs "sparse"
  • Introduce config LOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KB with 1 GB default and documentation
  • Add sparse checkout pattern helpers and differentiate cache keys by checkout mode

Changes Diagram

flowchart LR
  A["GitHub webhook payload"] --> B["Parse repository.size"]
  B --> C["Slash / PR / comment intake"]
  C --> D["Job payloads (review, ask, describe)"]
  D --> E["Executors pass to workspace"]
  E --> F["selectLocalPrWorkspaceCheckoutMode"]
  F --> G{"Repo size > cap?"}
  G -->|No| H["Full clone checkout"]
  G -->|Yes| I["Sparse changed-file checkout"]
  F --> J["Cache key includes mode"]
Loading

File Walkthrough

Enhancement (13 files)
Parse repository.size from webhook

src/webhook/payloads/common.ts

  • Add optional size field to repository schema
Thread repositorySizeKb through handlers

src/effect/services/webhookHandlers.ts

  • Pass data.repository.size into PR, comment, and slash intakes
Accept repositorySizeKb in slash commands

src/agentWork/intake/slashIntake.ts

  • Add repositorySizeKb to SlashCommandInput
  • Forward to PrRef
Add repositorySizeKb to PrRef and work payloads

src/agentWork/types.ts

  • PrRef.repositorySizeKb optional field
  • Review, Ask, Description payloads all accept it
Forward repositorySizeKb into job payloads

src/agentWork/intake/workItemRepository.ts

  • Set repositorySizeKb when creating review, description, and ask work items
Pass repositorySizeKb to workspace prep

src/agentWork/executors/reviewExecutor.ts

  • Thread payload.repositorySizeKb into prepare params
Pass repositorySizeKb to workspace prep

src/agentWork/executors/descriptionExecutor.ts

  • Thread payload.repositorySizeKb into prepare params
Pass repositorySizeKb to workspace prep

src/agentWork/executors/askExecutor.ts

  • Thread payload.repositorySizeKb into prepare params
Use checkout mode in cache key and forward size

src/prWorkspace/prRepositoryView.ts

  • Import selectLocalPrWorkspaceCheckoutMode
  • Append checkoutMode to cache key
  • Include cfg and repositorySizeKb in release params
Add checkout mode selector and sparse helpers

src/prWorkspace/localPrWorkspace.ts

  • Export LocalPrWorkspaceCheckoutMode type
  • Add selectLocalPrWorkspaceCheckoutMode function
  • Add sparseCheckoutPattern and sparseCheckoutPatterns helpers
  • Add repositorySizeKb and checkoutMode to types
Load new full-clone size cap config

src/config.ts

  • Read LOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KB env var
  • 1M KB default threshold
Define default full clone max repo size

src/settings/defaults.ts

  • DEFAULT_LOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KB = 1,000,000
Register new env key constant

src/settings/envKeys.ts

  • LOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KB env key
Documentation (2 files)
Document new env var example

.env.example

  • LOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KB=1000000
Document full clone repo size cap

docs/configuration.md

  • Describe sparse changed-file checkout above threshold
Tests (3 files)
Test full and sparse checkout behavior

test/localPrWorkspace.test.ts

  • Test full checkout below cap verifies all files present
  • Test sparse checkout above cap verifies only changed files
  • Assert checkoutMode field
Assert repository.size in parsed payload

test/parseGithubPayload.test.ts

  • Verify size: 1234 survives payload parse
Mock selectLocalPrWorkspaceCheckoutMode

test/prRepositoryView.test.ts

  • Add mock implementation matching real logic

- Store event repository size for workspace setup
- Use sparse changed-file checkout above cap
@zeus-review

zeus-review Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

PR Agent Review

Note

Adds sparse checkout support for large repositories. When the GitHub webhook payload includes repository.size (in KB) and it exceeds the configurable threshold (default 1 GB), the PR workspace switches from a full clone to a sparse checkout containing only the changed files.

EffortModerate · 2/5
FindingsNo issues on this pass.
Relevant testsyes
SecurityNo security concerns identified
Follow-upsThe test mock for selectLocalPrWorkspaceCheckoutMode in prRepositoryView.test.ts duplicates the production logic.
Follow-upsThe sparseCheckoutPatterns function returns an empty string when all changed files are deleted; verify this edge case in a test.

@zeus-review zeus-review 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.

Note

Full review is in the PR conversation. Expand below to copy fixes for your coding agent.

Fix all findings (agent prompt)
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate.

Repository: prathamdby/pr-agent
Pull request: #58
Head SHA: d2c29cba3073c478a0e2abd64c043fd3fd849d5e

Findings:

[P0] @src/prWorkspace/localPrWorkspace.ts lines 37-43
Add `checkoutMode: selectLocalPrWorkspaceCheckoutMode(cfg, params.repositorySizeKb)` to the return object in `prepareLocalPrWorkspace` (inside the try block alongside `rootDir`, `agentCwd`, etc.).

[P1] @src/prWorkspace/localPrWorkspace.ts lines 231-247
In `prepareLocalPrWorkspace`, when `checkoutMode === "sparse"`, use `git sparse-checkout init --cone` then `git sparse-checkout set` with patterns from `sparseCheckoutPatterns(changedFiles)`, and populate `checkoutPaths` from the changed file list instead of scanning the full tree.

@@ -36,6 +37,7 @@ export type LocalPrWorkspace = {
readonly agentCwd: string;

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.

P0 · Return object missing required checkoutMode property

src/prWorkspace/localPrWorkspace.ts · lines 37-43

The LocalPrWorkspace type at line 40 declares readonly checkoutMode: LocalPrWorkspaceCheckoutMode as required, but the return object in prepareLocalPrWorkspace (which returns Promise<LocalPrWorkspace>) never includes it. At runtime this will be undefined. The test at test/localPrWorkspace.test.ts:142 (expect(fullWorkspace.checkoutMode).toBe("full")) and line 180 will fail. The selectLocalPrWorkspaceCheckoutMode function (line 102-116) computes the mode correctly but its result is never assigned into the return value.

Prompt to fix
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate.

Repository: prathamdby/pr-agent
Pull request: #58
Head SHA: d2c29cba3073c478a0e2abd64c043fd3fd849d5e

[P0] @src/prWorkspace/localPrWorkspace.ts lines 37-43
Add `checkoutMode: selectLocalPrWorkspaceCheckoutMode(cfg, params.repositorySizeKb)` to the return object in `prepareLocalPrWorkspace` (inside the try block alongside `rootDir`, `agentCwd`, etc.).

@@ -219,6 +231,17 @@ async function indexCheckedOutFiles(agentCwd: string): Promise<Set<string>> {
return paths;

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.

P1 · Sparse checkout helpers defined but never wired into the clone flow

src/prWorkspace/localPrWorkspace.ts · lines 231-247

sparseCheckoutPattern and sparseCheckoutPatterns are defined and exported, and selectLocalPrWorkspaceCheckoutMode (line 102-116) computes the mode — but prepareLocalPrWorkspace never calls any of them. The repositorySizeKb param is destructured out of params at line 275 but never used. The function unconditionally does a full git checkout -f. Repositories above the size cap still get full clones; the sparse checkout feature is entirely non-functional.

Prompt to fix
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate.

Repository: prathamdby/pr-agent
Pull request: #58
Head SHA: d2c29cba3073c478a0e2abd64c043fd3fd849d5e

[P1] @src/prWorkspace/localPrWorkspace.ts lines 231-247
In `prepareLocalPrWorkspace`, when `checkoutMode === "sparse"`, use `git sparse-checkout init --cone` then `git sparse-checkout set` with patterns from `sparseCheckoutPatterns(changedFiles)`, and populate `checkoutPaths` from the changed file list instead of scanning the full tree.

- Configure sparse checkout before PR head checkout
@prathamdby
prathamdby marked this pull request as ready for review June 4, 2026 12:49

@zeus-review zeus-review 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 bugs found, see the updated review.

- Assert missing repo size keeps full checkout
- Align repository view selector mock

@zeus-review zeus-review 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 bugs found, see the updated review.

@prathamdby
prathamdby merged commit 40293c1 into main Jun 4, 2026
3 checks passed
@prathamdby
prathamdby deleted the pd/large-repo-sparse-checkout-6885 branch June 4, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants