Skip to content

refactor: improve exception logging for embedding utilities#765

Merged
vitali87 merged 3 commits into
vitali87:mainfrom
Shashank23123458867504:refactor/improve-exception-logging
Jul 17, 2026
Merged

refactor: improve exception logging for embedding utilities#765
vitali87 merged 3 commits into
vitali87:mainfrom
Shashank23123458867504:refactor/improve-exception-logging

Conversation

@Shashank23123458867504

Copy link
Copy Markdown
Contributor

Summary

  • Replace generic error logging with logger.exception() in embedding utilities.
  • Improve exception messages during UniXcoder model initialization and embedding generation.
  • Preserve existing functionality while improving debugging and observability.

Type of Change

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring (no functional changes)
  • Documentation
  • CI/CD or tooling
  • Dependencies

Related Issues

N/A

Test Plan

  • Unit tests pass (make test-parallel or uv run pytest -n auto -m "not integration")
  • New tests added
  • Integration tests pass (make test-integration, requires Docker)
  • Manual testing (describe below)

Manual Testing

  • Verified successful UniXcoder model initialization.
  • Verified code embeddings are generated successfully.
  • Verified exceptions now include complete stack traces via logger.exception().
  • Confirmed no functional changes to the embedding workflow.

Checklist

  • PR title follows Conventional Commits format
  • All pre-commit checks pass (make pre-commit)
  • No hardcoded strings in non-config/non-constants files
  • No # type: ignore, cast(), Any, or object type hints
  • No new comments or docstrings (code should be self-documenting)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request wraps model initialization and code embedding logic in try-except blocks to log exceptions before re-raising them. The reviewer points out that logging and re-raising in both functions results in duplicate stack traces, suggesting the removal of the redundant block in get_model(). Additionally, the reviewer recommends updating the log formatting in embed_code() to use brace-style formatting with loguru and removing a trailing comma.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread codebase_rag/embedder.py Outdated
Comment thread codebase_rag/embedder.py Outdated
@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR improves logging around single-snippet embedding failures. The main changes are:

  • Wraps embed_code generation in logger.exception() and re-raises the original error.
  • Adds a centralized EMBEDDING_SNIPPET_FAILED log message in codebase_rag/logs.py.
  • Updates lockfile metadata for the package version and resolved mcp dependency.

Confidence Score: 5/5

Safe to merge with minimal risk.

The code change is narrowly scoped to logging, keeps exception behavior unchanged, and follows the existing centralized log-message pattern.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex produced a proof for a posted P1 finding and linked it to the review comment detailing the finding.
  • The embedder path was validated by inspecting logs: the narrow pytest run showed an environment blocker, the after-run log captured a mocked embedding generation and a tokenization call, followed by a ValueError: tokenize boom, and UniXcoder initialization was raised without a captured init traceback.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/embedder.py Wraps single-snippet embedding generation in logger.exception() while preserving cache/model behavior and re-raising failures.
codebase_rag/logs.py Adds the centralized EMBEDDING_SNIPPET_FAILED Loguru template used by the embedding exception path.
uv.lock Updates the editable package version and resolves mcp to a compatible locked version under the existing dependency constraint.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Caller
participant Embedder as embed_code
participant Cache as EmbeddingCache
participant Model as UniXcoder
participant Logger

Caller->>Embedder: embed_code(code, max_length)
Embedder->>Cache: get(code)
alt cache hit
    Cache-->>Embedder: cached embedding
    Embedder-->>Caller: embedding
else cache miss
    Embedder->>Model: tokenize and infer embedding
    Model-->>Embedder: sentence embedding
    Embedder->>Cache: put(code, result)
    Embedder-->>Caller: embedding
end
opt exception during embedding path
    Embedder->>Logger: exception(EMBEDDING_SNIPPET_FAILED, length)
    Embedder-->>Caller: re-raise original exception
end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Caller
participant Embedder as embed_code
participant Cache as EmbeddingCache
participant Model as UniXcoder
participant Logger

Caller->>Embedder: embed_code(code, max_length)
Embedder->>Cache: get(code)
alt cache hit
    Cache-->>Embedder: cached embedding
    Embedder-->>Caller: embedding
else cache miss
    Embedder->>Model: tokenize and infer embedding
    Model-->>Embedder: sentence embedding
    Embedder->>Cache: put(code, result)
    Embedder-->>Caller: embedding
end
opt exception during embedding path
    Embedder->>Logger: exception(EMBEDDING_SNIPPET_FAILED, length)
    Embedder-->>Caller: re-raise original exception
end
Loading

Comments Outside Diff (1)

  1. General comment

    P1 UniXcoder initialization failures are not logged with stack traces

    • Bug
      • When get_model() fails during UniXcoder construction, the exception propagates without any logger.exception() call or captured traceback. The validation harness patched codebase_rag.embedder.UniXcoder to raise RuntimeError('init boom'); the error was raised, but the log sink did not contain RuntimeError: init boom or any corresponding traceback.
    • Cause
      • get_model() constructs and initializes UniXcoder directly without wrapping initialization/device-selection failures in a try/except that calls logger.exception(). Only embed_code() currently logs exceptions, so direct initialization failures from get_model() are silent unless they occur under an outer caller that logs them.
    • Fix
      • Wrap the body of get_model() in try/except Exception and call logger.exception(...) with an initialization-specific log message before re-raising. Add/adjust a targeted test that patches UniXcoder to raise and asserts the emitted log contains a traceback.

    T-Rex Ran code and verified through T-Rex

Reviews (3): Last reviewed commit: "refactor: move snippet-failure log to lo..." | Re-trigger Greptile

Comment thread codebase_rag/embedder.py Outdated
@vitali87

Copy link
Copy Markdown
Owner

@greptile review

@vitali87
vitali87 force-pushed the refactor/improve-exception-logging branch from e376efe to e380365 Compare July 17, 2026 05:40
@vitali87

Copy link
Copy Markdown
Owner

@greptile review

@vitali87
vitali87 merged commit 5a654ac into vitali87:main Jul 17, 2026
1 check passed
@vitali87

Copy link
Copy Markdown
Owner

Thanks @Shashank23123458867504 for the contribution! Merged with a small maintainer follow-up commit that moved the log literal into codebase_rag/logs.py and switched it to loguru's brace/kwargs formatting per repo convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants