Repository navigation
fix(agents): handle unresolvable task_data IDs - #595
Open
rohanbuilds-ai wants to merge 1 commit into
Open
rohanbuilds-ai wants to merge 1 commit into
rohanbuilds-ai wants to merge 1 commit into
Conversation
…t#589) - Gracefully handle missing/unresolvable vendor_id and invoice_id in specialized prompt builders - Move BaseAgent pre-loop setup into protected execution block - Return structured task_status='failed' instead of raising unhandled exceptions - Ensure MCP disconnection and workflow context cleanup in finally block even on setup failure - Add comprehensive regression tests for agent error handling
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
vendor_idandinvoice_idin specialized agent prompt construction (VendorOnboardingAgent,InvoiceAgent).BaseAgentsetup steps (_connect_mcp_servers,_get_user_prompt, workflow context registration) so unexpected failures return a structuredtask_status="failed"result instead of raising unhandled exceptions out ofprocess().finallyeven if setup fails or if disconnecting MCP servers raises an error.Root Cause
When
task_datacontains an unresolvable ID (such as a string like"invalid_vendor_id"or an ID not present in the database), specialized agents'_get_user_prompt()calledget_vendor_detailsorget_invoice_details, which raised exceptions before entering_run_agent_loop's main iterationtryblock. This resulted in an unhandled exception escapingprocess(), skipping proper task completion logging, MCP server cleanup, and workflow context clearing.Changes Made
finbot/agents/specialized/onboarding.py:vendor_idtointwhen present intask_data.(ValueError, TypeError)and log a warning if coercion fails or details cannot be retrieved, allowing prompt construction to proceed with empty vendor context rather than crashing.finbot/agents/specialized/invoice.py:invoice_idtointwhen present intask_data.(ValueError, TypeError)and log a warning if coercion fails, allowing prompt construction to proceed with empty invoice context.finbot/agents/base.py:_connect_mcp_servers, prompt generation, workflow context registration) inside a protectedtry/exceptblock that returns a structured{"task_status": "failed", "task_summary": "Agent setup failed: ..."}and logs task completion.finallyblock with separatetry/exceptguards for_disconnect_mcp_servers()andevent_bus.clear_workflow_context()to guarantee context cleanup even if MCP disconnect fails.tests/unit/agents/test_agent_error_handling.py:BaseAgentsetup exception catching and structuredfailedstatus return.Verification
uv run pytest tests/unit/agents/test_agent_error_handling.py -v: 12 passed in 0.65s.uv run pytest tests/unit/agents/test_base_agent.py -v: 12 passed in 0.60s.uv run pytest tests/unit/agents/test_specialized_agents.py -k "test_sai_von_005_onboarding_tracking" -v: 1 passed.origin/mainbaseline (commit1450fc4):test_sai_edge_001_invoice_agent_empty_task_data_prompt(unawaited coroutine in test, tracked in PR test(agents): await _get_user_prompt in the two SAI-EDGE prompt tests #588)test_sai_edge_002_vendor_agent_empty_task_data_prompt(unawaited coroutine in test, tracked in PR test(agents): await _get_user_prompt in the two SAI-EDGE prompt tests #588)test_sqlite_url_from_db_path(Windows backslash vs forward slash path formatting in test assertion)uv run isort --check-only: Clean.git diff --check: Clean (no trailing whitespace or whitespace errors).