Skip to content

Automate browser based workflows with AI

fix(SKY-9532): salvage verified workflow when copilot budget exhausts mid-correction (#5848)

Andrew Neilsond47a4564bcd8
diff --git a/pyproject.toml b/pyproject.toml
index f878dac51..7f551e2f8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -69,7 +69,6 @@ server = [
"onepassword-sdk==0.4.0",
"types-boto3[full]>=1.38.31,<2",
"lark>=1.2.2,<2",
- "selectolax>=0.4.7,<0.5",
"libcst>=1.8.2,<2",
"curlparser>=0.1.0,<0.2",
"pandas>=2.3.1,<4",
diff --git a/skyvern-frontend/src/components/ThemeProvider.tsx b/skyvern-frontend/src/components/ThemeProvider.tsx
index 789933ad3..805f24e22 100644
--- a/skyvern-frontend/src/components/ThemeProvider.tsx
+++ b/skyvern-frontend/src/components/ThemeProvider.tsx
@@ -1,6 +1,8 @@
import { useEffect, useState } from "react";
import { Theme, ThemeProviderContext } from "./themeProviderContext";
+const THEME_STORAGE_KEY = "skyvern-theme";
+
export type ThemeProviderProps = {
children: React.ReactNode;
defaultTheme?: Theme;
@@ -11,7 +13,10 @@ export function ThemeProvider({
defaultTheme = "system",
...props
}: ThemeProviderProps) {
- const [theme, setTheme] = useState<Theme>(defaultTheme);
+ const [theme, setTheme] = useState<Theme>(
+ () =>
+ (localStorage.getItem(THEME_STORAGE_KEY) as Theme | null) ?? defaultTheme,
+ );
useEffect(() => {
const root = window.document.documentElement;
@@ -33,6 +38,7 @@ export function ThemeProvider({
const value = {
theme,
setTheme: (theme: Theme) => {
+ localStorage.setItem(THEME_STORAGE_KEY, theme);
setTheme(theme);
},
};
diff --git a/skyvern-frontend/src/components/ui/css-vars.test.ts b/skyvern-frontend/src/components/ui/css-vars.test.ts
index 29bea2f85..b2d0d7871 100644
--- a/skyvern-frontend/src/components/ui/css-vars.test.ts
+++ b/skyvern-frontend/src/components/ui/css-vars.test.ts
@@ -15,17 +15,21 @@ import { fileURLToPath } from "node:url";
const HERE = dirname(fileURLToPath(import.meta.url));
const REPO_ROOT = resolve(HERE, "../../../..");
-// Multi-entrypoint layout (cloud / eval / src) exists in the cloud monorepo;
-// the OSS repo syncs only src/. Filter to whatever exists so the contract
-// holds in both contexts without per-repo divergence.
-const ALL_CSS_FILES = [
- "skyvern-frontend/src/index.css",
- "skyvern-frontend/cloud/index.css",
- "skyvern-frontend/eval/index.css",
-];
-const CSS_FILES = ALL_CSS_FILES.filter((f) =>
- existsSync(resolve(REPO_ROOT, f)),
-);
+// Gate by directory, not file: a deleted index.css inside an existing
+// entrypoint dir is the regression we want to fail loudly on.
+function entrypoint(dir: string): string | null {
+ if (!existsSync(resolve(REPO_ROOT, dir))) {
+ return null;
+ }
+ return `${dir}/index.css`;
+}
+const CSS_FILES = [
+ "skyvern-frontend/src",
+ "skyvern-frontend/cloud",
+ "skyvern-frontend/eval",
+]
+ .map(entrypoint)
+ .filter((f): f is string => f !== null);
function load(file: string): string {
return readFileSync(resolve(REPO_ROOT, file), "utf-8");
diff --git a/skyvern-frontend/src/index.css b/skyvern-frontend/src/index.css
index f66ae18f5..fd45c056d 100644
--- a/skyvern-frontend/src/index.css
+++ b/skyvern-frontend/src/index.css
@@ -43,6 +43,21 @@
--ring: 222.2 84% 5%;
--radius: 0.5rem;
+
+ --tertiary: 227.6 11.6% 48.8%;
+ --tertiary-foreground: 213 27% 84%;
+
+ --warning: 32.1 94.6% 43.7%; /* amber-600 */
+ --warning-foreground: 36 100% 97.1%; /* amber-50 */
+
+ --success: 142.1 76.2% 36.3%; /* green-600 */
+ --success-foreground: 138.5 76.5% 96.7%; /* green-50 */
+
+ --slate-elevation-1: 222 47% 96%;
+ --slate-elevation-2: 222 40% 93%;
+ --slate-elevation-3: 222 35% 90%;
+ --slate-elevation-4: 222 30% 87%;
+ --slate-elevation-5: 222 25% 84%;
}
.dark {
diff --git a/skyvern-frontend/src/routes/root/SidebarContent.tsx b/skyvern-frontend/src/routes/root/SidebarContent.tsx
index a5a6a69bf..ce8e7d77d 100644
--- a/skyvern-frontend/src/routes/root/SidebarContent.tsx
+++ b/skyvern-frontend/src/routes/root/SidebarContent.tsx
@@ -1,5 +1,6 @@
import { Logo } from "@/components/Logo";
import { LogoMinimized } from "@/components/LogoMinimized";
+import { ThemeToggle } from "@/components/ThemeSwitch";
import { useSidebarStore } from "@/store/SidebarStore";
import { Link } from "react-router-dom";
import { SideNav } from "./SideNav";
@@ -24,11 +25,12 @@ function SidebarContent({ useCollapsedState }: Props) {
</Link>
<SideNav />
<div
- className={cn("mt-auto flex min-h-16", {
+ className={cn("mt-auto flex min-h-16 items-center", {
"justify-center": collapsed,
- "justify-end": !collapsed,
+ "justify-end gap-2": !collapsed,
})}
>
+ <ThemeToggle />
<Button
size="icon"
variant="ghost"
diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.py
index 542722513..a0169152d 100644
--- a/skyvern/forge/agent.py
+++ b/skyvern/forge/agent.py
@@ -2042,19 +2042,31 @@ class ForgeAgent:
"display_width_px": settings.BROWSER_WIDTH,
}
]
- thinking = {"type": "enabled", "budget_tokens": 1024}
+ thinking: dict[str, Any]
+ output_config: dict[str, Any] | None
+ if LLMAPIHandlerFactory.requires_adaptive_thinking(llm_caller.llm_config.model_name):
+ thinking = {"type": "adaptive"}
+ output_config = {"effort": LLMAPIHandlerFactory.ADAPTIVE_THINKING_EFFORT}
+ else:
+ thinking = {"type": "enabled", "budget_tokens": 1024}
+ output_config = None
window_dimension = cast(Resolution, scraped_page.window_dimension) if scraped_page.window_dimension else None
+ call_kwargs: dict[str, Any] = {
+ "step": step,
+ "screenshots": scraped_page.screenshots,
+ "use_message_history": True,
+ "tools": tools,
+ "raw_response": True,
+ "betas": betas,
+ "thinking": thinking,
+ "window_dimension": window_dimension,
+ }
+ if output_config is not None:
+ call_kwargs["output_config"] = output_config
if not llm_caller.message_history:
llm_response = await llm_caller.call(
prompt=task.navigation_goal,
- step=step,
- screenshots=scraped_page.screenshots,
- use_message_history=True,
- tools=tools,
- raw_response=True,
- betas=betas,
- thinking=thinking,
- window_dimension=window_dimension,
+ **call_kwargs,
)
else:
current_context = skyvern_context.ensure_context()
@@ -2071,14 +2083,7 @@ class ForgeAgent:
llm_response = await llm_caller.call(
prompt=resp_content,
- step=step,
- screenshots=scraped_page.screenshots,
- use_message_history=True,
- tools=tools,
- raw_response=True,
- betas=betas,
- thinking=thinking,
- window_dimension=window_dimension,
+ **call_kwargs,
)
assistant_content = llm_response["content"]
llm_caller.message_history.append({"role": "assistant", "content": assistant_content})
diff --git a/skyvern/forge/forge_app.py b/skyvern/forge/forge_app.py
index 873172249..fc1ff0efe 100644
--- a/skyvern/forge/forge_app.py
+++ b/skyvern/forge/forge_app.py
@@ -151,7 +151,7 @@ def create_forge_app() -> ForgeApp:
app.LLM_API_HANDLER = LLMAPIHandlerFactory.get_llm_api_handler(settings.LLM_KEY)
app.OPENAI_CUA_MODEL = settings.OPENAI_CUA_MODEL
app.OPENAI_CLIENT = AsyncOpenAI(
- api_key=settings.OPENAI_API_KEY or "",
+ api_key=settings.OPENAI_API_KEY or "dummy",
http_client=ForgeAsyncHttpxClientWrapper(),
)
if settings.ENABLE_AZURE_CUA:
diff --git a/skyvern/forge/prompts/skyvern/workflow-copilot-agent.j2 b/skyvern/forge/prompts/skyvern/workflow-copilot-agent.j2
index 90081ff62..64c542132 100644
--- a/skyvern/forge/prompts/skyvern/workflow-copilot-agent.j2
+++ b/skyvern/forge/prompts/skyvern/workflow-copilot-agent.j2
@@ -169,6 +169,12 @@ Whenever you build or modify a workflow, you MUST call the `update_workflow` too
FINAL RESPONSE FORMAT:
+RESPONSE-TYPE CLASSIFICATION:
+- If your `user_response` asks the user to provide, choose, confirm, or correct information required before you can continue, you MUST use ASK_QUESTION (Option 2). This holds even when this turn built or tested a partial workflow. Choosing `goal_reached: false` on a REPLY does NOT substitute for ASK_QUESTION when input is required.
+- A REPLY that carries `updated_workflow` can surface an Accept/Reject proposal panel for the verified workflow. Pairing that panel with a question awaiting required user input is contradictory UX — the user does not know whether to type an answer or click Accept.
+- Classify by intent, not punctuation: if the answer would decide what block, value, credential, URL, selector, or correction to use next, choose ASK_QUESTION — even if phrased softly (e.g. "Does that match what you wanted?"). Courtesy questions on a complete verified proposal that the user can ignore without blocking your next turn — you would proceed identically whether they answer or not — are NOT ASK_QUESTION triggers.
+- ASK_QUESTION may still include `workflow_state` in `global_llm_context` to record the partial draft you built; a populated `workflow_state` does NOT imply REPLY.
+
When you are done using tools and ready to respond to the user, output a JSON object (and nothing else) with ONE of these actions:
**Option 1: Reply to the user**
diff --git a/skyvern/forge/sdk/api/llm/api_handler_factory.py b/skyvern/forge/sdk/api/llm/api_handler_factory.py
index c046f1d2b..7c25fdf64 100644
--- a/skyvern/forge/sdk/api/llm/api_handler_factory.py
+++ b/skyvern/forge/sdk/api/llm/api_handler_factory.py
@@ -450,6 +450,14 @@ class LLMAPIHandlerFactory:
# Anthropic API requires budget_tokens >= 1024
ANTHROPIC_MIN_THINKING_BUDGET = 1024
+ ADAPTIVE_THINKING_EFFORT = "low"
+
+ @staticmethod
+ def requires_adaptive_thinking(model_name: str | None) -> bool:
+ # Claude Opus 4.7 rejects `thinking.type=enabled` and requires
+ # `thinking.type=adaptive` + `output_config.effort`. Bedrock's translator
+ # does not yet accept the new shape, so gate to direct Anthropic.
+ return model_name == "anthropic/claude-opus-4-7"
@staticmethod
def _apply_anthropic_thinking_optimization(
@@ -458,6 +466,17 @@ class LLMAPIHandlerFactory:
"""Apply thinking optimization for Anthropic/Claude models."""
model_label = LLMAPIHandlerFactory._get_model_label(llm_config)
+ if LLMAPIHandlerFactory.requires_adaptive_thinking(model_label):
+ parameters["thinking"] = {"type": "adaptive"}
+ parameters.setdefault("output_config", {})["effort"] = LLMAPIHandlerFactory.ADAPTIVE_THINKING_EFFORT
+ LOG.debug(
+ "Applied thinking budget optimization (adaptive)",
+ prompt_name=prompt_name,
+ effort=LLMAPIHandlerFactory.ADAPTIVE_THINKING_EFFORT,
+ model=model_label,
+ )
+ return
+
if llm_config.reasoning_effort is not None:
# Use reasoning_effort if configured in LLM config - always use "low" per LiteLLM constants
parameters["reasoning_effort"] = "low"
@@ -2264,6 +2283,10 @@ class LLMCaller:
model_name = self.llm_config.model_name.replace("bedrock/", "").replace("anthropic/", "")
betas = active_parameters.get("betas", NOT_GIVEN)
thinking = active_parameters.get("thinking", NOT_GIVEN)
+ output_config = active_parameters.get("output_config", NOT_GIVEN)
+ extra_body: dict[str, Any] | None = None
+ if output_config is not NOT_GIVEN:
+ extra_body = {"output_config": output_config}
LOG.info(
"Anthropic request",
model_name=model_name,
@@ -2272,15 +2295,18 @@ class LLMCaller:
timeout=timeout,
messages_length=len(messages),
)
- response = await app.ANTHROPIC_CLIENT.beta.messages.create(
- max_tokens=max_tokens,
- messages=messages,
- model=model_name,
- tools=tools or NOT_GIVEN,
- timeout=timeout,
- betas=betas,
- thinking=thinking,
- )
+ create_kwargs: dict[str, Any] = {
+ "max_tokens": max_tokens,
+ "messages": messages,
+ "model": model_name,
+ "tools": tools or NOT_GIVEN,
+ "timeout": timeout,
+ "betas": betas,
+ "thinking": thinking,
+ }
+ if extra_body is not None:
+ create_kwargs["extra_body"] = extra_body
+ response = await app.ANTHROPIC_CLIENT.beta.messages.create(**create_kwargs)
LOG.info(
"Anthropic response",
model_name=model_name,
diff --git a/skyvern/forge/sdk/cache/extraction_cache.py b/skyvern/forge/sdk/cache/extraction_cache.py
index 39c39cc36..478db9c59 100644
--- a/skyvern/forge/sdk/cache/extraction_cache.py
+++ b/skyvern/forge/sdk/cache/extraction_cache.py
@@ -65,7 +65,6 @@ from typing import Any
from urllib.parse import urlparse, urlunparse
import structlog
-from selectolax.parser import HTMLParser
LOG = structlog.get_logger()
@@ -284,51 +283,200 @@ def _canonical_url(url: str | None) -> str | None:
return url
+# Raw-text element bodies are passed through verbatim; the canonicalizer must
+# not interpret their contents as HTML (e.g. textarea text containing literal
+# `<` or `>` would otherwise be tokenized as tags).
+_RAW_TEXT_ELEMENTS = frozenset({"script", "style", "textarea", "title"})
+
+# Pre-compiled close-tag matchers per raw-text element so `_walk_html` doesn't
+# rebuild the regex on every open tag.
+_RAW_TEXT_CLOSE_RES: dict[str, re.Pattern[str]] = {
+ name: re.compile(rf"</\s*{name}\s*>", re.IGNORECASE) for name in _RAW_TEXT_ELEMENTS
+}
+
+# Tag-name matcher (group 1 = name). Shared by `_canonicalize_tag` and `_walk_html`.
+_TAG_NAME_RE = re.compile(r"<([a-zA-Z][a-zA-Z0-9]*)")
+
+# Walks attribute tokens within a tag body. Quoted-value alternatives are
+# split by quote style so each alternative excludes only its own delimiter
+# (a double-quoted value can contain `'` and vice versa, per HTML spec).
+_ATTR_TOKEN_RE = re.compile(
+ r"\s+"
+ r"([a-zA-Z][a-zA-Z0-9_:-]*)"
+ r"(?:"
+ r"\s*=\s*"
+ r"(?:\"([^\"]*)\"|'([^']*)'|([^\s>\"']+))"
+ r")?",
+ re.IGNORECASE,
+)
+
+
+def _find_tag_end(html: str, start: int) -> int:
+ """Index of the `>` that closes the tag starting at `html[start] == '<'`,
+ respecting quoted attribute values. Returns -1 if no closing `>`.
+ """
+ i = start + 1
+ n = len(html)
+ while i < n:
+ c = html[i]
+ if c == '"':
+ j = html.find('"', i + 1)
+ if j < 0:
+ return -1
+ i = j + 1
+ elif c == "'":
+ j = html.find("'", i + 1)
+ if j < 0:
+ return -1
+ i = j + 1
+ elif c == ">":
+ return i
+ else:
+ i += 1
+ return -1
+
+
+def _canonicalize_tag(tag: str, tag_name: str) -> str:
+ """Rewrite suspect attributes and CSRF input/meta values inside one tag string."""
+ name_match = _TAG_NAME_RE.match(tag)
+ if not name_match:
+ return tag
+ body = tag[name_match.end() :]
+
+ name_attr_value = ""
+ if tag_name in ("input", "meta"):
+ for am in _ATTR_TOKEN_RE.finditer(body):
+ if am.group(1).lower() == "name":
+ name_attr_value = (am.group(2) or am.group(3) or am.group(4) or "").lower()
+ break
+ is_csrf_input = tag_name == "input" and name_attr_value in _CSRF_INPUT_NAMES
+ is_csrf_meta = tag_name == "meta" and name_attr_value in _CSRF_META_NAMES
+
+ def _rewrite_attr(am: re.Match) -> str:
+ full = am.group(0)
+ attr_name = am.group(1).lower()
+ if am.group(2) is not None:
+ value, quote = am.group(2), '"'
+ elif am.group(3) is not None:
+ value, quote = am.group(3), "'"
+ elif am.group(4) is not None:
+ value, quote = am.group(4), ""
+ else:
+ return full
+
+ if attr_name in _SUSPECT_ATTR_NAMES:
+ new_value = _redact_transient_in_value(value)
+ elif attr_name == "value" and is_csrf_input:
+ new_value = ""
+ elif attr_name == "content" and is_csrf_meta:
+ new_value = ""
+ else:
+ return full
+
+ ws = full[: len(full) - len(full.lstrip())]
+ if quote:
+ return f"{ws}{am.group(1)}={quote}{new_value}{quote}"
+ return f"{ws}{am.group(1)}={new_value}"
+
+ return tag[: name_match.end()] + _ATTR_TOKEN_RE.sub(_rewrite_attr, body)
+
+
+def _walk_html(html: str) -> str:
+ """Walk HTML producing a canonicalized copy. Tag-boundary aware (respects
+ quoted attribute values), raw-text aware (script/style/textarea/title
+ bodies pass through verbatim).
+ """
+ out: list[str] = []
+ i = 0
+ n = len(html)
+ while i < n:
+ if html[i] != "<":
+ j = html.find("<", i)
+ if j < 0:
+ out.append(html[i:])
+ break
+ out.append(html[i:j])
+ i = j
+ continue
+
+ if html.startswith("<!--", i):
+ end = html.find("-->", i + 4)
+ if end < 0:
+ out.append(html[i:])
+ break
+ out.append(html[i : end + 3])
+ i = end + 3
+ continue
+ if html.startswith("<![CDATA[", i):
+ end = html.find("]]>", i + 9)
+ if end < 0:
+ out.append(html[i:])
+ break
+ out.append(html[i : end + 3])
+ i = end + 3
+ continue
+ if html.startswith("<!", i) or html.startswith("<?", i):
+ end = html.find(">", i + 2)
+ if end < 0:
+ out.append(html[i:])
+ break
+ out.append(html[i : end + 1])
+ i = end + 1
+ continue
+ if html.startswith("</", i):
+ end = _find_tag_end(html, i)
+ if end < 0:
+ out.append(html[i:])
+ break
+ out.append(html[i : end + 1])
+ i = end + 1
+ continue
+ if i + 1 < n and html[i + 1].isalpha():
+ end = _find_tag_end(html, i)
+ if end < 0:
+ out.append(html[i:])
+ break
+ tag = html[i : end + 1]
+ tn_match = _TAG_NAME_RE.match(tag)
+ tag_name = tn_match.group(1).lower() if tn_match else ""
+ out.append(_canonicalize_tag(tag, tag_name))
+ i = end + 1
+ if tag_name in _RAW_TEXT_ELEMENTS and not tag.endswith("/>"):
+ close_re = _RAW_TEXT_CLOSE_RES[tag_name]
+ cm = close_re.search(html, i)
+ if cm:
+ out.append(html[i : cm.start()])
+ out.append(cm.group(0))
+ i = cm.end()
+ else:
+ out.append(html[i:])
+ i = n
+ continue
+ out.append(html[i])
+ i += 1
+ return "".join(out)
+
+
def _canonical_element_tree(html: str | None) -> str | None:
"""Return a canonicalized HTML string for cache-key derivation.
- Redacts UUID-v4 / random-hex-suffix substrings within identifier-style
- attribute values (id/for/aria-*/data-testid) and zeros CSRF-token
- <input>/<meta> contents. Stable business IDs (``id='submit-button'``,
- ``id='order-123456'``) and semantic fields (``class``, ``href``, ``src``,
- ``name``, text content, document structure) are preserved.
+ Redacts UUID-v4 / random-hex-suffix substrings inside id/for/aria-
+ labelledby/aria-describedby/data-testid values; zeros CSRF-token
+ <input>/<meta> contents. Other attributes and text content are preserved.
- Never raises. Returns the input unchanged if parsing fails.
+ No-longer-normalized vs. the prior parser round-trip (SKY-9535 supersedes):
+ whitespace inside tags, attribute order, attribute quote style, attribute-
+ name case, tag-name case. Never raises.
"""
if html is None:
return None
if html == "":
return ""
try:
- tree = HTMLParser(html)
- for node in tree.root.traverse(include_text=False):
- if not node.attributes:
- continue
- tag = node.tag
-
- # CSRF scrubbing reads `name` before the sentinel pass so it is
- # always available regardless of _SUSPECT_ATTR_NAMES membership.
- if tag == "input":
- input_name = (node.attributes.get("name", "") or "").lower()
- if input_name in _CSRF_INPUT_NAMES:
- node.attrs["value"] = ""
- elif tag == "meta":
- meta_name = (node.attributes.get("name", "") or "").lower()
- if meta_name in _CSRF_META_NAMES:
- node.attrs["content"] = ""
-
- # Pattern-based value redaction inside suspect attributes: UUIDs
- # and random hex suffixes collapse; stable business IDs survive.
- for attr_name in list(node.attributes.keys()):
- if attr_name.lower() in _SUSPECT_ATTR_NAMES:
- current_val = node.attributes.get(attr_name) or ""
- node.attrs[attr_name] = _redact_transient_in_value(current_val)
-
- # selectolax's html property returns the full serialized tree
- return tree.html or html
+ return _walk_html(html)
except Exception:
- # WARNING rather than DEBUG so a transient parser regression surfaces
- # in Datadog instead of silently degrading cache hits.
+ # WARNING (not DEBUG) so a transient regression surfaces in Datadog
+ # rather than silently degrading cache hits.
LOG.warning("canonical_element_tree_failed", exc_info=True)
return html
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.py
index 435f4932e..b748b819d 100644
--- a/skyvern/forge/sdk/copilot/agent.py
+++ b/skyvern/forge/sdk/copilot/agent.py
@@ -325,9 +325,26 @@ def _build_wip_exit_result(
cancelled: bool = False,
) -> AgentResult:
"""Selected non-success exits surface the most recent successfully parsed workflow."""
- # ``last_test_ok=None`` covers both "test never ran" and "test ran with
- # ambiguous output"; only the first case earns the carve-out (the REPLY
- # path is more permissive because its reply text carries the context).
+ # When an unverified edit/run has overwritten ``last_workflow`` since the
+ # last verified shape, prefer the verified shape. ``unvalidated=True``
+ # triggers the route's rollback so auto-accept does not silently keep the
+ # failed/in-flight shape.
+ if (
+ ctx.last_good_workflow is not None
+ and ctx.last_good_workflow_yaml
+ and ctx.last_workflow is not ctx.last_good_workflow
+ and not ctx.last_test_suspicious_success
+ ):
+ return AgentResult(
+ user_response=tested_reply,
+ updated_workflow=ctx.last_good_workflow,
+ global_llm_context=global_llm_context,
+ workflow_yaml=ctx.last_good_workflow_yaml,
+ workflow_was_persisted=ctx.workflow_persisted,
+ total_tokens=ctx.total_tokens_used,
+ unvalidated=True,
+ cancelled=cancelled,
+ )
if (
ctx.last_workflow is not None
and ctx.last_workflow_yaml
@@ -479,11 +496,24 @@ def _translate_to_agent_result(
ctx.last_workflow_yaml = last_workflow_yaml
ctx.last_test_ok = None
+ # An unverified edit/run sits in ``last_workflow`` after a recorded
+ # failure — surface the verified prior shape and skip the failure rewrite
+ # (which would describe the failed-shape block count).
+ salvaged_reply = (
+ resp_type == "REPLY"
+ and ctx.last_good_workflow is not None
+ and ctx.last_good_workflow_yaml
+ and ctx.last_workflow is not ctx.last_good_workflow
+ and bool(ctx.last_failed_workflow_yaml or ctx.last_test_ok is False)
+ and not ctx.last_test_suspicious_success
+ )
+
# ASK_QUESTION replies carry a specific clarifying question — often the
# "stop and ask" unblocker the system prompt now requires when the agent
# cannot test. The generic rewrite would replace it with a vague
- # "Could you share more context", so skip it for ASK_QUESTION.
- if resp_type != "ASK_QUESTION":
+ # "Could you share more context", so skip it for ASK_QUESTION (and for
+ # salvaged replies, which already describe the verified prefix).
+ if resp_type != "ASK_QUESTION" and not salvaged_reply:
user_response = _rewrite_failed_test_response(str(user_response), ctx)
verified_workflow, verified_yaml = _verified_workflow_or_none(ctx)
# Default-true preserves backwards-compat with stale prompts and missing fields.
@@ -494,6 +524,9 @@ def _translate_to_agent_result(
unvalidated = False
if verified_workflow is not None and not agent_admits_incomplete:
last_workflow, last_workflow_yaml = verified_workflow, verified_yaml
+ elif salvaged_reply:
+ last_workflow, last_workflow_yaml = ctx.last_good_workflow, ctx.last_good_workflow_yaml
+ unvalidated = True
elif resp_type == "REPLY" and ctx.last_workflow is not None and ctx.last_workflow_yaml:
# Failures are often environmental (captcha, transient block); surface the draft so the user can keep iterating.
last_workflow = ctx.last_workflow
diff --git a/skyvern/forge/sdk/copilot/context.py b/skyvern/forge/sdk/copilot/context.py
index ff9d4f1bb..dd208659e 100644
--- a/skyvern/forge/sdk/copilot/context.py
+++ b/skyvern/forge/sdk/copilot/context.py
@@ -206,6 +206,7 @@ class CopilotContext(AgentContext):
# shape-independent.
probable_site_block_streak_count: int = 0
probable_site_block_stop_nudge_count: int = 0
+ per_tool_budget_nudge_count: int = 0
# Per-request frontier state. `verified_block_outputs` and
# `verified_prefix_labels` are populated ONLY from fully-successful runs —
@@ -250,6 +251,11 @@ class CopilotContext(AgentContext):
pending_action_sequence_fingerprint: str | None = None
repeated_action_fingerprint_streak_count: int = 0
+ copilot_run_start_monotonic: float | None = None
+
+ last_good_workflow: Workflow | None = None
+ last_good_workflow_yaml: str | None = None
+
# Populated lazily by ``stream_to_sse`` and reused across enforcement
# iterations so cadence/last-emitted-at survive ``run_with_enforcement``
# retries. Declared here (rather than attached dynamically) so future
diff --git a/skyvern/forge/sdk/copilot/enforcement.py b/skyvern/forge/sdk/copilot/enforcement.py
index 78479ff9c..ce052b09c 100644
--- a/skyvern/forge/sdk/copilot/enforcement.py
+++ b/skyvern/forge/sdk/copilot/enforcement.py
@@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Any
import structlog
from agents.run import Runner
-from skyvern.forge.sdk.copilot.failure_tracking import normalize_failure_reason
+from skyvern.forge.sdk.copilot.failure_tracking import PER_TOOL_BUDGET_FAILURE_CATEGORY, normalize_failure_reason
from skyvern.forge.sdk.copilot.narration import TransitionKind
from skyvern.forge.sdk.copilot.output_utils import extract_final_text, parse_final_response
from skyvern.forge.sdk.copilot.screenshot_utils import ScreenshotEntry
@@ -52,13 +52,16 @@ PROBABLE_SITE_BLOCK_STREAK_STOP_AT = 2
# PROBABLE_SITE_BLOCK_STREAK_STOP_AT (both default to 2 but tune different
# axes: streak depth vs nudge count).
MAX_PROBABLE_SITE_BLOCK_STOP_NUDGES = 2
+# Caps how many times the per-tool-budget split nudge can fire. After two
+# trips the agent should already be at single-block granularity; further
+# trips fall through to the repeated-frontier escalation path.
+MAX_PER_TOOL_BUDGET_NUDGES = 2
MIN_BLOCKS_FOR_AUTO_COMPLETE = 10
TOTAL_TIMEOUT_SECONDS = 600
# Belt-and-braces cap alongside the elapsed-time budget. Per-nudge caps
# already prevent individual branches from looping; this stops a brand-new
# enforcement rule that forgets its own counter from spinning within 600s.
MAX_ITERATIONS = 50
-
SCREENSHOT_SENTINEL = "[copilot:screenshot] "
NUDGE_SENTINEL = "[copilot:nudge] "
SCREENSHOT_PLACEHOLDER = SCREENSHOT_SENTINEL + "[prior screenshot removed to save context]"
@@ -234,6 +237,24 @@ POST_PARAMETER_BINDING_STOP_NUDGE = (
"same parameter-binding drift."
)
+POST_PER_TOOL_BUDGET_NUDGE = (
+ "STOP — your last update_and_run_blocks call exceeded the per-tool-call "
+ "time budget while still making progress. This is NOT a site failure or "
+ "a wording problem — the chain you submitted is too long to complete in a "
+ "single tool call.\n"
+ "Do NOT retry the same chain. Do NOT change navigation_goal wording or "
+ "selectors hoping it will run faster.\n"
+ "1. Shrink the requested block_labels list to the first 1-2 unverified "
+ "blocks. The verified-prefix optimization will replay any earlier blocks "
+ "from cached state without re-running the browser, so passing a smaller "
+ "frontier is cheap.\n"
+ "2. Test that smaller frontier with update_and_run_blocks. If it succeeds, "
+ "extend by one block at a time on subsequent calls.\n"
+ "3. If your workflow only has 1-2 blocks and one block is still hitting "
+ "the budget, the single block is too ambitious — either narrow its "
+ "navigation_goal scope, or reply with a blocker explanation."
+)
+
POST_PROBABLE_SITE_BLOCK_STOP_NUDGE = (
"STOP — the target site has failed to scrape on every attempt across "
"multiple workflow shapes. Every run navigated successfully but the "
@@ -470,6 +491,12 @@ def _needs_suspicious_success_nudge(ctx: Any) -> bool:
return nudge_count < MAX_SUSPICIOUS_SUCCESS_NUDGES
+def _needs_per_tool_budget_nudge(ctx: Any) -> bool:
+ if getattr(ctx, "last_failure_category_top", None) != PER_TOOL_BUDGET_FAILURE_CATEGORY:
+ return False
+ return _get_int(ctx, "per_tool_budget_nudge_count") < MAX_PER_TOOL_BUDGET_NUDGES
+
+
def _needs_probable_site_block_stop_nudge(ctx: Any) -> bool:
"""Return True when the site-block-wall streak has reached the stop level
AND the per-streak nudge cap has not been exhausted."""
@@ -561,6 +588,13 @@ def _check_enforcement(ctx: Any, result: RunResultStreaming | None = None) -> st
if ctx.update_workflow_called and not ctx.test_after_update_done:
return POST_UPDATE_NUDGE
+ # A budget-trip is a structural problem (chain too long), not a
+ # workflow-shape problem — emit the targeted "split the chain" advice
+ # before the generic repeated-frontier and failed-test paths can fire.
+ if _needs_per_tool_budget_nudge(ctx):
+ ctx.per_tool_budget_nudge_count = _get_int(ctx, "per_tool_budget_nudge_count") + 1
+ return POST_PER_TOOL_BUDGET_NUDGE
+
repeated_frontier_nudge = _repeated_frontier_failure_nudge(ctx)
if repeated_frontier_nudge is not None:
# Latch the emitted level so each escalation fires at most once per streak.
@@ -888,6 +922,7 @@ _NUDGE_TYPE_BY_MESSAGE: dict[str, str] = {
POST_PARAMETER_BINDING_STOP_NUDGE: "parameter_binding_stop",
POST_ANTI_BOT_FAILED_TEST_NUDGE: "anti_bot_block",
POST_PROBABLE_SITE_BLOCK_STOP_NUDGE: "probable_site_block_stop",
+ POST_PER_TOOL_BUDGET_NUDGE: "per_tool_budget_split",
POST_FAILED_TEST_NUDGE: "post_failed_test",
SCREENSHOT_DROPPED_NUDGE: "screenshot_dropped_on_recovery",
}
@@ -1062,6 +1097,7 @@ async def run_with_enforcement(
session = runner_kwargs.pop("session", None)
current_input: str | list = initial_input
start_time = time.monotonic()
+ ctx.copilot_run_start_monotonic = start_time
iteration = 0
pending_recovery_nudge: str | None = None
diff --git a/skyvern/forge/sdk/copilot/failure_tracking.py b/skyvern/forge/sdk/copilot/failure_tracking.py
index 4da5eef7e..6552b53ab 100644
--- a/skyvern/forge/sdk/copilot/failure_tracking.py
+++ b/skyvern/forge/sdk/copilot/failure_tracking.py
@@ -30,6 +30,11 @@ if TYPE_CHECKING:
_FAILURE_REASON_MAX_CHARS = 200
+# Stable identifier for the per-tool budget failure category written into
+# ``failure_categories`` by the watchdog. Used by enforcement, reconciliation,
+# and signature normalization as a single source of truth.
+PER_TOOL_BUDGET_FAILURE_CATEGORY = "PER_TOOL_BUDGET"
+
def normalize_failure_reason(raw: str | None) -> str:
if not raw:
@@ -67,11 +72,13 @@ def compute_failure_signature(
return None
safe_label = frontier_start_label if isinstance(frontier_start_label, str) else ""
top_category = _top_failure_category(failure_categories)
- # PARAMETER_BINDING_ERROR failure_reason embeds the offending key name, so
- # collapse it to a stable constant or repeats on different keys won't hash
- # to the same signature.
+ # Categories whose failure_reason embeds per-call data (key name, run id):
+ # collapse to a stable constant so consecutive trips hash to the same
+ # signature instead of each one looking unique.
if top_category == "PARAMETER_BINDING_ERROR":
normalized = "parameter_binding_error"
+ elif top_category == PER_TOOL_BUDGET_FAILURE_CATEGORY:
+ normalized = "per_tool_budget"
parts = [
safe_label,
normalized,
diff --git a/skyvern/forge/sdk/copilot/runtime.py b/skyvern/forge/sdk/copilot/runtime.py
index 919e62a8c..7ded0c8c9 100644
--- a/skyvern/forge/sdk/copilot/runtime.py
+++ b/skyvern/forge/sdk/copilot/runtime.py
@@ -95,6 +95,11 @@ class AgentContext:
last_workflow: Any | None = None
last_workflow_yaml: str | None = None
+ copilot_run_start_monotonic: float | None = None
+
+ last_good_workflow: Any | None = None
+ last_good_workflow_yaml: str | None = None
+
def mcp_to_copilot(mcp_result: dict[str, Any]) -> dict[str, Any]:
"""Convert an MCP result dict to the copilot {ok, data, error} format."""
diff --git a/skyvern/forge/sdk/copilot/tools.py b/skyvern/forge/sdk/copilot/tools.py
index 222314652..1f14623cc 100644
--- a/skyvern/forge/sdk/copilot/tools.py
+++ b/skyvern/forge/sdk/copilot/tools.py
@@ -24,7 +24,9 @@ from skyvern.forge.sdk.artifact.models import ArtifactType
from skyvern.forge.sdk.copilot.attribution import resolve_copilot_created_by_stamp
from skyvern.forge.sdk.copilot.block_goal_wrapping import wrap_block_goals
from skyvern.forge.sdk.copilot.context import CopilotContext
+from skyvern.forge.sdk.copilot.enforcement import TOTAL_TIMEOUT_SECONDS
from skyvern.forge.sdk.copilot.failure_tracking import (
+ PER_TOOL_BUDGET_FAILURE_CATEGORY,
_canonical_block_config,
compute_action_sequence_fingerprint,
update_repeated_failure_state,
@@ -98,6 +100,13 @@ assert _TASK_ENVELOPE_BLOCK_TYPES <= _DATA_PRODUCING_BLOCK_TYPES, (
# cleanup before the SDK cancels.
RUN_BLOCKS_SAFETY_CEILING_SECONDS = 1200 # 20 min
+# Per-tool-call budget for active block runs — caps a single tool invocation
+# below the session-level wall clock (``enforcement.TOTAL_TIMEOUT_SECONDS``,
+# 600 s) so a long chain cannot consume the whole budget without giving the
+# copilot a chance to issue a smaller chain. Quiet-block runs keep the longer
+# ``RUN_BLOCKS_SAFETY_CEILING_SECONDS`` above.
+PER_TOOL_CALL_BUDGET_SECONDS = 240
+
# Primary exit condition: seconds of no observed progress across the combined
# run / block / step heartbeat. Sized to accommodate the slowest single LLM
# round-trip (~30-60 s in practice) with headroom; going tighter risks
@@ -211,15 +220,10 @@ def _trusted_post_drain_status(run: WorkflowRun | None) -> str | None:
def _maybe_clear_reconciliation_flag(copilot_ctx: Any, result: Any) -> None:
- """Clear ``pending_reconciliation_run_id`` iff ``result`` proves the
- pending run has reached a trustworthy-final status.
-
- Called from ``get_run_results_tool`` after ``_get_run_results`` returns.
- Requires (a) a pending run_id on the ctx, (b) a matching resolved run_id
- in ``result.data`` (so a ``workflow_run_id=None`` call that resolves to
- a different run does NOT clear), and (c) the resolved ``overall_status``
- passes ``is_final_excluding_canceled`` (so an ambiguous ``canceled``
- does NOT clear).
+ """Clear ``pending_reconciliation_run_id`` iff the matching resolved run
+ landed in a status the caller can move past: any ``is_final_excluding_canceled``
+ status, or any status (including ``canceled``) when the prior exit was an
+ internal per-tool-budget cancel.
"""
pending_run_id = getattr(copilot_ctx, "pending_reconciliation_run_id", None)
if not isinstance(pending_run_id, str) or not pending_run_id:
@@ -231,12 +235,16 @@ def _maybe_clear_reconciliation_flag(copilot_ctx: Any, result: Any) -> None:
return
resolved_run_id = data.get("workflow_run_id")
resolved_status = data.get("overall_status")
- if (
- isinstance(resolved_run_id, str)
- and resolved_run_id == pending_run_id
- and isinstance(resolved_status, str)
- and WorkflowRunStatus(resolved_status).is_final_excluding_canceled()
- ):
+ if not isinstance(resolved_run_id, str) or resolved_run_id != pending_run_id:
+ return
+ if not isinstance(resolved_status, str):
+ return
+ is_trusted_final = WorkflowRunStatus(resolved_status).is_final_excluding_canceled()
+ # ``last_failure_category_top`` reflects the prior block-running tool's outcome —
+ # only ``_record_run_blocks_result`` writes it, and the reconciliation guard
+ # prevents another block-running call from clobbering it before this read.
+ was_per_tool_budget = getattr(copilot_ctx, "last_failure_category_top", None) == PER_TOOL_BUDGET_FAILURE_CATEGORY
+ if is_trusted_final or was_per_tool_budget:
copilot_ctx.pending_reconciliation_run_id = None
@@ -448,6 +456,27 @@ def _tool_loop_error(ctx: AgentContext, tool_name: str, arguments: dict[str, Any
"regardless of subdomain or path variations. Reply to the user "
"explaining the failure and asking them to verify the URL."
)
+
+ # Gate on ``last_failed_workflow_yaml`` (sticky across
+ # ``update_workflow``) rather than ``last_test_ok``: otherwise the
+ # agent can sandwich an ``update_workflow`` call between the failure
+ # and the retry to clear ``last_test_ok=None`` and slip past.
+ start_ts = getattr(ctx, "copilot_run_start_monotonic", None)
+ last_failed_yaml = getattr(ctx, "last_failed_workflow_yaml", None)
+ last_good_yaml = getattr(ctx, "last_good_workflow_yaml", None)
+ if start_ts is not None and last_failed_yaml and last_good_yaml:
+ remaining = TOTAL_TIMEOUT_SECONDS - (time.monotonic() - start_ts)
+ if remaining < PER_TOOL_CALL_BUDGET_SECONDS:
+ return (
+ f"Wall-clock budget too low to retry: about "
+ f"{int(max(0.0, remaining))}s remain of the "
+ f"{TOTAL_TIMEOUT_SECONDS}s session budget. A verified "
+ "workflow exists from before the failure. Do NOT call "
+ "update_and_run_blocks or run_blocks_and_collect_debug "
+ "again. REPLY now: summarize what worked, name the "
+ "block that failed, and tell the user they can keep "
+ "the verified prefix or discard."
+ )
return None
@@ -1212,7 +1241,7 @@ def _seed_for_frontier(
# last-resort budget-exhausted branch, and ``task_exit_unfinalized`` is the
# rare race where ``execute_workflow`` naturally exits before writing a
# terminal row.
-WatchdogExitReason = Literal["success", "stagnation", "ceiling", "task_exit_unfinalized"]
+WatchdogExitReason = Literal["success", "stagnation", "ceiling", "per_tool_budget", "task_exit_unfinalized"]
# Block types that legitimately execute long silent periods: one DB write on
@@ -1310,16 +1339,10 @@ async def _watchdog_error_message(
ctx: AgentContext,
workflow_run_id: str,
run: WorkflowRun | None,
+ budget_seconds: int,
) -> str:
- """Build the LLM-facing error string for a non-success watchdog exit.
-
- Every variant ends with the same reconciliation instruction so the agent
- has a consistent next step: call ``get_run_results`` with the run_id to
- resolve the outcome before running more blocks. The ``pending_reconciliation_run_id``
- guard in ``_tool_loop_error`` enforces that the agent actually does so.
-
- None of the variants contain "timed out" or retry-inviting phrasing —
- that's the SKY-9163 regression we're fixing.
+ """LLM-facing error string for a non-success watchdog exit. No variant uses
+ "timed out" or other retry-inviting phrasing — those are SKY-9163 traps.
"""
if exit_reason == "stagnation":
body = (
@@ -1329,9 +1352,27 @@ async def _watchdog_error_message(
f"hidden validation error, or an infinite-retry loop on an action the agent "
f"cannot detect is failing."
)
+ elif exit_reason == "per_tool_budget":
+ message = (
+ f"The run exceeded the {budget_seconds}s per-tool-call budget while still "
+ f"making progress. This budget exists so a single in-flight call cannot "
+ f"consume the whole copilot session.\n"
+ f"Run ID: {workflow_run_id}.\n"
+ f"Next step: call get_run_results with this workflow_run_id to inspect what "
+ f"the cancelled run actually completed (the in-flight block was cancelled "
+ f"mid-execution and may have left partial side effects). Then call "
+ f"update_and_run_blocks with a smaller chain — the first 1-2 unverified "
+ f"blocks. Verified-prefix state is preserved, so the next call only re-runs "
+ f"from the new frontier. Do NOT retry the same chain unchanged — a longer "
+ f"run won't fit either."
+ )
+ current_url, _ = await _fallback_page_info(ctx)
+ if current_url:
+ message += f" Browser was on: {current_url}"
+ return message
elif exit_reason == "ceiling":
body = (
- f"The run exceeded the {RUN_BLOCKS_SAFETY_CEILING_SECONDS}s absolute ceiling "
+ f"The run exceeded the {budget_seconds}s absolute ceiling "
f"while still showing progress. The workflow is too long to fit in a single "
f"tool invocation — split it into smaller block groups."
)
@@ -1508,7 +1549,6 @@ async def _run_blocks_and_collect_debug(
progress_marker = _progress_marker(initial_run, initial_step_ts, initial_block_ts)
last_progress_monotonic = time.monotonic()
started_monotonic = last_progress_monotonic
- budget_seconds = max(1, RUN_BLOCKS_SAFETY_CEILING_SECONDS - 10)
final_status: str | None = None
run: Any = initial_run
exit_reason: WatchdogExitReason | None = None
@@ -1517,6 +1557,17 @@ async def _run_blocks_and_collect_debug(
# DB-silent periods; disable stagnation for any invocation that includes
# one. Safety ceiling still applies.
stagnation_enabled = not _any_quiet_block_requested(ctx, labels_to_execute)
+ # Active block runs use the tighter per-tool budget so a single in-flight
+ # call cannot consume the whole copilot session. Quiet-block runs keep the
+ # long safety ceiling because HumanInteractionBlock can legitimately pause
+ # indefinitely.
+ budget_exit_reason: WatchdogExitReason
+ if stagnation_enabled:
+ budget_seconds = max(1, PER_TOOL_CALL_BUDGET_SECONDS)
+ budget_exit_reason = "per_tool_budget"
+ else:
+ budget_seconds = max(1, RUN_BLOCKS_SAFETY_CEILING_SECONDS - 10)
+ budget_exit_reason = "ceiling"
# Mid-tool narrator bridge: feed block-status changes and step-level
# heartbeats into NarratorState so the narration ticker keeps emitting
@@ -1580,7 +1631,7 @@ async def _run_blocks_and_collect_debug(
break
if now - started_monotonic >= budget_seconds:
- exit_reason = "ceiling"
+ exit_reason = budget_exit_reason
break
if exit_reason is not None and exit_reason != "success":
@@ -1610,14 +1661,31 @@ async def _run_blocks_and_collect_debug(
exit_reason = "success"
if exit_reason != "success":
- # Turn-scoped reconciliation guard — cleared only by a
- # ``get_run_results`` call that resolves this run_id to an
- # ``is_final_excluding_canceled`` status
- # (``_maybe_clear_reconciliation_flag``).
- ctx.pending_reconciliation_run_id = workflow_run.workflow_run_id
assert exit_reason is not None # narrows for mypy; outer check excludes "success" but not None
- error_msg = await _watchdog_error_message(exit_reason, ctx, workflow_run.workflow_run_id, run)
- result = {"ok": False, "error": error_msg}
+ ctx.pending_reconciliation_run_id = workflow_run.workflow_run_id
+ error_msg = await _watchdog_error_message(
+ exit_reason, ctx, workflow_run.workflow_run_id, run, budget_seconds
+ )
+ result: dict[str, Any] = {"ok": False, "error": error_msg}
+ if exit_reason == "per_tool_budget":
+ # Stable failure_categories entry so consecutive budget trips
+ # hash to the same streak signature; without it the run_id in
+ # ``error_msg`` would make every trip unique.
+ result["data"] = {
+ "workflow_run_id": workflow_run.workflow_run_id,
+ "overall_status": run.status if run is not None else None,
+ "failure_reason": error_msg,
+ "failure_categories": [
+ {
+ "category": PER_TOOL_BUDGET_FAILURE_CATEGORY,
+ "confidence_float": 1.0,
+ "reasoning": (
+ f"Per-tool-call budget of {budget_seconds}s exceeded; "
+ "the run was making progress but cannot fit in a single tool call."
+ ),
+ }
+ ],
+ }
if run_cancelled_by_watchdog:
result[_INTERNAL_RUN_CANCELLED_BY_WATCHDOG_KEY] = True
return result
@@ -2446,6 +2514,7 @@ def _record_run_blocks_result(copilot_ctx: Any, result: dict[str, Any]) -> None:
copilot_ctx.last_test_suspicious_success = False
copilot_ctx.suspicious_success_nudge_count = 0
copilot_ctx.last_test_anti_bot = None
+ prior_budget_flag = copilot_ctx.last_failure_category_top == PER_TOOL_BUDGET_FAILURE_CATEGORY
copilot_ctx.last_failure_category_top = None
copilot_ctx.last_test_non_retriable_nav_error = None
@@ -2459,6 +2528,12 @@ def _record_run_blocks_result(copilot_ctx: Any, result: dict[str, Any]) -> None:
if isinstance(top_category, str):
copilot_ctx.last_failure_category_top = top_category
+ # A fresh budget trip on a different chain should get the dedicated split
+ # nudge again rather than falling through to the generic failed-test path,
+ # so reset the cap when the latest run is not itself a budget trip.
+ if prior_budget_flag and copilot_ctx.last_failure_category_top != PER_TOOL_BUDGET_FAILURE_CATEGORY:
+ copilot_ctx.per_tool_budget_nudge_count = 0
+
# Expose full failure classification in tool output for agent reasoning
if failure_categories:
data = result.get("data")
@@ -2487,6 +2562,8 @@ def _record_run_blocks_result(copilot_ctx: Any, result: dict[str, Any]) -> None:
# Real success: clear the signature latch so a subsequent bad URL in
# the same session can re-fire the stop nudge.
copilot_ctx.non_retriable_nav_error_last_emitted_signature = None
+ copilot_ctx.last_good_workflow = copilot_ctx.last_workflow
+ copilot_ctx.last_good_workflow_yaml = copilot_ctx.last_workflow_yaml
update_repeated_failure_state(copilot_ctx, result)
return
diff --git a/skyvern/forge/sdk/routes/debug_sessions.py b/skyvern/forge/sdk/routes/debug_sessions.py
index 3521148e3..9dba437f0 100644
--- a/skyvern/forge/sdk/routes/debug_sessions.py
+++ b/skyvern/forge/sdk/routes/debug_sessions.py
@@ -226,10 +226,18 @@ async def new_debug_session(
)
)
+ # Look up the workflow's proxy_location so the debug session browser
+ # uses the same proxy region the user configured on the workflow.
+ workflow = await app.WORKFLOW_SERVICE.get_workflow_by_permanent_id(
+ workflow_permanent_id=workflow_permanent_id,
+ organization_id=current_org.organization_id,
+ )
+ proxy_location = workflow.proxy_location or ProxyLocation.RESIDENTIAL
+
new_browser_session = await app.PERSISTENT_SESSIONS_MANAGER.create_session(
organization_id=current_org.organization_id,
timeout_minutes=settings.DEBUG_SESSION_TIMEOUT_MINUTES,
- proxy_location=ProxyLocation.RESIDENTIAL,
+ proxy_location=proxy_location,
)
debug_session = await app.DATABASE.debug.create_debug_session(
@@ -249,6 +257,7 @@ async def new_debug_session(
organization_id=current_org.organization_id,
user_id=current_user_id,
workflow_permanent_id=workflow_permanent_id,
+ proxy_location=str(proxy_location),
)
return debug_session
diff --git a/tests/unit/test_copilot_agent_helpers.py b/tests/unit/test_copilot_agent_helpers.py
index 23aa24fbe..0949f7ca0 100644
--- a/tests/unit/test_copilot_agent_helpers.py
+++ b/tests/unit/test_copilot_agent_helpers.py
@@ -738,3 +738,20 @@ class TestCredentialRefusalReachesAgent:
assert "redacted from" not in desc, f"{tool.name} still claims redaction"
assert "you may pass it via" not in desc, f"{tool.name} still permits inline secrets"
assert cross_ref.search(desc), f"{tool.name} missing refusal cross-reference"
+
+
+class TestResponseTypeClassificationRuleReachesAgent:
+ """Pin the classifier rule that selects ASK_QUESTION when `user_response` asks the user for required input — the agent.py null-out gate keys on `resp_type == "ASK_QUESTION"` and depends on this prompt text."""
+
+ def test_build_system_prompt_carries_classification_rule(self) -> None:
+ from skyvern.forge.sdk.copilot.agent import _build_system_prompt
+
+ prompt = _build_system_prompt(tool_usage_guide="", security_rules="")
+
+ assert "RESPONSE-TYPE CLASSIFICATION" in prompt
+ assert "required before you can continue" in prompt
+ assert "this turn built or tested a partial workflow" in prompt
+ assert "goal_reached: false" in prompt
+ assert "Classify by intent, not punctuation" in prompt
+ assert "does NOT imply REPLY" in prompt
+ assert prompt.index("RESPONSE-TYPE CLASSIFICATION") < prompt.index("**Option 1: Reply to the user**")
diff --git a/tests/unit/test_copilot_enforcement_pruning.py b/tests/unit/test_copilot_enforcement_pruning.py
index 2d65f98c2..f8b0fa98e 100644
--- a/tests/unit/test_copilot_enforcement_pruning.py
+++ b/tests/unit/test_copilot_enforcement_pruning.py
@@ -462,6 +462,8 @@ class TestEnforcement:
ctx.explore_without_workflow_nudge_count = 0
ctx.last_test_suspicious_success = False
ctx.last_test_anti_bot = None
+ ctx.last_failure_category_top = None
+ ctx.per_tool_budget_nudge_count = 0
for k, v in overrides.items():
setattr(ctx, k, v)
return ctx
diff --git a/tests/unit/test_copilot_mid_correction_guard.py b/tests/unit/test_copilot_mid_correction_guard.py
new file mode 100644
index 000000000..88a3ae2e0
--- /dev/null
+++ b/tests/unit/test_copilot_mid_correction_guard.py
@@ -0,0 +1,252 @@
+"""Tests for the mid-correction wall-clock guard and salvage path."""
+
+from __future__ import annotations
+
+import time
+from types import SimpleNamespace
+from typing import Any
+
+from skyvern.forge.sdk.copilot.agent import (
+ _TIMEOUT_REPLY_DEFAULT,
+ _TIMEOUT_REPLY_TESTED,
+ _build_timeout_exit_result,
+)
+from skyvern.forge.sdk.copilot.context import CopilotContext
+from skyvern.forge.sdk.copilot.enforcement import TOTAL_TIMEOUT_SECONDS
+from skyvern.forge.sdk.copilot.tools import (
+ PER_TOOL_CALL_BUDGET_SECONDS,
+ _record_run_blocks_result,
+ _tool_loop_error,
+)
+
+
+def _fresh_context() -> CopilotContext:
+ return CopilotContext(
+ organization_id="o",
+ workflow_id="w",
+ workflow_permanent_id="wp",
+ workflow_yaml="",
+ browser_session_id=None,
+ stream=SimpleNamespace(), # type: ignore[arg-type]
+ )
+
+
+def _ctx_after_failure_with_verified_prefix(*, elapsed_seconds: float) -> CopilotContext:
+ ctx = _fresh_context()
+ ctx.copilot_run_start_monotonic = time.monotonic() - elapsed_seconds
+ ctx.last_test_ok = False
+ ctx.last_failed_workflow_yaml = "yaml-failed"
+ ctx.last_good_workflow = SimpleNamespace(workflow_id="wf-good")
+ ctx.last_good_workflow_yaml = "yaml-good"
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-failed")
+ ctx.last_workflow_yaml = "yaml-failed"
+ return ctx
+
+
+def test_tool_loop_error_blocks_run_when_budget_low_after_failure() -> None:
+ elapsed = TOTAL_TIMEOUT_SECONDS - (PER_TOOL_CALL_BUDGET_SECONDS - 30)
+ ctx = _ctx_after_failure_with_verified_prefix(elapsed_seconds=elapsed)
+ for tool in ("update_and_run_blocks", "run_blocks_and_collect_debug"):
+ msg = _tool_loop_error(ctx, tool)
+ assert msg is not None and "Wall-clock budget too low" in msg, tool
+
+
+def test_tool_loop_error_no_guard_when_budget_sufficient() -> None:
+ ctx = _ctx_after_failure_with_verified_prefix(
+ elapsed_seconds=TOTAL_TIMEOUT_SECONDS - (PER_TOOL_CALL_BUDGET_SECONDS + 60)
+ )
+ assert _tool_loop_error(ctx, "update_and_run_blocks") is None
+
+
+def test_tool_loop_error_no_guard_on_first_call() -> None:
+ ctx = _fresh_context()
+ ctx.copilot_run_start_monotonic = time.monotonic() - (TOTAL_TIMEOUT_SECONDS - 10)
+ assert _tool_loop_error(ctx, "update_and_run_blocks") is None
+
+
+def test_tool_loop_error_no_guard_when_no_good_workflow_exists() -> None:
+ ctx = _fresh_context()
+ ctx.copilot_run_start_monotonic = time.monotonic() - (TOTAL_TIMEOUT_SECONDS - 10)
+ ctx.last_test_ok = False
+ ctx.last_failed_workflow_yaml = "yaml-failed"
+ assert _tool_loop_error(ctx, "update_and_run_blocks") is None
+
+
+def test_tool_loop_error_no_guard_for_non_block_running_tools() -> None:
+ elapsed = TOTAL_TIMEOUT_SECONDS - (PER_TOOL_CALL_BUDGET_SECONDS - 30)
+ ctx = _ctx_after_failure_with_verified_prefix(elapsed_seconds=elapsed)
+ for tool in ("update_workflow", "list_credentials", "get_run_results"):
+ assert _tool_loop_error(ctx, tool) is None, tool
+
+
+def test_tool_loop_error_guard_persists_through_update_workflow() -> None:
+ # ``last_test_ok`` flips to None on every ``update_workflow``, but
+ # ``last_failed_workflow_yaml`` stays — so the guard must still fire.
+ elapsed = TOTAL_TIMEOUT_SECONDS - (PER_TOOL_CALL_BUDGET_SECONDS - 30)
+ ctx = _ctx_after_failure_with_verified_prefix(elapsed_seconds=elapsed)
+ ctx.last_test_ok = None
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-edited")
+ ctx.last_workflow_yaml = "yaml-edited"
+ msg = _tool_loop_error(ctx, "update_and_run_blocks")
+ assert msg is not None and "Wall-clock budget too low" in msg
+
+
+def test_record_run_blocks_result_promotes_last_good_on_real_success() -> None:
+ ctx = _fresh_context()
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-1")
+ ctx.last_workflow_yaml = "yaml-1"
+ _record_run_blocks_result(ctx, {"ok": True, "data": {"blocks": []}})
+ assert ctx.last_good_workflow is ctx.last_workflow
+ assert ctx.last_good_workflow_yaml == "yaml-1"
+
+
+def test_record_run_blocks_result_does_not_promote_on_empty_data_success() -> None:
+ ctx = _fresh_context()
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-1")
+ ctx.last_workflow_yaml = "yaml-1"
+ blocks = [{"block_type": "EXTRACTION", "label": "x", "status": "completed", "extracted_data": None}]
+ _record_run_blocks_result(ctx, {"ok": True, "data": {"blocks": blocks}})
+ assert ctx.last_test_suspicious_success is True
+ assert ctx.last_good_workflow is None
+
+
+def test_record_run_blocks_result_does_not_promote_on_failure() -> None:
+ ctx = _fresh_context()
+ ctx.last_good_workflow = SimpleNamespace(workflow_id="wf-prev")
+ ctx.last_good_workflow_yaml = "yaml-prev"
+ _record_run_blocks_result(ctx, {"ok": False, "data": {"blocks": []}})
+ assert ctx.last_good_workflow is not None
+ assert ctx.last_good_workflow_yaml == "yaml-prev"
+
+
+def test_build_timeout_exit_result_surfaces_last_good_after_failure() -> None:
+ ctx = _fresh_context()
+ ctx.last_test_ok = False
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-failed")
+ ctx.last_workflow_yaml = "yaml-failed"
+ ctx.last_good_workflow = SimpleNamespace(workflow_id="wf-good")
+ ctx.last_good_workflow_yaml = "yaml-good"
+ ctx.workflow_persisted = True
+ result = _build_timeout_exit_result(ctx, global_llm_context=None)
+ assert result.updated_workflow is ctx.last_good_workflow
+ assert result.workflow_yaml == "yaml-good"
+ assert result.unvalidated is True
+ assert result.user_response == _TIMEOUT_REPLY_TESTED
+
+
+def test_build_timeout_exit_result_surfaces_last_good_on_mid_flight_cancellation() -> None:
+ # Deadline fires between ``_record_workflow_update_result`` and
+ # ``_record_run_blocks_result``: ``last_test_ok`` is None but
+ # ``last_workflow`` is the in-flight unverified shape.
+ ctx = _fresh_context()
+ ctx.last_test_ok = None
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-in-flight")
+ ctx.last_workflow_yaml = "yaml-in-flight"
+ ctx.last_good_workflow = SimpleNamespace(workflow_id="wf-good")
+ ctx.last_good_workflow_yaml = "yaml-good"
+ result = _build_timeout_exit_result(ctx, global_llm_context=None)
+ assert result.updated_workflow is ctx.last_good_workflow
+ assert result.unvalidated is True
+
+
+def test_build_timeout_exit_result_falls_through_when_no_last_good() -> None:
+ ctx = _fresh_context()
+ ctx.last_test_ok = False
+ result = _build_timeout_exit_result(ctx, global_llm_context=None)
+ assert result.user_response == _TIMEOUT_REPLY_DEFAULT
+ assert result.updated_workflow is None
+
+
+def _fake_run_result(envelope: dict[str, Any]) -> SimpleNamespace:
+ import json as _json
+
+ return SimpleNamespace(final_output=_json.dumps(envelope), new_items=[])
+
+
+def _fake_chat_request() -> SimpleNamespace:
+ return SimpleNamespace(
+ workflow_id="wf-id",
+ workflow_permanent_id="wfp-id",
+ workflow_yaml="",
+ message="",
+ browser_session_id=None,
+ workflow_copilot_chat_id="chat-id",
+ )
+
+
+def test_translate_to_agent_result_salvages_last_good_on_failed_reply() -> None:
+ from skyvern.forge.sdk.copilot.agent import _translate_to_agent_result
+
+ ctx = _fresh_context()
+ ctx.last_test_ok = False
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-failed")
+ ctx.last_workflow_yaml = "yaml-failed"
+ ctx.last_update_block_count = 5
+ ctx.last_good_workflow = SimpleNamespace(workflow_id="wf-good")
+ ctx.last_good_workflow_yaml = "yaml-good"
+ agent_text = "Built 4 verified blocks; block 5 failed."
+ result = _fake_run_result({"type": "REPLY", "user_response": agent_text, "goal_reached": False})
+ agent_result = _translate_to_agent_result(
+ result, ctx, global_llm_context=None, chat_request=_fake_chat_request(), organization_id="o"
+ )
+ assert agent_result.updated_workflow is ctx.last_good_workflow
+ assert agent_result.workflow_yaml == "yaml-good"
+ assert agent_result.unvalidated is True
+ # Failure rewrite would have replaced the agent's text with one based on
+ # ``last_update_block_count=5``; salvage must skip the rewrite.
+ assert agent_result.user_response == agent_text
+
+
+def test_translate_to_agent_result_salvages_after_failure_then_update_workflow() -> None:
+ # failure → ``update_workflow`` → guard → REPLY: ``last_test_ok`` is
+ # cleared by the edit but ``last_failed_workflow_yaml`` stays sticky.
+ from skyvern.forge.sdk.copilot.agent import _translate_to_agent_result
+
+ ctx = _fresh_context()
+ ctx.last_test_ok = None
+ ctx.last_failed_workflow_yaml = "yaml-failed"
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-edited")
+ ctx.last_workflow_yaml = "yaml-edited"
+ ctx.last_good_workflow = SimpleNamespace(workflow_id="wf-good")
+ ctx.last_good_workflow_yaml = "yaml-good"
+ agent_text = "Built 4 blocks; block 5 failed; ran out of time."
+ result = _fake_run_result({"type": "REPLY", "user_response": agent_text, "goal_reached": False})
+ agent_result = _translate_to_agent_result(
+ result, ctx, global_llm_context=None, chat_request=_fake_chat_request(), organization_id="o"
+ )
+ assert agent_result.updated_workflow is ctx.last_good_workflow
+ assert agent_result.unvalidated is True
+ assert agent_result.user_response == agent_text
+
+
+def test_translate_to_agent_result_does_not_salvage_on_standalone_edit() -> None:
+ # Pure "edited but never tested" — no failure recorded — must not salvage.
+ from skyvern.forge.sdk.copilot.agent import _translate_to_agent_result
+
+ ctx = _fresh_context()
+ ctx.last_test_ok = None
+ ctx.last_failed_workflow_yaml = None
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-edited")
+ ctx.last_workflow_yaml = "yaml-edited"
+ ctx.last_good_workflow = SimpleNamespace(workflow_id="wf-good")
+ ctx.last_good_workflow_yaml = "yaml-good"
+ result = _fake_run_result({"type": "REPLY", "user_response": "Drafted.", "goal_reached": False})
+ agent_result = _translate_to_agent_result(
+ result, ctx, global_llm_context=None, chat_request=_fake_chat_request(), organization_id="o"
+ )
+ assert agent_result.updated_workflow is ctx.last_workflow
+ assert agent_result.workflow_yaml == "yaml-edited"
+
+
+def test_salvage_skipped_on_suspicious_success() -> None:
+ # The empty-data carve-out in ``_build_wip_exit_result`` deliberately
+ # drops the proposal; salvage must respect that.
+ ctx = _fresh_context()
+ ctx.last_test_ok = None
+ ctx.last_test_suspicious_success = True
+ ctx.last_workflow = SimpleNamespace(workflow_id="wf-suspicious")
+ ctx.last_workflow_yaml = "yaml-suspicious"
+ ctx.last_good_workflow = SimpleNamespace(workflow_id="wf-good")
+ ctx.last_good_workflow_yaml = "yaml-good"
+ result = _build_timeout_exit_result(ctx, global_llm_context=None)
+ assert result.updated_workflow is None
diff --git a/tests/unit/test_copilot_per_tool_budget.py b/tests/unit/test_copilot_per_tool_budget.py
new file mode 100644
index 000000000..1691389e4
--- /dev/null
+++ b/tests/unit/test_copilot_per_tool_budget.py
@@ -0,0 +1,339 @@
+"""Tests for the per-tool-call budget cap and its enforcement nudge.
+
+Covers four surfaces:
+
+- ``_record_run_blocks_result`` — the ``PER_TOOL_BUDGET`` failure-category
+ entry must land on ``last_failure_category_top``.
+- ``_needs_per_tool_budget_nudge`` — fires while under the per-streak cap,
+ stops once the cap is reached.
+- ``_check_enforcement`` ordering — the budget nudge must pre-empt the
+ generic ``POST_FAILED_TEST_NUDGE`` and the repeated-frontier escalation.
+- ``compute_failure_signature`` — the run_id baked into the watchdog
+ message must not make consecutive trips hash differently.
+- ``_maybe_clear_reconciliation_flag`` — a ``canceled`` row clears the
+ guard for budget exits, but not for other watchdog cancels.
+"""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+import pytest
+
+from skyvern.forge.sdk.copilot.context import CopilotContext
+from skyvern.forge.sdk.copilot.enforcement import (
+ MAX_PER_TOOL_BUDGET_NUDGES,
+ POST_FAILED_TEST_NUDGE,
+ POST_PER_TOOL_BUDGET_NUDGE,
+ REPEATED_FRONTIER_STREAK_ESCALATE_AT,
+ _check_enforcement,
+ _needs_per_tool_budget_nudge,
+)
+from skyvern.forge.sdk.copilot.failure_tracking import (
+ PER_TOOL_BUDGET_FAILURE_CATEGORY,
+ compute_failure_signature,
+)
+from skyvern.forge.sdk.copilot.tools import _maybe_clear_reconciliation_flag, _record_run_blocks_result
+
+
+def _fresh_context() -> CopilotContext:
+ return CopilotContext(
+ organization_id="o",
+ workflow_id="w",
+ workflow_permanent_id="wp",
+ workflow_yaml="",
+ browser_session_id=None,
+ stream=SimpleNamespace(), # type: ignore[arg-type]
+ )
+
+
+def _budget_trip_result(workflow_run_id: str = "wr_1") -> dict:
+ return {
+ "ok": False,
+ "error": (
+ f"The run exceeded the 240s per-tool-call budget while still making progress. "
+ f"... Run ID: {workflow_run_id}. ..."
+ ),
+ "data": {
+ "workflow_run_id": workflow_run_id,
+ "overall_status": "running",
+ "failure_reason": f"per-tool-call budget exceeded (Run ID: {workflow_run_id})",
+ "failure_categories": [
+ {
+ "category": PER_TOOL_BUDGET_FAILURE_CATEGORY,
+ "confidence_float": 1.0,
+ "reasoning": "Per-tool-call budget exceeded",
+ }
+ ],
+ },
+ }
+
+
+def test_record_sets_top_category_on_per_tool_budget_result() -> None:
+ ctx = _fresh_context()
+ _record_run_blocks_result(ctx, _budget_trip_result())
+ assert ctx.last_failure_category_top == PER_TOOL_BUDGET_FAILURE_CATEGORY
+
+
+def test_record_clears_top_category_on_run_with_different_category() -> None:
+ ctx = _fresh_context()
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+
+ other_failure = {
+ "ok": False,
+ "error": "boom",
+ "data": {
+ "blocks": [{"status": "failed", "failure_reason": "something else"}],
+ "failure_categories": [{"category": "PARAMETER_BINDING_ERROR"}],
+ },
+ }
+ _record_run_blocks_result(ctx, other_failure)
+ assert ctx.last_failure_category_top == "PARAMETER_BINDING_ERROR"
+
+
+def test_record_clears_top_category_on_success() -> None:
+ ctx = _fresh_context()
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+
+ success = {
+ "ok": True,
+ "data": {
+ "blocks": [
+ {
+ "block_type": "EXTRACTION",
+ "status": "completed",
+ "extracted_data": {"price": 10},
+ }
+ ]
+ },
+ }
+ _record_run_blocks_result(ctx, success)
+ assert ctx.last_failure_category_top is None
+
+
+def test_gate_does_not_fire_when_top_category_unset() -> None:
+ ctx = _fresh_context()
+ assert not _needs_per_tool_budget_nudge(ctx)
+
+
+def test_gate_fires_when_top_category_is_budget_and_cap_not_reached() -> None:
+ ctx = _fresh_context()
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+ assert _needs_per_tool_budget_nudge(ctx)
+
+
+def test_gate_does_not_fire_after_cap_reached() -> None:
+ ctx = _fresh_context()
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+ ctx.per_tool_budget_nudge_count = MAX_PER_TOOL_BUDGET_NUDGES
+ assert not _needs_per_tool_budget_nudge(ctx)
+
+
+def test_check_enforcement_emits_budget_nudge_before_failed_test() -> None:
+ """A budget trip also looks like a failed test (last_test_ok=False), so
+ without the dedicated path it would land in POST_FAILED_TEST_NUDGE. The
+ budget nudge must pre-empt it."""
+ ctx = _fresh_context()
+ ctx.update_workflow_called = True
+ ctx.test_after_update_done = True
+ ctx.last_test_ok = False
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+
+ nudge = _check_enforcement(ctx)
+ assert nudge == POST_PER_TOOL_BUDGET_NUDGE
+ assert ctx.per_tool_budget_nudge_count == 1
+
+
+def test_check_enforcement_emits_budget_nudge_before_repeated_frontier_warn() -> None:
+ """The budget trip is structural (chain too long) and must not be silently
+ consumed by the repeated-frontier escalation, even when both signals fire
+ at the same iteration."""
+ ctx = _fresh_context()
+ ctx.update_workflow_called = True
+ ctx.test_after_update_done = True
+ ctx.last_test_ok = False
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+ ctx.repeated_failure_streak_count = REPEATED_FRONTIER_STREAK_ESCALATE_AT
+
+ nudge = _check_enforcement(ctx)
+ assert nudge == POST_PER_TOOL_BUDGET_NUDGE
+
+
+def test_check_enforcement_falls_through_to_failed_test_after_budget_cap() -> None:
+ ctx = _fresh_context()
+ ctx.update_workflow_called = True
+ ctx.test_after_update_done = True
+ ctx.last_test_ok = False
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+ ctx.per_tool_budget_nudge_count = MAX_PER_TOOL_BUDGET_NUDGES
+
+ nudge = _check_enforcement(ctx)
+ assert nudge == POST_FAILED_TEST_NUDGE
+
+
+def test_failure_signature_is_stable_across_budget_trips_with_different_run_ids() -> None:
+ """Without normalization the watchdog's run_id-laden message would make
+ each trip hash uniquely and the streak would never accrue."""
+ failure_categories = [{"category": PER_TOOL_BUDGET_FAILURE_CATEGORY, "confidence_float": 1.0}]
+ sig_a = compute_failure_signature(
+ frontier_start_label="block_a",
+ failure_reason="per-tool-call budget exceeded (Run ID: wr_aaaa)",
+ failure_categories=failure_categories,
+ suspicious_success=False,
+ )
+ sig_b = compute_failure_signature(
+ frontier_start_label="block_a",
+ failure_reason="per-tool-call budget exceeded (Run ID: wr_bbbb)",
+ failure_categories=failure_categories,
+ suspicious_success=False,
+ )
+ assert sig_a is not None
+ assert sig_a == sig_b
+
+
+def test_failure_signature_changes_when_frontier_label_differs() -> None:
+ """A budget trip on a different frontier should still produce a different
+ signature so the streak resets when the agent meaningfully changes shape."""
+ failure_categories = [{"category": PER_TOOL_BUDGET_FAILURE_CATEGORY, "confidence_float": 1.0}]
+ sig_a = compute_failure_signature(
+ frontier_start_label="block_a",
+ failure_reason="per-tool-call budget exceeded (Run ID: wr_aaaa)",
+ failure_categories=failure_categories,
+ suspicious_success=False,
+ )
+ sig_b = compute_failure_signature(
+ frontier_start_label="block_b",
+ failure_reason="per-tool-call budget exceeded (Run ID: wr_bbbb)",
+ failure_categories=failure_categories,
+ suspicious_success=False,
+ )
+ assert sig_a != sig_b
+
+
+def test_nudge_text_advises_splitting_chain() -> None:
+ assert "STOP" in POST_PER_TOOL_BUDGET_NUDGE
+ assert "split" in POST_PER_TOOL_BUDGET_NUDGE.lower() or "shrink" in POST_PER_TOOL_BUDGET_NUDGE.lower()
+ assert (
+ "verified-prefix" in POST_PER_TOOL_BUDGET_NUDGE.lower()
+ or "verified prefix" in POST_PER_TOOL_BUDGET_NUDGE.lower()
+ )
+ assert "Do NOT retry the same chain" in POST_PER_TOOL_BUDGET_NUDGE
+
+
+ "watchdog_phrase",
+ ["timed out", "wait and retry", "try again with a different selector"],
+)
+def test_nudge_does_not_invite_generic_retry(watchdog_phrase: str) -> None:
+ """The nudge must not lead the agent toward "wait and retry" — that's
+ exactly the failure mode this fix exists to prevent."""
+ assert watchdog_phrase not in POST_PER_TOOL_BUDGET_NUDGE.lower()
+
+
+def _get_run_results_response(workflow_run_id: str, status: str) -> dict:
+ return {"data": {"workflow_run_id": workflow_run_id, "overall_status": status}}
+
+
+def test_reconciliation_clears_for_per_tool_budget_even_on_canceled_status() -> None:
+ """The whole point of the budget exit is that the agent can issue a smaller
+ chain in the same turn. ``canceled`` would normally NOT clear the guard,
+ but for budget exits we know it was our own cancel."""
+ ctx = _fresh_context()
+ ctx.pending_reconciliation_run_id = "wr_1"
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+
+ _maybe_clear_reconciliation_flag(ctx, _get_run_results_response("wr_1", "canceled"))
+
+ assert ctx.pending_reconciliation_run_id is None
+
+
+def test_reconciliation_does_not_clear_for_non_budget_canceled() -> None:
+ """Non-budget watchdog cancels keep the existing strict semantics:
+ ``canceled`` is ambiguous and must not silently clear the guard."""
+ ctx = _fresh_context()
+ ctx.pending_reconciliation_run_id = "wr_1"
+ ctx.last_failure_category_top = None
+
+ _maybe_clear_reconciliation_flag(ctx, _get_run_results_response("wr_1", "canceled"))
+
+ assert ctx.pending_reconciliation_run_id == "wr_1"
+
+
+def test_reconciliation_clears_for_per_tool_budget_failed_status_too() -> None:
+ """``failed`` would clear the guard regardless, but check the budget path
+ doesn't accidentally regress that case."""
+ ctx = _fresh_context()
+ ctx.pending_reconciliation_run_id = "wr_1"
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+
+ _maybe_clear_reconciliation_flag(ctx, _get_run_results_response("wr_1", "failed"))
+
+ assert ctx.pending_reconciliation_run_id is None
+
+
+def test_reconciliation_does_not_clear_when_run_id_mismatches() -> None:
+ """Even with the budget category set, a get_run_results response for a
+ different run_id must not clear the pending reconciliation."""
+ ctx = _fresh_context()
+ ctx.pending_reconciliation_run_id = "wr_1"
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+
+ _maybe_clear_reconciliation_flag(ctx, _get_run_results_response("wr_other", "canceled"))
+
+ assert ctx.pending_reconciliation_run_id == "wr_1"
+
+
+def test_nudge_counter_resets_on_success() -> None:
+ """The counter must reset so a budget trip on a different chain in the
+ same turn gets the dedicated split nudge again."""
+ ctx = _fresh_context()
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+ ctx.per_tool_budget_nudge_count = MAX_PER_TOOL_BUDGET_NUDGES
+
+ success = {
+ "ok": True,
+ "data": {
+ "blocks": [
+ {
+ "block_type": "EXTRACTION",
+ "status": "completed",
+ "extracted_data": {"price": 10},
+ }
+ ]
+ },
+ }
+ _record_run_blocks_result(ctx, success)
+
+ assert ctx.per_tool_budget_nudge_count == 0
+
+
+def test_nudge_counter_resets_when_failure_changes_to_non_budget() -> None:
+ ctx = _fresh_context()
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+ ctx.per_tool_budget_nudge_count = MAX_PER_TOOL_BUDGET_NUDGES
+
+ other_failure = {
+ "ok": False,
+ "error": "boom",
+ "data": {
+ "blocks": [{"status": "failed", "failure_reason": "something else"}],
+ "failure_categories": [{"category": "PARAMETER_BINDING_ERROR"}],
+ },
+ }
+ _record_run_blocks_result(ctx, other_failure)
+
+ assert ctx.per_tool_budget_nudge_count == 0
+ assert ctx.last_failure_category_top == "PARAMETER_BINDING_ERROR"
+
+
+def test_nudge_counter_preserved_across_consecutive_budget_trips() -> None:
+ """Two consecutive budget trips should not reset the counter; otherwise
+ the cap would never kick in."""
+ ctx = _fresh_context()
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+ ctx.per_tool_budget_nudge_count = 1
+
+ _record_run_blocks_result(ctx, _budget_trip_result(workflow_run_id="wr_2"))
+
+ assert ctx.per_tool_budget_nudge_count == 1
+ assert ctx.last_failure_category_top == PER_TOOL_BUDGET_FAILURE_CATEGORY
diff --git a/tests/unit/test_copilot_timeout_wip.py b/tests/unit/test_copilot_timeout_wip.py
index 10250e679..0da45fdce 100644
--- a/tests/unit/test_copilot_timeout_wip.py
+++ b/tests/unit/test_copilot_timeout_wip.py
@@ -31,6 +31,8 @@ def _ctx(
last_workflow_yaml: str | None,
last_test_ok: bool | None,
last_test_suspicious_success: bool = False,
+ last_good_workflow: object | None = None,
+ last_good_workflow_yaml: str | None = None,
) -> MagicMock:
ctx = MagicMock()
ctx.last_workflow = last_workflow
@@ -40,6 +42,8 @@ def _ctx(
ctx.copilot_total_timeout_exceeded = False
ctx.workflow_persisted = last_workflow is not None
ctx.total_tokens_used = None
+ ctx.last_good_workflow = last_good_workflow
+ ctx.last_good_workflow_yaml = last_good_workflow_yaml
return ctx
diff --git a/tests/unit/test_copilot_watchdog.py b/tests/unit/test_copilot_watchdog.py
index 7dc9dee91..56cad8f95 100644
--- a/tests/unit/test_copilot_watchdog.py
+++ b/tests/unit/test_copilot_watchdog.py
@@ -33,6 +33,7 @@ from typing import Any
import pytest
from skyvern.forge.sdk.copilot.tools import (
+ PER_TOOL_CALL_BUDGET_SECONDS,
RUN_BLOCKS_SAFETY_CEILING_SECONDS,
RUN_BLOCKS_STAGNATION_WINDOW_SECONDS,
_any_quiet_block_requested,
@@ -250,7 +251,7 @@ async def test_stagnation_error_message_does_not_invite_retry() -> None:
"""The exact SKY-9163 bug: the old copy said "likely stuck repeating
failing actions" which the LLM read as "try again". The stagnation
message must explicitly discourage retry."""
- msg = await _watchdog_error_message("stagnation", _ErrorCtx(), "wr_test", _fake_run())
+ msg = await _watchdog_error_message("stagnation", _ErrorCtx(), "wr_test", _fake_run(), PER_TOOL_CALL_BUDGET_SECONDS)
assert "timed out" not in msg.lower()
assert "likely stuck repeating" not in msg.lower()
@@ -265,22 +266,45 @@ async def test_ceiling_error_message_advises_splitting() -> None:
"""The ceiling path is rare (a runaway run that keeps making progress
past 20 min). Its error must tell the LLM to split the workflow, not
retry — a longer run won't fit either."""
- msg = await _watchdog_error_message("ceiling", _ErrorCtx(), "wr_test", _fake_run())
+ quiet_budget = RUN_BLOCKS_SAFETY_CEILING_SECONDS - 10
+ msg = await _watchdog_error_message("ceiling", _ErrorCtx(), "wr_test", _fake_run(), quiet_budget)
assert "timed out" not in msg.lower()
- assert str(RUN_BLOCKS_SAFETY_CEILING_SECONDS) in msg
+ assert str(quiet_budget) in msg
assert "split" in msg.lower()
assert "Run ID: wr_test" in msg
assert "get_run_results" in msg
+async def test_per_tool_budget_message_advises_splitting_chain() -> None:
+ """A per-tool-budget trip names the budget value, tells the agent to
+ inspect the cancelled run via ``get_run_results``, then split the chain.
+ Does NOT carry the strict "Do NOT re-invoke block-running tools" gate
+ that the stagnation/ceiling/task_exit_unfinalized paths use — the budget
+ guard clears unconditionally once ``get_run_results`` confirms the row."""
+ msg = await _watchdog_error_message(
+ "per_tool_budget", _ErrorCtx(), "wr_test", _fake_run(), PER_TOOL_CALL_BUDGET_SECONDS
+ )
+
+ assert "timed out" not in msg.lower()
+ assert str(PER_TOOL_CALL_BUDGET_SECONDS) in msg
+ assert "Run ID: wr_test" in msg
+ assert "get_run_results" in msg
+ assert "smaller chain" in msg.lower()
+ assert "verified-prefix" in msg.lower() or "verified prefix" in msg.lower()
+ assert "Do NOT re-invoke block-running tools" not in msg
+
+
@pytest.mark.asyncio
async def test_task_exit_unfinalized_message_reports_last_observed_status() -> None:
"""When ``execute_workflow`` naturally exits but the row isn't terminal,
the error must name the last-observed status so the LLM has a concrete
anchor for the follow-up ``get_run_results`` call."""
run = _fake_run(status="running")
- msg = await _watchdog_error_message("task_exit_unfinalized", _ErrorCtx(), "wr_test", run)
+ msg = await _watchdog_error_message(
+ "task_exit_unfinalized", _ErrorCtx(), "wr_test", run, PER_TOOL_CALL_BUDGET_SECONDS
+ )
assert "timed out" not in msg.lower()
assert "last observed status: running" in msg
@@ -293,7 +317,9 @@ async def test_task_exit_unfinalized_message_tolerates_unreadable_run() -> None:
"""If the post-drain reread also fails (``run is None``), the message must
still be well-formed and mention the unreadable state rather than
crashing on a ``None.status`` access."""
- msg = await _watchdog_error_message("task_exit_unfinalized", _ErrorCtx(), "wr_test", None)
+ msg = await _watchdog_error_message(
+ "task_exit_unfinalized", _ErrorCtx(), "wr_test", None, PER_TOOL_CALL_BUDGET_SECONDS
+ )
assert "unreadable" in msg.lower()
assert "Run ID: wr_test" in msg
diff --git a/tests/unit/test_extraction_cache.py b/tests/unit/test_extraction_cache.py
index ef81d1d31..23b8085f0 100644
--- a/tests/unit/test_extraction_cache.py
+++ b/tests/unit/test_extraction_cache.py
@@ -454,6 +454,143 @@ class TestCanonicalElementTree:
h2 = '<div ID="fedcba98-8765-4321-abcd-123456789abc">x</div>'
assert extraction_cache._canonical_element_tree(h1) == extraction_cache._canonical_element_tree(h2)
+ def test_preserves_content_inside_frame_tags(self) -> None:
+ """Regression for SKY-9524: legacy framed apps place form controls
+ inside <frame> tags. HTML5-strict parsers treat <frame> as void and
+ drop child content on serialize, collapsing distinct per-record pages
+ into the same canonical output. Two pages whose only difference is
+ per-record form input values must produce different canonical output.
+ """
+ h1 = (
+ '<frameset><frame name="criteria" src="criteria.aspx">'
+ '<input name="txtLastName" value="Lastname1">'
+ '<input name="txtFirstName" value="Firstname1">'
+ "</frame></frameset>"
+ )
+ h2 = (
+ '<frameset><frame name="criteria" src="criteria.aspx">'
+ '<input name="txtLastName" value="Lastname2">'
+ '<input name="txtFirstName" value="Firstname2">'
+ "</frame></frameset>"
+ )
+ c1 = extraction_cache._canonical_element_tree(h1)
+ c2 = extraction_cache._canonical_element_tree(h2)
+ assert c1 != c2
+ assert c1 is not None and "Lastname1" in c1
+ assert c2 is not None and "Lastname2" in c2
+
+ def test_preserves_input_value_attributes(self) -> None:
+ """`value=` attributes on form inputs carry per-record data (member IDs,
+ patient names) and must always survive canonicalization unchanged.
+ """
+ h1 = '<input name="memberId" value="200002578">'
+ h2 = '<input name="memberId" value="200451314">'
+ c1 = extraction_cache._canonical_element_tree(h1)
+ c2 = extraction_cache._canonical_element_tree(h2)
+ assert c1 != c2
+ assert c1 is not None and "200002578" in c1
+ assert c2 is not None and "200451314" in c2
+
+ def test_preserves_selected_attribute_on_select(self) -> None:
+ """<select selected="..."> indicates the active option (e.g. DOB year)
+ and must differentiate two records.
+ """
+ h1 = '<select name="ddlDOBYear" selected="1968"><option>1968</option></select>'
+ h2 = '<select name="ddlDOBYear" selected="1957"><option>1957</option></select>'
+ assert extraction_cache._canonical_element_tree(h1) != extraction_cache._canonical_element_tree(h2)
+
+ def test_does_not_corrupt_text_with_angle_brackets(self) -> None:
+ """Stray `<` and `>` in text content (e.g. inequality math) must not
+ be tokenized as tag fragments by the walker."""
+ h = "<p>If x < 5 and y > 0 then z = x + y</p>"
+ out = extraction_cache._canonical_element_tree(h)
+ assert out is not None
+ assert "If x < 5 and y > 0 then z = x + y" in out
+
+ def test_scrubs_csrf_with_unquoted_value(self) -> None:
+ """Unquoted CSRF token values must still be scrubbed to empty so the
+ token doesn't leak into the cache key."""
+ h1 = '<input name="_csrf" value=abc123def>'
+ h2 = '<input name="_csrf" value=xyz789ghi>'
+ assert extraction_cache._canonical_element_tree(h1) == extraction_cache._canonical_element_tree(h2)
+
+ def test_preserves_non_redacted_aria_attributes(self) -> None:
+ """`aria-controls` / `aria-owns` are NOT in the suspect set — they
+ identify component anchors and must differentiate pages.
+ """
+ h1 = '<button aria-controls="panel-3f8a9b12c4">Toggle</button>'
+ h2 = '<button aria-controls="panel-fedcba9876">Toggle</button>'
+ assert extraction_cache._canonical_element_tree(h1) != extraction_cache._canonical_element_tree(h2)
+
+ def test_does_not_redact_id_inside_attribute_value(self) -> None:
+ """Substring `id='...'` inside another attribute's quoted value must
+ NOT be redacted — only attribute-position `id=` is in scope."""
+ h1 = "<div onclick=\"fn(id='abc123def')\">click</div>"
+ h2 = "<div onclick=\"fn(id='xyz789ghi')\">click</div>"
+ assert extraction_cache._canonical_element_tree(h1) != extraction_cache._canonical_element_tree(h2)
+
+ def test_url_with_id_query_param_in_src_does_not_collide(self) -> None:
+ """`<frame src="page?id=A">` and `<frame src="page?id=B">` must produce
+ DIFFERENT canonical output — the id query string is a real
+ differentiator and must survive."""
+ h1 = '<frame src="page.aspx?id=A&action=show">'
+ h2 = '<frame src="page.aspx?id=B&action=show">'
+ c1 = extraction_cache._canonical_element_tree(h1)
+ c2 = extraction_cache._canonical_element_tree(h2)
+ assert c1 != c2
+ assert c1 is not None and "id=A" in c1
+ assert c2 is not None and "id=B" in c2
+
+ def test_preserves_textarea_text_with_angle_brackets(self) -> None:
+ """`<textarea>` body is raw-text per HTML spec — its content must pass
+ through verbatim, including literal `<` and `>` from user input,
+ without being tokenized as tags by the canonicalizer.
+ """
+ h = "<textarea>if x < 5 and y > 0 then z = x + y</textarea>"
+ out = extraction_cache._canonical_element_tree(h)
+ assert out is not None
+ assert "if x < 5 and y > 0 then z = x + y" in out
+
+ def test_handles_attribute_value_containing_angle_bracket(self) -> None:
+ """A `>` inside a quoted attribute value must NOT close the tag —
+ the walker is quote-aware so the tag boundary is the outer `>`.
+ Suspect-attribute redaction still runs on subsequent attributes.
+ """
+ h1 = '<input value="a>b" id="x-3f8a9b12c4">'
+ h2 = '<input value="a>b" id="x-fedcba9876">'
+ assert extraction_cache._canonical_element_tree(h1) == extraction_cache._canonical_element_tree(h2)
+
+ def test_scrubs_csrf_with_apostrophe_in_double_quoted_value(self) -> None:
+ """Double-quoted attribute values are allowed to contain `'` per HTML
+ spec. The CSRF scrubber must still match and zero the value — two
+ tokens that differ only by the apostrophe-bearing payload must hash
+ identically after scrubbing.
+ """
+ h1 = '<input name="_csrf" value="abc\'123">'
+ h2 = '<input name="_csrf" value="xyz\'789">'
+ assert extraction_cache._canonical_element_tree(h1) == extraction_cache._canonical_element_tree(h2)
+
+ def test_scrubs_csrf_with_double_quote_in_single_quoted_value(self) -> None:
+ """Single-quoted attribute values are allowed to contain `"` per HTML
+ spec. Symmetric case to the apostrophe test.
+ """
+ h1 = "<input name='_csrf' value='abc\"123'>"
+ h2 = "<input name='_csrf' value='xyz\"789'>"
+ assert extraction_cache._canonical_element_tree(h1) == extraction_cache._canonical_element_tree(h2)
+
+ def test_handles_unescaped_double_quote_in_attribute_value(self) -> None:
+ """Pinned behavior under malformed scraper input (a known scraper bug:
+ `build_attribute` does not escape `"`). Must not crash, and two
+ distinct malformed inputs must NOT collapse to the same canonical
+ (graceful miss-churn is acceptable; cross-record collision is not).
+ """
+ h1 = '<input value="a"b" id="x-3f8a9b12c4">'
+ h2 = '<input value="c"d" id="x-fedcba9876">'
+ c1 = extraction_cache._canonical_element_tree(h1)
+ c2 = extraction_cache._canonical_element_tree(h2)
+ assert c1 is not None and c2 is not None
+ assert c1 != c2
+
# ---------------------------------------------------------------------------
# compute_cache_key — structured-path canonicalization integration
diff --git a/uv.lock b/uv.lock
index 8e1b77315..bc49550ed 100644
--- a/uv.lock
+++ b/uv.lock
@@ -5461,41 +5461,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/b7/46/f5af3402b579fd5e11573ce652019a67074317e18c1935cc0b4ba9b35552/secretstorage-3.5.0-py3-none-any.whl", hash = "sha256:0ce65888c0725fcb2c5bc0fdb8e5438eece02c523557ea40ce0703c266248137", size = 15554, upload-time = "2025-11-23T19:02:51.545Z" },
]
-[[package]]
-name = "selectolax"
-version = "0.4.7"
-source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/3b/5c/bf049c4aec4c102977abcac68a90dfb1031edc225e9a754fe2c7e624a2d2/selectolax-0.4.7.tar.gz", hash = "sha256:17f7ba5a21714d450b4eea0451608a36be2bba8d327990ddbda812eb3f36fa51", size = 4822635, upload-time = "2026-03-06T09:25:15.411Z" }
-wheels = [
- { url = "https://files.pythonhosted.org/packages/a4/6b/3409a8fd1d217f3449742e86fffe6e29d3f5f9a969a8a6121b1002f377fb/selectolax-0.4.7-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:48d95f3bbe37caa6fe341992ac7b4fb5b7efad1ed8bd939af67b6be0ccd5634e", size = 2062822, upload-time = "2026-03-06T09:23:50.634Z" },
- { url = "https://files.pythonhosted.org/packages/45/b3/ea286b3e89b56d55995927f8fa01cc01b985a14bb7f0c572f06db051c33e/selectolax-0.4.7-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f222827fef20c142131f1948bc08ebf1c9f3294c79bca8fa9c0a71e234be7b2f", size = 2059566, upload-time = "2026-03-06T09:23:52.274Z" },
- { url = "https://files.pythonhosted.org/packages/e2/e0/8014f221b5ae3a3b1dbd915318cb01ee37e31f29a4cce088b39baab4a59d/selectolax-0.4.7-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4cc5c190277ff34f2e42be473ec5947ad5d87c07a072e25d0701c03b7ceb5b12", size = 2253634, upload-time = "2026-03-06T09:23:53.959Z" },
- { url = "https://files.pythonhosted.org/packages/17/f8/3c15c68b5cd2126cdadb9c47dd8931330d0ef40d64533fed3460feb8a9e8/selectolax-0.4.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:26e24768ce86d376b50d311c1bdf54c5445139ac90cc5d955a7703402d2e2f7c", size = 2289548, upload-time = "2026-03-06T09:23:55.295Z" },
- { url = "https://files.pythonhosted.org/packages/5c/da/6d068419854eff6a83247804e358ef3abaa62815adac61f329583a992ab3/selectolax-0.4.7-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:50a668ede8d3f2dbe872c2713a28348e9e3e154a49118b898568243bfb356c96", size = 2265394, upload-time = "2026-03-06T09:23:56.916Z" },
- { url = "https://files.pythonhosted.org/packages/94/cb/8dbecbacf55d55dd5cfe046a4d943ae1df979a96a7a407ee7d8c277976d5/selectolax-0.4.7-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:5fb1c01d39570f0990e8e2a2037e3f0cf8d193da6ea9ca1936d5818d5cf6a260", size = 2296276, upload-time = "2026-03-06T09:23:58.689Z" },
- { url = "https://files.pythonhosted.org/packages/53/09/6dff1dcf77f762f3b088b63d6bc6ce15ce649066019e508031c140d483af/selectolax-0.4.7-cp311-cp311-win32.whl", hash = "sha256:8ca0af7156315d9193fac699e8e4c3281ea6dccc6262eed33b32001a633e57a9", size = 1740823, upload-time = "2026-03-06T09:24:00.367Z" },
- { url = "https://files.pythonhosted.org/packages/93/d8/2b8ff4f2cef4236ffc3bdf1c500517fddf9b0cf9d4db20d1d01a6c49a128/selectolax-0.4.7-cp311-cp311-win_amd64.whl", hash = "sha256:d322e725e0c575cacc8ba2f0041fb8405dc3932bff9073a563f568c6ef3a217b", size = 1836333, upload-time = "2026-03-06T09:24:02.066Z" },
- { url = "https://files.pythonhosted.org/packages/d5/cd/6a1989b9866430ad358865020e82e5aeb16a813df92455d4fd8608e27cae/selectolax-0.4.7-cp311-cp311-win_arm64.whl", hash = "sha256:3e3dac7de3864701a18cd6c4806d07944a5a48d1db2f107a0ce8531f72881462", size = 1791761, upload-time = "2026-03-06T09:24:03.546Z" },
- { url = "https://files.pythonhosted.org/packages/1f/1d/8d3db7dcc053f7f4088a826f9089324c7b37617f9caaf6a03f0ff5854bbd/selectolax-0.4.7-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:8fa541a520cc6213d754ec747ebbff12fdcc5b9f6bb7615784486e18697209fb", size = 2059304, upload-time = "2026-03-06T09:24:04.861Z" },
- { url = "https://files.pythonhosted.org/packages/42/64/de442c5056aa4f42d140556a8093bfadee72545919384cf38d6f651b75b0/selectolax-0.4.7-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:2a0e9b1e3b1d091a0133b44b3967c79db8de73d99efe38af85bab615775aa4e8", size = 2057450, upload-time = "2026-03-06T09:24:06.25Z" },
- { url = "https://files.pythonhosted.org/packages/e4/42/969e084f59c845fbb304d55f8e3899ffe823f3cd78d85d083edffe772766/selectolax-0.4.7-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7134b119c011e18d1e914d5adbb8f953e391649b4af734fcec61dad691a16f59", size = 2251180, upload-time = "2026-03-06T09:24:07.536Z" },
- { url = "https://files.pythonhosted.org/packages/e9/1b/d8f84cb6385637cd793aad3a53618d3ee1b4329e0feb0f4db7a7f81af4da/selectolax-0.4.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3840b79f5f39744b95dc80e3b428cf4e49b86d8c6e9cbb3e7df3e702bf240cce", size = 2292532, upload-time = "2026-03-06T09:24:08.896Z" },
- { url = "https://files.pythonhosted.org/packages/85/54/15c3b5d94cf969748ffcca7289245d477ef69ce30a359c5a764b0bc2226e/selectolax-0.4.7-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:eb6faf15e6cc6a7c61c04e15c3490e3f6693c98f732e531941687093de36db81", size = 2263969, upload-time = "2026-03-06T09:24:10.556Z" },
- { url = "https://files.pythonhosted.org/packages/e2/4f/fa4125a9a92b2a15a3b332592270e003e9092bb97c3d6c3a7f2714b4c507/selectolax-0.4.7-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:3799b39d60266f7d4c48f322fac8eaecc6dec38f4342d6d3b17085d11815bcb4", size = 2298497, upload-time = "2026-03-06T09:24:11.919Z" },
- { url = "https://files.pythonhosted.org/packages/dd/9d/fef3b7d4f8da87762574ea20ff9612485639d6b0a9b7d3839738d8ced105/selectolax-0.4.7-cp312-cp312-win32.whl", hash = "sha256:88344c8764f3a2fbcae2fd2353201c330920943c2da34a16e9b063f918deb7d6", size = 1735965, upload-time = "2026-03-06T09:24:13.407Z" },
- { url = "https://files.pythonhosted.org/packages/31/25/5b893677a0acfc579d9ccb3f01204c4554ba533db5c144cc3b18e33e347b/selectolax-0.4.7-cp312-cp312-win_amd64.whl", hash = "sha256:00953c3c6a7e4dfd990a5651315b713d50131706c239c1f1c5b6d4a75a11975a", size = 1833805, upload-time = "2026-03-06T09:24:14.726Z" },
- { url = "https://files.pythonhosted.org/packages/63/ad/bb94f409f33871b6d9b3b4d56fb82d14d9b2fd2e7657f32c25a35167187e/selectolax-0.4.7-cp312-cp312-win_arm64.whl", hash = "sha256:e6b8d0f7cbdc6ca5cbf52dbd37f70c170184040499ac59a23409724724276784", size = 1783620, upload-time = "2026-03-06T09:24:16.062Z" },
- { url = "https://files.pythonhosted.org/packages/d2/6b/238c03a1be1aa73c5392026ae4efbcf9f8356bb5a07dda1134f07d33e78c/selectolax-0.4.7-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:fb8f169511f037b662dac1a0e27cff30f4317f9aa30af2e37c8a37c3ca8c7e3c", size = 2058636, upload-time = "2026-03-06T09:24:17.787Z" },
- { url = "https://files.pythonhosted.org/packages/f3/44/22e433b7dc31ff83574051dd9951175bcd0e36b56c0e25cb277929e77ecb/selectolax-0.4.7-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:feaea6ac95da2fa137abad3c1ae13596bffed44c8e2bfa7802f89a37a1e5e39a", size = 2056263, upload-time = "2026-03-06T09:24:19.51Z" },
- { url = "https://files.pythonhosted.org/packages/af/95/05f264c622d0f0839954d0f197d420cffe5723354521b6ce543d32b272a1/selectolax-0.4.7-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:fdc5ec34ccce3a691e1664a14bf0f40ad6a41117e5de88e85d8ac8e68a7ea8bd", size = 2247850, upload-time = "2026-03-06T09:24:21.28Z" },
- { url = "https://files.pythonhosted.org/packages/59/24/324a271f7ef49786d7bed5674e23718504fe996866e23c75f91ac06c3bfa/selectolax-0.4.7-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1a7016db9c55ae541f1669a3433aee03fc0a1111d70c84aa5636a5a6b9499854", size = 2287889, upload-time = "2026-03-06T09:24:23.948Z" },
- { url = "https://files.pythonhosted.org/packages/91/b0/779ab6c428be5cf53ebae1bc2539ebe9df9d8b76e2f9810f107a0338800e/selectolax-0.4.7-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:d3da9e1609cefc9bb403f62c2b03d2f5622cbe3057c2f06e308a29fad8ae5654", size = 2261143, upload-time = "2026-03-06T09:24:25.552Z" },
- { url = "https://files.pythonhosted.org/packages/b6/c2/34b132d14922b7d8dbb50d0b487d22aeb7af8a47421baaf05f2cc1cc2dbd/selectolax-0.4.7-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:9c70be8f4154a80b8d435bcc3217c04a82f928849fa2f6acd554d24c5b911db6", size = 2293796, upload-time = "2026-03-06T09:24:26.974Z" },
- { url = "https://files.pythonhosted.org/packages/24/67/6ba2b7140d7e92a3a0f815ac6c8001171973248a9f27206b339019e0b288/selectolax-0.4.7-cp313-cp313-win32.whl", hash = "sha256:df8a8db519484c868839f1d36be720feeb228c8f75cf7b745e325db183b319c6", size = 1735965, upload-time = "2026-03-06T09:24:28.463Z" },
- { url = "https://files.pythonhosted.org/packages/6c/1c/d22cbd6c5828a59addd42626c22b2afb3422bfce59cf88d15095da05243f/selectolax-0.4.7-cp313-cp313-win_amd64.whl", hash = "sha256:5a613760d2b890d7befd2e585a37dd0bdae9e23eee0cacb15d24adb83232c94e", size = 1834806, upload-time = "2026-03-06T09:24:29.875Z" },
- { url = "https://files.pythonhosted.org/packages/59/d7/d2206d9f38a534b4fc4383c7dd427ba0b927075c96881274a60978411723/selectolax-0.4.7-cp313-cp313-win_arm64.whl", hash = "sha256:7cbd1143920b7bd1b80e092d5a16c97fdc741b0325a42862f20edcb55ab493e8", size = 1783517, upload-time = "2026-03-06T09:24:31.843Z" },
-]
-
[[package]]
name = "send2trash"
version = "2.1.0"
@@ -5603,7 +5568,6 @@ server = [
{ name = "python-docx" },
{ name = "python-multipart" },
{ name = "requests-toolbelt" },
- { name = "selectolax" },
{ name = "sqlalchemy", extra = ["mypy"] },
{ name = "sse-starlette" },
{ name = "starlette-context" },
@@ -5730,7 +5694,6 @@ requires-dist = [
{ name = "python-multipart", marker = "extra == 'server'", specifier = ">=0.0.22,<1" },
{ name = "requests-toolbelt", marker = "extra == 'server'", specifier = ">=1.0.0,<2" },
{ name = "rich", specifier = ">=13.7.0,<14" },
- { name = "selectolax", marker = "extra == 'server'", specifier = ">=0.4.7,<0.5" },
{ name = "sqlalchemy", extras = ["mypy"], marker = "extra == 'server'", specifier = ">=2.0.29,<3" },
{ name = "sse-starlette", marker = "extra == 'server'", specifier = ">=3.0.3,<4" },
{ name = "starlette-context", marker = "extra == 'server'", specifier = ">=0.3.6,<0.6" },