Skip to content

fix(tools): import asyncio in handlers — data-gen errors raised NameError - #13

Open
marekolszewski wants to merge 1 commit into
Liquid4All:mainfrom
marekolszewski:fix/handlers-missing-asyncio-import
Open

fix(tools): import asyncio in handlers — data-gen errors raised NameError#13
marekolszewski wants to merge 1 commit into
Liquid4All:mainfrom
marekolszewski:fix/handlers-missing-asyncio-import

Conversation

@marekolszewski

Copy link
Copy Markdown

What

lqh/tools/handlers.py uses asyncio on exactly one line — except asyncio.CancelledError: in _execute_pipeline — but never imports it. This adds the missing import asyncio.

Filing directly per CONTRIBUTING's "trivial, mechanical fixes that a reviewer can verify at a glance" — happy to move it to an issue/prompt instead if you'd rather.

Why it matters

Python evaluates an except clause's expression only when an exception actually reaches it, so this stayed invisible on the happy path. But on any failure inside that try block, evaluating asyncio.CancelledError raises NameError — which replaces the real exception and skips the except Exception as e: handler right below it, so the telemetry and project_log error recording never run.

The try block starts at handlers.py:1774 with load_config() / require_token(), so the most common trigger is simply running data generation while logged out:

# before
Traceback (most recent call last):
  File "lqh/tools/handlers.py", line 1775, in _execute_pipeline
    token = require_token()
RuntimeError: Not logged in. Run /login to authenticate with lqh.ai.

During handling of the above exception, another exception occurred:
  File "lqh/tools/handlers.py", line 2025, in _execute_pipeline
    except asyncio.CancelledError:
NameError: name 'asyncio' is not defined
# after
❌ Pipeline failed: RuntimeError: Not logged in. Run /login to authenticate with lqh.ai.

The intended CancelledError path (Esc / Ctrl+C mid-generation) was equally affected.

Verification

  • uv run pytest tests/unit1379 passed, 25 skipped
  • uv tool run ruff check . --select F821 → no undefined names remain in handlers.py

Heads-up, unrelated to this PR

CI's python lint job is currently red on main independently of this change, so this PR's check will likely come back red too. It's been failing on every push since 2026-07-13 (last green run: 2026-07-10). It began as 2 unused imports; because uv tool run ruff check . pins no version and the repo has no [tool.ruff] config, newer ruff defaults have since expanded it to 796 findings. Glad to open a separate issue if useful.

…rror

`_execute_pipeline` guards its body with `except asyncio.CancelledError:`,
but `handlers.py` never imported asyncio — that line was the module's only
reference to the name.

Python evaluates an except clause's expression only when an exception
actually propagates to it, so this stayed invisible on the happy path. On
any failure inside the try block, evaluating `asyncio.CancelledError`
raised `NameError: name 'asyncio' is not defined`, which replaced the real
exception and skipped the `except Exception` handler below it (telemetry +
project-log error recording).

Reproduced with no credentials, where `require_token()` — the second
statement in the try block — raises RuntimeError:

  before:  NameError: name 'asyncio' is not defined
  after:   ❌ Pipeline failed: RuntimeError: Not logged in.
           Run /login to authenticate with lqh.ai.

`ruff check --select F821` reports no undefined names in handlers.py after
this change, and `pytest tests/unit` passes (1379 passed, 25 skipped).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H8BG6fPGiZjZ8nCB7f9x5h
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.

1 participant