fix(web-probe): avoid loading segment gap overcount (#677)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -3140,10 +3140,10 @@ function loadingContinuityThresholdMs(events) {
|
||||
const delta = events[index].tsMs - events[index - 1].tsMs;
|
||||
if (Number.isFinite(delta) && delta > 0) deltas.push(delta);
|
||||
}
|
||||
if (deltas.length === 0) return 15000;
|
||||
if (deltas.length === 0) return 5000;
|
||||
const sorted = deltas.slice().sort((a, b) => a - b);
|
||||
const median = sorted[Math.floor(sorted.length / 2)];
|
||||
return Math.max(15000, Math.round(median * 2.5));
|
||||
return Math.min(15000, Math.max(1500, Math.round(median * 2.5)));
|
||||
}
|
||||
|
||||
function buildLoadingSegments(events, continuityThresholdMs, countForEvent, ownersForEvent) {
|
||||
@@ -3196,9 +3196,11 @@ function buildLoadingSegments(events, continuityThresholdMs, countForEvent, owne
|
||||
|
||||
function finalizeLoadingSegment(segment, absentEvent) {
|
||||
const startMs = Date.parse(segment.firstAt || "");
|
||||
const endAnchor = absentEvent?.ts || segment.lastAt;
|
||||
const endMs = Date.parse(endAnchor || "");
|
||||
const durationSeconds = Number.isFinite(startMs) && Number.isFinite(endMs) && endMs >= startMs ? Number(((endMs - startMs) / 1000).toFixed(3)) : 0;
|
||||
const lastMs = Date.parse(segment.lastAt || "");
|
||||
const absentMs = Date.parse(absentEvent?.ts || "");
|
||||
const durationSeconds = Number.isFinite(startMs) && Number.isFinite(lastMs) && lastMs >= startMs ? Number(((lastMs - startMs) / 1000).toFixed(3)) : 0;
|
||||
const upperBoundSeconds = Number.isFinite(startMs) && Number.isFinite(absentMs) && absentMs >= startMs ? Number(((absentMs - startMs) / 1000).toFixed(3)) : durationSeconds;
|
||||
const endedGapSeconds = Number.isFinite(lastMs) && Number.isFinite(absentMs) && absentMs >= lastMs ? Number(((absentMs - lastMs) / 1000).toFixed(3)) : null;
|
||||
return {
|
||||
firstAt: segment.firstAt,
|
||||
lastAt: segment.lastAt,
|
||||
@@ -3207,6 +3209,8 @@ function finalizeLoadingSegment(segment, absentEvent) {
|
||||
lastSeq: segment.lastSeq,
|
||||
endSeq: absentEvent?.seq ?? null,
|
||||
durationSeconds,
|
||||
upperBoundSeconds,
|
||||
endedGapSeconds,
|
||||
sampleCount: segment.sampleCount,
|
||||
maxCount: segment.maxCount,
|
||||
ownerCount: segment.ownerKeys.size,
|
||||
@@ -4067,7 +4071,7 @@ function renderMarkdown(report) {
|
||||
? report.sampleMetrics.rounds.map((item) => "- round " + item.promptIndex + " promptHash=" + (item.promptTextHash || "-") + " samples=" + item.sampleCount + " loadingSamples=" + (item.loadingSamples ?? 0) + " maxLoading=" + (item.maxLoadingCount ?? 0) + " loadingOwners=" + (item.loadingOwnerCount ?? 0) + " totalMax=" + (item.maxTotalElapsedSeconds ?? "-") + " totalLast=" + (item.lastTotalElapsedSeconds ?? "-") + " recentMax=" + (item.maxRecentUpdateSeconds ?? "-") + " recentLast=" + (item.lastRecentUpdateSeconds ?? "-") + " totalDecrease=" + (item.turnTimingTotalElapsedDecreaseCount ?? 0) + " totalForwardJump=" + (item.turnTimingTotalElapsedForwardJumpCount ?? 0) + " totalForwardJumpMax=" + (item.turnTimingTotalElapsedForwardJumpMaxSeconds ?? 0) + " terminalGrowth=" + (item.turnTimingTerminalElapsedGrowthCount ?? 0) + " terminalGrowthMax=" + (item.turnTimingTerminalElapsedGrowthMaxSeconds ?? 0) + " recentJump=" + (item.turnTimingRecentUpdateJumpCount ?? 0) + " recentSawtoothJump=" + (item.turnTimingRecentUpdateSawtoothJumpCount ?? item.turnTimingRecentUpdateJumpCount ?? 0) + " recentStep=" + (item.turnTimingRecentUpdateStepCount ?? 0) + " recentMaxIncrease=" + (item.turnTimingRecentUpdateMaxIncreaseSeconds ?? "-") + " recentMaxExcess=" + (item.turnTimingRecentUpdateMaxExcessSeconds ?? 0) + " recentReset=" + (item.turnTimingRecentUpdateResetCount ?? 0) + " diagnostics=" + item.diagnosticSamples + " terminal=" + item.terminalSamples + " finalText=" + item.finalTextSamples).join("\n")
|
||||
: "- 无轮次指标。";
|
||||
const loadingSegmentLines = Array.isArray(loading.segments) && loading.segments.length > 0
|
||||
? loading.segments.slice(0, 80).map((item) => "- duration=" + (item.durationSeconds ?? 0) + "s countMax=" + (item.maxCount ?? 0) + " owners=" + (item.ownerCount ?? 0) + " seq=" + (item.firstSeq ?? "-") + ".." + (item.lastSeq ?? "-") + " ts=" + (item.firstAt || "-") + ".." + (item.lastAt || "-") + " endedAt=" + (item.endedAt || (item.ongoing ? "ongoing" : "-")) + " ownerLabels=" + ((Array.isArray(item.owners) ? item.owners : []).slice(0, 6).map((owner) => (owner.ownerKind || "-") + ":" + (owner.ownerLabel || "-") + "x" + (owner.count ?? 0)).join(",") || "-")).join("\n")
|
||||
? loading.segments.slice(0, 80).map((item) => "- observedDuration=" + (item.durationSeconds ?? 0) + "s upperBound=" + (item.upperBoundSeconds ?? item.durationSeconds ?? 0) + "s endedGap=" + (item.endedGapSeconds ?? "-") + "s samples=" + (item.sampleCount ?? 0) + " countMax=" + (item.maxCount ?? 0) + " owners=" + (item.ownerCount ?? 0) + " seq=" + (item.firstSeq ?? "-") + ".." + (item.lastSeq ?? "-") + " ts=" + (item.firstAt || "-") + ".." + (item.lastAt || "-") + " endedAt=" + (item.endedAt || (item.ongoing ? "ongoing" : "-")) + " ownerLabels=" + ((Array.isArray(item.owners) ? item.owners : []).slice(0, 6).map((owner) => (owner.ownerKind || "-") + ":" + (owner.ownerLabel || "-") + "x" + (owner.count ?? 0)).join(",") || "-")).join("\n")
|
||||
: "- 未观察到“加载中”可见区间。";
|
||||
const loadingOwnerLines = Array.isArray(loading.owners) && loading.owners.length > 0
|
||||
? loading.owners.slice(0, 80).map((item) => "- " + (item.ownerKind || "-") + " " + escapeMarkdownCell(item.ownerLabel || item.ownerKey || "-") + " samples=" + (item.sampleCount ?? 0) + " occurrences=" + (item.occurrenceCount ?? 0) + " maxCount=" + (item.maxSimultaneousCount ?? 0) + " longest=" + (item.longestContinuousSeconds ?? 0) + "s seq=" + (item.firstSeq ?? "-") + ".." + (item.lastSeq ?? "-") + " prompts=" + (Array.isArray(item.promptIndexes) ? item.promptIndexes.join(",") : "-")).join("\n")
|
||||
|
||||
Reference in New Issue
Block a user