Improve error handling resilience across extractors and parsers
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
1.16.1
Cloud or Self Hosted
Self Hosted (Docker), Self Hosted (Source)
Steps to reproduce
This is a preventative maintenance issue discovered via proactive code review. There are no specific end-user steps to reproduce a crash, but the oversights can be observed directly in the codebase:
api/core/rag/extractor/notion_extractor.py: The_get_notion_block_dataand_read_blockmethods use an unboundedwhile True:loop for pagination without a safety limit.api/core/moderation/output_moderation.py: Theexcept Exception:block logs an error but doesn't clarify that the design intentionally fails open.api/core/agent/output_parser/cot_output_parser.py: A bareexcept:is used to catch JSON parsing errors, which also catches system signals.api/core/tools/tool_manager.py: Tool credential parsing failures are swallowed without any logging.
✔️ Expected Behavior
- Extractors should have sensible pagination limits (e.g., max_pages = 1000) to prevent infinite loops (OOM / CPU lockup).
- Moderation failure logs should clearly indicate the intentional fail-open behavior to operators.
- Parsers should only catch specific application exceptions (e.g. json.JSONDecodeError, ValueError).
- Silent credential fallbacks should emit a warning log for operator visibility.
❌ Actual Behavior
- Unbounded
while Trueloop can run infinitely if the Notion API returns unexpected cursor states. - Log message is vague (
"Moderation Output error") and could cause operators to think the app crashed. - Bare
except:catchesKeyboardInterruptandSystemExit, preventing graceful shutdowns. - Credential parsing silently falls back to
{}with no log, making debugging broken tool auth impossible.
One detail that may help narrow this down: in the reported 1.16.1 tag, both json.loads calls in cot_output_parser.py are already inside exception handlers. parse_action catches JSONDecodeError, and extra_json_from_code_block catches parsing failures and returns an empty list. The other three listed files contain no json.loads calls at that tag. The same two parser calls are guarded on current main as well.
Reported-version parser: https://github.com/langgenius/dify/blob/6f8ed69ee15f9a2e7189ca066275e973d091d1e9/api/core/agent/output_parser/cot_output_parser.py#L15-L53
Current parser: https://github.com/langgenius/dify/blob/e5acabc3d529887d15e7836560d64ce1f06a3114/api/core/agent/output_parser/cot_output_parser.py#L15-L53
Could you share the exact commit, plus a minimal failing input and traceback with secrets and personal data removed? That should help locate which path actually escapes handling. This is source inspection only; I haven't reproduced a runtime failure.