@@ -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"};}
0 commit comments