Real memory-lifecycle bug found while auditing code for optimizations (not test padding). show_damage_number() created a tween whose callback captured the label object directly. When the pool hit MAX_FLOATING_NUMBERS (16), the oldest label was queue_free()d while its tween still held that captured reference; when the callback later fired, Godot logged "Lambda capture at index 0 was freed" on every hit. Test logs had 2019 such errors, silently treated as a "note" by the log audit. Fix: capture the label's instance ID (an int, never freed) and resolve it with instance_from_id() in the callback; _release_floating_number still validates with is_instance_valid. Re-running the two worst tests dropped errors 184->0 and 509->0; across all logs 2019->0. Also tightened tools/audit_logs.py: "Lambda capture ... was freed" is now a hard failure signature (dangling_lambda), with a negative test proving a regression is caught instead of being waved through as a shutdown note. Full gate P2_CHECKS_PASS. prototype/ untracked.
89 lines
3.7 KiB
Python
89 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Hard log audit across every Godot test artifact.
|
|
|
|
AGENTS.md/CURRENT_EXECUTION rules: exit code zero alone is insufficient. Logs
|
|
must be scanned for script errors, parse/resource/import failures, assertion
|
|
and leak messages, and owned-process cleanup. This gate turns that rule into
|
|
an automated check so a passing marker can never hide a runtime error.
|
|
|
|
Scans p2_godot_sample/artifacts/*.log. Whitelists nothing by default: any
|
|
match is a failure. A short allowlist is kept only for messages that are
|
|
engine-shutdown observations with no product impact, and each entry must name
|
|
an issue id that documents why it is benign.
|
|
|
|
Usage: python3 tools/audit_logs.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Dict, List
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
LOG_DIR = ROOT / "p2_godot_sample/artifacts"
|
|
|
|
# Error signatures that must never appear in a passing run.
|
|
BAD_PATTERNS: Dict[str, str] = {
|
|
"script_error": r"SCRIPT ERROR",
|
|
"parse_error": r"Parse Error|parse error",
|
|
"resource_load": r"Failed loading resource|Error opening file|No loader found|Cannot open file|Error importing",
|
|
"import_failure": r"ERROR:.*import|Import failed",
|
|
"assertion": r"Assertion failed|assertion '.*' failed",
|
|
"tween_callback": r"Error calling method from CallbackTweener|CallbackTweener",
|
|
# A tween/timer lambda capturing a node that was freed (e.g. a pooled
|
|
# floating-number label force-released at the pool cap). The callback then
|
|
# receives null and Godot logs this. It is a real lifecycle bug, not a note.
|
|
"dangling_lambda": r"Lambda capture at index \d+ was freed",
|
|
"format_error": r"String formatting error|unsupported format character",
|
|
"owned_cleanup": r"Owned process.*still running|failed to terminate",
|
|
}
|
|
|
|
# Engine-shutdown resource notes are NOT product leaks: they are Godot's
|
|
# headless process releasing its static ResourceLoader cache on exit, after
|
|
# the test scene tree is already gone. They appear only in test processes and
|
|
# never during normal gameplay. Count and report them, but they do not fail
|
|
# the audit. Anything that happens during a run (script error, failed load,
|
|
# callback/format error, assertion) still fails hard.
|
|
EXIT_NOTE = re.compile(r"ObjectDB instances leaked at exit|resources? still in use at exit|unclaimed string names at exit", re.IGNORECASE)
|
|
|
|
|
|
def main() -> int:
|
|
if not LOG_DIR.exists():
|
|
print(f"LOG_AUDIT_FAIL no log directory: {LOG_DIR}")
|
|
return 1
|
|
|
|
logs = sorted(LOG_DIR.glob("*.log"))
|
|
findings: List[str] = []
|
|
exit_notes = 0
|
|
scanned = 0
|
|
for path in logs:
|
|
scanned += 1
|
|
text = path.read_text(encoding="utf-8", errors="replace")
|
|
for line_no, line in enumerate(text.splitlines(), 1):
|
|
if EXIT_NOTE.search(line):
|
|
exit_notes += 1
|
|
continue
|
|
for label, pattern in BAD_PATTERNS.items():
|
|
if not re.search(pattern, line, re.IGNORECASE):
|
|
continue
|
|
findings.append(f"{path.name}:{line_no} [{label}] {line.strip()}")
|
|
|
|
print(f"scanned {scanned} logs in {LOG_DIR}")
|
|
if exit_notes:
|
|
print(f"NOTE {exit_notes} engine-shutdown resource note(s) in test logs (Static ResourceLoader cache; not product leaks)")
|
|
if findings:
|
|
print(f"LOG_AUDIT_FAIL {len(findings)} error line(s)")
|
|
for finding in findings[:40]:
|
|
print(f" {finding}")
|
|
if len(findings) > 40:
|
|
print(f" ... {len(findings) - 40} more")
|
|
return 1
|
|
print("LOG_AUDIT_PASS no script/parse/resource/leak errors in any log")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|