Skip to content

perf(analytics): pattern analysis has no cooperative cancel token; executor threads outlive the request deadline #22094

Open

Description

@mrveiss

Problem

CodePatternAnalyzer.analyze_directory (autobot-backend/code_intelligence/pattern_analysis/analyzer.py) has no cooperative cancel token. Only the clone-detection phase carries a deadline (ANALYZER_TIMEOUT); the other phases run file work through run_in_executor with none. The report route bounds the whole analysis with an outer asyncio.wait_for of about 180 s, which stops the awaiting coroutine but not the executor threads: they keep walking the tree after the request has been answered. _get_api_endpoint_analysis already solves the same shape with new_cancel_token / run_cancellable (utils/cancel_tokens.py).

Fix

Give the pattern analyzer a cancel token checked between files and phases, and have _get_pattern_analysis in endpoints/report.py create one with new_cancel_token and cancel it when the outer deadline fires, as _get_api_endpoint_analysis does.

Context

Found while removing the "scan only AutoBot's backend directory" shortcut from the report (#20513, PR #22092): with it gone, a large source relies on this deadline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendphase:M4.11Safety net: tests and analysers reach the whole tree

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions