fix: add instruction size safeguard to prevent Copilot context overflow#34
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds an instruction-size/count safeguard that scans active Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant SyncManager
participant FileSystem as File System
participant NotificationManager
participant UI as User Interface
User->>SyncManager: Trigger sync
SyncManager->>SyncManager: Recreate active prompt symlinks
SyncManager->>SyncManager: cleanupInactivePrompts()
SyncManager->>FileSystem: List `.instructions.md` files and request sizes
FileSystem-->>SyncManager: Return file list and sizes
SyncManager->>SyncManager: Compute totalSizeKB and activeCount
alt Thresholds exceeded
SyncManager->>NotificationManager: showPromptSizeWarning(details)
NotificationManager->>UI: Display warning with actions
UI-->>User: Present "Manage Prompts" / "Open Settings" / "Dismiss"
else Within limits
SyncManager->>SyncManager: Continue and complete sync
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a post-sync safeguard in Promptitude to help prevent GitHub Copilot context overflow by cleaning up inactive prompts from the active prompts directory and warning users when active prompts exceed configured safety thresholds.
Changes:
- Introduces prompt/repo threshold constants for warning triggers.
- Adds an always-visible warning notification with actions to help users remediate oversized prompt sets.
- Hooks inactive prompt cleanup and a new prompt-size validation step into the sync lifecycle.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/constant.ts |
Defines size/count/repo thresholds used by the safeguard. |
src/utils/notifications.ts |
Adds a dedicated warning notification UI with action buttons. |
src/syncManager.ts |
Runs inactive prompt cleanup and validates active prompt size/count after sync. |
CHANGELOG.md |
Documents the new safeguard behavior under [Unreleased]. |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/syncManager.ts (1)
1235-1293: Well-structured validation method with appropriate error handling.The implementation correctly:
- Measures actual content size (fs.stat follows symlinks)
- Validates after cleanup operations complete
- Logs appropriately and doesn't block sync on validation failure
One minor suggestion: the empty catch block at lines 1260-1262 silently skips files. Consider adding a debug log for troubleshooting.
💡 Optional: Add debug logging for skipped files
} catch { - // Skip files that can't be stat'd + // Skip files that can't be stat'd (e.g., broken symlinks) + this.logger.debug(`Skipped file during size validation: ${file}`); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/syncManager.ts` around lines 1235 - 1293, The inner catch in validatePromptSize silently skips files that can't be stat'd; update that catch to log a debug message including the file name/path and the caught error using this.logger.debug (or this.logger.warn if preferred) so failures in fs.stat are visible for troubleshooting—locate the loop over promptFiles in validatePromptSize, find the try { const stats = await fs.stat(filePath); ... } catch { ... } and replace the empty catch with a log that references filePath and the caught error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/utils/notifications.ts`:
- Around line 165-187: In showPromptSizeWarning, the invoked command ID
'promptitude-prompts.focus' doesn't exist and will throw at runtime; replace it
with the correct view-focus command matching the view ID in package.json (likely
'promptitude.cards.focus') when calling
vscode.commands.executeCommand('promptitude-prompts.focus'), or if the intent
was to focus the Prompt Details view use 'promptitude.details.focus' instead;
update the executeCommand invocation(s) in showPromptSizeWarning to use the
exact view ID(s) (promptitude.cards.focus or promptitude.details.focus) so the
command resolves successfully.
---
Nitpick comments:
In `@src/syncManager.ts`:
- Around line 1235-1293: The inner catch in validatePromptSize silently skips
files that can't be stat'd; update that catch to log a debug message including
the file name/path and the caught error using this.logger.debug (or
this.logger.warn if preferred) so failures in fs.stat are visible for
troubleshooting—locate the loop over promptFiles in validatePromptSize, find the
try { const stats = await fs.stat(filePath); ... } catch { ... } and replace the
empty catch with a log that references filePath and the caught error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1aa043df-5323-411d-8d74-6a77780912fb
📒 Files selected for processing (4)
CHANGELOG.mdsrc/constant.tssrc/syncManager.tssrc/utils/notifications.ts
ea4d0be to
c558ebe
Compare
f8a8b15 to
7f43750
Compare
There was a problem hiding this comment.
Pull request overview
Adds a post-sync safeguard to prevent GitHub Copilot context overflow by measuring active .instructions.md files and warning users when size/count/repo thresholds are exceeded, while also cleaning inactive prompts out of the active prompts directory.
Changes:
- Add instruction size/count/repo-count warning thresholds as constants.
- Add a dedicated warning notification with actions to help users manage prompts/settings.
- Run inactive-prompt cleanup and instruction-size validation after each sync; document the feature in the changelog.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/notifications.ts | Adds a new warning notification with actions for managing prompts/settings. |
| src/utils/fileSystem.ts | Adds a helper to read file sizes for instruction-size aggregation. |
| src/syncManager.ts | Hooks inactive prompt cleanup into the sync lifecycle; adds instruction-size validation + warning trigger. |
| src/constant.ts | Introduces size/count/repo-count threshold constants. |
| CHANGELOG.md | Documents the new safeguard and inactive prompt cleanup behavior. |
You can also share your feedback on Copilot code review. Take the survey.
6eaa17d to
a054e9f
Compare
a295e77 to
a2d194c
Compare
86fec93 to
de5a15b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/syncManager.ts`:
- Line 13: The safeguard currently only checks
INSTRUCTION_SIZE_WARNING_THRESHOLD_BYTES and INSTRUCTION_COUNT_WARNING_THRESHOLD
but omits the repository-count threshold; add the repository-count constant to
the import list (e.g., REPO_SYNC_REPO_COUNT_WARNING_THRESHOLD) alongside
REPO_SYNC_PROMPT_PATH/INSTRUCTION_* and then update the safeguard conditional
(the block referencing INSTRUCTION_SIZE_WARNING_THRESHOLD_BYTES and
INSTRUCTION_COUNT_WARNING_THRESHOLD around the 1305–1338 logic) to also check
repoCount > REPO_SYNC_REPO_COUNT_WARNING_THRESHOLD and include that condition in
the warning message text so the repo-count case triggers the same warning
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 14d442b0-f950-4410-b516-d2259ec72ca5
📒 Files selected for processing (5)
CHANGELOG.mdsrc/constant.tssrc/syncManager.tssrc/utils/fileSystem.tssrc/utils/notifications.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/utils/notifications.ts
- src/utils/fileSystem.ts
- src/constant.ts
…ow & bump version to 1.5.6
6add00a to
d74d6e6
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/syncManager.ts (1)
1300-1352: Well-structured safeguard with one minor terminology inconsistency to address.The method correctly targets only
.instructions.mdfiles (which are auto-loaded into Copilot's context), has appropriate error handling at both per-file and method levels, and provides clear threshold violation reasons to the user.The error log at line 1350 should say "Failed to validate instruction size" rather than "Failed to validate prompt size" to align with the method name and JSDoc terminology.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/syncManager.ts` around lines 1300 - 1352, In validateInstructionSize(), update the final error log message to use the correct terminology: change the logger.error call that currently logs "Failed to validate prompt size" to "Failed to validate instruction size" so it matches the method name and JSDoc; locate the logger.error invocation inside validateInstructionSize (the catch block that currently passes error or undefined) and replace only the message string.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/syncManager.ts`:
- Around line 1300-1352: In validateInstructionSize(), update the final error
log message to use the correct terminology: change the logger.error call that
currently logs "Failed to validate prompt size" to "Failed to validate
instruction size" so it matches the method name and JSDoc; locate the
logger.error invocation inside validateInstructionSize (the catch block that
currently passes error or undefined) and replace only the message string.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6a2180bf-c9f4-4150-a85f-322fc93b849f
📒 Files selected for processing (6)
CHANGELOG.mdpackage.jsonsrc/constant.tssrc/syncManager.tssrc/utils/fileSystem.tssrc/utils/notifications.ts
✅ Files skipped from review due to trivial changes (3)
- package.json
- src/constant.ts
- CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (2)
- src/utils/fileSystem.ts
- src/utils/notifications.ts
Problem
When Automatic Sync is enabled with multiple repositories, the extension syncs all prompts, agents, and instructions into the local prompts directory.
GitHub Copilot automatically loads
.instructions.mdfiles into its context window, which can cause the context/token budget to exceed 100% — effectively blocking users from interacting with Copilot.Solution
Added a post-sync validation step that detects when active instructions are too large and warns the user with actionable next steps.
What changed
src/constant.tsINSTRUCTION_SIZE_WARNING_THRESHOLD_BYTES,INSTRUCTION_COUNT_WARNING_THRESHOLD,REPO_COUNT_WARNING_THRESHOLD)src/utils/notifications.tsshowPromptSizeWarning()— always-visible warning with "Manage Prompts" and "Open Settings" actionssrc/syncManager.tscleanupInactivePrompts()into sync lifecycle to exclude disabled prompts; addedvalidatePromptSize()that scans only.instructions.mdfiles after sync and triggers the warning if thresholds are exceededCHANGELOG.md[Unreleased]How it works
.instructions.md) are measured (total bytes + count). Only instructions are counted because they are auto-loaded into Copilot's context —.prompt.mdfiles are invoked on-demand and don't consume context window.showNotificationssetting — it's a safeguard, not informational.No breaking changes
Screenshot
Summary by CodeRabbit