fix(coding-agent): drain advisor reviews in print mode

This commit is contained in:
Christian Stewart
2026-07-18 01:51:00 -07:00
parent 3fdd85ab6c
commit c8f1972c8c
11 changed files with 424 additions and 22 deletions
+23 -13
View File
@@ -219,8 +219,7 @@ interface PendingDelta {
interface CatchupWaiter {
threshold: number;
resolve: () => void;
finish: () => void;
finish: (caughtUp: boolean) => void;
timer?: NodeJS.Timeout;
}
@@ -366,7 +365,13 @@ export class AdvisorRuntime {
}
}
waitForCatchup(maxMs: number, threshold: number, signal?: AbortSignal): Promise<void> {
/**
* Wait until the advisor backlog falls below `threshold`.
*
* Returns `false` when the deadline, abort signal, or a runtime failure releases
* the waiter before the requested backlog was drained.
*/
waitForCatchup(maxMs: number, threshold: number, signal?: AbortSignal): Promise<boolean> {
if (
this.disposed ||
signal?.aborted ||
@@ -378,21 +383,26 @@ export class AdvisorRuntime {
// primary would otherwise park for the full catch-up budget.
this.#failing
)
return Promise.resolve();
const { promise, resolve } = Promise.withResolvers<void>();
return Promise.resolve(this.#backlog < threshold);
const { promise, resolve } = Promise.withResolvers<boolean>();
let waiter!: CatchupWaiter;
const finish = (): void => {
const finish = (caughtUp: boolean): void => {
const idx = this.#waiters.indexOf(waiter);
if (idx >= 0) this.#waiters.splice(idx, 1);
clearTimeout(waiter.timer);
signal?.removeEventListener("abort", finish);
resolve();
signal?.removeEventListener("abort", abort);
resolve(caughtUp);
};
const abort = (): void => finish(false);
waiter = {
threshold,
finish,
timer: setTimeout(abort, maxMs),
};
waiter = { threshold, resolve, finish, timer: setTimeout(finish, maxMs) };
this.#waiters.push(waiter);
signal?.addEventListener("abort", finish, { once: true });
signal?.addEventListener("abort", abort, { once: true });
if (signal?.aborted) {
finish();
abort();
}
return promise;
}
@@ -571,14 +581,14 @@ export class AdvisorRuntime {
for (let i = this.#waiters.length - 1; i >= 0; i--) {
const w = this.#waiters[i];
if (this.#backlog < w.threshold) {
w.finish();
w.finish(true);
}
}
}
#wakeAllWaiters(): void {
for (const w of [...this.#waiters]) {
w.finish();
w.finish(false);
}
}