Skip to content

Commit 5029f53

Browse files
feat(dashboard): expose exact-review pressure telemetry (#555)
* feat(dashboard): expose exact-review pressure telemetry Co-authored-by: brokemac79 <[email protected]> * docs(dashboard): describe exact-review pressure telemetry Co-authored-by: brokemac79 <[email protected]> * feat(dashboard): render exact-review pressure Co-authored-by: brokemac79 <[email protected]> * chore: remove unreleased changelog entry --------- Co-authored-by: brokemac79 <[email protected]> Co-authored-by: brokemac79 <[email protected]> (cherry picked from commit 41ea43b)
1 parent ea22ada commit 5029f53

5 files changed

Lines changed: 210 additions & 5 deletions

File tree

‎dashboard/exact-review-health.ts‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ export type ExactReviewHandoffHealth = {
4242
phases: Record<ExactReviewPhase, ExactReviewPhaseSummary>;
4343
};
4444

45+
export type ExactReviewPressureStatus = "idle" | "congested" | "saturated" | "unknown";
46+
47+
export type ExactReviewPressureSummary = {
48+
status: ExactReviewPressureStatus;
49+
reason:
50+
| "capacity_unavailable"
51+
| "capacity_available"
52+
| "no_ready_backlog"
53+
| "no_admissible_backlog"
54+
| "dispatcher_inactive"
55+
| "handoff_unknown"
56+
| "capacity_full_with_backlog";
57+
capacity: number;
58+
active: number;
59+
pending: number;
60+
ready_pending: number;
61+
admissible_pending: number;
62+
};
63+
4564
const PHASES: ExactReviewPhase[] = ["pending", "dispatching", "leased"];
4665

4766
export function summarizeExactReviewHandoff({
@@ -176,6 +195,57 @@ export function summarizeExactReviewHandoff({
176195
};
177196
}
178197

198+
export function summarizeExactReviewPressure({
199+
pending,
200+
readyPending,
201+
admissiblePending,
202+
dispatching,
203+
leased,
204+
capacity,
205+
dispatcherState,
206+
handoffStatus,
207+
}: {
208+
pending: number;
209+
readyPending: number;
210+
admissiblePending: number;
211+
dispatching: number;
212+
leased: number;
213+
capacity: number;
214+
dispatcherState?: string;
215+
handoffStatus?: string;
216+
}): ExactReviewPressureSummary {
217+
const safePending = nonNegativeInteger(pending);
218+
const safeReadyPending = Math.min(safePending, nonNegativeInteger(readyPending));
219+
const safeAdmissiblePending = Math.min(safeReadyPending, nonNegativeInteger(admissiblePending));
220+
const safeCapacity = nonNegativeInteger(capacity);
221+
const active = nonNegativeInteger(dispatching) + nonNegativeInteger(leased);
222+
const common = {
223+
capacity: safeCapacity,
224+
active,
225+
pending: safePending,
226+
ready_pending: safeReadyPending,
227+
admissible_pending: safeAdmissiblePending,
228+
};
229+
230+
if (safeCapacity < 1) return { status: "unknown", reason: "capacity_unavailable", ...common };
231+
if (safeReadyPending < 1) return { status: "idle", reason: "no_ready_backlog", ...common };
232+
if (safeAdmissiblePending < 1) {
233+
return { status: "idle", reason: "no_admissible_backlog", ...common };
234+
}
235+
if (active < safeCapacity) return { status: "idle", reason: "capacity_available", ...common };
236+
if (dispatcherState !== "active") {
237+
return { status: "unknown", reason: "dispatcher_inactive", ...common };
238+
}
239+
if (!["healthy", "degraded", "stalled"].includes(String(handoffStatus || ""))) {
240+
return { status: "unknown", reason: "handoff_unknown", ...common };
241+
}
242+
return {
243+
status: safeAdmissiblePending >= safeCapacity ? "saturated" : "congested",
244+
reason: "capacity_full_with_backlog",
245+
...common,
246+
};
247+
}
248+
179249
function exactReviewPhaseStartedAt(
180250
item: ExactReviewHealthItem,
181251
now: number,
@@ -230,3 +300,8 @@ function finiteNumber(value: unknown, fallback: number) {
230300
const number = Number(value);
231301
return Number.isFinite(number) ? number : fallback;
232302
}
303+
304+
function nonNegativeInteger(value: unknown) {
305+
const number = Number(value);
306+
return Number.isFinite(number) ? Math.max(0, Math.floor(number)) : 0;
307+
}

‎dashboard/exact-review-queue.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { stableJson } from "../src/stable-json.ts";
2-
import { summarizeExactReviewHandoff } from "./exact-review-health.ts";
2+
import {
3+
summarizeExactReviewHandoff,
4+
summarizeExactReviewPressure,
5+
} from "./exact-review-health.ts";
36

47
type GithubAppJsonOptions = { method?: string; body?: BodyInit; errorLabel?: string };
58
const GITHUB_TIMEOUT_MS = 4500;
@@ -3559,8 +3562,31 @@ function exactReviewQueueStats(
35593562
publicationCapacity,
35603563
),
35613564
};
3565+
const readyPending = items.filter(
3566+
(item) => item.state === "pending" && item.nextAttemptAt <= now,
3567+
).length;
3568+
const admissiblePending = exactReviewQueueAdmittedItems(
3569+
state,
3570+
now,
3571+
Number.MAX_SAFE_INTEGER,
3572+
targetCapacity,
3573+
publicationCapacity,
3574+
).length;
3575+
const pressure = summarizeExactReviewPressure({
3576+
pending: handoffHealth.phases.pending.count,
3577+
readyPending,
3578+
admissiblePending,
3579+
dispatching: handoffHealth.phases.dispatching.count,
3580+
leased: handoffHealth.phases.leased.count,
3581+
capacity,
3582+
dispatcherState: state.dispatcher?.state,
3583+
handoffStatus: handoffHealth.status,
3584+
});
35623585
return {
3586+
generated_at: handoffHealth.observed_at,
35633587
pending: handoffHealth.phases.pending.count,
3588+
ready_pending: readyPending,
3589+
admissible_pending: admissiblePending,
35643590
shed_since_reset: exactReviewShedSinceReset(state),
35653591
dispatching: handoffHealth.phases.dispatching.count,
35663592
leased: handoffHealth.phases.leased.count,
@@ -3573,6 +3599,7 @@ function exactReviewQueueStats(
35733599
oldest_leased_age_seconds: handoffHealth.phases.leased.oldest_age_seconds,
35743600
handoff_health: handoffHealth,
35753601
lanes,
3602+
pressure,
35763603
next_wake_at: nextWakeAt === null ? null : new Date(nextWakeAt).toISOString(),
35773604
dispatcher: {
35783605
state: state.dispatcher?.state || "unknown",

‎docs/live-dashboard.md‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ is absent or a cache event lands in another Cloudflare colo.
149149
apply-ready candidate count and an estimated number of cursor windows to
150150
revisit the close queue; scheduled cadence time is explanatory only because
151151
successful windows can dispatch immediate continuations
152+
- exact-review queue backlog, retry-ready backlog, target-admissible backlog,
153+
and pressure classification from the current durable queue snapshot
152154

153155
The Worker fetches job details only for the bounded active-run set, limits that
154156
GitHub fanout to 12 concurrent requests, and caches each run's jobs for 60
@@ -287,9 +289,17 @@ workflow state, check time, and retry time so an intentional pause cannot look
287289
like occupied executor capacity. Re-enabling the workflow does not require a
288290
queue mutation; the next status check resumes normal admission.
289291

290-
The same endpoint exposes `handoff_health` plus oldest timestamps and ages for
291-
the pending, dispatching, and leased phases. New dispatch and claim transitions
292-
carry explicit phase timestamps. Rows written by an older deployment derive
292+
The same endpoint exposes `generated_at`, `ready_pending`,
293+
`admissible_pending`, `pressure`, `handoff_health`, and oldest timestamps and
294+
ages for the pending, dispatching, and leased phases. `ready_pending` excludes
295+
retry-delayed items. `admissible_pending` further excludes ready items blocked
296+
by their target's exact-review cap. `pressure` is a deterministic observation
297+
from that same queue snapshot: it reports `congested` or `saturated` only when
298+
capacity is full, the dispatcher and handoff telemetry are known, and
299+
target-admissible backlog remains. The snapshot adds no GitHub API fanout, and
300+
no workflow, planner, admission, continuation, or dispatch decision consumes
301+
the pressure value. New dispatch and claim transitions carry explicit phase
302+
timestamps. Rows written by an older deployment derive
293303
their phase start from the active dispatch or execution lease; a stale timestamp
294304
left by a rollback cannot override that newer lease, and a wholly unknown legacy
295305
age stays non-alarming. A claim is degraded after one third of the dispatch

‎test/dashboard-worker.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,10 @@ test("dashboard status reads the exact-review handoff model from the durable que
744744
});
745745

746746
assert.ok(status);
747+
assert.match(status.generated_at, /^\d{4}-\d{2}-\d{2}T/);
747748
assert.equal(status.pending, 2);
749+
assert.equal(status.ready_pending, 1);
750+
assert.equal(status.admissible_pending, 1);
748751
assert.equal(status.dispatching, 0);
749752
assert.equal(status.leased, 2);
750753
assert.equal(status.handoff_health.status, "healthy");
@@ -778,6 +781,8 @@ test("dashboard status reads the exact-review handoff model from the durable que
778781
assert.equal(typeof status.lanes.review.oldest_pending_at, "string");
779782
assert.equal(status.lanes.review.oldest_pending_key, "openclaw/gogcli#597");
780783
assert.equal(typeof status.lanes.review.next_attempt_at, "string");
784+
assert.equal(status.pressure.status, "idle");
785+
assert.equal(status.pressure.reason, "capacity_available");
781786
assert.equal(await exactReviewQueueStatusSnapshot({}), null);
782787
});
783788

@@ -6140,6 +6145,9 @@ test("dashboard hero treats apply and exact-review handoff health as attention",
61406145
reconcilers: { running: 1, waiting: 0 },
61416146
},
61426147
exact_review_queue: {
6148+
pending: 4,
6149+
ready_pending: 3,
6150+
admissible_pending: 2,
61436151
lanes: {
61446152
review: {
61456153
pending: 4,
@@ -6199,6 +6207,15 @@ test("dashboard hero treats apply and exact-review handoff health as attention",
61996207
},
62006208
},
62016209
},
6210+
pressure: {
6211+
status: "congested",
6212+
reason: "capacity_full_with_backlog",
6213+
capacity: 28,
6214+
active: 28,
6215+
pending: 4,
6216+
ready_pending: 3,
6217+
admissible_pending: 2,
6218+
},
62026219
handoff_health: {
62036220
status: "healthy",
62046221
message: "Dispatch-to-claim handoffs are within the expected window.",
@@ -6335,6 +6352,8 @@ test("dashboard hero treats apply and exact-review handoff health as attention",
63356352
assert.match(elementFor("exact-review-handoff").innerHTML, /Dispatching/);
63366353
assert.match(elementFor("exact-review-handoff").innerHTML, /2 of 28 exact-review slots open/);
63376354
assert.match(elementFor("exact-review-handoff").innerHTML, /health-badge healthy/);
6355+
assert.match(elementFor("exact-review-handoff").innerHTML, /pressure congested/);
6356+
assert.match(elementFor("exact-review-handoff").innerHTML, /4 total · 3 ready · 2 admissible/);
63386357
assert.match(elementFor("exact-review-lanes").innerHTML, /Review admission/);
63396358
assert.match(elementFor("exact-review-lanes").innerHTML, /52 review admission slots open/);
63406359
assert.match(elementFor("exact-review-lanes").innerHTML, /Result publication/);
@@ -6396,13 +6415,15 @@ test("dashboard hero treats apply and exact-review handoff health as attention",
63966415

63976416
status.recent.apply_health.items = [];
63986417
status.exact_review_queue.handoff_health.status = "stalled";
6418+
status.exact_review_queue.pressure.status = "saturated";
63996419
status.exact_review_queue.handoff_health.message =
64006420
"A dispatched review has not been claimed within the expected handoff window.";
64016421
context.renderDashboard(status, "");
64026422

64036423
assert.equal(elementFor("hero-dot").className, "hero-dot red");
64046424
assert.match(elementFor("hero-headline").textContent, /^Needs attention/);
64056425
assert.match(elementFor("exact-review-handoff").innerHTML, /health-badge stalled/);
6426+
assert.match(elementFor("exact-review-handoff").innerHTML, /pressure saturated/);
64066427

64076428
Object.assign(status, { exact_review_queue: null });
64086429
status.diagnostics.exact_review_queue_error = "exact-review queue timed out";

‎test/exact-review-health.test.ts‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
33

4-
import { summarizeExactReviewHandoff } from "../dashboard/exact-review-health.ts";
4+
import {
5+
summarizeExactReviewHandoff,
6+
summarizeExactReviewPressure,
7+
} from "../dashboard/exact-review-health.ts";
58

69
const NOW = Date.parse("2026-07-13T02:00:00.000Z");
710
const DISPATCH_LEASE_MS = 10 * 60_000;
@@ -198,3 +201,72 @@ test("exact-review handoff health derives legacy leased age from its execution l
198201
assert.equal(health.phases.leased.oldest_at, "2026-07-13T01:59:20.000Z");
199202
assert.equal(health.phases.leased.oldest_age_seconds, 40);
200203
});
204+
205+
test("exact-review pressure distinguishes available, congested, and saturated capacity", () => {
206+
const base = {
207+
pending: 4,
208+
readyPending: 4,
209+
admissiblePending: 4,
210+
dispatching: 4,
211+
leased: 60,
212+
capacity: 64,
213+
dispatcherState: "active",
214+
handoffStatus: "healthy",
215+
};
216+
217+
assert.deepEqual(summarizeExactReviewPressure({ ...base, leased: 59 }), {
218+
status: "idle",
219+
reason: "capacity_available",
220+
capacity: 64,
221+
active: 63,
222+
pending: 4,
223+
ready_pending: 4,
224+
admissible_pending: 4,
225+
});
226+
assert.equal(summarizeExactReviewPressure({ ...base, admissiblePending: 3 }).status, "congested");
227+
assert.equal(
228+
summarizeExactReviewPressure({ ...base, pending: 64, readyPending: 64, admissiblePending: 64 })
229+
.status,
230+
"saturated",
231+
);
232+
});
233+
234+
test("exact-review pressure preserves non-dispatchable and unknown states", () => {
235+
const base = {
236+
pending: 5,
237+
readyPending: 5,
238+
admissiblePending: 5,
239+
dispatching: 4,
240+
leased: 60,
241+
capacity: 64,
242+
dispatcherState: "active",
243+
handoffStatus: "healthy",
244+
};
245+
246+
assert.equal(
247+
summarizeExactReviewPressure({ ...base, readyPending: 0 }).reason,
248+
"no_ready_backlog",
249+
);
250+
assert.equal(
251+
summarizeExactReviewPressure({ ...base, admissiblePending: 0 }).reason,
252+
"no_admissible_backlog",
253+
);
254+
assert.deepEqual(
255+
summarizeExactReviewPressure({
256+
...base,
257+
pending: 2.9,
258+
readyPending: 9,
259+
admissiblePending: 8,
260+
dispatcherState: "paused",
261+
}),
262+
{
263+
status: "unknown",
264+
reason: "dispatcher_inactive",
265+
capacity: 64,
266+
active: 64,
267+
pending: 2,
268+
ready_pending: 2,
269+
admissible_pending: 2,
270+
},
271+
);
272+
});

0 commit comments

Comments
 (0)