Skip to content

Commit 56cb78d

Browse files
authored
Recover exact-review quota handoffs (#1150)
* Recover exact-review quota handoffs * Record current Phase 0.5 proof * Prove Bay quota recovery rendering * Refresh final Phase 0.5 proof receipt * Refresh rebased Phase 0.5 proof * Document quota recovery status * Clarify staggered quota recovery
1 parent 637c333 commit 56cb78d

25 files changed

Lines changed: 1269 additions & 70 deletions

‎dashboard/bay-page.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ dialog{border:0;padding:0;margin:0 0 0 auto;width:min(580px,94vw);height:100vh;m
256256
function bayLaneCard(title,laneName){var queue=state.data&&state.data.exact_review_queue||{};var lane=queue.lanes&&queue.lanes[laneName]||{};var samples=bayHistory(laneName);var rateSamples=bayRateHistory(samples,laneName);var historyStale=samples.length>0&&!bayHistoryIsCurrent(samples);var historyGap=samples.length>0&&!samples[samples.length-1].valid;var trend=historyGap?{className:"collecting",label:"History gap · awaiting current sample"}:historyStale?{className:"collecting",label:"History stale · awaiting current sample"}:bayPendingTrend(samples);var latestSample=samples[samples.length-1];var latestRateSample=rateSamples[rateSamples.length-1];var latestRate=!historyStale&&!historyGap&&latestSample&&latestRateSample&&latestSample.at===latestRateSample.at?Math.round(latestRateSample.rate):null;var rate=historyGap?{className:"collecting",label:"No rate across a history gap"}:bayRateCopy(latestRate,historyStale);var pending=Number(lane.pending||0);var live=[];if(Number(lane.ready||0))live.push(lane.ready+" ready");if(Number(lane.backoff||0))live.push(lane.backoff+" backoff");if(Number(lane.dispatching||0))live.push(lane.dispatching+" dispatching");if(Number(lane.leased||0))live.push(lane.leased+" leased");var label=title+". "+pending+" pending; "+(live.join(", ")||"no active queue items")+". Historical samples are from the dashboard's cached health history.";return '<section class="bay-control-card" title="'+esc(label)+'"><h2>'+esc(title)+'</h2><div class="bay-control-summary"><strong>'+pending+' waiting</strong><span>'+esc(live.join(" · ")||"No active items")+'</span></div><div class="bay-control-charts">'+bayPendingSparkline(samples,title)+bayRateSparkline(rateSamples,title)+'</div><div class="bay-control-rate '+trend.className+'">'+esc(trend.label)+' · '+esc(rate.label)+'</div></section>';}
257257
function bayHandoffHistory(){return (state.healthHistory||[]).map(function(sample){var at=Date.parse(sample&&sample.at||"");if(!Number.isFinite(at))return null;var exact=sample&&sample.exact_review;if(!exact||exact.collection_ok!==true)return {at:sample.at,valid:false};var handoff=exact.handoff||{};var pending=Number(handoff.pending);if(!Number.isFinite(pending))pending=Number(exact.review&&exact.review.pending);if(!Number.isFinite(pending))return {at:sample.at,valid:false};var dispatching=Number(handoff.dispatching);var leased=Number(handoff.leased);return {at:sample.at,valid:true,pending:Math.max(0,pending),dispatching:Number.isFinite(dispatching)?Math.max(0,dispatching):null,leased:Number.isFinite(leased)?Math.max(0,leased):null};}).filter(Boolean);}
258258
function bayHandoffSparkline(samples){var valid=samples.filter(function(sample){return sample.valid;});if(!valid.length)return '<div class="bay-control-empty">Awaiting handoff history.</div>';var width=430,height=46,left=27,right=3,top=3,bottom=3;var first=Date.parse(samples[0].at),last=Date.parse(samples[samples.length-1].at),span=Math.max(1,last-first);var values=valid.flatMap(function(sample){return [sample.pending,sample.dispatching,sample.leased].filter(function(value){return Number.isFinite(value);});});var maximum=bayNiceMaximum(Math.max.apply(null,values));var plotWidth=width-left-right,plotHeight=height-top-bottom;var pathFor=function(field){var previous=null;return samples.map(function(sample){var value=sample.valid?sample[field]:null;if(!Number.isFinite(value)){previous=null;return "";}var at=Date.parse(sample.at);var point={x:left+(at-first)/span*plotWidth,y:height-bottom-(value/maximum)*plotHeight};var connected=previous!==null&&at-previous<=12*60000;previous=at;return (connected?"L":"M")+point.x.toFixed(1)+" "+point.y.toFixed(1);}).filter(Boolean).join(" ");};return '<div class="bay-handoff-chart"><svg viewBox="0 0 '+width+' '+height+'" role="img" aria-label="Pending, dispatching, and leased queue handoffs over '+esc(bayRangeLabel())+'"><line class="bay-control-grid" x1="'+left+'" x2="'+(width-right)+'" y1="'+top+'" y2="'+top+'"></line><line class="bay-control-grid" x1="'+left+'" x2="'+(width-right)+'" y1="'+(height-bottom)+'" y2="'+(height-bottom)+'"></line><text class="bay-control-axis-label" x="'+(left-3)+'" y="'+(top+3)+'" text-anchor="end">'+maximum+'</text><text class="bay-control-axis-label" x="'+(left-3)+'" y="'+(height-bottom+1)+'" text-anchor="end">0</text><path class="bay-handoff-line pending" d="'+pathFor("pending")+'"></path><path class="bay-handoff-line dispatching" d="'+pathFor("dispatching")+'"></path><path class="bay-handoff-line leased" d="'+pathFor("leased")+'"></path></svg><div class="bay-handoff-legend"><span><i></i>pending</span><span class="dispatching"><i></i>dispatching</span><span class="leased"><i></i>leased</span></div></div>';}
259-
function bayHandoffCard(){var queue=state.data&&state.data.exact_review_queue||{};var handoff=queue.handoff_health||{};var phases=handoff.phases||{};var hasPhases=["pending","dispatching","leased"].every(function(name){return phases[name]&&Number.isFinite(Number(phases[name].count));});if(!hasPhases)return '<section class="bay-control-card"><h2>Queue handoff</h2><p class="bay-control-empty">Handoff telemetry is unavailable in this snapshot.</p></section>';var pending=Number(phases.pending.count);var dispatching=Number(phases.dispatching.count);var leased=Number(phases.leased.count);var pendingAge=Number(phases.pending.oldest_age_seconds);var dispatchingAge=Number(phases.dispatching.oldest_age_seconds);var status=String(handoff.status||"unknown");var message=String(handoff.message||handoff.reason||"No handoff explanation was reported.");var ages=[];if(Number.isFinite(pendingAge)&&pendingAge>0)ages.push("oldest pending "+formatLaneDuration(pendingAge*1000));if(Number.isFinite(dispatchingAge)&&dispatchingAge>0)ages.push("oldest dispatch "+formatLaneDuration(dispatchingAge*1000));var title="Queue handoff health. Pending work awaits review admission; dispatching work is awaiting a run claim; leased work is owned by an active run.";return '<section class="bay-control-card" title="'+esc(title)+'"><h2>Queue handoff</h2><div class="bay-handoff"><div><span>Pending</span><strong>'+pending+'</strong></div><div><span>Dispatching</span><strong>'+dispatching+'</strong></div><div><span>Leased</span><strong>'+leased+'</strong></div></div>'+bayHandoffSparkline(bayHandoffHistory())+'<span class="bay-handoff-status '+esc(status)+'">'+esc(status)+'</span><p class="bay-handoff-copy">'+esc(message+(ages.length?" · "+ages.join(" · "):""))+'</p></section>';}
259+
function bayHandoffCard(){var queue=state.data&&state.data.exact_review_queue||{};var handoff=queue.handoff_health||{};var phases=handoff.phases||{};var hasPhases=["pending","dispatching","leased"].every(function(name){return phases[name]&&Number.isFinite(Number(phases[name].count));});if(!hasPhases)return '<section class="bay-control-card"><h2>Queue handoff</h2><p class="bay-control-empty">Handoff telemetry is unavailable in this snapshot.</p></section>';var pending=Number(phases.pending.count);var dispatching=Number(phases.dispatching.count);var leased=Number(phases.leased.count);var pendingAge=Number(phases.pending.oldest_age_seconds);var dispatchingAge=Number(phases.dispatching.oldest_age_seconds);var status=String(handoff.status||"unknown");var message=String(handoff.message||handoff.reason||"No handoff explanation was reported.");var ages=[];var recovery=handoff.recovery_reasons||{};[["claim_timeout","claim timeout"],["execution_timeout","execution timeout"],["workflow_cancelled","workflow cancelled"],["workflow_failed","workflow failed"]].forEach(function(entry){var count=Number(recovery[entry[0]]||0);if(count>0)ages.push(count+" recovering after "+entry[1]);});if(Number.isFinite(pendingAge)&&pendingAge>0)ages.push("oldest pending "+formatLaneDuration(pendingAge*1000));if(Number.isFinite(dispatchingAge)&&dispatchingAge>0)ages.push("oldest dispatch "+formatLaneDuration(dispatchingAge*1000));var title="Queue handoff health. Pending work awaits review admission; dispatching work is awaiting a run claim; leased work is owned by an active run.";return '<section class="bay-control-card" title="'+esc(title)+'"><h2>Queue handoff</h2><div class="bay-handoff"><div><span>Pending</span><strong>'+pending+'</strong></div><div><span>Dispatching</span><strong>'+dispatching+'</strong></div><div><span>Leased</span><strong>'+leased+'</strong></div></div>'+bayHandoffSparkline(bayHandoffHistory())+'<span class="bay-handoff-status '+esc(status)+'">'+esc(status)+'</span><p class="bay-handoff-copy">'+esc(message+(ages.length?" · "+ages.join(" · "):""))+'</p></section>';}
260260
function renderBayControl(){var board=document.getElementById("bay-control-board");if(!board)return;document.querySelectorAll("[data-bay-history-range]").forEach(function(button){var active=button.getAttribute("data-bay-history-range")===state.healthRange;button.classList.toggle("active",active);button.setAttribute("aria-pressed",String(active));});var queue=state.data&&state.data.exact_review_queue;if(!queue){board.innerHTML='<section class="bay-control-card"><h2>Exact review control board</h2><p class="bay-control-empty">Queue telemetry is unavailable in this snapshot.</p></section>';return;}board.innerHTML=bayLaneCard("Review admission","review")+bayLaneCard("Result publication","publication")+bayHandoffCard();}
261261
function setBayHistoryRange(range){if(["6h","24h","7d"].indexOf(range)<0||range===state.healthRange)return;state.healthRange=range;state.healthHistory=state.healthHistoryByRange[range]||[];renderBayControl();void loadBayHistory();}
262262
async function loadBayHistory(){var range=state.healthRange;var loadedAt=Number(state.healthHistoryLoadedAt[range]||0);if(state.healthHistoryLoading[range]||Date.now()-loadedAt<60000)return;state.healthHistoryLoading[range]=true;state.healthHistoryLoadedAt[range]=Date.now();try{var origin=state.previewSource?["https://clawsweeper","openclaw","ai"].join("."):"";var response=await fetch(origin+"/api/health-history?range="+encodeURIComponent(range),{cache:"no-store"});if(!response.ok)throw new Error("history returned "+response.status);var payload=await response.json();var samples=Array.isArray(payload.samples)?payload.samples:[];state.healthHistoryByRange[range]=samples;state.healthHistoryLoadedAt[range]=Date.now();if(range===state.healthRange)state.healthHistory=samples;renderBayControl();}catch(_){renderBayControl();}finally{delete state.healthHistoryLoading[range];}}

‎dashboard/exact-review-health.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export type ExactReviewPhase = "pending" | "dispatching" | "leased";
2+
export type ExactReviewReviewRecoveryReason =
3+
| "claim_timeout"
4+
| "execution_timeout"
5+
| "workflow_cancelled"
6+
| "workflow_failed";
27

38
export type ExactReviewHealthItem = {
49
key?: string;
@@ -8,6 +13,7 @@ export type ExactReviewHealthItem = {
813
leaseExpiresAt?: number;
914
dispatchedAt?: number;
1015
claimedAt?: number;
16+
reviewRecoveryReason?: ExactReviewReviewRecoveryReason;
1117
};
1218

1319
export type ExactReviewHealthDispatcher = {
@@ -39,6 +45,7 @@ export type ExactReviewHandoffHealth = {
3945
available_slots: number;
4046
pending_depth: number;
4147
shed_since_reset: number;
48+
recovery_reasons: Record<ExactReviewReviewRecoveryReason, number>;
4249
phases: Record<ExactReviewPhase, ExactReviewPhaseSummary>;
4350
};
4451

@@ -109,8 +116,18 @@ export function summarizeExactReviewHandoff({
109116
dispatching: { count: 0, oldestAt: null, oldestKey: null },
110117
leased: { count: 0, oldestAt: null, oldestKey: null },
111118
};
119+
const recoveryReasons: Record<ExactReviewReviewRecoveryReason, number> = {
120+
claim_timeout: 0,
121+
execution_timeout: 0,
122+
workflow_cancelled: 0,
123+
workflow_failed: 0,
124+
};
112125

113126
for (const item of items) {
127+
const recoveryReason = String(item.reviewRecoveryReason || "");
128+
if (recoveryReason in recoveryReasons) {
129+
recoveryReasons[recoveryReason as ExactReviewReviewRecoveryReason] += 1;
130+
}
114131
const startedAt = exactReviewPhaseStartedAt(item, safeNow, safeLeaseMs, safeExecutionLeaseMs);
115132
const phase = phaseValues[item.state];
116133
if (!phase) continue;
@@ -154,6 +171,7 @@ export function summarizeExactReviewHandoff({
154171
available_slots: Math.max(0, safeCapacity - active),
155172
pending_depth: phases.pending.count,
156173
shed_since_reset: safeShedSinceReset,
174+
recovery_reasons: recoveryReasons,
157175
phases,
158176
};
159177
if (items.length === 0) {

0 commit comments

Comments
 (0)