Files

64 lines
7.4 KiB
GDScript

extends "/Users/korizatou114/Projects/とりにく工房ゲーム制作部/artifacts/original-completion-2026-10-02/p23-02-build-preview-monitor-compressed-r06.gd"
# One instrumented r274/library275 tick. Freeze counters immediately after the synchronous tick.
func run() -> void:
output = OS.get_environment("THE_TREE_RUNTIME_MONITOR_OUTPUT")
var input_path := OS.get_environment("THE_TREE_REPLAY_SNAPSHOT")
var candidate := OS.get_environment("THE_TREE_PAIRED_CANDIDATE")
if not output.is_absolute_path() or not input_path.is_absolute_path() or candidate != "r274": quit(98); return
var original := FileAccess.get_file_as_bytes(input_path).decompress(11411840, FileAccess.COMPRESSION_ZSTD)
var initial: Dictionary = bytes_to_var(original)
runtime = root.get_node("SimulationRuntime")
clock = root.get_node("GameClock")
runtime.initialize(clock, root.get_node("GameState"), int(initial[&"systems"][&"runtime"][&"world_seed"]))
check(runtime.restore_snapshot(initial), "fixed646 public restore")
check(var_to_bytes(runtime.create_snapshot()) == original, "complete input bytes identical")
check(clock.absolute_minute == 646 and clock.paused and clock.speed == 1, "same paused646 speed1")
var path_listeners: Array = runtime.path_service.get_signal_connection_list(&"path_query_measured")
check(path_listeners.size() == 1 and path_listeners[0]["callable"] == Callable(runtime, "_on_path_query_measured") and int(path_listeners[0]["flags"]) == 0, "only builtin path listener")
check(clock.performance_budget.get_signal_connection_list(&"budget_exceeded").is_empty(), "no external budget listener")
check(clock.get_signal_connection_list(&"tick_phase_started").is_empty() and clock.get_signal_connection_list(&"tick_completed").is_empty(), "no phase or completion instrumentation")
check(runtime.path_service.cache_hits == 0 and runtime.path_service.cache_misses == 0 and runtime.path_service.cached_path_count() == 0, "same cold derived cache")
check(runtime.path_service._query_batch.is_empty() and runtime.path_service._guest_tree_workspace.is_empty() and runtime.path_service._guest_step_connector_memo.is_empty(), "same cold tree/native-edge/step workspace")
check(runtime._guest_access_batch_can_select(), "current builtin active fast guard")
runtime._p23r311_metrics.clear()
runtime.path_service._p23r311_metrics.clear()
clock._p23r311_metrics.clear()
runtime.guest_service._p23r311_metrics.clear()
check(runtime._p23r311_metrics.is_empty() and runtime.path_service._p23r311_metrics.is_empty() and clock._p23r311_metrics.is_empty() and runtime.guest_service._p23r311_metrics.is_empty(), "diagnostic counters reset after restore")
var declared: Dictionary = {"runtime": ["_project_guest_candidates", "_decide_guest_with_log", "_find_facility_access_path", "_estimated_actor_path_minutes", "_facility_access_candidates", "_guest_access_batch_can_select", "_project_guest_candidates_without_native", "_need_relief_for_facility_tags", "_service_category_for_tags", "get_facility_business_price", "_publish_snapshot"], "path": ["begin_guest_path_query_batch", "query_nearest_guest_access", "_build_guest_query_tree_shared_result", "_resolve_ready_guest_batch_point", "_guest_tree_reconstruct_path", "_cache_key", "_copy_path", "_guest_tree_cost", "_guest_batch_has_permitted_layer_crossing"], "guest": ["extract_candidates", "rank_candidates", "evaluate_candidate"], "kernel_phases": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]}
var targets: Dictionary = {"runtime":runtime, "path":runtime.path_service, "guest":runtime.guest_service, "kernel_phases":clock}
for group: String in declared:
var counters: Dictionary = targets[group]._p23r311_metrics
for key: String in declared[group]: counters[key] = {"calls":0,"inclusive_us":0,"max_us":0}
var started := Time.get_ticks_usec()
clock.advance_minutes(1)
var elapsed := Time.get_ticks_usec() - started
var metrics: Dictionary = {"runtime":runtime._p23r311_metrics.duplicate(true), "path":runtime.path_service._p23r311_metrics.duplicate(true), "kernel_phases":clock._p23r311_metrics.duplicate(true)._p23r311_metrics.duplicate(true), "guest":runtime.guest_service._p23r311_metrics.duplicate(true)}
check(clock.absolute_minute == 647 and clock.paused, "tick returns at paused647")
var after: Dictionary = runtime.create_snapshot()
var oracle := FileAccess.get_file_as_bytes(OS.get_environment("THE_TREE_CANDIDATE_ORACLE")).decompress(11487732, FileAccess.COMPRESSION_ZSTD)
check(var_to_bytes(after) == oracle, "complete after647 equals pinned r32 oracle")
var after_pin := typed("after647", after)
check(after_pin["uncompressed_sha256"] == "9df3c1b6f65dfd8be944cd5cab8c631f7533530dfef3820d9fa5d74a5b1ac30f", "complete output digest identical")
var metrics_valid: bool = true
for group: String in declared:
metrics_valid = metrics_valid and metrics[group].size() == declared[group].size()
for key: String in declared[group]:
var row: Dictionary = metrics[group].get(key,{})
var count := int(row.get("calls",-1))
metrics_valid = metrics_valid and count>=0 and int(row.get("inclusive_us",-1)) >= int(row.get("max_us",-1)) and int(row.get("max_us",-1)) >= 0
if count==0: metrics_valid = metrics_valid and int(row["inclusive_us"])==0 and int(row["max_us"])==0
for phase_index: int in range(11): metrics_valid = metrics_valid and int(metrics["kernel_phases"][str(phase_index)]["calls"]) == 1
for key: String in ["extract_candidates","rank_candidates","evaluate_candidate"]: metrics_valid = metrics_valid and int(metrics["guest"][key]["calls"])>0
for key: String in ["_project_guest_candidates","_decide_guest_with_log","get_facility_business_price","_publish_snapshot"]: metrics_valid = metrics_valid and int(metrics["runtime"][key]["calls"])>0
metrics_valid = metrics_valid and int(metrics["path"]["begin_guest_path_query_batch"]["calls"])>0 and int(metrics["path"]["_build_guest_query_tree_shared_result"]["calls"])>0
check(metrics_valid, "declared counters cover zero/native bypass and positive scopes; ordered eleven phases observed")
check(int(metrics["runtime"]["_project_guest_candidates_without_native"]["calls"])==0, "every projected candidate call selected current native pipeline; no whole fallback")
var metric_pin := typed("inclusive-residual-metrics", metrics)
var report := {"plan_id":"P23-02", "candidate":candidate, "sample":OS.get_environment("THE_TREE_PAIRED_SAMPLE"), "pid":OS.get_process_id(), "observed_instrumented_tick_us":elapsed, "metrics":metric_pin, "diagnostic_only":true, "after647":after_pin, "cache_hits":runtime.path_service.cache_hits, "cache_misses":runtime.path_service.cache_misses, "checks":checks, "failures":failures, "passed":failures.is_empty(), "unit_accepted":false, "performance_budget_accepted":false, "normal_OS_accepted":false, "Windows_accepted":false, "candidate_adopted":false, "limits":["One instrumented r274/library275 cold646 tick. Original bodies retained, typed state oracle equality required. Nested inclusive durations include diagnostic overhead and children; do not sum/subtract for pure CPU or compare against uninstrumented timings; no performance acceptance.", "No Main, rendering, OS input or realtime x3. Timed interval contains builtin production callbacks; snapshot verification and compression occur after timing."]}
var file := FileAccess.open(output.path_join("report.json"), FileAccess.WRITE)
if file == null: quit(98); return
file.store_string(JSON.stringify(report, "\t")); file.close()
print("Residual diagnostic whole647: %d checks, %d failures" % [checks, failures.size()])
quit(0 if failures.is_empty() else 1)