Skip to content

fix(logging): convert loguru printf-style calls to {} (fixes #458) - #479

Open
gauravkr2209 wants to merge 9 commits into
chunkhound:mainfrom
gauravkr2209:fix-458-loguru-printf
Open

gauravkr2209 wants to merge 9 commits into
chunkhound:mainfrom
gauravkr2209:fix-458-loguru-printf

Conversation

@gauravkr2209

Copy link
Copy Markdown

19 loguru calls converted from %s/%d to {} across those 4 files, args/kwargs unchanged; new AST guard test that scans loguru-importing files; rapid_yaml_parser.py intentionally excluded because it uses stdlib logging where %s is correct; tests actually run — guard test 2 passed, smoke test 3 passed / 3 failed with the same 3 failing on pristine main due to the missing chunkhound_native Rust module (not this change), ruff 151 pre-existing errors identical on both trees, full suite/mypy not run locally — please rely on CI.

@HananKavitzAmat

HananKavitzAmat commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary: The conversions that are in the PR are correct, but the fix is incomplete. One loguru call still prints a raw %r, and the new guard's regex can't catch it.

Strengths

  • The 19 conversions match line for line and keep their arguments. The %ds → {}s change in the Codex timeout message is right.
  • The guard test is thorough. It handles logger.opt(...).() and .log(level, msg), flags "..." % x, and treats %% as an escaped percent. It also has unit tests for the detector.
  • rapid_yaml_parser.py and llm_provider.py are correctly left alone, because both use stdlib logging, where %s is right.

Issues

Major

  • Missed call. chunkhound/services/diff_aware_search_service.py:151 still has vector_source=%r. That file uses from loguru import logger (line 13), so the log line prints a literal %r.
  • Guard blind spot. tests/test_loguru_format_guard.py:220 has _PRINTF_SPEC = ...[sdifgeE], which has no r (or a/x/o/c). The guard therefore passes on exactly the %r call in the missed file. It gives false confidence, and %r is the conversion this codebase already uses. The fix is to add r and a to the character class.

Minor

  • Weak verification. The PR body says 3 smoke tests failed on both this branch and main, and that mypy and the full suite weren't run. The failures come from the missing chunkhound_native module, which is an environment problem. The guard test passing confirms the guard runs. It doesn't confirm the log output is correct.
  • Placement. The new test sits at tests/test_loguru_format_guard.py.
  • logger name only. The guard only recognises the literal name logger. A from loguru import logger as log alias would slip through.
    Reusability
  • No existing helper to extend. The per-method parts of the detector (_is_loguru_call, _is_loguru_log_call) are small and fine as they are.
  • Handling logger aliases would let the guithout assuming a name.
  • A better long-term fix is a ruff or flake8 rule rather than a test, but that's out of scope here.

Decision: REQUEST CHANGES.

  1. Fix diff_aware_search_service.py:151.
  2. Add r (and a) to _PRINTF_SPEC and add a unit case for %r.
  3. Ideally handle import logger as ... aliases.

@VakninAriel VakninAriel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — PR #479

Verdict: ✅ Approve

Summary

Loguru does not interpolate printf-style placeholders, leaving important runtime details as literal %s or %d text in logs. This PR converts 19 calls across the database, Codex CLI, indexing and multi-hop search code to brace formatting and adds an AST-based guard against recurrence.

What's good

  • The production edits preserve the existing logging arguments while fixing diagnostic values such as Codex transport attempts, timeout seconds and search result caps; the timeout becomes {}s rather than leaving its unit-suffixed placeholder behind.
  • The guard operates on AST call nodes and includes explicit controls for brace formatting and the unit-suffixed %ds case, while leaving stdlib-only logging modules outside its scan.

Freshness warning: Package freshness checked 2026-11-11T15:38:58.574960+00:00: STALE: included heads/eligibility changed; see overview and freshness audit before posting. This report applies only to its pinned SHA.

Severity Count
🔴 Critical 0
🟠 High 0
🟡 Medium 0
🟢 Minor 0

Findings

No retained findings. This is not a guarantee that the code is defect-free.


Review metadata and audit

Draft review for human approval. Nothing has been posted to GitHub.

Pinned head SHA: ec69e1456c7cd478c9422a6a914f285e2f41efa4

Package freshness checked 2026-11-11T15:38:58.574960+00:00: STALE: included heads/eligibility changed; see overview and freshness audit before posting. This report applies only to its pinned SHA.

PR: #479

Title: fix(logging): convert loguru printf-style calls to {} (fixes #458)

Author: gauravkr2209 · Branches: fix-458-loguru-printf → main

Diff merge base: 42c5711

Review scope: Full merge-base 42c5711 to pinned head ec69e14 diff against main: four production Python files and the new logging guard. Reviewed both completed reports and the complete pinned diff. PR #472 addresses overlapping logging fixes independently; do not apply both conversions blindly.

Eligibility: Bug fix addressing existing behavior; no new feature.

Overall assessment (audit only)

All 19 production Loguru conversions preserve arguments and correctly interpolate their values. No substantiated introduced production bug or current CI failure remains after reconciliation.

Strength evidence

  • {"strength_index": 0, "path": "chunkhound/providers/llm/codex_cli_provider.py; chunkhound/services/search/multi_hop_strategy.py", "source": "pr-479.pinned.diff", "detail": "The pinned hunks replace format strings without changing call arguments, including 'Codex CLI timeout on attempt {} after {}s' and the result_limit diagnostics."}
  • {"strength_index": 1, "path": "tests/test_loguru_format_guard.py", "source": "pr-479.pinned.diff", "detail": "find_printf_loguru_calls walks ast.Call nodes; test_scanner_catches_printf_style_and_ignores_braces includes %ds and brace controls, and the package scan skips sources without loguru. This is specific coverage, not a claim of an exhaustive logging analyzer."}

Verification

  • Sonnet: UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync python -m pytest -p no:cacheprovider --basetemp /tmp/chunkhound-pr-479-sonnet-a1-k8noq76y/bt tests/test_loguru_format_guard.py -q (120s timeout): 2 passed in 0.46s.
  • Astra: timeout 45s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest -p no:cacheprovider --basetemp=/tmp/chunkhound-pr-479-astra-a1-t54o70w9/pytest-guard tests/test_loguru_format_guard.py: exit 0, 2 passed in 0.47s.
  • Astra: timeout 75s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 CHUNKHOUND_CODEX_DEBUG=1 uv run --no-sync pytest -p no:cacheprovider --basetemp=/tmp/chunkhound-pr-479-astra-a1-t54o70w9/pytest-codex tests/unit/test_codex_cli_provider.py tests/unit/test_codex_stdin_first.py tests/unit/test_codex_overlay_cleanup.py tests/unit/test_codex_error_redaction.py: exit 1, 21 setup errors from missing chunkhound_native.chunkhound_native.
  • Astra: timeout 120s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync mypy chunkhound --cache-dir=/tmp/chunkhound-pr-479-astra-a1-t54o70w9/mypy-cache: exit 1, 993 errors in 89 files. Repeated with --shadow-file for all four changed production files exported at merge base and a separate cache; output byte-for-byte identical (diff exit 0). Exact full baseline command retained in Astra report/provenance. Sonnet independently reported the same diagnostic counts without a baseline comparison.
  • Astra: timeout 30s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync python /tmp/chunkhound-pr-479-astra-a1-t54o70w9/check_logging.py: exit 0; all 19 conversions render correctly with unchanged arguments/kwargs, and the guard detects their merge-base equivalents.
  • Reconciler read the complete 311-line pinned diff; git rev-parse HEAD matched and sha256sum matched both report hashes. An inline UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync python script loaded the guard with runpy and executed logger.debug("missing for %s" % "demo.py"): guard flagged it, installed Loguru rendered missing for demo.py, exit 0.
  • Reconciler verified both runner jobs succeeded; provenance valid=true, clean successful completion, pinned head/merge base, raw-report SHA256, and every assistant_messages provider/model/responseModel identity; two distinct backend models confirmed. Worktree HEAD matches manifest.

Limitations

  • No full suite or native-enabled database/indexing validation was run. Codex tests were blocked at setup by the absent native extension, not shown to regress in this PR.
  • Mypy does not pass; Astra baseline comparison found no new diagnostics. Reviewer commands/outcomes are attributed to their completed reports, not claimed as fresh reconciler test runs.
  • CI is a captured snapshot, not a fresh run or a guarantee of current branch status.
  • Model identities are verified declarations supplied by the reconciler; the renderer does not inspect raw reports or provenance events.

Disposition of discarded / merged findings

  • Rejected Astra Minor candidate at tests/test_loguru_format_guard.py:83-86: eager Python percent interpolation is indeed valid and the comment is misleading, as independently reproduced. However, this only restricts a prospective formatting style in the new guard; no current source or supported runtime contract breaks. Under the requested actionable-bug-only scope this is optional guard-policy/documentation cleanup, not a retained defect.
  • Rejected Sonnet guard blind spots (logger aliases, exception, additional percent specifiers) and silent SyntaxError handling: no actual current violation or regression was demonstrated; these are potential future guard hardening, not actionable introduced failures.

Independent reviewer provenance

  • sonnet — provider: amat-tfy; requested model: standard-chat-dev/claude-sonnet-5.5; verified response model: aws-aidev-models/us.anthropic.claude-sonnet-5-5. Identity evidence · Raw report
  • astra — provider: amat-tfy; requested model: frontier-chat-dev/gpt-6-astra; verified response model: gpt-6-astra. Identity evidence · Raw report

CI snapshot

Captured: 2026-11-11T14:18:23.581921+00:00. Eligibility green: True. Counts: {"SKIPPED": 2, "SUCCESS": 23}

Reviewed by Ariel Vaknin via pi.dev

…ff_aware_search_service.py and codex_cli_provider.py
…ff_aware_search_service.py and codex_cli_provider.py
…ff_aware_search_service.py and codex_cli_provider.py
@ofriw

ofriw commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Please resolve the merge conflicts so we can merge this 🙏 @VakninAriel next time, please merge with your approval so the PR doesn't drift 🙏

This branch has not been deployed

No deployments
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.

4 participants