fix: propagate AddResult failures and log embedding errors (#2821)#2830
fix: propagate AddResult failures and log embedding errors (#2821)#2830muhamedfazalps wants to merge 1 commit into
Conversation
β¦ison#2821) - knowledge.py: Check AddResult.success before appending ID to results; log warning when embedding/storage fails instead of silently counting failed chunks as successes - factories.py: Log embedding exceptions at WARNING level in both ChromaKnowledgeAdapter.add() and .search() instead of silently swallowing them This fixes the issue where `praisonai index` reports success but Chroma stays empty when embedding fails, and where `praisonai search` returns empty results with no explanation.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more β On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
No actionable comments were generated in the recent review. π βΉοΈ Recent review infoβοΈ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: π Files selected for processing (2)
π WalkthroughWalkthroughEmbedding exception handlers in ChromaKnowledgeAdapter's search and add methods now bind and log the caught exception as a warning instead of silently ignoring it. Knowledge._process_single_input now appends a memory id to results only when the returned AddResult.success is truthy, logging a warning otherwise. ChangesEmbedding failure handling
Estimated code review effort: 2 (Simple) | ~10 minutes π₯ Pre-merge checks | β 4 | β 1β Failed checks (1 warning)
β Passed checks (4 passed)
β¨ Finishing Touchesπ§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request improves error handling and logging by capturing exceptions during embedding generation in the search and add adapters, and by checking for success before storing chunks in the knowledge processing pipeline. The review feedback recommends adhering to PEP 8 by moving the inline logging imports to the top of the file, and suggests adding 'exc_info=True' to the warning logs to preserve the full stack trace for easier debugging.
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.
| except Exception as e: | ||
| import logging | ||
| logging.getLogger(__name__).warning("Embedding failed for search: %s", e) | ||
| query_embedding = None |
There was a problem hiding this comment.
To adhere to the PEP 8 style guide, imports should be placed at the top of the file rather than inline within exception blocks.
Additionally, when catching general exceptions during embedding, it is highly recommended to include 'exc_info=True' in the log call. This ensures that the full stack trace is preserved in the logs, which is crucial for diagnosing the root cause of embedding failures (e.g., API authentication issues, network timeouts, or rate limits).
| except Exception as e: | |
| import logging | |
| logging.getLogger(__name__).warning("Embedding failed for search: %s", e) | |
| query_embedding = None | |
| except Exception as e: | |
| import logging | |
| logging.getLogger(__name__).warning("Embedding failed for search: %s", e, exc_info=True) | |
| query_embedding = None |
References
- PEP 8: Imports should be placed at the top of the file, just after any module comments and docstrings, and before module globals and constants. (link)
| except Exception as e: | ||
| import logging | ||
| logging.getLogger(__name__).warning("Embedding failed for add: %s", e) | ||
| content_embedding = None |
There was a problem hiding this comment.
To adhere to the PEP 8 style guide, imports should be placed at the top of the file rather than inline within exception blocks.
Additionally, when catching general exceptions during embedding, it is highly recommended to include 'exc_info=True' in the log call. This ensures that the full stack trace is preserved in the logs, which is crucial for diagnosing the root cause of embedding failures (e.g., API authentication issues, network timeouts, or rate limits).
| except Exception as e: | |
| import logging | |
| logging.getLogger(__name__).warning("Embedding failed for add: %s", e) | |
| content_embedding = None | |
| except Exception as e: | |
| import logging | |
| logging.getLogger(__name__).warning("Embedding failed for add: %s", e, exc_info=True) | |
| content_embedding = None |
References
- PEP 8: Imports should be placed at the top of the file, just after any module comments and docstrings, and before module globals and constants. (link)
|
@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Focus ONLY on Python packages (praisonaiagents, praisonai). Do NOT modify praisonai-rust or praisonai-ts. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding. Phase 1: Review per AGENTS.md
Phase 2: FIX Valid Issues Phase 3: Final Verdict |
|
Claude finished @MervinPraison's task ββ View job Final Architecture Review β PR #2830 β Approved
Phase 1 β Architecture Review (per AGENTS.md)
Phase 2 β Fixes AppliedValid reviewer feedback (Gemini):
Files modified:
Skipped (with rationale):
Phase 3 β VerdictApproved. The core bug fix is correct, minimal, backward-compatible, and adds real SDK value (accurate index accounting + actionable embedding diagnostics). Greptile 4/5 and CodeRabbit found no actionable code issues. The only outstanding item (CLI non-zero exit) belongs to a package not in this fork and is properly tracked as a follow-up β non-blocking for this PR. Syntax validated on both changed files. Pushed 1 commit ( --- β’ Branch: |
|
@claude this PR has merge conflicts with |
|
Claude finished @MervinPraison's task ββ View job Rebase & Conflict Resolution β Complete β
Files resolved (2)
Skipped / Notes
Validation
--- β’ Branch: |
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2830 +/- ##
==========================================
+ Coverage 27.15% 29.15% +1.99%
==========================================
Files 635 598 -37
Lines 94451 69205 -25246
Branches 15159 0 -15159
==========================================
- Hits 25649 20177 -5472
+ Misses 68693 49028 -19665
+ Partials 109 0 -109
Flags with carried forward coverage won't be shown. Click here to find out more. β View full report in Codecov by Harness. π New features to boost your workflow:
|
|
@claude this PR has merge conflicts with main. Please rebase onto latest main, resolve conflicts (keep this PR's intent, merge in newer main logic), run targeted tests, and force-push with --force-with-lease. Comment which files you resolved. Do not bloat the Agent class with additional params β only if absolutely required; we already support many params. |
|
Claude finished @MervinPraison's task ββ View job Rebase & Conflict Resolution β Complete β
Files resolved (2)
Skipped / Notes
Validation
--- β’ Branch: |
|
@muhamedfazalps can you please rebase and fix merge conflicts |
Summary
Fixes #2821 β
praisonai indexreports success but Chroma stays empty when embedding fails.When embedding fails (e.g., model access denied, API key issues), the current code silently swallows the error and counts failed chunks as successes. This PR fixes the root cause across the knowledge pipeline.
Changes
1.
knowledge.pyβ CheckAddResult.successbefore appending (line ~542)Before:
AddResult(success=False, id="")was truthy, soif memory_result:passed and the empty ID was appended to results, making the index command report "1 chunk" when 0 were actually stored.After: Checks
memory_result.successbefore appending, and logs a warning with the failure message.2.
factories.pyβ Log embedding errors (lines ~148, ~227)Before: Embedding exceptions were caught with bare
except Exception:, setting the embedding toNonewith no log output. Users had no way to know why indexing or searching failed.After: Captures the exception as
eand logs it at WARNING level:"Embedding failed for add/search: %s". This gives users actionable diagnostic information.3.
retrieval.pyβ Filter empty IDs (referenced in issue, not in fork)The
praisonai-codepackage containingretrieval.pywas added to the upstream monorepo after this fork was created. The retrieval CLI fix (filtering empty IDs and reporting failure) should be applied tosrc/praisonai-code/praisonai_code/cli/commands/retrieval.pyas a follow-up.Impact
praisonai indexexits 0 with "β 1 chunks" when embedding fails; Chroma has 0 documents;praisonai searchsilently returns empty resultsAcceptance criteria from issue
praisonai indexno longer reports false success for failed chunkspraisonai indexexits non-zero when all chunks fail (requiresretrieval.pyfix β see note above)Summary by CodeRabbit