Scope completion truncation to active provider - #49
Conversation
📝 WalkthroughWalkthroughThis PR refactors prompt truncation in the OpenAI completion flow to use only the selected model's token limits instead of applying the most restrictive limit across all configured providers. The truncation API now accepts a provider parameter, the internal logic is simplified to check only the resolved model, and callers delegate truncation responsibility to the request factory. ChangesProvider-Aware Prompt Truncation
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…-scoped fix The no-arg truncatePromptForCompletion lost its only production caller in #49 and silently assumed the OPENAI provider; the provider-arg overload was reachable only from tests. Both removed per [AB1d]; the regression tests now exercise buildCompletionRequest, covering the full provider-to-model-id truncation path.
Summary
buildCompletionRequestso fallback providers use their own model limitsgpt-4oalongside the default GitHub Modelsopenai/gpt-5Fixes#40.
Verification
JAVA_HOME=C:\Users\Admin\AppData\Local\Codex\jdks\temurin-25\jdk-25.0.3+9 ./gradlew.bat test --tests com.williamcallahan.javachat.service.OpenAiRequestFactoryTestJAVA_HOME=C:\Users\Admin\AppData\Local\Codex\jdks\temurin-25\jdk-25.0.3+9 ./gradlew.bat test --tests com.williamcallahan.javachat.service.OpenAIStreamingServiceTestJAVA_HOME=C:\Users\Admin\AppData\Local\Codex\jdks\temurin-25\jdk-25.0.3+9 ./gradlew.bat spotlessCheckgit diff --checkFull
./gradlew.bat testruns 244 tests but fails on the existing Windows environment becauseEnvironmentVariablePrecedenceTesthardcodes/bin/bash, which is not present here.Greptile Summary
This PR fixes issue #40 by moving prompt truncation inside
buildCompletionRequestso that each provider attempt uses its own model's token limits, rather than applying a single pre-loop truncation derived from the union of both providers' characteristics.OpenAIStreamingService.complete()now passes the raw prompt tobuildCompletionRequest, which calls the privatetruncatePromptForCompletion(String, String)with the resolved model ID for the active provider.OpenAiRequestFactorygains a public provider-arg overload oftruncatePromptForCompletionand a private model-ID overload that contains the actual logic; the original no-arg public method now delegates to the OPENAI provider by default.gpt-4o(OpenAI) leaves an ~8K-token prompt untouched whileopenai/gpt-5(GitHub Models) truncates it with the appropriate notice.Confidence Score: 4/5
Safe to merge; the core logic change is correct and well-tested for the targeted scenarios.
The refactor correctly scopes truncation to the active provider on each attempt. Two dead public overloads have no production callers after the change, and the o-series 7K limit assumption silently under-serves larger-context models. Neither issue affects correctness for the currently configured models.
OpenAiRequestFactory.java — the dead public overloads and the o-series token limit assumption are worth a second look before this code path grows further.
Important Files Changed
Sequence Diagram
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "Scope completion truncation to active pr..." | Re-trigger Greptile
Context used: