-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-dropped-frame-ears.ts
More file actions
1480 lines (1358 loc) · 59.6 KB
/
Copy pathcheck-dropped-frame-ears.ts
File metadata and controls
1480 lines (1358 loc) · 59.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env tsx
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (c) 2025-2026 Matthew Kissinger
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { join, relative, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
type CheckStatus = 'pass' | 'warn' | 'fail';
export type DroppedFrameEarsClassification = 'proven' | 'diagnostic' | 'rejected';
type RequiredScenario = 'open_frontier' | 'a_shau_valley';
export interface DroppedFrameEarsCheck {
id: string;
status: CheckStatus;
message: string;
value?: string | number | boolean | null;
}
export interface DroppedFrameEarsArtifactEvaluation {
artifactDir: string;
artifactRelPath: string;
scenario: string | null;
classification: DroppedFrameEarsClassification;
contactQualified: boolean;
materializationQualified: boolean;
completionLaneQualified: boolean;
criticalPass: boolean;
failCount: number;
warnCount: number;
checks: DroppedFrameEarsCheck[];
}
export interface DroppedFrameEarsEvaluation {
status: CheckStatus;
requiredScenarios: readonly RequiredScenario[];
passingScenarios: RequiredScenario[];
missingScenarios: RequiredScenario[];
artifacts: DroppedFrameEarsArtifactEvaluation[];
}
type ValidationCheck = {
id?: string;
status?: CheckStatus;
value?: unknown;
message?: string;
};
type ThresholdCheck = {
id: string;
maxExclusive: number;
fallbackPath: readonly string[];
label: string;
};
type BooleanRuntimeFlag = {
id: string;
path: readonly string[];
equals?: boolean | string;
message: string;
};
const ARTIFACT_ROOT = join(process.cwd(), 'artifacts', 'perf');
const REQUIRED_SCENARIOS = ['open_frontier', 'a_shau_valley'] as const satisfies readonly RequiredScenario[];
const REQUIRED_FILES = [
'summary.json',
'validation.json',
'measurement-trust.json',
'presentation-epochs.json',
'runtime-render-submission-samples.json',
'final-frame.png',
] as const;
const MIN_SUSTAINED_MATERIALIZATION_SAMPLES = 3;
const MIN_SUSTAINED_MATERIALIZATION_RATIO = 0.1;
const MIN_SUSTAINED_COMBAT_SHOT_INCREASE_SAMPLES = 3;
const MIN_SUSTAINED_COMBAT_SHOT_INCREASE_RATIO = 0.05;
const RENDER_MAIN_RENDER_WARN_MS = 33;
const RENDER_MAIN_RENDER_FAIL_MS = 100;
const ATMOSPHERE_SYNC_WARN_MS = 4;
const ATMOSPHERE_SYNC_FAIL_MS = 16;
const RENDERER_RESOURCE_TEXTURE_JUMP_WARN = 16;
const RENDERER_RESOURCE_GEOMETRY_JUMP_WARN = 16;
const RENDERER_RESOURCE_PROGRAM_JUMP_WARN = 2;
const COMBAT_FIRE_TERRAIN_BLOCK_MIN_REQUESTS = 10;
const COMBAT_FIRE_TERRAIN_BLOCK_WARN_RATE = 0.25;
const COMBAT_FIRE_TERRAIN_BLOCK_FAIL_RATE = 0.5;
const RAF_THRESHOLDS: readonly ThresholdCheck[] = [
{
id: 'raf_stutter_25ms_percent',
maxExclusive: 0.5,
fallbackPath: ['droppedFrameMetrics', 'browserRaf', 'stutter25Percent'],
label: 'rAF gaps >25ms percent',
},
{
id: 'raf_hitch_33ms_percent',
maxExclusive: 0.25,
fallbackPath: ['droppedFrameMetrics', 'browserRaf', 'hitch33Percent'],
label: 'rAF gaps >33ms percent',
},
{
id: 'raf_estimated_dropped_60hz_frames_per_second',
maxExclusive: 0.1,
fallbackPath: ['droppedFrameMetrics', 'browserRaf', 'estimatedDropped60HzFramesPerSecond'],
label: 'estimated dropped 60Hz frames per second',
},
{
id: 'raf_dropped_frame_time_60hz_ms_per_second',
maxExclusive: 1,
fallbackPath: ['droppedFrameMetrics', 'browserRaf', 'droppedFrameTime60HzMsPerSecond'],
label: 'dropped-frame time over 60Hz budget per second',
},
];
const HARNESS_EQUIVALENCE_IDS = [
'harness_route_snap_trust',
'harness_frontline_compression_equivalence',
'harness_movement_mode_equivalence',
'harness_view_slew_request_equivalence',
'harness_shot_presentation_context_equivalence',
] as const;
const FORBIDDEN_RUNTIME_FLAGS: readonly BooleanRuntimeFlag[] = [
{
id: 'presentation_context_capture_disabled',
path: ['perfRuntime', 'presentationContextCapture'],
equals: false,
message: 'rich presentation context capture is disabled',
},
{
id: 'frontline_compression_requested',
path: ['perfRuntime', 'frontlineCompressionRequested'],
message: 'frontline compression was requested',
},
{
id: 'npc_close_models_disabled',
path: ['perfRuntime', 'npcCloseModelsDisabled'],
message: 'close NPC models are disabled',
},
{
id: 'terrain_shadows_disabled',
path: ['perfRuntime', 'terrainShadowsDisabled'],
message: 'terrain shadows are disabled',
},
{
id: 'terrain_full_shadow_pass_enabled',
path: ['perfRuntime', 'terrainFullShadowPassEnabled'],
message: 'full terrain shadow pass is a diagnostic variant',
},
{
id: 'bounded_terrain_shadow_pass_requested',
path: ['perfRuntime', 'boundedTerrainShadowPassRequested'],
message: 'bounded terrain shadow pass was explicitly requested as a diagnostic flag',
},
{
id: 'terrain_force_instance_upload_enabled',
path: ['perfRuntime', 'terrainForceInstanceUploadEnabled'],
message: 'terrain instance uploads are forced',
},
{
id: 'terrain_height_aware_frustum_requested',
path: ['perfRuntime', 'terrainHeightAwareFrustumRequested'],
message: 'height-aware terrain frustum was explicitly requested as a diagnostic flag',
},
{
id: 'terrain_height_bounds_heuristic_enabled',
path: ['perfRuntime', 'terrainHeightBoundsSource'],
equals: 'heuristic-samples',
message: 'heuristic-sampled terrain height bounds are diagnostic-only',
},
{
id: 'terrain_full_skirts_requested',
path: ['perfRuntime', 'terrainFullSkirtsRequested'],
message: 'legacy full terrain skirts are explicitly requested',
},
{
id: 'terrain_sparse_skirts_requested',
path: ['perfRuntime', 'terrainSparseSkirtsRequested'],
message: 'adaptive terrain skirts are explicitly requested by diagnostic flag',
},
{
id: 'terrain_skirts_disabled',
path: ['perfRuntime', 'terrainSkirtsDisabled'],
message: 'terrain skirts are disabled',
},
{
id: 'terrain_far_canopy_tint_disabled',
path: ['perfRuntime', 'terrainFarCanopyTintDisabled'],
message: 'far-canopy terrain tint is disabled',
},
{
id: 'terrain_low_sun_occlusion_disabled',
path: ['perfRuntime', 'terrainLowSunOcclusionDisabled'],
message: 'low-sun terrain occlusion is disabled',
},
{
id: 'wildlife_disabled',
path: ['perfRuntime', 'wildlifeDisabled'],
message: 'wildlife is disabled',
},
];
const FORBIDDEN_QUERY_FLAGS = [
'perfDisableNpcCloseModels',
'perfDisableTerrainShadows',
'perfBoundedTerrainShadowPass',
'terrainFullShadowPass',
'terrainForceInstanceUpload',
'terrainEnableHeightAwareFrustum',
'perfTerrainHeightAwareFrustum',
'terrainFullTerrainSkirts',
'terrainSparseTerrainSkirts',
'perfDisableTerrainSkirts',
'perfDisableTerrainFarCanopyTint',
'perfDisableTerrainLowSunOcclusion',
'perfDisableWildlife',
] as const;
function asRecord(value: unknown): Record<string, unknown> | null {
return value !== null && typeof value === 'object' && !Array.isArray(value)
? value as Record<string, unknown>
: null;
}
function asArray(value: unknown): unknown[] {
return Array.isArray(value) ? value : [];
}
function getRendererCounter(sample: unknown, key: 'textures' | 'geometries' | 'programs'): number | null {
const renderer = asRecord(asRecord(sample)?.renderer);
const value = renderer?.[key];
return typeof value === 'number' && Number.isFinite(value) ? value : null;
}
function readJsonObject(path: string): Record<string, unknown> | null {
if (!existsSync(path)) return null;
try {
return asRecord(JSON.parse(readFileSync(path, 'utf-8')));
} catch {
return null;
}
}
function readJsonArray(path: string): unknown[] | null {
if (!existsSync(path)) return null;
try {
const parsed = JSON.parse(readFileSync(path, 'utf-8'));
return Array.isArray(parsed) ? parsed : null;
} catch {
return null;
}
}
function getPath(root: Record<string, unknown> | null, path: readonly string[]): unknown {
let cursor: unknown = root;
for (const part of path) {
const record = asRecord(cursor);
if (!record) return undefined;
cursor = record[part];
}
return cursor;
}
function getString(root: Record<string, unknown> | null, path: readonly string[]): string | null {
const value = getPath(root, path);
return typeof value === 'string' ? value : null;
}
function getNumber(root: Record<string, unknown> | null, path: readonly string[]): number | null {
const value = getPath(root, path);
return typeof value === 'number' && Number.isFinite(value) ? value : null;
}
function getBoolean(root: Record<string, unknown> | null, path: readonly string[]): boolean | null {
const value = getPath(root, path);
return typeof value === 'boolean' ? value : null;
}
function getValidationChecks(validation: Record<string, unknown> | null, summary: Record<string, unknown> | null): ValidationCheck[] {
const directChecks = asArray(getPath(validation, ['checks']));
const summaryChecks = asArray(getPath(summary, ['validation', 'checks']));
const checks = directChecks.length > 0 ? directChecks : summaryChecks;
return checks
.map((value) => asRecord(value))
.filter((value): value is Record<string, unknown> => value !== null)
.map((value) => ({
id: typeof value.id === 'string' ? value.id : undefined,
status: value.status === 'pass' || value.status === 'warn' || value.status === 'fail'
? value.status
: undefined,
value: value.value,
message: typeof value.message === 'string' ? value.message : undefined,
}));
}
function validationCheck(checks: readonly ValidationCheck[], id: string): ValidationCheck | null {
return checks.find((check) => check.id === id) ?? null;
}
function checkPassed(checks: readonly DroppedFrameEarsCheck[], id: string): boolean {
return checks.some((check) => check.id === id && check.status === 'pass');
}
function checkStatus(status: boolean, id: string, passMessage: string, failMessage: string, value?: DroppedFrameEarsCheck['value']): DroppedFrameEarsCheck {
return {
id,
status: status ? 'pass' : 'fail',
message: status ? passMessage : failMessage,
value,
};
}
function closeEnough(actual: number | null, expected: number | null): boolean {
if (actual === null || expected === null || !Number.isFinite(actual) || !Number.isFinite(expected)) {
return false;
}
const tolerance = Math.max(0.01, Math.abs(expected) * 0.000001);
return Math.abs(actual - expected) <= tolerance;
}
function formatPercent(value: number | null): string {
return value === null ? 'missing' : `${(value * 100).toFixed(1)}%`;
}
function rel(path: string): string {
return relative(process.cwd(), path).replaceAll('\\', '/');
}
function isRequiredScenario(value: string | null): value is RequiredScenario {
return value === 'open_frontier' || value === 'a_shau_valley';
}
function validationOverall(validation: Record<string, unknown> | null, summary: Record<string, unknown> | null): string | null {
return getString(validation, ['overall']) ?? getString(summary, ['validation', 'overall']);
}
function measurementTrustStatus(measurementTrust: Record<string, unknown> | null, summary: Record<string, unknown> | null): string | null {
return getString(measurementTrust, ['status']) ?? getString(summary, ['measurementTrust', 'status']);
}
function rendererResolvedBackend(measurementTrust: Record<string, unknown> | null, summary: Record<string, unknown> | null): string | null {
return getString(summary, ['rendererBackend', 'resolvedBackend'])
?? getString(summary, ['measurementTrust', 'rendererBackend', 'resolvedBackend'])
?? getString(measurementTrust, ['rendererBackend', 'resolvedBackend']);
}
function rendererStrictWebGpu(measurementTrust: Record<string, unknown> | null, summary: Record<string, unknown> | null): boolean {
return getBoolean(summary, ['rendererBackend', 'strictWebGPU'])
?? getBoolean(summary, ['measurementTrust', 'rendererBackend', 'strictWebGPU'])
?? getBoolean(measurementTrust, ['rendererBackend', 'strictWebGPU'])
?? false;
}
function urlSearchParams(summary: Record<string, unknown> | null): URLSearchParams | null {
const rawUrl = getString(summary, ['url']);
if (!rawUrl) return null;
try {
return new URL(rawUrl).searchParams;
} catch {
return null;
}
}
function addRequiredFileChecks(artifactDir: string, checks: DroppedFrameEarsCheck[]): void {
for (const fileName of REQUIRED_FILES) {
const path = join(artifactDir, fileName);
const present = existsSync(path);
checks.push(checkStatus(
present,
`required_file_${fileName.replaceAll('.', '_').replaceAll('-', '_')}`,
`${fileName} is present`,
`${fileName} is missing`,
present
));
}
}
function addRafChecks(
checks: DroppedFrameEarsCheck[],
validationChecks: readonly ValidationCheck[],
summary: Record<string, unknown> | null
): void {
for (const threshold of RAF_THRESHOLDS) {
const fromValidation = validationCheck(validationChecks, threshold.id);
const value = typeof fromValidation?.value === 'number'
? fromValidation.value
: getNumber(summary, threshold.fallbackPath);
const passed = value !== null && value < threshold.maxExclusive;
checks.push({
id: threshold.id,
status: passed ? 'pass' : 'fail',
value,
message: value === null
? `${threshold.label} is missing; threshold is <${threshold.maxExclusive}`
: `${threshold.label} ${value.toFixed(3)}; threshold is <${threshold.maxExclusive}`,
});
}
}
function addQuietMachineSnapshotCheck(
checks: DroppedFrameEarsCheck[],
summary: Record<string, unknown> | null,
quietMachineAttested: boolean | null
): void {
if (quietMachineAttested !== true) return;
const snapshotStatus = getString(summary, ['captureEnvironment', 'quietMachineSnapshot', 'status']);
const cpuAvg = getNumber(summary, ['captureEnvironment', 'quietMachineSnapshot', 'cpu', 'avgPercent']);
const cpuMax = getNumber(summary, ['captureEnvironment', 'quietMachineSnapshot', 'cpu', 'maxPercent']);
const gpuUtil = getNumber(summary, ['captureEnvironment', 'quietMachineSnapshot', 'gpu', 'utilizationPercent']);
const gpuLoadClass = getString(summary, ['captureEnvironment', 'quietMachineSnapshot', 'gpu', 'loadClass']);
const warnings = asArray(getPath(summary, ['captureEnvironment', 'quietMachineSnapshot', 'warnings']))
.filter((value): value is string => typeof value === 'string');
const warningSummary = warnings.length > 0 ? ` warnings=${warnings.join(' | ')}` : '';
checks.push({
id: 'quiet_machine_snapshot_idle',
status: snapshotStatus === 'pass' || snapshotStatus === 'warn'
? snapshotStatus
: 'fail',
value: snapshotStatus,
message: snapshotStatus === 'pass'
? `Quiet-machine snapshot passed (cpuAvg=${cpuAvg ?? 'missing'}%, cpuMax=${cpuMax ?? 'missing'}%, gpu=${gpuUtil ?? 'missing'}%/${gpuLoadClass ?? 'unknown'})`
: snapshotStatus === 'warn'
? `Quiet-machine snapshot had warning-band sensors but no recorded busy failure (cpuAvg=${cpuAvg ?? 'missing'}%, cpuMax=${cpuMax ?? 'missing'}%, gpu=${gpuUtil ?? 'missing'}%/${gpuLoadClass ?? 'unknown'}).${warningSummary}`
: `Quiet-machine snapshot is missing or busy (status=${snapshotStatus ?? 'missing'}, cpuAvg=${cpuAvg ?? 'missing'}%, cpuMax=${cpuMax ?? 'missing'}%, gpu=${gpuUtil ?? 'missing'}%/${gpuLoadClass ?? 'unknown'}).${warningSummary}`,
});
}
function runtimeSampleShotCount(sample: unknown): number | null {
const record = asRecord(sample);
if (!record) return null;
const harnessDriver = asRecord(record.harnessDriver);
const driverShots = harnessDriver ? harnessDriver.engineShotsFired : undefined;
if (typeof driverShots === 'number' && Number.isFinite(driverShots)) return driverShots;
const sessionShots = record.shotsThisSession;
return typeof sessionShots === 'number' && Number.isFinite(sessionShots) ? sessionShots : null;
}
function addCombatFireTerrainBlockChecks(
checks: DroppedFrameEarsCheck[],
validationChecks: readonly ValidationCheck[],
runtimeSamples: readonly unknown[] | null
): void {
const validationTerrainBlock = validationCheck(validationChecks, 'combat_fire_terrain_block_rate');
if (runtimeSamples === null) {
checks.push({
id: 'combat_fire_terrain_block_rate',
status: validationTerrainBlock?.status ?? 'warn',
value: typeof validationTerrainBlock?.value === 'number' ? validationTerrainBlock.value : null,
message: validationTerrainBlock?.message
?? 'Runtime samples are unavailable; cannot prove combat-fire terrain blocking stayed low',
});
return;
}
let bestBudget: Record<string, unknown> | null = null;
let bestTotalRequested = -1;
for (const sample of runtimeSamples) {
const sampleRecord = asRecord(sample);
const combatBreakdown = asRecord(sampleRecord?.combatBreakdown);
const budget = asRecord(combatBreakdown?.combatFireRaycastBudget);
if (!budget) continue;
const totalRequested = typeof budget.totalRequested === 'number' && Number.isFinite(budget.totalRequested)
? budget.totalRequested
: -1;
if (totalRequested >= bestTotalRequested) {
bestTotalRequested = totalRequested;
bestBudget = budget;
}
}
if (!bestBudget) {
checks.push({
id: 'combat_fire_terrain_block_rate',
status: validationTerrainBlock?.status ?? 'warn',
value: typeof validationTerrainBlock?.value === 'number' ? validationTerrainBlock.value : null,
message: validationTerrainBlock?.message
?? 'Combat-fire terrain-block telemetry is missing; cannot prove the measured fight had valid fire geometry',
});
return;
}
const totalRequested = Math.max(0, Number(bestBudget.totalRequested ?? 0));
const totalTerrainBlocked = Math.max(0, Number(bestBudget.totalTerrainBlocked ?? 0));
const reportedRate = Number(bestBudget.terrainBlockRate);
const blockRate = Number.isFinite(reportedRate)
? reportedRate
: totalRequested > 0
? totalTerrainBlocked / totalRequested
: 0;
const status: CheckStatus = totalRequested < COMBAT_FIRE_TERRAIN_BLOCK_MIN_REQUESTS
? 'warn'
: blockRate < COMBAT_FIRE_TERRAIN_BLOCK_WARN_RATE
? 'pass'
: blockRate < COMBAT_FIRE_TERRAIN_BLOCK_FAIL_RATE
? 'warn'
: 'fail';
checks.push({
id: 'combat_fire_terrain_block_rate',
status,
value: blockRate,
message: totalRequested < COMBAT_FIRE_TERRAIN_BLOCK_MIN_REQUESTS
? `Combat-fire terrain-block sample is too thin (${totalTerrainBlocked}/${totalRequested}); keep contact geometry diagnostic`
: status === 'pass'
? `Combat-fire terrain blocking stayed low (${formatPercent(blockRate)}, ${totalTerrainBlocked}/${totalRequested})`
: `Combat-fire terrain blocking is high (${formatPercent(blockRate)}, ${totalTerrainBlocked}/${totalRequested}; warn>=${formatPercent(COMBAT_FIRE_TERRAIN_BLOCK_WARN_RATE)}, fail>=${formatPercent(COMBAT_FIRE_TERRAIN_BLOCK_FAIL_RATE)}); contact geometry/LOS must be fixed before trusting dropped-frame completion evidence`,
});
}
function addCombatChecks(
checks: DroppedFrameEarsCheck[],
validationChecks: readonly ValidationCheck[],
runtimeSamples: readonly unknown[] | null
): void {
const shots = validationCheck(validationChecks, 'harness_min_shots_fired')
?? validationCheck(validationChecks, 'player_shots_recorded');
const hits = validationCheck(validationChecks, 'harness_min_hits_recorded')
?? validationCheck(validationChecks, 'player_hits_recorded');
const aggregateCombatPassed = shots?.status === 'pass' && hits?.status === 'pass';
checks.push(checkStatus(
shots?.status === 'pass',
'active_combat_shots',
'active combat shot threshold passed',
'active combat shot threshold is missing or failed',
typeof shots?.value === 'number' ? shots.value : null
));
checks.push(checkStatus(
hits?.status === 'pass',
'active_combat_hits',
'active combat hit threshold passed',
'active combat hit threshold is missing or failed',
typeof hits?.value === 'number' ? hits.value : null
));
if (runtimeSamples === null) {
checks.push({
id: 'active_combat_sustained_contact',
status: aggregateCombatPassed ? 'pass' : 'fail',
value: null,
message: aggregateCombatPassed
? 'Aggregate combat thresholds passed; runtime sample distribution is unavailable in this artifact'
: 'Aggregate combat thresholds failed and runtime sample distribution is unavailable',
});
return;
}
const shotCounts = runtimeSamples
.map(runtimeSampleShotCount)
.filter((value): value is number => value !== null);
let previousMaxShots = 0;
let samplesWithAnyShots = 0;
let samplesWithShotIncreases = 0;
for (const shotCount of shotCounts) {
if (shotCount > 0) samplesWithAnyShots++;
if (shotCount > previousMaxShots) {
samplesWithShotIncreases++;
previousMaxShots = shotCount;
}
}
const shotIncreaseRatio = shotCounts.length > 0
? samplesWithShotIncreases / shotCounts.length
: null;
const sustained = aggregateCombatPassed
&& samplesWithAnyShots >= MIN_SUSTAINED_COMBAT_SHOT_INCREASE_SAMPLES
&& samplesWithShotIncreases >= MIN_SUSTAINED_COMBAT_SHOT_INCREASE_SAMPLES
&& shotIncreaseRatio !== null
&& shotIncreaseRatio >= MIN_SUSTAINED_COMBAT_SHOT_INCREASE_RATIO;
checks.push({
id: 'active_combat_sustained_contact',
status: sustained ? 'pass' : 'fail',
value: shotIncreaseRatio,
message: sustained
? `Active combat was sustained across runtime samples (shot increases=${samplesWithShotIncreases}/${shotCounts.length}, samplesWithShots=${samplesWithAnyShots}, ${formatPercent(shotIncreaseRatio)})`
: `Active combat was absent or too bursty for completion comparison (shot increases=${samplesWithShotIncreases}/${shotCounts.length}, samplesWithShots=${samplesWithAnyShots}, ${formatPercent(shotIncreaseRatio)}; min increases=${MIN_SUSTAINED_COMBAT_SHOT_INCREASE_SAMPLES}, min ratio=${formatPercent(MIN_SUSTAINED_COMBAT_SHOT_INCREASE_RATIO)})`,
});
}
function addMaterializationEnvelopeChecks(
checks: DroppedFrameEarsCheck[],
validationChecks: readonly ValidationCheck[],
summary: Record<string, unknown> | null
): void {
const validationPressure = validationCheck(validationChecks, 'npc_materialization_pressure');
const peakCandidates = typeof validationPressure?.value === 'number'
? validationPressure.value
: getNumber(summary, ['closeModelEnvelope', 'peakCandidatesWithinCloseRadius']);
const peakRendered = getNumber(summary, ['closeModelEnvelope', 'peakRenderedCloseModels']);
const samplesWithCandidates = getNumber(summary, ['closeModelEnvelope', 'samplesWithCandidates']);
const sampleCount = getNumber(summary, ['closeModelEnvelope', 'sampleCount']);
const samplesWithRenderedCloseModels = getNumber(summary, ['closeModelEnvelope', 'samplesWithRenderedCloseModels']);
const candidateSampleRatio = sampleCount !== null && sampleCount > 0 && samplesWithCandidates !== null
? samplesWithCandidates / sampleCount
: null;
const fallbackPassed = peakCandidates !== null
&& peakRendered !== null
&& samplesWithCandidates !== null
&& peakCandidates >= 4
&& peakRendered >= 2
&& samplesWithCandidates >= 2;
const passed = validationPressure
? validationPressure.status === 'pass'
: fallbackPassed;
checks.push({
id: 'npc_materialization_pressure',
status: passed ? 'pass' : 'fail',
value: peakCandidates,
message: passed
? `NPC materialization pressure was represented (peak candidates=${peakCandidates ?? 'unknown'}, peak rendered=${peakRendered ?? 'unknown'}, samplesWithCandidates=${samplesWithCandidates ?? 'unknown'}/${sampleCount ?? 'unknown'})`
: `NPC materialization pressure is missing or thin (peak candidates=${peakCandidates ?? 'missing'}, peak rendered=${peakRendered ?? 'missing'}, samplesWithCandidates=${samplesWithCandidates ?? 'missing'}/${sampleCount ?? 'missing'}); completion evidence must not close a materialization fix from low-contact route variance`,
});
const sustained = sampleCount !== null
&& samplesWithCandidates !== null
&& samplesWithRenderedCloseModels !== null
&& samplesWithCandidates >= MIN_SUSTAINED_MATERIALIZATION_SAMPLES
&& samplesWithRenderedCloseModels >= MIN_SUSTAINED_MATERIALIZATION_SAMPLES
&& candidateSampleRatio !== null
&& candidateSampleRatio >= MIN_SUSTAINED_MATERIALIZATION_RATIO;
checks.push({
id: 'npc_materialization_sustained_contact',
status: sustained ? 'pass' : 'fail',
value: candidateSampleRatio,
message: sustained
? `NPC materialization contact was sustained across detailed samples (${samplesWithCandidates}/${sampleCount}, ${formatPercent(candidateSampleRatio)}; rendered=${samplesWithRenderedCloseModels})`
: `NPC materialization contact was too bursty for completion comparison (${samplesWithCandidates ?? 'missing'}/${sampleCount ?? 'missing'}, ${formatPercent(candidateSampleRatio)}; rendered=${samplesWithRenderedCloseModels ?? 'missing'}; min samples=${MIN_SUSTAINED_MATERIALIZATION_SAMPLES}, min ratio=${formatPercent(MIN_SUSTAINED_MATERIALIZATION_RATIO)})`,
});
}
function addCloseModelRuntimePoolLoadChecks(
checks: DroppedFrameEarsCheck[],
runtimeSamples: readonly unknown[] | null
): void {
if (runtimeSamples === null) {
checks.push({
id: 'npc_close_model_runtime_pool_loads_clear',
status: 'warn',
value: null,
message: 'Runtime samples are unavailable; cannot prove close-model pools stayed resident during measured play',
});
return;
}
let samplesWithCloseModelStats = 0;
let samplesWithPoolLoads = 0;
let maxPoolLoads = 0;
for (const sample of runtimeSamples) {
const sampleRecord = asRecord(sample);
const closeModelStats = asRecord(sampleRecord?.closeModelStats);
if (!closeModelStats) continue;
samplesWithCloseModelStats++;
const poolLoads = typeof closeModelStats.poolLoads === 'number' && Number.isFinite(closeModelStats.poolLoads)
? closeModelStats.poolLoads
: 0;
maxPoolLoads = Math.max(maxPoolLoads, poolLoads);
if (poolLoads > 0) samplesWithPoolLoads++;
}
if (samplesWithCloseModelStats === 0) {
checks.push({
id: 'npc_close_model_runtime_pool_loads_clear',
status: 'warn',
value: null,
message: 'Runtime close-model stats are unavailable; cannot prove no live close-model pool loads occurred',
});
return;
}
checks.push({
id: 'npc_close_model_runtime_pool_loads_clear',
status: samplesWithPoolLoads === 0 ? 'pass' : 'fail',
value: samplesWithPoolLoads,
message: samplesWithPoolLoads === 0
? `No live close-model pool loads during measured runtime (${samplesWithCloseModelStats} close-model samples, max poolLoads=${maxPoolLoads})`
: `Close-model pools were still loading during measured runtime (${samplesWithPoolLoads}/${samplesWithCloseModelStats} close-model samples, max poolLoads=${maxPoolLoads}); materialization evidence is diagnostic until pool residency is prepared before play`,
});
}
function addMaterializationTransitionTelemetryChecks(
checks: DroppedFrameEarsCheck[],
summary: Record<string, unknown> | null,
runtimeSamples: readonly unknown[] | null,
): void {
const peakActiveCloseModels = getNumber(summary, ['closeModelEnvelope', 'peakActiveCloseModels']);
const samplesWithRenderedCloseModels = getNumber(summary, ['closeModelEnvelope', 'samplesWithRenderedCloseModels']);
const summaryEventTotal = getNumber(summary, ['materializationTierMetrics', 'totalEvents']);
const transitionWindowTotal = getNumber(summary, ['materializationTierMetrics', 'transitionWindowTotalEvents']);
const closeModelsWereActive = (peakActiveCloseModels ?? 0) > 0
&& (samplesWithRenderedCloseModels ?? 0) > 0;
let samplesWithEventArrays = 0;
let runtimeEventTotal = 0;
if (runtimeSamples) {
for (const sample of runtimeSamples) {
const sampleRecord = asRecord(sample);
const events = sampleRecord?.materializationTierEvents;
if (Array.isArray(events)) {
samplesWithEventArrays++;
runtimeEventTotal += events.length;
}
const closeModelStats = asRecord(sampleRecord?.closeModelStats);
const transitionWindow = asRecord(closeModelStats?.transitionWindow);
const transitionTotal = typeof transitionWindow?.total === 'number' && Number.isFinite(transitionWindow.total)
? transitionWindow.total
: 0;
runtimeEventTotal += transitionTotal;
}
}
const eventTotal = Math.max(summaryEventTotal ?? 0, transitionWindowTotal ?? 0, runtimeEventTotal);
if (!closeModelsWereActive) {
checks.push({
id: 'npc_materialization_transition_telemetry',
status: 'pass',
value: eventTotal,
message: 'No active close models were sampled; tier-transition telemetry is not required for this artifact',
});
return;
}
if (runtimeSamples === null && summaryEventTotal === null) {
checks.push({
id: 'npc_materialization_transition_telemetry',
status: 'warn',
value: null,
message: 'Runtime samples and materialization event summary are unavailable; cannot prove tier-transition telemetry was captured',
});
return;
}
checks.push({
id: 'npc_materialization_transition_telemetry',
status: eventTotal > 0 ? 'pass' : 'fail',
value: eventTotal,
message: eventTotal > 0
? `Tier-transition telemetry was captured while close models were active (events=${eventTotal}, eventSamples=${samplesWithEventArrays}, transitionWindowEvents=${transitionWindowTotal ?? 0})`
: `Close models were active (${peakActiveCloseModels ?? 'unknown'} peak, ${samplesWithRenderedCloseModels ?? 'unknown'} rendered samples) but no materialization tier events were captured; this artifact cannot be trusted for transition-stutter claims`,
});
}
function addHarnessEquivalenceChecks(checks: DroppedFrameEarsCheck[], validationChecks: readonly ValidationCheck[]): void {
for (const id of HARNESS_EQUIVALENCE_IDS) {
const check = validationCheck(validationChecks, id);
const passed = check?.status === 'pass';
checks.push({
id,
status: passed ? 'pass' : 'fail',
value: typeof check?.value === 'number' || typeof check?.value === 'string' ? check.value : null,
message: passed
? `${id} passed`
: `${id} is missing, warning, or failed; completion evidence must explain or remove this harness mismatch`,
});
}
}
function addForbiddenRuntimeChecks(
checks: DroppedFrameEarsCheck[],
summary: Record<string, unknown> | null,
searchParams: URLSearchParams | null
): void {
for (const flag of FORBIDDEN_RUNTIME_FLAGS) {
const actual = getPath(summary, flag.path);
const forbiddenValue = flag.equals ?? true;
const enabled = actual === forbiddenValue;
checks.push({
id: `forbidden_${flag.id}`,
status: enabled ? 'fail' : 'pass',
value: typeof actual === 'string' || typeof actual === 'boolean' || typeof actual === 'number'
? actual
: null,
message: enabled
? `Rejected content/runtime variant: ${flag.message}`
: `Forbidden runtime flag is not set: ${flag.id}`,
});
}
const shadowMode = getString(summary, ['perfRuntime', 'terrainShadowPassMode']);
const diagnosticShadowMode = shadowMode === 'bounded-requested' || shadowMode === 'full-diagnostic';
checks.push({
id: 'forbidden_terrain_shadow_pass_mode',
status: diagnosticShadowMode ? 'fail' : 'pass',
value: shadowMode,
message: diagnosticShadowMode
? `Rejected terrain shadow pass mode: ${shadowMode}`
: `Terrain shadow pass mode is completion-compatible: ${shadowMode ?? 'unknown'}`,
});
const vegetationDensityScale = getNumber(summary, ['perfRuntime', 'vegetationDensityScale'])
?? (searchParams?.has('perfVegetationDensityScale')
? Number(searchParams.get('perfVegetationDensityScale'))
: null);
const changedVegetationDensity = vegetationDensityScale !== null
&& Number.isFinite(vegetationDensityScale)
&& Math.abs(vegetationDensityScale - 1) > 0.001;
checks.push({
id: 'forbidden_vegetation_density_scale',
status: changedVegetationDensity ? 'fail' : 'pass',
value: vegetationDensityScale,
message: changedVegetationDensity
? `Rejected vegetation density scale: ${vegetationDensityScale}`
: `Vegetation density scale is default-compatible: ${vegetationDensityScale ?? 'default'}`,
});
const weatherStateOverride = getString(summary, ['perfRuntime', 'weatherStateOverride']);
const changedWeatherState = weatherStateOverride !== null && weatherStateOverride !== 'default';
checks.push({
id: 'forbidden_weather_state_override',
status: changedWeatherState ? 'fail' : 'pass',
value: weatherStateOverride,
message: changedWeatherState
? `Rejected weather-state diagnostic override: ${weatherStateOverride}`
: `Weather state is scenario default-compatible: ${weatherStateOverride ?? 'default'}`,
});
for (const queryFlag of FORBIDDEN_QUERY_FLAGS) {
const enabled = searchParams?.get(queryFlag) === '1';
checks.push({
id: `forbidden_query_${queryFlag}`,
status: enabled ? 'fail' : 'pass',
value: enabled,
message: enabled
? `Rejected URL/runtime diagnostic flag: ${queryFlag}=1`
: `Forbidden query flag is not set: ${queryFlag}`,
});
}
}
function addPressureReadyWarmupChecks(
checks: DroppedFrameEarsCheck[],
summary: Record<string, unknown> | null
): void {
const requested = getBoolean(summary, ['perfRuntime', 'pressureReadyWarmupRequested']);
const status = getString(summary, ['perfRuntime', 'pressureReadyWarmupStatus']);
const reason = getString(summary, ['perfRuntime', 'pressureReadyWarmupReason']);
const elapsedMs = getNumber(summary, ['perfRuntime', 'pressureReadyWarmupElapsedMs']);
const samples = getNumber(summary, ['perfRuntime', 'pressureReadyWarmupSamples']);
const snapshot = asRecord(getPath(summary, ['perfRuntime', 'pressureReadyWarmupLastSnapshot']));
const closeCandidates = getNumber(snapshot, ['closeCandidates']);
const renderedCloseModels = getNumber(snapshot, ['renderedCloseModels']);
const engineShotsFired = getNumber(snapshot, ['engineShotsFired']);
const botState = getString(snapshot, ['botState']);
if (requested !== true) {
checks.push({
id: 'pressure_ready_measurement_window',
status: 'fail',
value: requested,
message: 'Pressure-ready warmup was not requested; cannot prove the measured window began under contact/materialization pressure.',
});
return;
}
checks.push({
id: 'pressure_ready_measurement_window',
status: status === 'ready' ? 'pass' : 'fail',
value: status,
message: status === 'ready'
? `Measured window started after pressure-ready warmup (${reason ?? 'unknown'}, elapsed=${elapsedMs ?? 'n/a'}ms, samples=${samples ?? 'n/a'}, close=${renderedCloseModels ?? 'n/a'}/${closeCandidates ?? 'n/a'}, shots=${engineShotsFired ?? 'n/a'}, state=${botState ?? 'unknown'}).`
: `Pressure-ready warmup did not pass (status=${status ?? 'unknown'}, reason=${reason ?? 'unknown'}, elapsed=${elapsedMs ?? 'n/a'}ms, samples=${samples ?? 'n/a'}, close=${renderedCloseModels ?? 'n/a'}/${closeCandidates ?? 'n/a'}, shots=${engineShotsFired ?? 'n/a'}, state=${botState ?? 'unknown'}); keep this artifact diagnostic for contact/routing, not perf completion.`,
});
}
function addTerrainHeightBoundsTrustChecks(
checks: DroppedFrameEarsCheck[],
summary: Record<string, unknown> | null
): void {
const source = getString(summary, ['perfRuntime', 'terrainHeightBoundsSource']);
const tests = getNumber(summary, ['perfRuntime', 'terrainHeightBoundsTests']);
const fallbacks = getNumber(summary, ['perfRuntime', 'terrainHeightBoundsFallbacks']);
if (source !== 'baked-grid') {
checks.push({
id: 'terrain_height_bounds_baked_grid_trust',
status: 'pass',
value: source,
message: `Production baked-grid terrain bounds are not active: ${source ?? 'unknown'}`,
});
return;
}
const trusted = tests !== null && tests > 0 && fallbacks === 0;
checks.push({
id: 'terrain_height_bounds_baked_grid_trust',
status: trusted ? 'pass' : 'fail',
value: fallbacks,
message: trusted
? `Baked-grid terrain bounds covered selection (${tests} tests, ${fallbacks} fallbacks)`
: `Baked-grid terrain bounds were incomplete (${tests ?? 'missing'} tests, ${fallbacks ?? 'missing'} fallbacks)`,
});
}
function addTerrainVisualDomainTrustChecks(
checks: DroppedFrameEarsCheck[],
summary: Record<string, unknown> | null
): void {
const playableWorldSize = getNumber(summary, ['perfRuntime', 'terrainPlayableWorldSize']);
const visualWorldSize = getNumber(summary, ['perfRuntime', 'terrainVisualWorldSize']);
const visualMargin = getNumber(summary, ['perfRuntime', 'terrainVisualMargin']);
const maxLODLevels = getNumber(summary, ['perfRuntime', 'terrainMaxLODLevels']);
const lodRange0 = getNumber(summary, ['perfRuntime', 'terrainLodRange0']);
const lodRangeLast = getNumber(summary, ['perfRuntime', 'terrainLodRangeLast']);
const lod0VertexSpacing = getNumber(summary, ['perfRuntime', 'terrainLod0VertexSpacing']);
const expectedVisualWorldSize = playableWorldSize !== null && visualMargin !== null
? playableWorldSize + visualMargin * 2
: null;
const visualExtentAligned = closeEnough(visualWorldSize, expectedVisualWorldSize);
checks.push({
id: 'terrain_visual_world_size_alignment',
status: visualExtentAligned ? 'pass' : 'fail',
value: visualWorldSize,
message: visualExtentAligned
? `Terrain visual world size matches playable extent plus margin (${visualWorldSize})`
: `Terrain visual world size is not aligned with playable extent plus margin (actual ${visualWorldSize ?? 'missing'}, expected ${expectedVisualWorldSize ?? 'missing'})`,
});
const lodCount = maxLODLevels !== null && Number.isInteger(maxLODLevels) && maxLODLevels > 0
? maxLODLevels
: null;
const expectedLodRange0 = visualWorldSize !== null && lodCount !== null
? (visualWorldSize / Math.pow(2, lodCount)) * 4
: null;
const expectedLodRangeLast = expectedLodRange0 !== null && lodCount !== null
? expectedLodRange0 * Math.pow(2, lodCount - 1)
: null;
const rangesAligned = closeEnough(lodRange0, expectedLodRange0)
&& closeEnough(lodRangeLast, expectedLodRangeLast)
&& lod0VertexSpacing !== null
&& lod0VertexSpacing > 0;
checks.push({
id: 'terrain_lod_ranges_visual_extent_alignment',
status: rangesAligned ? 'pass' : 'fail',
value: lodRange0,
message: rangesAligned
? `Terrain LOD ranges are derived from the visual quadtree extent (LOD0 ${lodRange0}, last ${lodRangeLast})`
: `Terrain LOD ranges are not derived from the visual quadtree extent (LOD0 ${lodRange0 ?? 'missing'} expected ${expectedLodRange0 ?? 'missing'}, last ${lodRangeLast ?? 'missing'} expected ${expectedLodRangeLast ?? 'missing'}, spacing ${lod0VertexSpacing ?? 'missing'})`,
});
}
function addTerrainPresentationIntegrityChecks(
checks: DroppedFrameEarsCheck[],
summary: Record<string, unknown> | null
): void {
const presentationGapCount = getNumber(summary, ['presentationGapContexts', 'gapCount']);
const noPresentationGaps = presentationGapCount === 0;
const unsyncedBufferVisibleChanges = getNumber(
summary,
['presentationGapContexts', 'terrain', 'terrainStageBufferVisibleChangedWithoutSubmissionCount']
);
const bufferVisibleChanges = getNumber(
summary,
['presentationGapContexts', 'terrain', 'terrainStageBufferVisibleChangedCount']
);
const morphChanges = getNumber(
summary,
['presentationGapContexts', 'terrain', 'terrainStageMorphHashChangedCount']
);
const terrainGapCount = getNumber(summary, ['presentationGapContexts', 'terrain', 'gapCount']);
const terrainSelectionSaturatedCount = getNumber(
summary,
['presentationGapContexts', 'terrain', 'terrainSelectionSaturatedCount']
);
const hasTerrainGapSummary = terrainGapCount !== null;
const coherent = noPresentationGaps || (
hasTerrainGapSummary
&& unsyncedBufferVisibleChanges !== null
&& unsyncedBufferVisibleChanges === 0
);
checks.push({
id: 'terrain_stage_buffer_submission_integrity',
status: coherent ? 'pass' : 'fail',
value: unsyncedBufferVisibleChanges,
message: noPresentationGaps
? 'No presentation gaps were captured; no dropped-frame CDLOD stage mismatch to classify'
: coherent
? `CDLOD buffer-visible terrain stage changes were submitted (${bufferVisibleChanges ?? 0} buffer-visible changes; ${morphChanges ?? 0} morph-only changes may use shader uniforms)`
: hasTerrainGapSummary
? `CDLOD buffer-visible terrain stage changed without terrain buffer submission (${unsyncedBufferVisibleChanges ?? 'missing'} unsynced of ${bufferVisibleChanges ?? 'missing'} changes)`
: 'Presentation gap terrain summary is missing; cannot prove CDLOD buffer submission integrity',
});
const selectionCapacityTrusted = noPresentationGaps || (
hasTerrainGapSummary
&& terrainSelectionSaturatedCount !== null
&& terrainSelectionSaturatedCount === 0
);
checks.push({
id: 'terrain_cdlod_selection_capacity',
status: selectionCapacityTrusted ? 'pass' : 'fail',
value: terrainSelectionSaturatedCount,
message: noPresentationGaps
? 'No presentation gaps were captured; CDLOD selection capacity did not coincide with a dropped-frame context'
: selectionCapacityTrusted
? 'CDLOD selection did not hit the tile cap in dropped-frame contexts'
: hasTerrainGapSummary
? `CDLOD selection hit the tile cap in ${terrainSelectionSaturatedCount ?? 'missing'} dropped-frame contexts`