Skip to content

Commit fd4c0c7

Browse files
committed
fix(settle): hold the quiet window in the loop that re-prices it
The window helper had one call site and one reader per side of it, so the loop holds the window directly: an unrequested window is re-priced from each capture it performs, a requested one stays fixed. Behaviour is unchanged; the priced value the result reports is the same window.
1 parent d371573 commit fd4c0c7

1 file changed

Lines changed: 10 additions & 25 deletions

File tree

‎src/commands/interaction/runtime/stable-capture.ts‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ export async function runStableCaptureLoop(
118118
let deadlineMs = start + timeoutMs;
119119
let privateAxRecoveryBudgetReset = false;
120120
const session = await runtime.sessions.get(options.session ?? 'default');
121-
const window = createStableCaptureWindow(params.quietMs);
121+
// The quiet window the run holds. An unrequested window is re-priced from each capture the loop
122+
// performs: the read that pays the window is the loop's own, not the one the baseline came from,
123+
// which can be several commands stale and served by another producer, and a mid-run fallback
124+
// changes the price mid-wait. The confirmation applies its own floor on top of the price, so
125+
// re-pricing is never a shorter wait. A window the caller asked for is fixed.
126+
const requestedQuietMs = params.quietMs;
127+
let quietMs = requestedQuietMs ?? DEFAULT_STABLE_QUIET_MS;
122128
const confirmation = broadTransitionConfirmation({
123129
baselineNodes: params.broadTransitionBaselineNodes,
124130
platform: runtime.backend.platform,
@@ -138,7 +144,7 @@ export async function runStableCaptureLoop(
138144
waitedMs,
139145
captures,
140146
nodeCount: pacing.lastNodeCount,
141-
quietMs: window.baseQuietMs,
147+
quietMs,
142148
lastCapture,
143149
});
144150
while (now(runtime) < deadlineMs) {
@@ -151,12 +157,12 @@ export async function runStableCaptureLoop(
151157
if (!capture) return result(false, true, now(runtime) - start);
152158
captures += 1;
153159
lastCapture = capture;
154-
const defaultQuietMs = window.price(capture.snapshot);
160+
if (requestedQuietMs === undefined) quietMs = defaultQuietMsForCapture(capture.snapshot);
155161
const signal = stableCaptureSignal(capture.snapshot);
156162
// One value carries both: how long this capture must stay quiet, and therefore the cadence that
157163
// can measure it. Sampling an extended wait on the caller's tight grid would spend the whole
158164
// extension in capture round trips.
159-
const requiredQuietMs = confirmation.requiredQuietMs(capture.snapshot, defaultQuietMs);
165+
const requiredQuietMs = confirmation.requiredQuietMs(capture.snapshot, quietMs);
160166
const pollMs = stableCapturePollMs(requiredQuietMs);
161167
preferredBackend ??= preferredSnapshotBackendForVerdict(capture.snapshot.snapshotQuality);
162168
const nowMs = now(runtime);
@@ -200,27 +206,6 @@ export async function runStableCaptureLoop(
200206
return result(false, false, now(runtime) - start);
201207
}
202208

203-
/**
204-
* The quiet window the run holds. An unrequested window is re-priced from each capture the loop
205-
* performs: the read that pays the window is the loop's own, not the one the baseline came from,
206-
* which can be several commands stale and served by another producer, and a mid-run fallback changes
207-
* the price mid-wait. The confirmation applies its own floor on top of the returned price, so
208-
* re-pricing is never a shorter wait. A window the caller asked for is fixed.
209-
*/
210-
function createStableCaptureWindow(requestedQuietMs: number | undefined) {
211-
let baseQuietMs = requestedQuietMs ?? DEFAULT_STABLE_QUIET_MS;
212-
return {
213-
get baseQuietMs(): number {
214-
return baseQuietMs;
215-
},
216-
/** Re-prices the window from a capture the loop just completed, and reports that price. */
217-
price(snapshot: SnapshotState): number {
218-
if (requestedQuietMs === undefined) baseQuietMs = defaultQuietMsForCapture(snapshot);
219-
return baseQuietMs;
220-
},
221-
};
222-
}
223-
224209
/**
225210
* The once-per-run budget extension a private-AX recovery buys. The recovery re-read the same
226211
* surface through another backend, so the quiet window restarts on that capture rather than carrying

0 commit comments

Comments
 (0)