BUG-HUNT: [resource] Temporary file leak in M3ValidationAddSuite benchmark #3781

Open
opened 2026-04-06 06:17:40 +00:00 by freemo · 0 comments
Owner

Bug Report: [resource] — Temporary file leak in M3ValidationAddSuite benchmark

Severity Assessment

  • Impact: Low. Can lead to accumulation of temporary files in the long run, consuming disk space.
  • Likelihood: High. The benchmark is part of the standard suite and will be run regularly.
  • Priority: Low

Location

  • File: benchmarks/m3_smoke_bench.py
  • Function/Class: M3ValidationAddSuite
  • Lines: 167-174

Description

The setup method of the M3ValidationAddSuite class creates a temporary file using tempfile.NamedTemporaryFile(delete=False). However, the teardown method does not contain any logic to clean up this file. Because delete=False is used, the file is not automatically deleted when it's closed, leading to a resource leak.

Evidence

class M3ValidationAddSuite:
    """Benchmark validation add CLI command."""

    def setup(self) -> None:
        # ... (mocks setup)
        config_content = (
            "name: local/coverage-check\n"
            "description: Check code coverage meets threshold\n"
            "source: custom\n"
            "mode: required\n"
            "code: |\n"
            "  def run(inputs):\n"
            "      return {'passed': inputs['coverage'] >= 80}\n"
        )
        with tempfile.NamedTemporaryFile(
            mode="w",
            suffix=".yaml",
            delete=False,
        ) as tmp:
            tmp.write(config_content)
            self._config_path = tmp.name

    def teardown(self) -> None:
        self._patcher.stop()

Expected Behavior

The teardown method should remove the temporary file created in the setup method to ensure proper resource cleanup after the benchmark runs.

Actual Behavior

The temporary file is not deleted, and will accumulate each time the benchmark suite is run.

Suggested Fix

Add os.remove(self._config_path) to the teardown method.

import os

# ...

    def teardown(self) -> None:
        self._patcher.stop()
        os.remove(self._config_path)

Category

resource


Metadata

  • Branch: fix/benchmark-m3-validation-add-suite-tmpfile-leak
  • Commit Message: fix(benchmarks): clean up temporary file in M3ValidationAddSuite teardown
  • Milestone: None (Backlog)
  • Parent Epic: #362

Subtasks

  • Add import os to benchmarks/m3_smoke_bench.py if not already present
  • Add os.remove(self._config_path) to the teardown method of M3ValidationAddSuite
  • Verify no other benchmark suites in the file have the same issue
  • Write/update Behave scenario to cover teardown resource cleanup
  • Run nox to confirm all quality gates pass

Definition of Done

  • teardown method in M3ValidationAddSuite removes the temporary file
  • No other benchmark suites in m3_smoke_bench.py have the same resource leak
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone v3.4.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: ca-new-issue-creator

## Bug Report: [resource] — Temporary file leak in M3ValidationAddSuite benchmark ### Severity Assessment - **Impact**: Low. Can lead to accumulation of temporary files in the long run, consuming disk space. - **Likelihood**: High. The benchmark is part of the standard suite and will be run regularly. - **Priority**: Low ### Location - **File**: `benchmarks/m3_smoke_bench.py` - **Function/Class**: `M3ValidationAddSuite` - **Lines**: 167-174 ### Description The `setup` method of the `M3ValidationAddSuite` class creates a temporary file using `tempfile.NamedTemporaryFile(delete=False)`. However, the `teardown` method does not contain any logic to clean up this file. Because `delete=False` is used, the file is not automatically deleted when it's closed, leading to a resource leak. ### Evidence ```python class M3ValidationAddSuite: """Benchmark validation add CLI command.""" def setup(self) -> None: # ... (mocks setup) config_content = ( "name: local/coverage-check\n" "description: Check code coverage meets threshold\n" "source: custom\n" "mode: required\n" "code: |\n" " def run(inputs):\n" " return {'passed': inputs['coverage'] >= 80}\n" ) with tempfile.NamedTemporaryFile( mode="w", suffix=".yaml", delete=False, ) as tmp: tmp.write(config_content) self._config_path = tmp.name def teardown(self) -> None: self._patcher.stop() ``` ### Expected Behavior The `teardown` method should remove the temporary file created in the `setup` method to ensure proper resource cleanup after the benchmark runs. ### Actual Behavior The temporary file is not deleted, and will accumulate each time the benchmark suite is run. ### Suggested Fix Add `os.remove(self._config_path)` to the `teardown` method. ```python import os # ... def teardown(self) -> None: self._patcher.stop() os.remove(self._config_path) ``` ### Category resource --- ## Metadata - **Branch**: `fix/benchmark-m3-validation-add-suite-tmpfile-leak` - **Commit Message**: `fix(benchmarks): clean up temporary file in M3ValidationAddSuite teardown` - **Milestone**: None (Backlog) - **Parent Epic**: #362 ## Subtasks - [ ] Add `import os` to `benchmarks/m3_smoke_bench.py` if not already present - [ ] Add `os.remove(self._config_path)` to the `teardown` method of `M3ValidationAddSuite` - [ ] Verify no other benchmark suites in the file have the same issue - [ ] Write/update Behave scenario to cover teardown resource cleanup - [ ] Run `nox` to confirm all quality gates pass ## Definition of Done - [ ] `teardown` method in `M3ValidationAddSuite` removes the temporary file - [ ] No other benchmark suites in `m3_smoke_bench.py` have the same resource leak - [ ] All nox stages pass - [ ] Coverage >= 97% > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.4.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#362 Epic: Security & Safety Hardening
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3781
No description provided.