{"record":{"id":"37083e7803e1f857","repo":"infiniflow/ragflow","slug":"execution-timed-out-after-exec-timeout-seconds-37083e","errorCode":null,"errorMessage":"Execution timed out after {exec_timeout} seconds","messagePattern":"Execution timed out after (.+?) seconds","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"agent/sandbox/providers/ucloud_agent_sandbox.py","lineNumber":208,"sourceCode":"        requested_timeout = self.timeout if timeout is None else int(timeout)\n        if requested_timeout <= 0:\n            raise RuntimeError(f\"Execution timeout must be greater than 0 seconds, got {requested_timeout}.\")\n        exec_timeout = min(requested_timeout, self.timeout)\n        sdk = _get_ucloud_sandbox_module()\n\n        start_time = time.time()\n        try:\n            sandbox.set_timeout(max(self.sandbox_timeout, exec_timeout + 30), request_timeout=self.timeout)\n            result = sandbox.commands.run(\n                f\"{executable} {shlex.quote(script_path)}\",\n                cwd=remote_work_dir,\n                timeout=exec_timeout,\n                request_timeout=max(self.timeout, exec_timeout),\n            )\n        except sdk.CommandExitException as exc:\n            result = exc\n        except sdk.TimeoutException as exc:\n            raise TimeoutError(f\"Execution timed out after {exec_timeout} seconds\") from exc\n        except Exception as exc:\n            raise RuntimeError(f\"UCloud Agent Sandbox execution failed: {exc}\") from exc\n        execution_time = time.time() - start_time\n\n        stdout = result.stdout or \"\"\n        stderr = result.stderr or \"\"\n        exit_code = int(result.exit_code)\n        self._validate_output_size(stdout, stderr)\n        stdout, structured_result = extract_structured_result(stdout)\n\n        return ExecutionResult(\n            stdout=stdout,\n            stderr=stderr,\n            exit_code=exit_code,\n            execution_time=execution_time,\n            metadata={\n                \"instance_id\": instance_id,\n                \"sandbox_id\": sandbox.sandbox_id,","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/providers/ucloud_agent_sandbox.py#L190-L226","documentation":"Raised when running the user's script via `sandbox.commands.run(...)` throws `sdk.TimeoutException`: the command did not finish within `exec_timeout`, which is min(requested_timeout, self.timeout). Before running, the provider extends the sandbox lifetime to max(sandbox_timeout, exec_timeout+30) so the VM outlives the command. Note this TimeoutError fires after execution started — contrast with error 265 which fires at creation.","triggerScenarios":"User code with an infinite loop, blocking network read, or long computation executed with exec_timeout shorter than the runtime; per-call timeout requested below the work's real duration.","commonSituations":"LLM-generated code with `while True:` or unbounded polling; scripts sleeping longer than the timeout; raising per-call timeout but forgetting the provider-level `timeout` cap (exec_timeout is min()ed against it, so a per-call 120 with provider timeout 30 still runs only 30s).","solutions":["Fix the user code to finish within the limit (add internal deadlines, bounded loops).","Raise the timeout — and remember the provider-level `timeout` config caps it, so raise both.","Catch TimeoutError in the agent loop and report a user-readable 'code took too long' result instead of crashing the session.","For legitimately long jobs, run them outside the sandbox or chunk the work."],"exampleFix":"# before\nresult = provider.execute(inst, \"train_model()\", timeout=120)  # provider timeout=30 -> dies at 30s\n\n# after\n# raise the provider-level cap too: config timeout=300\nresult = provider.execute(inst, \"train_model()\", timeout=120)","handlingStrategy":"retry","validationCode":"# cannot precheck user-code runtime; enforce a script-level budget instead\nwrapper = \"import time\\ntime_left = %d\\n\" % exec_timeout + user_code\n# or at minimum ensure per-call timeout does not exceed the provider cap\nexec_timeout = min(int(timeout or provider.timeout), provider.timeout)","typeGuard":"def is_execution_timeout(exc: TimeoutError) -> bool:\n    return \"timed out after\" in str(exc)","tryCatchPattern":"try:\n    result = provider.execute(instance_id, code, timeout=60)\nexcept TimeoutError as e:\n    result = make_result(stderr=f\"execution {e}: reduce workload or raise provider 'timeout' config\")\n    # only rerun with a larger timeout if the provider-level cap allows it","preventionTips":["Raise BOTH the per-call timeout and the provider-level `timeout` config — exec_timeout is min()ed against the latter.","Inject time budgets/deadlines into generated code so it self-terminates before the sandbox kills it.","Report TimeoutError to the model as a fixable failure (code too slow), not an infrastructure crash."],"tags":["timeout","execution","ucloud","sandbox","infinite-loop"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}