Gate full clone by repository size - #58
Conversation
- Store event repository size for workspace setup - Use sparse changed-file checkout above cap
PR Agent ReviewNote 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.
|
There was a problem hiding this comment.
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; | |||
There was a problem hiding this comment.
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; | |||
There was a problem hiding this comment.
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
- Assert missing repo size keeps full checkout - Align repository view selector mock
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.sizethrough webhook intake and durable work payloads, documents the new workspace configuration knob, and covers the missing-size full-checkout fallback in tests.PR Agent Description
PR Type
Enhancement, Tests
Description
repository.sizefrom GitHub webhooks and thread it through intake, job payloads, and executorsLocalPrWorkspaceCheckoutModetype andselectLocalPrWorkspaceCheckoutModeto choose "full" vs "sparse"LOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KBwith 1 GB default and documentationChanges 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"]File Walkthrough
Enhancement (13 files)
Parse repository.size from webhook
src/webhook/payloads/common.tssizefield to repository schemaThread repositorySizeKb through handlers
src/effect/services/webhookHandlers.tsdata.repository.sizeinto PR, comment, and slash intakesAccept repositorySizeKb in slash commands
src/agentWork/intake/slashIntake.tsrepositorySizeKbto SlashCommandInputAdd repositorySizeKb to PrRef and work payloads
src/agentWork/types.tsPrRef.repositorySizeKboptional fieldForward repositorySizeKb into job payloads
src/agentWork/intake/workItemRepository.tsrepositorySizeKbwhen creating review, description, and ask work itemsPass repositorySizeKb to workspace prep
src/agentWork/executors/reviewExecutor.tspayload.repositorySizeKbinto prepare paramsPass repositorySizeKb to workspace prep
src/agentWork/executors/descriptionExecutor.tspayload.repositorySizeKbinto prepare paramsPass repositorySizeKb to workspace prep
src/agentWork/executors/askExecutor.tspayload.repositorySizeKbinto prepare paramsUse checkout mode in cache key and forward size
src/prWorkspace/prRepositoryView.tsselectLocalPrWorkspaceCheckoutModecheckoutModeto cache keycfgandrepositorySizeKbin release paramsAdd checkout mode selector and sparse helpers
src/prWorkspace/localPrWorkspace.tsLocalPrWorkspaceCheckoutModetypeselectLocalPrWorkspaceCheckoutModefunctionsparseCheckoutPatternandsparseCheckoutPatternshelpersrepositorySizeKbandcheckoutModeto typesLoad new full-clone size cap config
src/config.tsLOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KBenv varDefine default full clone max repo size
src/settings/defaults.tsDEFAULT_LOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KB = 1,000,000Register new env key constant
src/settings/envKeys.tsLOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KBenv keyDocumentation (2 files)
Document new env var example
.env.exampleLOCAL_WORKSPACE_FULL_CLONE_MAX_REPO_KB=1000000Document full clone repo size cap
docs/configuration.mdTests (3 files)
Test full and sparse checkout behavior
test/localPrWorkspace.test.tscheckoutModefieldAssert repository.size in parsed payload
test/parseGithubPayload.test.tssize: 1234survives payload parseMock selectLocalPrWorkspaceCheckoutMode
test/prRepositoryView.test.ts