ContextualAIParseTool can poll forever when a parse job never reaches a terminal state
Summary
ContextualAIParseTool._run() submits a Contextual AI parse job and then polls its status in an unconditional while True loop:
status_url = f"{base_url}/parse/jobs/{job_id}/status"
while True:
result = requests.get(status_url, headers=headers, timeout=30)
parse_response = json.loads(result.text)["status"]
if parse_response == "completed":
break
if parse_response == "failed":
raise RuntimeError("Document parsing failed")
sleep(5)
Each individual GET has a 30-second request timeout, but there is no bound on the number of polls or total elapsed time. If the remote job remains in a non-terminal state such as pending/processing indefinitely, the CrewAI tool invocation never returns.
Why this matters
Tool-level HTTP timeouts only bound one request; they do not bound an asynchronous job lifecycle. A stuck upstream job can therefore hold an agent task indefinitely, which is particularly problematic for autonomous crews where the tool call may block subsequent steps.
Expected behavior
The parser should enforce a configurable or documented maximum polling duration / attempt count and return a clear timeout error when that budget is exhausted.
For example, a narrow implementation could use a monotonic deadline:
from time import monotonic, sleep
poll_timeout = 300
started = monotonic()
while True:
...
if monotonic() - started >= poll_timeout:
raise TimeoutError(
f"Document parsing did not complete within {poll_timeout}s"
)
sleep(5)
A max-attempts approach would also work. Ideally the budget should be configurable on the tool while preserving the current polling interval by default.
Related request-boundary hardening
The same polling path parses response bodies with json.loads(result.text) without calling raise_for_status(). A 4xx/5xx response containing JSON with a different shape can currently surface as KeyError('status') rather than a clear HTTP failure. This can be handled separately if maintainers prefer keeping the polling-deadline change narrowly scoped.
Regression coverage
A deterministic test can mock:
- the submit request returning a job id;
- repeated status responses returning
processing; - a monotonic clock crossing the configured deadline;
and assert that _run() returns/fails with a bounded timeout instead of continuing to poll. A second case can verify that completed still exits normally before the deadline.
I searched the current CrewAI issue and PR trackers for this specific ContextualAI parse polling-deadline problem and did not find an existing report.
AI-assisted review disclosure: an AI coding assistant was used to inspect the polling control flow and help prepare this source-backed report.
I hit an unbounded-polling loop like this myself — same failure class: async job status treated as if the outer HTTP timeout bounds the whole lifecycle, when it only bounds one GET.
Root cause, in the issue's own terms: "Each individual GET has a 30-second request timeout, but there is no bound on the number of polls or total elapsed time." The while True only exits on completed or failed strings from the upstream response — if Contextual AI ever returns something else indefinitely (stuck job, a status value that's neither, or silently keeps returning pending), the loop has no exit condition of its own. It's borrowing a per-request timeout and treating it as a job-level one, which is a category error.
The deterministic check that would've caught this pre-merge: assert, at the polling boundary itself, that _run() raises within a bounded wall-clock budget when every mocked status response returns processing with no request-level exception. Concretely — mock requests.get to always return {"status": "processing"}, patch time.monotonic to advance past a fixed deadline (or use freezegun), call _run(), and assert it raises TimeoutError/similar rather than blocking. That's a contract on the loop's exit condition, not on the HTTP client. No such test can exist today because the code has no deadline to assert against — the absence of a testable exit condition is the bug.
Uncertainty: I haven't checked whether crewAI has a global tool-execution timeout wrapper upstream that already kills long-running _run() calls at the crew/task level — if so this is a defense-in-depth gap rather than a true unbounded hang, and that would soften the severity.
Advisory SFA-2026-250CF91160 · Full redacted write-up: https://impartshadow.github.io/echo-site/failure-cases/contextualaiparsetool-can-poll-forever-when-a-parse-250cf91160.html If this diagnosis is useful, react 👍 to this comment; if it is wrong, react 👎 — I use the verdict to choose what I investigate next.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
I rechecked the current parser implementation: _run() still has a while True status loop that exits only for completed or failed; timeout=30 bounds each request, not the whole polling lifecycle.
I also ran an isolated probe of that method with mocked HTTP and sleep. After 100 processing responses and 500 seconds of simulated sleeps, it attempted poll 101 and stopped only because of the probe's external guard. No real requests or waits were used. This verifies the method's control flow, not the full CrewAI execution stack.
@Vidit-Ostwal, could this issue be reopened/triaged, and could #7444 be reconsidered? That PR was closed because the linked issue was closed, and it already proposes a polling deadline and regression tests. I can help validate that existing work once maintainers confirm the path forward.