Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
c8e986c
feat(context): condense context after idle time
DavidWAbrahams Nov 6, 2026
0ad4da0
clamp the to conext threshold sliders together
DavidWAbrahams Nov 6, 2026
4c42cd1
nest idle condensing under auto condense and reword idle description
DavidWAbrahams Nov 6, 2026
5e97895
Merge branch 'main' into feature/idle-condensing
DavidWAbrahams Nov 7, 2026
6df461e
fix formatting and repair eslint-suppressions.json merge corruption
DavidWAbrahams Nov 7, 2026
6710459
fix Task.spec.ts condense stub to resolve with CondenseContextResult
DavidWAbrahams Nov 7, 2026
19952ce
test webview-ui idle-condense state and condense queueing for patch c…
DavidWAbrahams Nov 7, 2026
93f0d4f
fix: address review findings on idle-condense clamping, inheritance, …
DavidWAbrahams Nov 8, 2026
bf6e469
Update webview-ui/src/components/settings/ContextManagementSettings.tsx
DavidWAbrahams Nov 8, 2026
731f803
fix: type idle-condensing checkbox change event with checkbox target …
DavidWAbrahams Nov 8, 2026
1b1fbeb
fix: slice long idle timer delays and reset countdown on every edit
DavidWAbrahams Nov 8, 2026
bf9d892
style: apply prettier formatting to idle-condense sources
DavidWAbrahams Nov 8, 2026
ae763be
test: define abort as own property in idle-condense task stub
DavidWAbrahams Nov 8, 2026
2eecdb3
test: redefine abort instead of assigning in aborted-task test
DavidWAbrahams Nov 9, 2026
c617e45
Merge branch 'main' into feature/idle-condensing
DavidWAbrahams Nov 9, 2026
3a7e6ef
test: cover idle-condensing patch gaps flagged by codecov
DavidWAbrahams Nov 9, 2026
c353db3
fix: re-arm idle countdown with newly saved delay
DavidWAbrahams Nov 9, 2026
7137625
fix(context): address CodeRabbit review feedback for idle condensing
DavidWAbrahams Nov 9, 2026
019af57
test(webview): regenerate idle condensing visual baselines
DavidWAbrahams Nov 9, 2026
bd5c1bd
fix(task): resolve condense profile thresholds from the task's own pr…
DavidWAbrahams Nov 9, 2026
537eed3
fix(context): address idle-condense review findings (reset signals, v…
DavidWAbrahams Nov 9, 2026
e2e0740
test(webview): assert idleCondenseReset on setChatBoxMessage invoke path
DavidWAbrahams Nov 10, 2026
d2465cd
Merge branch 'main' into feature/idle-condensing
DavidWAbrahams Nov 10, 2026
4f14bd2
Merge branch 'main' into feature/idle-condensing
DavidWAbrahams Nov 10, 2026
23bde53
i18n: simplify idle condensing threshold and idle time descriptions
DavidWAbrahams Nov 10, 2026
1496acc
test(webview): cover idleCondenseReset on programmatic input rewrites
DavidWAbrahams Nov 10, 2026
93a0ae8
fix(condense): address pre-merge checks for idle condensing
DavidWAbrahams Dec 1, 2026
a42c4c0
Merge remote-tracking branch 'origin/main' into pr-2340-fix
DavidWAbrahams Dec 1, 2026
4099c19
test(chat): pin execCommand absent so the idle-condense enhanced-prom…
DavidWAbrahams Dec 1, 2026
5e3a5cf
test(task): adapt condense tests to durable overwrite seam and 5-arg …
DavidWAbrahams Dec 1, 2026
59de054
fix(review): harden idle condense per coderabbit review
DavidWAbrahams Dec 2, 2026
398496c
fix(context): hold direct response across condense drain, re-arm idle…
DavidWAbrahams Dec 3, 2026
2562935
test(context): run idle expiry and suppression tests on the real lease
DavidWAbrahams Dec 4, 2026
71f1727
docs(context): model the condense commit order in TLA+
DavidWAbrahams Dec 4, 2026
91056ee
test(queue): model the held-response drain guard in check-queue-ask-l…
DavidWAbrahams Dec 4, 2026
ee0c2df
fix(context): skip durable-overwrite rollback when newer history land…
DavidWAbrahams Dec 4, 2026
df3df3c
fix(context): fall back to current profile when the task's saved prof…
DavidWAbrahams Dec 4, 2026
8a38a65
fix(context): skip condense says when choosing the resume ask
DavidWAbrahams Dec 4, 2026
b277c8b
fix(context): exclude resume prompts and the auto-approval budget ask…
DavidWAbrahams Dec 4, 2026
04d267f
fix(context): obey auto-approval budgets and the provider rate limit …
DavidWAbrahams Dec 4, 2026
6866b94
docs(context): document how a user response interacts with an in-flig…
DavidWAbrahams Dec 4, 2026
cc4425e
chore: remove review-thread citations from idle-condensing comments
DavidWAbrahams Dec 4, 2026
1cc2581
fix(chat): show the Stop button while a condense is in progress
DavidWAbrahams Dec 4, 2026
a8b79cd
fix(condense): stop an in-progress condense promptly on cancel
DavidWAbrahams Dec 4, 2026
bae9305
test(condense): cover durable-write failure rollback, error row, and …
DavidWAbrahams Dec 4, 2026
06cff20
fix(condense): stop when the pending tool-result flush fails
DavidWAbrahams Dec 4, 2026
a77ccea
fix(settings): bound idle condense percent and time in the global set…
DavidWAbrahams Dec 5, 2026
86d135a
fix(settings): keep the idle delay when the idle time field is cleared
DavidWAbrahams Dec 5, 2026
eb33e62
perf(condense): re-arm the idle countdown per keystroke without re-ru…
DavidWAbrahams Dec 5, 2026
e993cd8
refactor(chat): restart the idle-condense countdown from a single dra…
DavidWAbrahams Dec 5, 2026
fa420c1
test(settings): cover all five idle-condense settings in the save pay…
DavidWAbrahams Dec 5, 2026
d2c8383
refactor(context): resolve the condense threshold through the shared …
DavidWAbrahams Dec 5, 2026
093e4d3
fix(condense): record the idle-triggered summary as an automatic trigger
DavidWAbrahams Dec 6, 2026
cef20cc
chore(i18n): update idle condensing description in all locales
DavidWAbrahams Dec 6, 2026
619e10c
chore(i18n): reword idle condensing threshold description in all locales
DavidWAbrahams Dec 6, 2026
d32ec66
test(auto-approval): pin wouldExceedLimits to the interactive limit math
DavidWAbrahams Dec 6, 2026
2906d97
refactor(auto-approval): share budget counting between limit checks a…
DavidWAbrahams Dec 6, 2026
b641709
refactor(idle-condense): share setting defaults and rate-limit window…
DavidWAbrahams Dec 6, 2026
05995f8
test(visual): refresh context-management-settings baselines after idl…
DavidWAbrahams Dec 6, 2026
90def65
fix(context): drain queued messages when an idle condense aborts on u…
DavidWAbrahams Dec 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/architecture/tla/CondenseCommitOrder.Unfixed.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions docs/architecture/tla/CondenseCommitOrder.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions docs/architecture/tla/CondenseCommitOrder.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---- MODULE CondenseCommitOrder ----
\* Models the order between the summarization request and the history commit in
\* src/core/task/Task.ts. Source: condenseContextWithActiveApi reads the history,
\* snapshots apiHistoryRevision, and runs the seconds-long summarizeConversation call.
\* Sink: the commit replaces the history with overwriteApiConversationHistoryDurable.
\* Every history mutation (addToApiConversationHistory, overwriteApiConversationHistory,
\* startTask reset) bumps apiHistoryRevision.
\* Failure (PR 2340 review, thread 4756204775): the user rewinds a turn while the
\* summarization request runs. The commit writes the pre-rewind snapshot and
\* resurrects the deleted turns.
\* Invariant DeletedStaysDeleted: an id the user deleted with a rewind never
\* re-enters the history.
\* Modes: Fixed is the code with the revision guard (discard the stale summary).
\* Unfixed is the code before the guard (commit always writes). Unfixed is also the
\* sabotage check for the invariant.
\* Model notes: a history is a sequence of unique ids, oldest first. Id 0 is the
\* summary token; summarizeConversation appends it. The summarize oracle returns the
\* snapshot captured at BeginSummarize. apiHistoryRevision is rev. The guard makes
\* the commit safe because rev changes exactly when the history changes.
\* Not modeled: token counts, the summary text, the durable write failure path, and
\* the in-progress cue. They do not change the commit order.
\* Expected before the run: Fixed holds the invariant. Unfixed violates
\* DeletedStaysDeleted with the trace Prompt, BeginSummarize, Rewind, Commit.
\* Cost: each run takes under 5 seconds.
\* Result: CondenseCommitOrder.cfg (Fixed) holds with 336 distinct states.
\* CondenseCommitOrder.Unfixed.cfg fails with 17 distinct states. The first run
\* used MaxMsgs 4, MaxIds 3 and no rev bound: the revision grew with every
\* action and blew the state space past 40 million states. MaxRev bounds it.
\* Replay: the counterexample is Prompt, BeginSummarize, Rewind, Commit: the
\* commit writes the captured snapshot and the deleted turn 2 returns. The real
\* code replays this order in the Task.spec.ts stale-summary regression test.
\* Findings: added 1 (PR 2340 thread 4756204775: the stale commit resurrects a
\* rewound turn; the guard and this spec came from that finding).

EXTENDS Naturals, Sequences, FiniteSets

CONSTANTS Mode, MaxMsgs, MaxIds, MaxRev

\* Ids 1..MaxIds are user turns. Id 0 is the summary token the oracle appends.
MsgId == 0..MaxIds

VARIABLES msgs, rev, busy, capMsgs, capRev, nextId, gone

vars == <<msgs, rev, busy, capMsgs, capRev, nextId, gone>>

\* The user turns in a history. Id 0 is the summary marker: a rewind that drops a
\* summary, then a later condense that adds a new one, must not look like a resurrection.
IdSet(s) == {s[x] : x \in {i \in DOMAIN s : s[i] # 0}}

\* A talk turn appends one message and bumps the revision.
Prompt ==
/\ nextId <= MaxIds
/\ Len(msgs) < MaxMsgs
/\ rev < MaxRev
/\ msgs' = Append(msgs, nextId)
/\ nextId' = nextId + 1
/\ rev' = rev + 1
/\ UNCHANGED <<busy, capMsgs, capRev, gone>>

\* The user deletes the newest turns. The deleted ids join gone, and the
\* revision bumps. The summary token at the tail is removed with them.
Rewind ==
/\ Len(msgs) > 1
/\ rev < MaxRev
/\ \E k \in 1..(Len(msgs) - 1) :
/\ msgs' = SubSeq(msgs, 1, k)
/\ gone' = gone \cup IdSet(SubSeq(msgs, k + 1, Len(msgs)))
/\ rev' = rev + 1
/\ UNCHANGED <<busy, capMsgs, capRev, nextId>>

\* The summarize call begins: capture the history and the revision. The oracle
\* result is the captured snapshot plus the summary token.
BeginSummarize ==
/\ ~busy
/\ capMsgs' = msgs
/\ capRev' = rev
/\ busy' = TRUE
/\ UNCHANGED <<msgs, rev, nextId, gone>>

\* The commit. Fixed discards the result when the revision moved during the
\* request. Unfixed always writes the captured snapshot.
Commit ==
/\ busy
/\ busy' = FALSE
/\ IF Mode = "Fixed" /\ capRev # rev
THEN UNCHANGED <<msgs, rev, capMsgs, capRev, nextId, gone>>
ELSE /\ msgs' = Append(capMsgs, 0)
/\ UNCHANGED <<rev, capMsgs, capRev, nextId, gone>>

Init ==
/\ msgs = <<1>>
/\ rev = 1
/\ busy = FALSE
/\ capMsgs = <<>>
/\ capRev = 0
/\ nextId = 2
/\ gone = {}

Next == \/ Prompt \/ Rewind \/ BeginSummarize \/ Commit

Spec == Init /\ [][Next]_vars

\* Keep the state space finite: bound the history length and the revision count.
Bounded == /\ Len(msgs) <= MaxMsgs
/\ rev <= MaxRev

TypeOK ==
/\ msgs \in Seq(MsgId)
/\ rev \in Nat
/\ busy \in BOOLEAN
/\ capMsgs \in Seq(MsgId)
/\ capRev \in Nat
/\ nextId \in 2..(MaxIds + 1)
/\ gone \subseteq MsgId

\* The opposite of the failure: a turn deleted by a rewind never returns.
DeletedStaysDeleted == IdSet(msgs) \cap gone = {}

====
22 changes: 22 additions & 0 deletions packages/types/src/__tests__/global-settings.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions packages/types/src/global-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ export const MAX_CHECKPOINT_TIMEOUT_SECONDS = 60
*/
export const DEFAULT_CHECKPOINT_TIMEOUT_SECONDS = 15

/**
* Default for `idleCondenseContext`: idle condensing is opt-in.
*/
export const DEFAULT_IDLE_CONDENSE_CONTEXT = false

/**
* Default for `idleCondenseContextPercent`: the context-window percentage at
* or above which an idle condense may run.
*/
export const DEFAULT_IDLE_CONDENSE_CONTEXT_PERCENT = 50

/**
* Default for `idleCondenseTimeInSeconds`: seconds the task must wait on the
* user before an idle condense runs.
*/
export const DEFAULT_IDLE_CONDENSE_TIME_IN_SECONDS = 180

/**
* GlobalSettings
*/
Expand Down Expand Up @@ -190,6 +207,41 @@ export const globalSettingsSchema = z.object({
allowedMaxCost: z.number().nullish(),
autoCondenseContext: z.boolean().optional(),
autoCondenseContextPercent: z.number().optional(),
/**
* Master toggle for idle condensing: opportunistically condense the context
* while the task is waiting on the user, once the context exceeds the
* (typically lower) idle trigger threshold and the idle time has elapsed.
* @default false
*/
idleCondenseContext: z.boolean().optional(),
/**
* Context-window percentage (relative to the condensing context window) at
* or above which an idle condense is allowed to run. Must not exceed the
* effective autoCondenseContextPercent. Bounded so an imported settings
* file cannot carry a value outside the range the settings UI offers;
* values beyond it are rejected by the import sanitizer like any other
* schema failure.
* @default 50
*/
idleCondenseContextPercent: z.number().min(5).max(100).optional(),
/**
* Seconds of waiting-on-user (idle) time before an idle condense runs.
* The countdown restarts when the user types in the prompt input.
* @default 180
*/
idleCondenseTimeInSeconds: z.number().min(0).optional(),
/**
* Per-model-profile overrides for idleCondenseContextPercent. A value of -1
* inherits the global idleCondenseContextPercent; values outside
* [MIN_CONDENSE_THRESHOLD, MAX_CONDENSE_THRESHOLD] fall back to global.
*/
profileIdleThresholds: z.record(z.string(), z.number()).optional(),
/**
* Per-model-profile overrides for idleCondenseTimeInSeconds. A value of -1
* inherits the global idleCondenseTimeInSeconds; negative values other than
* -1 fall back to global.
*/
profileIdleCondenseTimes: z.record(z.string(), z.number()).optional(),

/**
* Whether to include current time in the environment details
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/vscode-extension-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ export type ExtensionState = Pick<
| "codebaseIndexConfig"
| "codebaseIndexModels"
| "profileThresholds"
| "profileIdleThresholds"
| "profileIdleCondenseTimes"
| "includeDiagnosticMessages"
| "maxDiagnosticMessages"
| "imageGenerationProvider"
Expand Down Expand Up @@ -450,6 +452,9 @@ export type ExtensionState = Pick<

autoCondenseContext: boolean
autoCondenseContextPercent: number
idleCondenseContext: boolean
idleCondenseContextPercent: number
idleCondenseTimeInSeconds: number
marketplaceItems?: MarketplaceItem[]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
marketplaceInstalledMetadata?: { project: Record<string, any>; global: Record<string, any> }
Expand Down Expand Up @@ -676,6 +681,7 @@ export interface WebviewMessage {
| "zooCodeSignOut"
| "switchOrganization"
| "condenseTaskContextRequest"
| "idleCondenseReset"
| "requestIndexingStatus"
| "startIndexing"
| "stopIndexing"
Expand Down
68 changes: 64 additions & 4 deletions scripts/check-queue-ask-landing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { initialRunState, nextRunState, type RunEvent, type RunState } from "../
// - the askResponse slot: Task.handleWebviewAskResponse sets it with no check for a pending ask,
// and every Task.ask() start resets it (Task.ts around L2063-2116);
// - the setTimeout(0) between a drain and Task.submitUserMessage, kept as an in-flight list.
// - Task.processQueuedMessages now returns before draining while the slot holds a direct
// response (guardDrainWhenSlotFull), so a condense drain cannot overwrite a held response
// (PR 2340 review thread 4756204794). Unfixed policies keep guardDrainWhenSlotFull false.
// The queue is replayed from the action list for each state, because the service is mutable.
// Command policy, protected asks, message text and aborted tasks are outside this model.

Expand All @@ -19,13 +22,21 @@ interface Policy {
name: string
// How Task.submitQueuedMessage lands a message that reaches the slot.
land: "always-set" | "set-if-ask-pending" | "requeue-unless-ask-and-empty-slot"
// Task.processQueuedMessages skips the drain entirely while the slot holds a response.
guardDrainWhenSlotFull: boolean
}

const production: Policy = { name: "production", land: "always-set" }
const production: Policy = { name: "production", land: "always-set", guardDrainWhenSlotFull: false }
// Current production: the same landing, plus the drain guard from Task.processQueuedMessages.
const guarded: Policy = { name: "guarded-production", land: "always-set", guardDrainWhenSlotFull: true }
// Proposed fix: set the slot only when an ask waits and the slot is empty. Otherwise keep the message queued.
const requeue: Policy = { name: "requeue-unless-ask-and-empty-slot", land: "requeue-unless-ask-and-empty-slot" }
const requeue: Policy = {
name: "requeue-unless-ask-and-empty-slot",
land: "requeue-unless-ask-and-empty-slot",
guardDrainWhenSlotFull: false,
}
// Injected unsafe fix: checks the ask but not the slot, so a second message overwrites the first.
const askOnly: Policy = { name: "set-if-ask-pending", land: "set-if-ask-pending" }
const askOnly: Policy = { name: "set-if-ask-pending", land: "set-if-ask-pending", guardDrainWhenSlotFull: false }

const MAX_DEPTH = 10
const MAX_STATES = 50_000
Expand Down Expand Up @@ -84,6 +95,7 @@ class World {
return
}
if (this.slot !== undefined) {
this.tags.add("slot-overwrite")
this.lost.push(this.slot)
}
this.slot = text
Expand Down Expand Up @@ -130,6 +142,14 @@ class World {
}
case "drain": {
// Task.processQueuedMessages: drain, then submitQueuedMessage defers through setTimeout(0).
// The guard returns before draining while a direct response is held in the slot.
if (this.policy.guardDrainWhenSlotFull && this.slot !== undefined) {
this.tags.add("drain-held-response")
return
}
if (this.slot !== undefined) {
this.tags.add("drain-while-held")
}
const message = this.queue.drain()
if (message) this.inflight.push(message.text)
return
Expand Down Expand Up @@ -233,6 +253,33 @@ function explore(policy: Policy): Exploration {
return { states: visited.size, tags }
}

// Same search, but the first violation does not stop it: the landmark tags need the
// full state space even when a violation exists early (guarded and production runs).
function exploreAll(policy: Policy): Exploration {
const queue: Action[][] = [[]]
const visited = new Set<string>([new World(policy).canonical()])
const tags = new Set<string>()
let violation: Exploration["violation"]
for (let index = 0; index < queue.length; index++) {
const trace = queue[index]!
const world = replay(policy, trace)
world.tags.forEach((tag) => tags.add(tag))
const found = world.violation()
if (!violation && found) violation = { message: found, trace }
if (trace.length === MAX_DEPTH) continue
for (const action of ACTIONS) {
if (!world.enabled(action)) continue
const next = [...trace, action]
const key = replay(policy, next).canonical()
if (visited.has(key)) continue
visited.add(key)
queue.push(next)
if (visited.size > MAX_STATES) throw new Error(`Queue landing model exceeded ${MAX_STATES} states`)
}
}
return { violation, states: visited.size, tags }
}

const format = (trace: Action[]): string => trace.map((action, index) => `${index + 1}. ${action}`).join("\n")

// The proposed fix must be clean, with every landmark reachable.
Expand All @@ -249,10 +296,23 @@ assert.deepEqual(missing, [], `Queue landing model has unreachable landmarks: ${
// Injected unsafe policy: it must fail, so the invariant can see an overwrite.
const unsafe = explore(askOnly)
assert.ok(unsafe.violation, `Injected policy ${askOnly.name} must violate the invariant`)
assert.ok(unsafe.tags.has("slot-overwrite"), `Injected policy ${askOnly.name} never exercised the overwrite path`)

// PR 2340 thread 4756204794: with the drain guard, a condense drain cannot replace a held
// direct response. The guard path must be reachable. Without the guard, the model drains on
// top of a held slot (the unguarded processQueuedMessages call sites), which lands as an
// overwrite; with the guard, that drain never happens.
const guardedRun = exploreAll(guarded)
assert.ok(guardedRun.tags.has("drain-held-response"), `Guard path unreachable under ${guarded.name}`)
const unguarded = exploreAll(production)
assert.ok(
unguarded.tags.has("drain-while-held"),
`Unguarded drain-while-held path unreachable under ${production.name}`,
)

// Known gap (#2421 finding V2): production sets the slot with no ask pending, and the next ask() drops it.
// The requeue policy above is the proposed fix. This witness keeps the gap visible until production changes.
const gap = explore(production)
const gap = unguarded
assert.ok(gap.violation, "Known queue landing gap no longer reproduces: update the model and the document")

console.log(
Expand Down
Loading
Loading