Skip to content

[Code scan] Missing or failed inference-efficiency results can crash or change schema #439

Description

@njzjz

This issue was found by a Codex global repository scan of tracked non-test files at commit 8c93925cb10b401b2b83c738bd9263fd74474468.

Relevant code

def fetch_inference_efficiency_results_for_one_model(
self, model: BaseLargeAtomModel
) -> dict[str, float]:
"""This function returns the inference efficiency results for a given LAM."""
task_results = CalculatorRecord.query(
model_name=model.model_name, task_name="inference_efficiency"
)
if len(task_results) != 1:
logging.warning(
f"Expected one record for {model.model_name} and inference_efficiency, but got {len(task_results)}"
)
return aggregated_inference_efficiency_results(task_results[0].metrics)

def aggregated_inference_efficiency_results(
results: dict[str, dict[str, float]],
) -> dict[str, float]:
system_level_avg = []
system_level_std = []
system_level_success_rate = []
success_count = len(results)
for _, result in results.items():
if result["average_time"] is None:
success_count -= 1
continue
system_level_avg.append(result["average_time"])
system_level_std.append(result["std_time"])
system_level_success_rate.append(result["success_rate"])
if success_count != len(results):
return {"average_time": None, "std_time": None, "success_rate": 0.0}
return {
"average_time": np.round(np.mean(system_level_avg), 6),
"standard_deviation": np.round(
np.sqrt(np.mean(np.square(system_level_std))), 6
),
"success_rate": np.round(np.mean(system_level_success_rate), 2),

Impact

fetch_inference_efficiency_results_for_one_model() logs a warning when the database query returns zero or multiple records, but it still indexes task_results[0]. A missing record therefore raises IndexError during result generation.

There is also a schema inconsistency: the successful aggregation branch returns standard_deviation, while the failure branch returns std_time. Consumers of the generated JSON see different keys depending on whether any system failed.

Suggested fix

Return None or a consistent failure object when len(task_results) != 1, before indexing. Also make the failure branch return the same keys as the success branch, for example average_time, standard_deviation, and success_rate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions