From ffe9ed5531b6e62706ea555c48964ea0e560b780 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 3 Sep 2025 16:00:26 +0300 Subject: Phase 2: add configurable completion debounce\n\n- App config: completion_debounce_ms (default 200)\n- Server: wait until no input for debounce before LLM calls\n- Applies to chat and provider-native completion paths\n- Tests: add debounce and adjust to verify behavior\n\nAll unit tests pass. --- internal/appconfig/config.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'internal/appconfig') diff --git a/internal/appconfig/config.go b/internal/appconfig/config.go index 7bcafda..2110831 100644 --- a/internal/appconfig/config.go +++ b/internal/appconfig/config.go @@ -25,6 +25,14 @@ type App struct { // to proceed without structural triggers. 0 means always allow. ManualInvokeMinPrefix int `json:"manual_invoke_min_prefix"` + // Completion debounce in milliseconds. When > 0, the server waits until + // there has been no text change for at least this duration before sending + // an LLM completion request. + CompletionDebounceMs int `json:"completion_debounce_ms"` + // Completion throttle in milliseconds. When > 0, caps the minimum spacing + // between LLM requests (both chat and code-completer paths). + CompletionThrottleMs int `json:"completion_throttle_ms"` + TriggerCharacters []string `json:"trigger_characters"` Provider string `json:"provider"` @@ -59,6 +67,8 @@ func newDefaultConfig() App { OllamaTemperature: &t, CopilotTemperature: &t, ManualInvokeMinPrefix: 0, + CompletionDebounceMs: 200, + CompletionThrottleMs: 0, } } @@ -139,6 +149,8 @@ func (a *App) mergeBasics(other *App) { if other.ManualInvokeMinPrefix >= 0 { a.ManualInvokeMinPrefix = other.ManualInvokeMinPrefix } + if other.CompletionDebounceMs > 0 { a.CompletionDebounceMs = other.CompletionDebounceMs } + if other.CompletionThrottleMs > 0 { a.CompletionThrottleMs = other.CompletionThrottleMs } if len(other.TriggerCharacters) > 0 { a.TriggerCharacters = slices.Clone(other.TriggerCharacters) } @@ -238,6 +250,12 @@ func loadFromEnv(logger *log.Logger) *App { if n, ok := parseInt("HEXAI_MANUAL_INVOKE_MIN_PREFIX"); ok { out.ManualInvokeMinPrefix = n; any = true } + if n, ok := parseInt("HEXAI_COMPLETION_DEBOUNCE_MS"); ok { + out.CompletionDebounceMs = n; any = true + } + if n, ok := parseInt("HEXAI_COMPLETION_THROTTLE_MS"); ok { + out.CompletionThrottleMs = n; any = true + } if f, ok := parseFloatPtr("HEXAI_CODING_TEMPERATURE"); ok { out.CodingTemperature = f; any = true } -- cgit v1.2.3