Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-10628): captcha timeout circuit breaker (#6349)
LawyZheng1704b3fdba43
diff --git a/skyvern/forge/sdk/core/skyvern_context.py b/skyvern/forge/sdk/core/skyvern_context.pyindex 0cf25d800..10d905d6c 100644--- a/skyvern/forge/sdk/core/skyvern_context.py+++ b/skyvern/forge/sdk/core/skyvern_context.py@@ -183,6 +183,10 @@ class SkyvernContext:# preventing repeated injection loops when the captcha solver succeeds but the page doesn't changeproactive_captcha_task_ids: set[str] = field(default_factory=set)+ # Circuit breaker: consecutive captcha solve timeouts for this workflow run.+ # When this reaches the threshold, further captcha solve attempts are short-circuited.+ consecutive_captcha_timeouts: int = 0+# Browser dialogs captured since the last agent prompt build, surfaced into the# next extract-action prompt so the LLM can react to validation rejections.recent_dialog_messages: list[DialogEntry] = field(default_factory=list)@@ -407,20 +411,31 @@ def _restore(token: Token[SkyvernContext | None]) -> None:@contextmanager-def scoped(context: SkyvernContext) -> Iterator[SkyvernContext]:+def scoped(+ context: SkyvernContext,+ *,+ propagate_captcha_timeout: bool = False,+) -> Iterator[SkyvernContext]:"""Temporarily scope the current context to a fresh child context.Args:context: The child context to set for the scope+ propagate_captcha_timeout: When True, copy the child's+ ``consecutive_captcha_timeouts`` back to the parent on exit.+ Only enable for scopes that represent real task executions+ (e.g. run_task_v2), not placeholder contexts.Yields:The child context"""+ parent = _context.get() if propagate_captcha_timeout else Nonetoken = _context.set(context)try:yield contextfinally:+ if parent is not None:+ parent.consecutive_captcha_timeouts = context.consecutive_captcha_timeouts_restore(token)diff --git a/skyvern/services/task_v2_service.py b/skyvern/services/task_v2_service.pyindex d1a55b889..cd4ac5906 100644--- a/skyvern/services/task_v2_service.py+++ b/skyvern/services/task_v2_service.py@@ -505,11 +505,12 @@ async def run_task_v2(loop_internal_state=copy.deepcopy(parent_context.loop_internal_state) if parent_context else None,trigger_type=parent_context.trigger_type if parent_context else None,use_flex_llm_routing=parent_context.use_flex_llm_routing if parent_context else False,+ consecutive_captcha_timeouts=parent_context.consecutive_captcha_timeouts if parent_context else 0,)# SKY-7005: scoped() restores the parent context on exit, preserving# loop_internal_state so per-iteration download filtering continues to# work for subsequent blocks in the same loop iteration.- with skyvern_context.scoped(context):+ with skyvern_context.scoped(context, propagate_captcha_timeout=True):try:workflow, workflow_run, task_v2 = await run_task_v2_helper(organization=organization,