Skip to content

Fix argument list mutation in summarize()#10127

Open
abhu85 wants to merge 1 commit intoaws:developfrom
abhu85:fix/benchmark-utils-mutation
Open

Fix argument list mutation in summarize()#10127
abhu85 wants to merge 1 commit intoaws:developfrom
abhu85:fix/benchmark-utils-mutation

Conversation

@abhu85
Copy link
Contributor

@abhu85 abhu85 commented Mar 13, 2026

Summary

Fixes #10121

The summarize() function in scripts/performance/benchmark_utils.py mutates the argument list when calling the subprocess for JSON output. This is done using list.extend() which modifies the original list in place.

Problem

The function constructs summarize_args and reuses it for both subprocess calls:

with open(os.path.join(summary_dir, 'summary.txt'), 'wb') as f:
    subprocess.check_call(summarize_args, stdout=f)
with open(os.path.join(summary_dir, 'summary.json'), 'wb') as f:
    summarize_args.extend(['--output-format', 'json'])  # Mutation!
    subprocess.check_call(summarize_args, stdout=f)

While this doesn't cause immediate issues in the current implementation (since summarize_args is a local variable), it violates best practices for CLI argument construction and could cause subtle bugs if the code is refactored.

Solution

Use list concatenation instead of mutation to create a fresh list for the JSON output call:

with open(os.path.join(summary_dir, 'summary.json'), 'wb') as f:
    json_args = summarize_args + ['--output-format', 'json']
    subprocess.check_call(json_args, stdout=f)

Testing

  • Added unit tests in tests/unit/test_benchmark_utils.py
  • Tests verify that the argument list is not mutated between subprocess calls
  • All existing unit tests pass (2777 passed)
$ python -m pytest tests/unit/test_benchmark_utils.py -v
tests/unit/test_benchmark_utils.py::TestSummarize::test_summarize_does_not_mutate_args PASSED
tests/unit/test_benchmark_utils.py::TestSummarize::test_summarize_multiple_calls_are_independent PASSED

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

The summarize() function in benchmark_utils.py was mutating the
argument list when calling the subprocess for JSON output. This
could cause issues if the list is reused or referenced elsewhere.

Instead of using list.extend() which mutates in place, use list
concatenation to create a new list for the JSON output call.

Fixes aws#10121

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

summarize() Mutates Argument List Between Calls

1 participant