Skip to content

Commit fa92ec4

Browse files
fix: resolve race condition in context condensing prompt input (#10876)
1 parent 9ab279a commit fa92ec4

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to agents when working with code in this repository.
4+
5+
- Settings View Pattern: When working on `SettingsView`, inputs must bind to the local `cachedState`, NOT the live `useExtensionState()`. The `cachedState` acts as a buffer for user edits, isolating them from the `ContextProxy` source-of-truth until the user explicitly clicks "Save". Wiring inputs directly to the live state causes race conditions.

webview-ui/src/components/settings/PromptsSettings.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ import { SearchableSetting } from "./SearchableSetting"
2323
interface PromptsSettingsProps {
2424
customSupportPrompts: Record<string, string | undefined>
2525
setCustomSupportPrompts: (prompts: Record<string, string | undefined>) => void
26+
customCondensingPrompt?: string
27+
setCustomCondensingPrompt?: (value: string) => void
2628
includeTaskHistoryInEnhance?: boolean
2729
setIncludeTaskHistoryInEnhance?: (value: boolean) => void
2830
}
2931

3032
const PromptsSettings = ({
3133
customSupportPrompts,
3234
setCustomSupportPrompts,
35+
customCondensingPrompt: propsCustomCondensingPrompt,
36+
setCustomCondensingPrompt: propsSetCustomCondensingPrompt,
3337
includeTaskHistoryInEnhance: propsIncludeTaskHistoryInEnhance,
3438
setIncludeTaskHistoryInEnhance: propsSetIncludeTaskHistoryInEnhance,
3539
}: PromptsSettingsProps) => {
@@ -40,12 +44,16 @@ const PromptsSettings = ({
4044
setEnhancementApiConfigId,
4145
condensingApiConfigId,
4246
setCondensingApiConfigId,
43-
customCondensingPrompt,
44-
setCustomCondensingPrompt,
47+
customCondensingPrompt: contextCustomCondensingPrompt,
48+
setCustomCondensingPrompt: contextSetCustomCondensingPrompt,
4549
includeTaskHistoryInEnhance: contextIncludeTaskHistoryInEnhance,
4650
setIncludeTaskHistoryInEnhance: contextSetIncludeTaskHistoryInEnhance,
4751
} = useExtensionState()
4852

53+
// Use props if provided, otherwise fall back to context
54+
const customCondensingPrompt = propsCustomCondensingPrompt ?? contextCustomCondensingPrompt
55+
const setCustomCondensingPrompt = propsSetCustomCondensingPrompt ?? contextSetCustomCondensingPrompt
56+
4957
// Use props if provided, otherwise fall back to context
5058
const includeTaskHistoryInEnhance = propsIncludeTaskHistoryInEnhance ?? contextIncludeTaskHistoryInEnhance ?? true
5159
const setIncludeTaskHistoryInEnhance = propsSetIncludeTaskHistoryInEnhance ?? contextSetIncludeTaskHistoryInEnhance
@@ -76,10 +84,6 @@ const PromptsSettings = ({
7684

7785
if (type === "CONDENSE") {
7886
setCustomCondensingPrompt(finalValue ?? supportPrompt.default.CONDENSE)
79-
vscode.postMessage({
80-
type: "updateCondensingPrompt",
81-
text: finalValue ?? supportPrompt.default.CONDENSE,
82-
})
8387
// Also update the customSupportPrompts to trigger change detection
8488
const updatedPrompts = { ...customSupportPrompts }
8589
if (finalValue === undefined) {
@@ -102,10 +106,6 @@ const PromptsSettings = ({
102106
const handleSupportReset = (type: SupportPromptType) => {
103107
if (type === "CONDENSE") {
104108
setCustomCondensingPrompt(supportPrompt.default.CONDENSE)
105-
vscode.postMessage({
106-
type: "updateCondensingPrompt",
107-
text: supportPrompt.default.CONDENSE,
108-
})
109109
// Also update the customSupportPrompts to trigger change detection
110110
const updatedPrompts = { ...customSupportPrompts }
111111
delete updatedPrompts[type]

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
900900
<PromptsSettings
901901
customSupportPrompts={customSupportPrompts || {}}
902902
setCustomSupportPrompts={setCustomSupportPromptsField}
903+
customCondensingPrompt={customCondensingPrompt}
904+
setCustomCondensingPrompt={(value) =>
905+
setCachedStateField("customCondensingPrompt", value)
906+
}
903907
includeTaskHistoryInEnhance={includeTaskHistoryInEnhance}
904908
setIncludeTaskHistoryInEnhance={(value) =>
905909
setCachedStateField("includeTaskHistoryInEnhance", value)

0 commit comments

Comments
 (0)