fix(hitl): log pre-review failures and add learn_strict mode (closes #5725)#5726
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
fix(hitl): log pre-review failures and add learn_strict mode (closes #5725)#5726devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
Closes #5725. In _pre_review_with_lessons (lib/crewai/src/crewai/flow/human_feedback.py), a broad except Exception: return method_output silently swallowed any LLM, network, auth, or structured-output failure during the pre-review step. Callers could not distinguish pre-reviewed output from raw output, and there was no log or event surfaced. Changes: - Add a module logger. - Narrow the try/except in _pre_review_with_lessons so the mem is None and not matches short-circuits stay outside the failure path (those are not error cases). - On recall or LLM pre-review failure, log a WARNING with exc_info=True so the silent fallback is observable. Continue to fall back to the raw method_output so the flow does not break. - Add an opt-in learn_strict=True parameter on the human_feedback decorator and HumanFeedbackConfig that re-raises pre-review failures instead of falling back, for callers that need fail-closed behavior. - Update the Graceful degradation docs section to reflect the new observable-by-default behavior and document learn_strict. Tests (lib/crewai/tests/test_human_feedback_decorator.py): - New TestHumanFeedbackPreReviewFailure class with 7 tests covering WARNING logging on LLM and recall failures, learn_strict propagation in both sync and async paths, and config introspection of the new learn_strict flag. Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #5725.
@human_feedback(..., learn=True)runs_pre_review_with_lessonsto apply past HITL lessons via an LLM before the human sees the output. Today, that helper wraps the entire pre-review path in a broadexcept Exception: return method_output, which swallows LLM/network/auth/structured-output errors with no log, no event, and no return signal — callers cannot distinguish a pre-reviewed output from a raw one.This PR makes the failure observable by default, and adds opt-in fail-closed behavior:
lib/crewai/src/crewai/flow/human_feedback.pylogging.getLogger(__name__)).try/exceptin_pre_review_with_lessonsso themem is Noneandnot matchesshort-circuits stay outside the failure path (those are not errors).memory.recallfailure or pre-review LLM failure, logWARNINGwithexc_info=Trueso the silent fallback is detectable. By default the flow still falls back to the rawmethod_outputand continues — we don't change the default fail-open contract.learn_strict: bool = Falseto thehuman_feedbackdecorator andHumanFeedbackConfig. Whenlearn_strict=True, recall/pre-review failures are re-raised instead of falling back, for callers that need fail-closed behavior.docs/en/learn/human-feedback-in-flows.mdxWARNINGwith traceback and to introduce thelearn_strictparameter.lib/crewai/tests/test_human_feedback_decorator.pyTestHumanFeedbackPreReviewFailureclass with 7 tests:exc_info, raw output shown to human;memory.recallfailure → WARNING logged withexc_info, raw output shown to human;learn_strict=True→ pre-review LLMRuntimeErrorpropagates;learn_strict=True→ recallRuntimeErrorpropagates;exc_info, raw output shown to human;learn_strict=True→ pre-review LLMRuntimeErrorpropagates;learn_strictdefaults toFalseand round-trips throughHumanFeedbackConfig.Behavior outside the pre-review step (distillation, outcome collapse, resume
emitfallback, listener failures) is intentionally untouched — issue #5725 is scoped only to pre-review.All 40 tests in
test_human_feedback_decorator.pypass locally.ruff check,ruff format --check, andmypyon the modified file are clean.Review & Testing Checklist for Human
learn_strictdecorator argument name matches your preferred public API surface (the issue suggested it as one option; alternatives likepre_review_strictor a separatestrict=flag would be one-line renames).learn_strictwould just need to be flipped (and one test inverted)."HITL pre-review failed for %s; falling back to raw output."and"HITL pre-review: memory recall failed for %s; falling back to raw output.") — these will show up in user logs.docs/en/learn/human-feedback-in-flows.mdx— only the English doc was updated; the pt-BR/ko/ar mirrors still describe silent degradation. Happy to follow up with translations if you'd like them in this PR.Notes
@human_feedback(learn=True)+ seeded memory + LLM raising during pre-review) now produces a singleWARNINGunder thecrewai.flow.human_feedbacklogger with full traceback, instead of silent passthrough._pre_review_with_lessons. Distillation's existingexcept Exception: passremains untouched per the issue's "out of scope" note, but it would be a natural follow-up to give it the same WARNING-on-failure treatment.Link to Devin session: https://app.devin.ai/sessions/8615574d124449a5a1b09ea4d1fd88bd