Skip to content

fix(logging): use Loguru placeholders and prevent printf regressions - #472

Open
shizwan wants to merge 7 commits into
chunkhound:mainfrom
shizwan:fix/loguru-printf-placeholders
Open

shizwan wants to merge 7 commits into
chunkhound:mainfrom
shizwan:fix/loguru-printf-placeholders

Conversation

@shizwan

@shizwan shizwan commented Nov 2, 2026

Copy link
Copy Markdown

No description provided.

@HananKavitzAmat

Copy link
Copy Markdown
Collaborator

Summary: The placeholder conversions are correct, but the PR leaves one printf placeholder unconverted (%ds), and the new regression test passes anyway because of a regex bug. The guard doesn't catch
the case it was written for.

Review groups:

  1. Placeholder conversions in 5 production files (duckdb_provider, codex_cli_provider, diff_aware_search_service, indexing_coordinator, multi_hop_strategy). Each change is the same mechanical rewrite.
  2. The new regression guard, tests/unit/test_loguru_formatting.py.

The PR is small (+87/−24), so I reviewed both groups myself instead of spawning reviewers.

Limitations: the gh tokens on this machine are invalid (401), and unauthenticated API calls were rate-limited. That meant I couldn't read the PR description, comments or review history. I fetched
pull/472/head with git and reviewed the diff, the surrounding code, ruff output, and a direct run of the test function. Pytest itself couldn't run the test because the chunkhound_native module wasn't
built in my worktree; that is my environment, not the PR.

Strengths:

  • Every conversion I checked is correct: %s/%d became {} and %r became {!r}. No message contains literal braces that the formatter would misread.
  • The guard only checks files that import logger from loguru (aliases included), so stdlib logging users like mcp_server/tools.py can keep % formatting.
  • The test is a cheap static AST scan with no runtime dependencies, which suits a repo-wide rule like this.

Issues:

  • Major
    • chunkhound/providers/llm/codex_cli_provider.py:699: "Codex CLI timeout on attempt {} after %ds" still has %ds. In that log line the timeout value is never filled in, and readers see a literal %ds.
    • tests/unit/test_loguru_formatting.py:13: the regex %(?:\d+(?:.\d+)?)?[sdrf]\b requires a word boundary after the placeholder. That fails whenever a letter follows, as in %ds or %5.1fs. I
      confirmed that running the test function on this branch passes even with the leftover above. The regex also ignores %i, %x, %e, %g and flags such as %-5s. A sturdier pattern would be %[-+
      #0]*(\d+|*)?(.\d+)?[sdifrxXeEgGc] with no \b.
  • Minor
    • test_loguru_formatting.py:55: for logger.log(level, msg, ...) the message is the second argument, but the test always reads node.args[0], which is the level. So log calls are never really checked
      even though "log" is in _LOG_METHODS.
    • The new test fails ruff: an unsorted import block (I001), a 93-character line at :56 (E501), and it needs ruff format. diff_aware_search_service.py:151 grows to 90 characters, adding one new E501.
    • indexing_coordinator.py:1551 (touched by this PR, and also :607, :1080, :1203): exc_info=True is stdlib syntax. Loguru treats it as a formatting keyword, so no traceback is attached. The repo
      already uses logger.opt(exception=True) in capability_cache.py:186 and recorder.py:186. This predates the PR, but it sits on a line the PR changed.
    • The history has 5 identical "fix: use Loguru format placeholders…" commits plus a style fix; squash on merge.

Reusability:

  • Once fixed, the test regex and the AST walk could live in a shared lint-style test helper or a ruff/pre-commit check. That could also cover the exc_info= misuse and log_if_not_mcp(...) messages, which
    go through Loguru as well (utils/logging_guard.py).
  • In the same pass, switch the exc_info=True calls to the existing logger.opt(exception=True) pattern rather than inventing a new one.

Decision: REQUEST CHANGES. Fix %ds at codex_cli_provider.py:699, fix the test regex and the log argument index so the guard actually catches leftovers, and clean up the ruff findings.

@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 #472

Verdict: ✅ Approve

Summary

Several Loguru calls used printf-style placeholders, causing logs to omit the diagnostic values passed as arguments. This PR replaces those placeholders with brace formatting across provider, indexing and search code and adds an AST-based regression guard.

What's good

  • The conversions restore concrete diagnostic context for Codex request/transport failures and multi-hop result limits, including {!r} where a representation-formatted value is intended.
  • The guard derives logger names from actual from-loguru imports, including aliases, so it does not apply Loguru placeholder rules indiscriminately to stdlib logger calls.

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: 35eea333ac310072e91ec2efbc6a81d49f1a47ae

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: #472

Title: fix(logging): use Loguru placeholders and prevent printf regressions

Author: shizwan · Branches: fix/loguru-printf-placeholders → main

Diff merge base: f4d5b85

Review scope: Full merge-base f4d5b85 to pinned head 35eea33 diff against main: five production files and tests/unit/test_loguru_formatting.py. Both complete reports and entire pinned diff inspected. This independently overlaps PR #479 logging conversions; coordinate the alternatives rather than stacking duplicate fixes.

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

Overall assessment (audit only)

No substantiated introduced user-facing regression remains. Production interpolation improves; the new guard misses an existing unit-suffixed placeholder, but this is incomplete coverage of preexisting logging debt rather than a newly broken runtime or enforced CI contract. Preserve the concrete counterexample as optional nonblocking cleanup, not a ready-to-post bug.

Strength evidence

  • {"strength_index": 0, "path": "chunkhound/providers/llm/codex_cli_provider.py; chunkhound/services/diff_aware_search_service.py; chunkhound/services/search/multi_hop_strategy.py", "source": "pr-472.pinned.diff", "detail": "Request/transport/result-limit strings use brace placeholders, and the Codex model warning and diff-aware vector_source diagnostic use {!r}. The remaining %ds timeout fragment is intentionally not praised as repaired."}
  • {"strength_index": 1, "path": "tests/unit/test_loguru_formatting.py", "source": "pr-472.pinned.diff", "detail": "logger_names is built from ast.ImportFrom nodes with module == 'loguru' and alias.asname or alias.name, and calls are checked against that set. This scoped import handling does not make the placeholder regex exhaustive."}

Verification

  • 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-472-astra-a1-af3b_6m5/mypy-cache: exit 1, 994 errors in 90 files. Repeated with all five changed production files exported from merge base via --shadow-file and --cache-dir=/tmp/chunkhound-pr-472-astra-a1-af3b_6m5/mypy-base-cache: byte-identical diagnostics (cmp exit 0). Exact shell baseline command retained in Astra report/provenance.
  • Astra: timeout 60s 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-472-astra-a1-af3b_6m5/pytest-guard tests/unit/test_loguru_formatting.py: exit 1, one setup error due to missing chunkhound_native.chunkhound_native; body not executed. Sonnet likewise could not execute the test normally.
  • Astra: timeout 60s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest --noconftest -p no:cacheprovider --basetemp=/tmp/chunkhound-pr-472-astra-a1-af3b_6m5/pytest-guard-isolated tests/unit/test_loguru_formatting.py: exit 0, 1 passed in 0.57s; only self-contained AST guard verified.
  • Reconciler independently executed the self-contained guard body and regex/Loguru probe described in finding evidence, exit 0; read the complete pinned diff and both reports.
  • 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

  • Normal test setup is blocked by the absent native module; isolated guard execution bypasses that fixture and is not application integration validation. No full suite was run.
  • Mypy remains failing at baseline; Astra demonstrated no new diagnostics. Sonnet piped output through tail, so its shell exit 0 was not a passing typecheck.
  • 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

  • Final audit reclassifies the merged guard-gap candidate as a nonblocking observation and preserves its complete counterexample/evidence above. A newly written internal test missing an already-broken printf token does not by itself introduce a user/caller/CI failure. The timeout placeholder predates the PR and the changed call improves attempt interpolation. This is optional coverage cleanup, not grounds for Needs Work under meaningful-actionable-bug scope; consistent with rejecting #479 guard-policy nits.
  • Rejected Sonnet separate Medium runtime finding at codex_cli_provider.py:699 as introduced-bug attribution: %ds is unchanged from merge base; the PR improves attempt interpolation but does not newly lose the timeout. Mentioned only as evidence and associated fix for the new guard.
  • Discarded additional proposed guard expansion (all conversion types, logger.log positional handling, f-strings/percent expressions) as speculative follow-up without another concrete missed supported call in the current tree; no separate findings.

Nonblocking observations (audit only)

  • {"title": "Recognize unit-suffixed printf tokens in the new regression guard", "severity": "Minor", "path": "tests/unit/test_loguru_formatting.py", "line_start": 13, "line_end": 13, "description": "The trailing word-boundary requirement after [sdrf] makes the new guard miss %ds, %dms and similar unit-suffixed conversions. This is not merely hypothetical: codex_cli_provider.py:699 still contains \"Codex CLI timeout on attempt {} after %ds\" and the new package-wide test passes while Loguru renders a literal %ds instead of the timeout value. When CHUNKHOUND_CODEX_DEBUG is enabled and execution times out, that existing missing diagnostic remains undetected. The introduced defect is the guard false negative; the unconverted runtime %ds predates this PR.", "suggested_fix": "Parse printf conversion tokens without requiring a word boundary after the conversion letter. Cover %ds and %dms with focused guard cases, and finish the timeout message conversion to {}s so the strengthened guard passes.", "evidence": ["Reconciler loaded tests/unit/test_loguru_formatting.py with runpy and executed the actual test body: passed. _PRINTF_PLACEHOLDER.search(\"%ds\") returned no match; installed Loguru emitted \"Codex CLI timeout on attempt 1 after %ds\" for arguments 1,30. UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync python inline probe exited 0.", "Pinned diff shows the regex newly introduced at line 13 and the timeout changing from \"attempt %d after %ds\" to \"attempt {} after %ds\" at line 699. Thus runtime suffix defect is preexisting, while guard coverage failure is new.", "Astra independently reproduced the exact false negative and ran the guard with --noconftest: 1 passed. Sonnet independently reproduced unit/precision/flag regex misses."], "reviewers": ["sonnet", "astra"], "id": 1}

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

@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