Repository navigation
fix(user-profile-analysis): cap context sent to profile LLM - #186
Merged
Merged
Conversation
buildUserAnalysisContext now truncates the prompt payload at CONFIG.userProfileMaxContextBytes (default 32768). This keeps retry loops affordable when the profile LLM call fails repeatedly with oversized context. Adds a new config knob userProfileMaxContextBytes, wired through OpenCodeMemConfig, DEFAULTS, and the buildConfig resolver following the same pattern as userProfileAnalysisInterval. README updated with the new field in Configuration Essentials.
Merged
Owner
|
Merged into |
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.
Fixes #176 (partial)
What this addresses
Item #3 of the suggested fixes in #176: cap the total assembled prompt size that
buildUserAnalysisContextships to the profile-analysis LLM. Today the function concatenates the template + all N user prompts with no size guard, so a single oversized prompt or a large backlog can push the payload past the model window.This PR adds the total-size cap (default 32 KB). It does not add the per-item cap or skip-analysis-prompt logic from items #1 and #2 — those are a separate, deeper surgery on the
prompts.map((p, i) => \${i + 1}. ${p.content}`).join("\n\n")` line and will come as a follow-up if there is interest.Changes
src/services/user-memory-learning.ts(+9/-2): introduce a localtruncate(s)helper and apply it to both branches (basealone, andbase + validationPrompt).src/config.ts(+4): new optional knobuserProfileMaxContextByteswired throughOpenCodeMemConfig,DEFAULTS, andbuildConfigin the same shape asuserProfileAnalysisInterval.README.md(+1): added the new field to the Configuration Essentials example block.Verification
bun run typecheck— cleanbun run build— cleanbunx prettier --check— cleanManual check
Set
userProfileMaxContextBytes: 1024in~/.config/opencode/opencode-mem.jsoncand trigger a profile analysis with enough prompts to exceed 1 KB. The LLM payload should be truncated and include the marker[... context truncated to userProfileMaxContextBytes ...].Background
See #issuecomment-5033470016 for the full analysis this is based on.