fix: cap OpenRouter context history#3339
Open
desmond-rai wants to merge 1 commit into
Open
Conversation
Contributor
Greptile SummaryThis PR adds a configurable cap for OpenRouter request history. The main changes are:
Confidence Score: 5/5Safe to merge with minimal risk. The change is localized to OpenRouter request construction and settings defaults. Invalid cap values are clamped, the existing in-memory session history behavior is preserved, and tests cover the new settings and capped request behavior. No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Worker as Worker session
participant Provider as OpenRouterProvider
participant Settings as SettingsDefaultsManager
participant API as OpenRouter API
Worker->>Provider: query(conversationHistory)
Provider->>Settings: loadFromFile(USER_SETTINGS_PATH)
Settings-->>Provider: max context setting/default
Provider->>Provider: clamp setting to 2..200
Provider->>Provider: keep first message + newest messages
Provider->>API: POST /chat/completions with bounded messages
API-->>Provider: completion + usage
Provider-->>Worker: ProviderQueryResult
Note over Worker,Provider: Full in-memory conversationHistory remains unchanged
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Worker as Worker session
participant Provider as OpenRouterProvider
participant Settings as SettingsDefaultsManager
participant API as OpenRouter API
Worker->>Provider: query(conversationHistory)
Provider->>Settings: loadFromFile(USER_SETTINGS_PATH)
Settings-->>Provider: max context setting/default
Provider->>Provider: clamp setting to 2..200
Provider->>Provider: keep first message + newest messages
Provider->>API: POST /chat/completions with bounded messages
API-->>Provider: completion + usage
Provider-->>Worker: ProviderQueryResult
Note over Worker,Provider: Full in-memory conversationHistory remains unchanged
Reviews (1): Last reviewed commit: "fix: cap OpenRouter context history" | Re-trigger Greptile |
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.
What changed
CLAUDE_MEM_OPENROUTER_MAX_CONTEXT_MESSAGESwith a default of 20 and a safe 2-200 range.Why
OpenRouter observation requests reused the complete multi-turn history. Long Claude Mem sessions therefore resent an ever-growing context for every tool event, causing extreme token usage even when the configured context-message cap was present in
settings.json.Impact
OpenRouter requests remain bounded by default while retaining the observer instructions and latest context. Existing users can tune the cap through settings without changing providers or models.
Validation
bun test tests/openrouter_provider.test.ts tests/shared/settings-defaults-manager.test.ts- 37 passed, 0 failedbun run typecheck:rootnode --check plugin/scripts/worker-service.cjs