Skip to content

Automate browser based workflows with AI

SKY-10673: restore recursion limit after code-block mypy preflight (#6471)

Andrew Neilsoncd19b32cb4c9
diff --git a/skyvern/forge/sdk/copilot/code_block_preflight.py b/skyvern/forge/sdk/copilot/code_block_preflight.py
index edf0661b9..162cad153 100644
--- a/skyvern/forge/sdk/copilot/code_block_preflight.py
+++ b/skyvern/forge/sdk/copilot/code_block_preflight.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import ast
import keyword
import re
+import sys
import tempfile
import textwrap
from dataclasses import dataclass
@@ -45,20 +46,26 @@ def preflight_code_block(
return []
source = _build_typed_module(code, parameter_keys=parameter_keys)
+ # mypy's API raises the interpreter recursion limit and never restores it,
+ # which leaks into the rest of the process; snapshot and restore it ourselves.
+ recursion_limit = sys.getrecursionlimit()
with tempfile.TemporaryDirectory(prefix="skyvern-code-block-preflight-") as tmpdir:
path = Path(tmpdir) / "code_block.py"
path.write_text(source, encoding="utf-8")
- stdout, stderr, status = mypy_api.run(
- [
- str(path),
- "--config-file=/dev/null",
- "--no-error-summary",
- "--show-error-codes",
- "--ignore-missing-imports",
- "--no-incremental",
- "--cache-dir=/dev/null",
- ]
- )
+ try:
+ stdout, stderr, status = mypy_api.run(
+ [
+ str(path),
+ "--config-file=/dev/null",
+ "--no-error-summary",
+ "--show-error-codes",
+ "--ignore-missing-imports",
+ "--no-incremental",
+ "--cache-dir=/dev/null",
+ ]
+ )
+ finally:
+ sys.setrecursionlimit(recursion_limit)
if status == 0:
return []
diff --git a/tests/unit/test_copilot_code_block_synthesis.py b/tests/unit/test_copilot_code_block_synthesis.py
index bfecc8e63..f9f3ca52b 100644
--- a/tests/unit/test_copilot_code_block_synthesis.py
+++ b/tests/unit/test_copilot_code_block_synthesis.py
@@ -7,6 +7,7 @@ from __future__ import annotations
import ast
import keyword
+import sys
from typing import Any
from skyvern.forge.sdk.copilot.code_block_preflight import preflight_code_block
@@ -645,3 +646,10 @@ class TestSynthesizedArtifactMetadata:
text = render_synthesized_offer_text(synthesized)
assert "code_artifact_metadata" not in text
assert "```json" not in text
+
+
+def test_code_block_preflight_restores_recursion_limit() -> None:
+ before = sys.getrecursionlimit()
+ preflight_code_block("await page.locator('button[type=submit]').first.click(timeout=5000)\n")
+
+ assert sys.getrecursionlimit() == before