Skip to content

Commit a484445

Browse files
committed
fix(dashboard): retain large history totals
1 parent 1e53681 commit a484445

6 files changed

Lines changed: 71 additions & 28 deletions

‎dashboard/bay-page.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,14 @@ dialog{border:0;padding:0;margin:0 0 0 auto;width:min(580px,94vw);height:100vh;m
258258
var BAY_HEALTH_WRITER_MODES=["single_item","batch","mixed","unknown"];
259259
function bayHealthCount(value){return strictBayCount(value,10000000);}
260260
function bayHealthOptionalCount(value){return value===undefined?undefined:bayHealthCount(value);}
261+
function bayHealthOptionalTotal(value){return value===undefined?undefined:strictBayCount(value,1000000000000);}
261262
function bayHealthPercentiles(value){var source=bayObject(value);if(!source)return null;var p50=source.p50===null?null:bayHealthOptionalCount(source.p50),p95=source.p95===null?null:bayHealthOptionalCount(source.p95),samples=bayHealthCount(source.samples),pair=p50!==null&&p50!==undefined&&p95!==null&&p95!==undefined;if(p50===undefined||p95===undefined||samples===null||(samples===0&&(p50!==null||p95!==null))||(samples>0&&(!pair||p50>p95)))return null;return {p50:p50,p95:p95,samples:samples};}
262-
function bayHealthLane(value,includeShed){var source=bayObject(value);if(!source)return null;var pending=bayHealthCount(source.pending),enqueued=bayHealthOptionalCount(source.enqueued_total),completed=bayHealthOptionalCount(source.completed_total),shed=includeShed?bayHealthOptionalCount(source.shed_total):undefined;if(pending===null||enqueued===null||completed===null||shed===null||(enqueued===undefined)!==(completed===undefined))return null;var result={pending:pending};if(enqueued!==undefined)result.enqueued_total=enqueued;if(completed!==undefined)result.completed_total=completed;if(shed!==undefined)result.shed_total=shed;return result;}
263+
function bayHealthLane(value,includeShed){var source=bayObject(value);if(!source)return null;var pending=bayHealthCount(source.pending),enqueued=bayHealthOptionalTotal(source.enqueued_total),completed=bayHealthOptionalTotal(source.completed_total),shed=includeShed?bayHealthOptionalCount(source.shed_total):undefined;if(pending===null||enqueued===null||completed===null||shed===null||(enqueued===undefined)!==(completed===undefined))return null;var result={pending:pending};if(enqueued!==undefined)result.enqueued_total=enqueued;if(completed!==undefined)result.completed_total=completed;if(shed!==undefined)result.shed_total=shed;return result;}
263264
function bayHealthExactReview(value){var source=bayObject(value);if(!source||typeof source.collection_ok!=="boolean")return null;if(!source.collection_ok)return {collection_ok:false};var review=bayHealthLane(source.review,true),publication=bayHealthLane(source.publication,false);if(!review||!publication)return null;var result={collection_ok:true,review:review,publication:publication};if(source.handoff!==undefined){var handoff=bayObject(source.handoff),pending=handoff&&bayHealthCount(handoff.pending),dispatching=handoff&&bayHealthCount(handoff.dispatching),leased=handoff&&bayHealthCount(handoff.leased);if(!handoff||HANDOFF_STATUSES.indexOf(handoff.status)<0||pending===null||dispatching===null||leased===null)return null;result.handoff={status:handoff.status,pending:pending,dispatching:dispatching,leased:leased};}return result;}
264265
function bayHealthStateWriter(value){var source=bayObject(value);if(!source||typeof source.collection_ok!=="boolean")return null;if(!source.collection_ok)return {collection_ok:false};if(typeof source.terminal_collection_ok!=="boolean"||BAY_HEALTH_WRITER_MODES.indexOf(source.mode)<0)return null;var result={collection_ok:true,terminal_collection_ok:source.terminal_collection_ok,mode:source.mode};["tracked_holding","tracked_waiting","tracked_releasing","accepted_operations_total","state_commits_total","materialized_items_total","contention_timeouts_total"].forEach(function(field){var parsed=bayHealthOptionalCount(source[field]);if(parsed===null)result.invalid=true;else if(parsed!==undefined)result[field]=parsed;});if(result.invalid)return null;var wait=bayHealthPercentiles(source.wait_ms),hold=bayHealthPercentiles(source.hold_ms);if(!wait||!hold)return null;var last=source.last_successful_materialization_at===null?null:strictBayTimestamp(source.last_successful_materialization_at);if(last===null&&source.last_successful_materialization_at!==null)return null;result.wait_ms=wait;result.hold_ms=hold;result.last_successful_materialization_at=last;return result;}
265266
function bayHealthSample(value){var source=bayObject(value),at=source&&strictBayTimestamp(source.at);if(!source||!at)return null;var operationalFields=["status","collection_ok","queued","queued_over_30m","oldest_queued_minutes","running","running_over_150m","oldest_running_minutes"],hasOperational=operationalFields.some(function(field){return Object.prototype.hasOwnProperty.call(source,field);}),result={at:at};if(hasOperational){if(BAY_HEALTH_STATUSES.indexOf(source.status)<0||typeof source.collection_ok!=="boolean")return null;var counts={};for(var index=2;index<operationalFields.length;index+=1){var field=operationalFields[index],parsed=bayHealthCount(source[field]);if(parsed===null)return null;counts[field]=parsed;}if(counts.queued_over_30m>counts.queued||counts.running_over_150m>counts.running)return null;result.status=source.status;result.collection_ok=source.collection_ok;Object.assign(result,counts);}if(source.exact_review!==undefined){var exact=bayHealthExactReview(source.exact_review);if(!exact)return null;result.exact_review=exact;}if(source.state_writer!==undefined){var writer=bayHealthStateWriter(source.state_writer);if(!writer)return null;result.state_writer=writer;}return hasOperational||result.exact_review||result.state_writer?result:null;}
266267
function bayHealthHistorySnapshot(value,requestedRange){var source=bayObject(value),rangeMs=BAY_HEALTH_RANGE_MS[requestedRange];if(!source||!rangeMs||source.schema_version!==1||source.range!==requestedRange||source.retention_days!==7||!Array.isArray(source.samples))return null;var limit=Math.ceil(rangeMs/BAY_HEALTH_SAMPLE_MS)+1;if(source.samples.length>limit)return null;var samples=[],slots={},previous=null,now=Date.now();for(var index=0;index<source.samples.length;index+=1){var sample=bayHealthSample(source.samples[index]);if(!sample)return null;var at=Date.parse(sample.at),slot=Math.floor(at/BAY_HEALTH_SAMPLE_MS);if((previous!==null&&at<=previous)||slots[slot]||at<now-rangeMs-BAY_HEALTH_SAMPLE_MS||at>now+BAY_HEALTH_SAMPLE_MS)return null;previous=at;slots[slot]=true;samples.push(sample);}return {schema_version:1,range:requestedRange,retention_days:7,samples:samples};}
267-
function bayHistory(lane){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 value=exact[lane];if(!value||typeof value!=="object")return {at:sample.at,valid:false};var pending=bayHealthCount(value.pending),enqueued=bayHealthOptionalCount(value.enqueued_total),completed=bayHealthOptionalCount(value.completed_total),shed=lane==="review"?bayHealthOptionalCount(value.shed_total):0;if(pending===null||enqueued===null||completed===null||shed===null)return {at:sample.at,valid:false};return {at:sample.at,valid:true,pending:pending,enqueued:enqueued,completed:completed,shed:shed};}).filter(Boolean);}
268+
function bayHistory(lane){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 value=exact[lane];if(!value||typeof value!=="object")return {at:sample.at,valid:false};var pending=bayHealthCount(value.pending),enqueued=bayHealthOptionalTotal(value.enqueued_total),completed=bayHealthOptionalTotal(value.completed_total),shed=lane==="review"?bayHealthOptionalCount(value.shed_total):0;if(pending===null||enqueued===null||completed===null||shed===null)return {at:sample.at,valid:false};return {at:sample.at,valid:true,pending:pending,enqueued:enqueued,completed:completed,shed:shed};}).filter(Boolean);}
268269
function bayFormatTime(iso){var date=new Date(iso);return Number.isFinite(date.getTime())?date.toLocaleTimeString([], {hour:"2-digit",minute:"2-digit"}):"unknown time";}
269270
function bayHistoryIsCurrent(samples){var latest=samples[samples.length-1];var at=Date.parse(latest&&latest.at||"");var toAt=Math.max(Date.now(),at);return Boolean(latest&&latest.valid)&&Number.isFinite(at)&&toAt-at<=12*60000;}
270271
function bayPendingTrend(samples){var gapIndex=-1;samples.forEach(function(sample,index){if(!sample.valid)gapIndex=index;});var segment=samples.slice(gapIndex+1).filter(function(sample){return sample.valid;});if(!segment.length)return {className:"collecting",label:"History gap · awaiting current sample"};if(segment.length<2)return {className:"collecting",label:"Collecting 1h trend"};var latest=segment[segment.length-1];var cutoff=Date.parse(latest.at)-3600000;var baseline=segment.filter(function(sample){return Date.parse(sample.at)<=cutoff;}).pop();if(!baseline||cutoff-Date.parse(baseline.at)>12*60000)return {className:"collecting",label:"Collecting 1h trend"};var delta=latest.pending-baseline.pending;if(delta>0)return {className:"rising",label:"Rising · +"+delta+" in 1h"};if(delta<0)return {className:"",label:"Draining · −"+Math.abs(delta)+" in 1h"};return {className:"",label:"Stable · no change in 1h"};}

‎dashboard/dashboard-pages.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,11 +2479,12 @@ const DASHBOARD_HEALTH_HISTORY_RANGE_MS = {
24792479
};
24802480
const DASHBOARD_HEALTH_HISTORY_SAMPLE_MS = 5 * 60 * 1000;
24812481
const DASHBOARD_HEALTH_HISTORY_RETENTION_DAYS = 7;
2482+
const DASHBOARD_HEALTH_HISTORY_MAX_TOTAL = 1000000000000;
24822483
const DASHBOARD_HEALTH_HISTORY_STATUSES = ["healthy", "degraded", "stalled", "unknown"];
24832484
const DASHBOARD_HEALTH_HISTORY_HANDOFF_STATUSES = ["idle", "healthy", "degraded", "stalled"];
24842485
const DASHBOARD_HEALTH_HISTORY_WRITER_MODES = ["single_item", "batch", "mixed", "unknown"];
2485-
function dashboardHealthHistoryOptionalCount(value) {
2486-
return value === undefined ? undefined : dashboardObservabilityCount(value);
2486+
function dashboardHealthHistoryOptionalCount(value, maximum = DASHBOARD_OBSERVABILITY_MAX_COUNT) {
2487+
return value === undefined ? undefined : dashboardObservabilityCount(value, maximum);
24872488
}
24882489
function dashboardHealthHistoryPercentiles(value) {
24892490
const source = dashboardObservabilityObject(value);
@@ -2503,8 +2504,8 @@ function dashboardHealthHistoryLane(value, includeShed) {
25032504
const source = dashboardObservabilityObject(value);
25042505
if (!source) return null;
25052506
const pending = dashboardObservabilityCount(source.pending);
2506-
const enqueuedTotal = dashboardHealthHistoryOptionalCount(source.enqueued_total);
2507-
const completedTotal = dashboardHealthHistoryOptionalCount(source.completed_total);
2507+
const enqueuedTotal = dashboardHealthHistoryOptionalCount(source.enqueued_total, DASHBOARD_HEALTH_HISTORY_MAX_TOTAL);
2508+
const completedTotal = dashboardHealthHistoryOptionalCount(source.completed_total, DASHBOARD_HEALTH_HISTORY_MAX_TOTAL);
25082509
const shedTotal = includeShed ? dashboardHealthHistoryOptionalCount(source.shed_total) : undefined;
25092510
if (
25102511
pending === null || enqueuedTotal === null || completedTotal === null || shedTotal === null ||

‎dashboard/operational-health.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const OPERATIONAL_RUNNING_STALLED_MS = 150 * 60 * 1000;
55
export const HEALTH_HISTORY_SAMPLE_MS = 5 * 60 * 1000;
66
export const HEALTH_HISTORY_RETENTION_DAYS = 7;
77
const HEALTH_HISTORY_MAX_COUNT = 10_000_000;
8+
const HEALTH_HISTORY_MAX_TOTAL = 1_000_000_000_000;
89
const HEALTH_HISTORY_TIMESTAMP_PATTERN =
910
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/;
1011
const HEALTH_HISTORY_TIMESTAMP_MIN_MS = Date.UTC(2020, 0, 1);
@@ -435,8 +436,8 @@ function laneHistorySample(
435436
shedValue: unknown,
436437
): ExactReviewLaneHistorySample | null {
437438
const pending = nonNegativeInteger(pendingValue);
438-
const enqueuedTotal = optionalNonNegativeInteger(enqueuedValue);
439-
const completedTotal = optionalNonNegativeInteger(completedValue);
439+
const enqueuedTotal = optionalNonNegativeInteger(enqueuedValue, HEALTH_HISTORY_MAX_TOTAL);
440+
const completedTotal = optionalNonNegativeInteger(completedValue, HEALTH_HISTORY_MAX_TOTAL);
440441
const shedTotal = optionalNonNegativeInteger(shedValue);
441442
if (pending === null || enqueuedTotal === null || completedTotal === null || shedTotal === null) {
442443
return null;
@@ -484,17 +485,14 @@ function ageMs(value: string | undefined, now: number) {
484485
return Number.isFinite(timestamp) ? Math.max(0, now - timestamp) : null;
485486
}
486487

487-
function nonNegativeInteger(value: unknown) {
488-
return typeof value === "number" &&
489-
Number.isSafeInteger(value) &&
490-
value >= 0 &&
491-
value <= HEALTH_HISTORY_MAX_COUNT
488+
function nonNegativeInteger(value: unknown, maximum = HEALTH_HISTORY_MAX_COUNT) {
489+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= maximum
492490
? value
493491
: null;
494492
}
495493

496-
function optionalNonNegativeInteger(value: unknown) {
497-
return value === undefined ? undefined : nonNegativeInteger(value);
494+
function optionalNonNegativeInteger(value: unknown, maximum = HEALTH_HISTORY_MAX_COUNT) {
495+
return value === undefined ? undefined : nonNegativeInteger(value, maximum);
498496
}
499497

500498
function canonicalHistoryTimestamp(value: unknown) {

‎test/dashboard-operational-health.test.ts‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,15 @@ test("health history preserves legacy samples and normalizes exact-review backlo
211211
lanes: {
212212
review: {
213213
pending: 317,
214-
enqueued_total: 90,
215-
completed_total: 70,
214+
enqueued_total: 10_000_090,
215+
completed_total: 10_000_070,
216216
shed_since_reset: 3,
217217
},
218-
publication: { pending: 1502, enqueued_total: 50, completed_total: 42 },
218+
publication: {
219+
pending: 1502,
220+
enqueued_total: 10_000_050,
221+
completed_total: 10_000_042,
222+
},
219223
},
220224
handoff_health: {
221225
status: "degraded",
@@ -229,8 +233,17 @@ test("health history preserves legacy samples and normalizes exact-review backlo
229233
const normalized = normalizeHealthHistorySample({ ...legacy, exact_review: exactReview });
230234
assert.deepEqual(normalized?.exact_review, {
231235
collection_ok: true,
232-
review: { pending: 317, enqueued_total: 90, completed_total: 70, shed_total: 3 },
233-
publication: { pending: 1502, enqueued_total: 50, completed_total: 42 },
236+
review: {
237+
pending: 317,
238+
enqueued_total: 10_000_090,
239+
completed_total: 10_000_070,
240+
shed_total: 3,
241+
},
242+
publication: {
243+
pending: 1502,
244+
enqueued_total: 10_000_050,
245+
completed_total: 10_000_042,
246+
},
234247
handoff: { status: "degraded", pending: 317, dispatching: 8, leased: 34 },
235248
});
236249
assert.deepEqual(normalizeHealthHistorySample({ at: CHECKED_AT, exact_review: exactReview }), {
@@ -271,6 +284,17 @@ test("health history preserves legacy samples and normalizes exact-review backlo
271284
}),
272285
null,
273286
);
287+
assert.equal(
288+
normalizeHealthHistorySample({
289+
at: CHECKED_AT,
290+
exact_review: {
291+
collection_ok: true,
292+
review: { pending: 1, enqueued_total: 1_000_000_000_001, completed_total: 0 },
293+
publication: { pending: 1, enqueued_total: 0, completed_total: 0 },
294+
},
295+
}),
296+
null,
297+
);
274298
});
275299

276300
test("health history keeps legacy samples when optional state_writer is absent or invalid", () => {

‎test/dashboard-worker-bay-records-routes.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3434,8 +3434,17 @@ test("OpenClaw Bay is a public, indexable, hardened canonical route", async () =
34343434
at: new Date(bayAt).toISOString(),
34353435
exact_review: {
34363436
collection_ok: true,
3437-
review: { pending: 4, enqueued_total: 20, completed_total: 16, shed_total: 1 },
3438-
publication: { pending: 2, enqueued_total: 18, completed_total: 16 },
3437+
review: {
3438+
pending: 4,
3439+
enqueued_total: 10_000_020,
3440+
completed_total: 10_000_016,
3441+
shed_total: 1,
3442+
},
3443+
publication: {
3444+
pending: 2,
3445+
enqueued_total: 10_000_018,
3446+
completed_total: 10_000_016,
3447+
},
34393448
handoff: { status: "healthy", pending: 4, dispatching: 1, leased: 2 },
34403449
},
34413450
state_writer: {
@@ -3459,6 +3468,7 @@ test("OpenClaw Bay is a public, indexable, hardened canonical route", async () =
34593468
bayPayload = validBayHistory;
34603469
await bayHistoryRuntime.loadBayHistory();
34613470
assert.equal(bayHistoryRuntime.bayHistory("review")[0].pending, 4);
3471+
assert.equal(bayHistoryRuntime.bayHistory("review")[0].enqueued, 10_000_020);
34623472
assert.equal(bayHistoryRuntime.bayHandoffHistory()[0].dispatching, 1);
34633473
assert.equal(bayHistoryRuntime.bayStateWriterHistory()[0].pending, 2);
34643474
const projectedBayHistory = bayHistoryRuntime.bayHealthHistorySnapshot(validBayHistory, "6h");

‎test/dashboard-worker-dashboard-status.test.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,17 @@ function dashboardHealthHistoryFixture(range = "6h") {
254254
at: new Date(at).toISOString(),
255255
exact_review: {
256256
collection_ok: true,
257-
review: { pending: 4, enqueued_total: 20, completed_total: 16, shed_total: 1 },
258-
publication: { pending: 2, enqueued_total: 18, completed_total: 16 },
257+
review: {
258+
pending: 4,
259+
enqueued_total: 10_000_020,
260+
completed_total: 10_000_016,
261+
shed_total: 1,
262+
},
263+
publication: {
264+
pending: 2,
265+
enqueued_total: 10_000_018,
266+
completed_total: 10_000_016,
267+
},
259268
handoff: { status: "healthy", pending: 4, dispatching: 1, leased: 2 },
260269
},
261270
state_writer: {
@@ -1756,14 +1765,14 @@ test("dashboard hero treats apply and exact-review handoff health as attention",
17561765
collection_ok: true,
17571766
review: {
17581767
pending: 100 + index,
1759-
enqueued_total: index * 8,
1760-
completed_total: index * 5,
1768+
enqueued_total: 10_000_000 + index * 8,
1769+
completed_total: 10_000_000 + index * 5,
17611770
shed_total: 0,
17621771
},
17631772
publication: {
17641773
pending: 200 - index,
1765-
enqueued_total: index * 4,
1766-
completed_total: index * 10,
1774+
enqueued_total: 10_000_000 + index * 4,
1775+
completed_total: 10_000_000 + index * 10,
17671776
},
17681777
},
17691778
}));

0 commit comments

Comments
 (0)