Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
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.pyindex 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 annotationsimport astimport keywordimport re+import sysimport tempfileimport textwrapfrom 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.pyindex 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 annotationsimport astimport keyword+import sysfrom typing import Anyfrom 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 textassert "```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