fix(gui): Correct indentation bug in _render_mma_dashboard that caused crash

The code after the 'prior session' return block was incorrectly indented
at 1 space, placing it inside the 'if is_viewing_prior_session' block
instead of after it. This caused 'total_cost' and 'perc' to be undefined
when viewing an active session, triggering an IM_ASSERT error.

Fix: Moved 'track_name', 'track_stats', and 'total_cost' to the
correct 2-space indentation (method body level).
This commit is contained in:
2026-05-06 19:41:22 -04:00
parent 6bd052efc5
commit f6feab9243
9 changed files with 356 additions and 12 deletions
+39 -10
View File
@@ -3,6 +3,39 @@ import re
import ast
from collections import Counter
class ScopeAuditor(ast.NodeVisitor):
def __init__(self, findings):
self.scope_stack = [([], "")]
self.findings = findings
def visit_ClassDef(self, node):
self.scope_stack[-1][0].append(node.name)
parent_label = self.scope_stack[-1][1]
new_label = f"{parent_label}.{node.name}" if parent_label else node.name
self.scope_stack.append(([], new_label))
self.generic_visit(node)
defs, label = self.scope_stack.pop()
self.check_duplicates(defs, label)
def visit_FunctionDef(self, node):
self.scope_stack[-1][0].append(node.name)
parent_label = self.scope_stack[-1][1]
new_label = f"{parent_label}.{node.name}" if parent_label else node.name
self.scope_stack.append(([], new_label))
self.generic_visit(node)
defs, label = self.scope_stack.pop()
self.check_duplicates(defs, label)
def visit_AsyncFunctionDef(self, node):
self.visit_FunctionDef(node)
def check_duplicates(self, defs, label):
counts = Counter(defs)
for name, count in counts.items():
if count > 1:
scope_str = f" in scope '{label}'" if label else " at top-level"
self.findings.append(f"Duplicate definition{scope_str}: '{name}' ({count} times)")
def audit_file(path):
with open(path, 'r', encoding='utf-8') as f:
lines = f.readlines()
@@ -31,18 +64,14 @@ def audit_file(path):
findings.append(f"Mixed indentation: 4-space block found at line {i+1}")
break # Only report once per file
# 4. List all functions and classes that appear more than once
# 4. List all functions and classes that appear more than once in the same scope
try:
tree = ast.parse(content)
defs = []
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
defs.append(node.name)
def_counts = Counter(defs)
for name, count in def_counts.items():
if count > 1:
findings.append(f"Duplicate definition: '{name}' ({count} times)")
auditor = ScopeAuditor(findings)
auditor.visit(tree)
if auditor.scope_stack:
defs, label = auditor.scope_stack.pop()
auditor.check_duplicates(defs, label)
except Exception as e:
findings.append(f"AST Parse Error: {e}")