From 6e8efb9054fb47905c4deb2fc8176fe474e76dcb Mon Sep 17 00:00:00 2001 From: Michael Suchacz <203725896+ibetitsmike@users.noreply.github.com> Date: Fri, 9 Oct 2026 17:24:01 +0000 Subject: [PATCH] refactor(coderd/x/chatd): drop the unreachable override window gate With the fixed 80% trigger, an override trigger is disabled only for a zero window, which the context_limit > 0 check rejects, so a set override always becomes the organization trigger and summarizer. The 80% comment now calls the rest of the window headroom rather than a guarantee, and a test chat title matches its subtest. --- coderd/x/chatd/chatd_test.go | 2 +- coderd/x/chatd/generation_preparer.go | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/coderd/x/chatd/chatd_test.go b/coderd/x/chatd/chatd_test.go index 04833174444..0b8df0a29e5 100644 --- a/coderd/x/chatd/chatd_test.go +++ b/coderd/x/chatd/chatd_test.go @@ -7281,7 +7281,7 @@ func TestActiveServer_CompactionModelOverride(t *testing.T) { OwnerID: user.ID, WorkspaceID: uuid.NullUUID{UUID: ws.ID, Valid: true}, AgentID: uuid.NullUUID{UUID: dbAgent.ID, Valid: true}, - Title: "compaction-override-threshold-lowered", + Title: "compaction-override-added-lower-trigger", ModelConfigID: model.ID, InitialUserContent: []codersdk.ChatMessagePart{ codersdk.ChatMessageText("read the file and continue"), diff --git a/coderd/x/chatd/generation_preparer.go b/coderd/x/chatd/generation_preparer.go index 675fc96f7bf..67d97a8afda 100644 --- a/coderd/x/chatd/generation_preparer.go +++ b/coderd/x/chatd/generation_preparer.go @@ -850,16 +850,12 @@ func (server *Server) prepareGeneration( thresholdPercent: compactionOverrideWindowPercent, contextLimit: resolvedCompactionOverride.Config.ContextLimit, } - // With an unknown window, nothing bounds the history by the - // override's window, so the chat model summarizes instead. - if overrideTrigger.enabled() { - compactionOverride = &resolvedCompactionOverride - otherTrigger = overrideTrigger - bindingSource = bindingCompactionTriggerSource(chatTrigger, overrideTrigger) - if bindingSource == compactionTriggerSourceOrganization { - binding = overrideTrigger - otherTrigger = chatTrigger - } + compactionOverride = &resolvedCompactionOverride + otherTrigger = overrideTrigger + bindingSource = bindingCompactionTriggerSource(chatTrigger, overrideTrigger) + if bindingSource == compactionTriggerSourceOrganization { + binding = overrideTrigger + otherTrigger = chatTrigger } } compactionStepUsage := latestPromptUsage(promptRows) @@ -959,8 +955,9 @@ func latestPromptUsage(messages []database.ChatMessage) fantasy.Usage { return fantasy.Usage{} } -// compactionOverrideWindowPercent leaves room in the override's window for -// the summary prompt and the summary. +// compactionOverrideWindowPercent leaves the rest of the override's window as +// headroom for the summary prompt and summary. It is a target margin, not a +// guarantee: the trigger reads the previous step's prompt usage. const compactionOverrideWindowPercent = int32(80) type compactionTrigger struct {