feat(server): implement prompt text truncation safety#1238
Open
D4rk-Pho3nix wants to merge 2 commits into
Open
feat(server): implement prompt text truncation safety#1238D4rk-Pho3nix wants to merge 2 commits into
D4rk-Pho3nix wants to merge 2 commits into
Conversation
Signed-off-by: D4rk-Pho3nix <manish.srmist23@gmail.com>
Signed-off-by: D4rk-Pho3nix <manish.srmist23@gmail.com>
|
@D4rk-Pho3nix is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1102
Summary (program: GSSoC)
Large code graph results can exceed LLM context windows silently. This PR cuts payloads at a configurable limit, appends a visible notice, and logs a warning so nothing fails quietly.
What's New
🔒 Dual config knobs: Added
MAX_PROMPT_CHARSalongsideMAX_TOOL_RESPONSE_TOKENS. Whichever is stricter wins.To test: Set
MAX_PROMPT_CHARS=500andMAX_TOOL_RESPONSE_TOKENS=50in CGC config, run a graph query with large output, and confirm truncation fires.✂️ Truncation logic: Updated
_apply_response_token_limit()to use_effective_char_limit()for the budget, cut at a clean JSON boundary, and append a[CGC] Response truncatednotice to the payload.To test: Query a large codebase and look for the
[CGC] Response truncatednotice at the end of the response.📢 Truncation warnings: Prints a
[CGC WARNING]line to stderr on every truncation, withtool,original_chars,truncated_chars, andlimit. No more silent failures.🧪 Tests: Unit tests for
_effective_char_limit,_limit_source_label, and the full_apply_response_token_limitflow: both knobs, stricter-wins, unlimited, at-limit, non-JSON, and warning emission.Implementation
Feature Testing (Scenario) 👇
1102.1.mp4
Testing Edge Cases 👇
Files Changed
src/codegraphcontext/server.py(53 additions, 12 deletions): added_effective_char_limit()and_limit_source_label(); updated_apply_response_token_limit()to read both config knobs and emit a stderr warning on truncation.src/codegraphcontext/cli/config_manager.py(13 additions): registeredMAX_PROMPT_CHARSwith default value, config description, and non-negative integer validation.tests/unit/tools/test_prompt_truncation_safety.py(269 additions): new test file covering both config knobs, stricter-wins logic, at-limit/below-limit edge cases, non-JSON payloads, stderr warning emission, andMAX_PROMPT_CHARSconfig validation.tests/test_truncation_real_scenario.py(new): real-scenario integration test mirroring an actual CGC config state with realistic tool response payloads.Edge cases covered