fix: use positional insertion in log_features to preserve model attribution

log_features() appended test results in call-completion order, causing
model attribution swaps when LLM responses arrived out of order. Pass
test_index through and use positional insertion instead of append.
This commit is contained in:
Kevin Turcios 2026-02-15 03:45:42 -05:00
parent 496033539e
commit e5d70443db
3 changed files with 21 additions and 10 deletions

View file

@ -544,6 +544,7 @@ async def testgen_javascript(
user_id=request.user,
generated_tests=[generated_test_source],
instrumented_generated_tests=[instrumented_behavior_tests],
test_index=test_index,
test_framework=data.test_framework,
metadata={
"test_timeout": data.test_timeout,

View file

@ -528,6 +528,7 @@ async def testgen_python(
generated_tests=[raw_llm_content],
instrumented_generated_tests=[instrumented_behavior_tests],
instrumented_perf_tests=[instrumented_perf_tests],
test_index=test_index,
test_framework=data.test_framework,
metadata={
"test_timeout": data.test_timeout,

View file

@ -37,6 +37,7 @@ def log_features(
generated_tests: list[str] | None = None,
instrumented_generated_tests: list[str] | None = None,
instrumented_perf_tests: list[str] | None = None,
test_index: int | None = None,
test_framework: str | None = None,
datetime: dt.datetime | None = None,
aiservice_commit: str | None = None,
@ -148,16 +149,24 @@ def log_features(
f.optimizations_origin = merge_dicts(f.optimizations_origin or {}, optimizations_origin)
update_fields.append("optimizations_origin")
# List append fields
if generated_tests:
f.generated_test = (f.generated_test or []) + generated_tests
update_fields.append("generated_test")
if instrumented_generated_tests:
f.instrumented_generated_test = (f.instrumented_generated_test or []) + instrumented_generated_tests
update_fields.append("instrumented_generated_test")
if instrumented_perf_tests:
f.instrumented_perf_test = (f.instrumented_perf_test or []) + instrumented_perf_tests
update_fields.append("instrumented_perf_test")
# List fields — positional insertion when test_index is given, else append
list_updates = [
("generated_test", f.generated_test, generated_tests),
("instrumented_generated_test", f.instrumented_generated_test, instrumented_generated_tests),
("instrumented_perf_test", f.instrumented_perf_test, instrumented_perf_tests),
]
for field, existing, new_items in list_updates:
if not new_items:
continue
current = existing or []
if test_index is not None and len(new_items) == 1:
while len(current) <= test_index:
current.append(None)
current[test_index] = new_items[0]
else:
current = current + new_items
setattr(f, field, current)
update_fields.append(field)
if update_fields:
f.save(update_fields=update_fields)