feat(session): add ratio-based auto-commit threshold with model context awareness#1360
feat(session): add ratio-based auto-commit threshold with model context awareness#1360mvanhorn wants to merge 1 commit intovolcengine:mainfrom
Conversation
…xt awareness Add auto_commit_threshold_ratio and context_window parameters to Session, allowing the commit threshold to scale with model context window size. When both are set, effective threshold = context_window * ratio, which prevents premature compression on large-context models (1M tokens) while remaining conservative on smaller models (200K). Also adds commitTokenThresholdRatio to the OpenClaw plugin config. Priority: ratio > fixed value > default (8000). Fixes volcengine#1172
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Description
Add
auto_commit_threshold_ratioandcontext_windowparameters toSession.__init__, allowing the commit threshold to scale with the model's context window size. When users switch between models (1M vs 200K tokens), the threshold adapts automatically instead of requiring manual recalculation.Also adds
commitTokenThresholdRatioto the OpenClaw plugin config.Related Issue
Fixes #1172
Type of Change
Changes Made
auto_commit_threshold_ratio: Optional[float]andcontext_window: Optional[int]params toSession.__init__with input validationeffective_commit_thresholdproperty: computesint(context_window * ratio)when both are set, falls back to the fixedauto_commit_thresholdotherwisecommitTokenThresholdRatioto the OpenClaw plugin config type, schema parser, allowed keys list, and uiHintsPriority order:
ratio * context_window> fixedauto_commit_threshold> default8000.Testing
9 test cases cover: default threshold, fixed override, ratio with 1M model, ratio with 200K model, ratio overriding fixed value, ratio without context_window fallback, and 4 validation error cases.
Checklist
Screenshots (if applicable)
Demo
Shows the
effective_commit_thresholdproperty computing different thresholds: default 8000, 1M model at 38% = 380K, 200K model at 38% = 76K, and ratio overriding a fixed value.Additional Notes
The
Sessionclass storesauto_commit_thresholdbut the actual commit decision is made by the caller (OpenClaw plugin or bot). This PR adds the ratio computation on both sides: PythonSession.effective_commit_thresholdfor callers using the Python API directly, andcommitTokenThresholdRatioin the TS plugin config for OpenClaw users. The existingcommitTokenThreshold/auto_commit_thresholdparameters remain unchanged for backward compatibility.This contribution was developed with AI assistance (Claude Code).