Skip to content

Automate browser based workflows with AI

Stop hard-blocking Copilot replies that name a run id or internal tool (SKY-15313) (#8376)

Andrew Neilson11de5f6bef02
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.py
index b173324d3..27e20c5e5 100644
--- a/skyvern/forge/sdk/copilot/agent.py
+++ b/skyvern/forge/sdk/copilot/agent.py
@@ -2764,13 +2764,7 @@ def _clean_recorded_failure_text(value: Any, max_chars: int = 240) -> str:
text = clean_recorded_failure_text(value, max_chars=max_chars).rstrip(".")
if not text:
return ""
- verdict = evaluate_output_policy(
- request_policy=None,
- response_type="REPLY",
- user_response=text,
- output_kind=CopilotOutputKind.INFORMATIONAL_ANSWER,
- )
- if OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK in verdict.reason_codes:
+ if contains_internal_machinery_leak(text):
return "The previous workflow run did not finish before the turn budget expired"
return text
@@ -2804,13 +2798,7 @@ def _recorded_failure_is_internal_tool_instruction(ctx: CopilotContext) -> bool:
# Evaluate the redacted form at the same truncation the reply embeds:
# standard redaction already neutralizes browser-session references,
# so flag only what would still leak.
- verdict = evaluate_output_policy(
- request_policy=None,
- response_type="REPLY",
- user_response=clean_recorded_failure_text(value, max_chars=240),
- output_kind=CopilotOutputKind.INFORMATIONAL_ANSWER,
- )
- if OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK in verdict.reason_codes:
+ if contains_internal_machinery_leak(clean_recorded_failure_text(value, max_chars=240)):
return True
return False
diff --git a/skyvern/forge/sdk/copilot/output_policy.py b/skyvern/forge/sdk/copilot/output_policy.py
index b671d4966..e2c3843ea 100644
--- a/skyvern/forge/sdk/copilot/output_policy.py
+++ b/skyvern/forge/sdk/copilot/output_policy.py
@@ -7,7 +7,6 @@ from dataclasses import dataclass, field
from enum import StrEnum
from typing import Any, cast
-from skyvern.forge.sdk.copilot.blocker_signal import contains_internal_machinery_leak
from skyvern.forge.sdk.copilot.context import COPILOT_RESPONSE_TYPES, ResponseType
from skyvern.forge.sdk.copilot.output_utils import (
looks_like_workflow_delivery_claim,
@@ -66,24 +65,6 @@ UNVALIDATED_DISCLOSURE_PHRASES = (
"hasn't been verified",
"unvalidated",
)
-_INTERNAL_TOOL_INSTRUCTION_MARKERS = (
- "call get_run_results",
- "call update_and_run_blocks",
-)
-_INTERNAL_TOOL_RETRY_PHRASES = ("do not retry", "do not re-invoke")
-_INTERNAL_TOOL_RETRY_CONTEXT_MARKERS = (
- "block running tool",
- "block running tools",
- "block-running tool",
- "block-running tools",
- "get_run_results",
- "update_and_run_blocks",
- "tool call",
- "this tool",
- "the tool",
- "workflow_run_id",
-)
-_INTERNAL_TOOL_INSTRUCTION_TRANSLATION = str.maketrans({char: " " for char in "`'\"()[]{}.,:;"})
_INTERNAL_BLOCK_TYPE_TERMS = frozenset(
{
"navigation",
@@ -200,7 +181,6 @@ class OutputPolicyReason(StrEnum):
UNBACKED_WORKFLOW_DELIVERY_CLAIM = "unbacked_workflow_delivery_claim"
MISSING_PROPOSAL_STATE = "missing_proposal_state"
PERSISTENCE_STATE_MISMATCH = "persistence_state_mismatch"
- INTERNAL_TOOL_INSTRUCTION_LEAK = "internal_tool_instruction_leak"
OUTPUT_POLICY_CONTEXT_MISSING = "output_policy_context_missing"
INTERNAL_BLOCK_TAXONOMY_LEAK = "internal_block_taxonomy_leak"
INTERNAL_CLASSIFIER_VOCAB_LEAK = "internal_classifier_vocab_leak"
@@ -235,7 +215,6 @@ _FINAL_OUTPUT_HARD_BLOCK_REASONS: frozenset[OutputPolicyReason] = frozenset(
OutputPolicyReason.UNAPPROVED_CREDENTIAL_REFERENCE,
OutputPolicyReason.CREDENTIAL_SCOPE_BROADENED,
OutputPolicyReason.PERSISTENCE_STATE_MISMATCH,
- OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK,
OutputPolicyReason.OUTPUT_POLICY_CONTEXT_MISSING,
}
)
@@ -429,8 +408,6 @@ def evaluate_output_policy(
# reaches storage, and scanning a draft judged the YAML encoding rather than the value.
if _contains_raw_secret(user_response):
verdict.add(OutputPolicyReason.RAW_SECRET_LEAK)
- if _contains_internal_tool_instruction(user_response):
- verdict.add(OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK)
if (
response_type == "REPLY"
and not has_workflow_proposal
@@ -582,19 +559,6 @@ def _is_lexical_token_assignment(matched: str, assignment: str) -> bool:
return rhs_match is not None and _parses_a_value_out_of_something(rhs_match.group(1))
-def _contains_internal_tool_instruction(user_response: str | None) -> bool:
- if not isinstance(user_response, str):
- return False
- if contains_internal_machinery_leak(user_response):
- return True
- normalized = " ".join(user_response.lower().translate(_INTERNAL_TOOL_INSTRUCTION_TRANSLATION).split())
- if any(marker in normalized for marker in _INTERNAL_TOOL_INSTRUCTION_MARKERS):
- return True
- return any(phrase in normalized for phrase in _INTERNAL_TOOL_RETRY_PHRASES) and any(
- marker in normalized for marker in _INTERNAL_TOOL_RETRY_CONTEXT_MARKERS
- )
-
-
def _policy_text_values(value: Any) -> list[str]:
if value is None:
return []
diff --git a/tests/unit/test_copilot_agent_blocker_renderer.py b/tests/unit/test_copilot_agent_blocker_renderer.py
index 400bc027e..b5614d503 100644
--- a/tests/unit/test_copilot_agent_blocker_renderer.py
+++ b/tests/unit/test_copilot_agent_blocker_renderer.py
@@ -295,7 +295,7 @@ def test_output_policy_generic_block_uses_only_safety_and_draft_evidence() -> No
_seed_terminal_evidence(ctx)
ctx.last_test_anti_bot = "challenge-gated disabled submit/search control"
- result = _blocked_result(ctx, OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK)
+ result = _blocked_result(ctx, OutputPolicyReason.PERSISTENCE_STATE_MISMATCH)
assert result.response_type == "ASK_QUESTION"
assert result.updated_workflow is fake_workflow
@@ -323,7 +323,7 @@ def test_output_policy_recorded_evidence_does_not_create_a_policy_recheck(monkey
result = _blocked_result(
ctx,
- OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK,
+ OutputPolicyReason.PERSISTENCE_STATE_MISMATCH,
output_kind=CopilotOutputKind.REFUSAL,
)
@@ -337,7 +337,7 @@ def test_output_policy_generic_block_requires_clean_terminal_evidence() -> None:
adversarial.last_run_blocks_workflow_run_id = "wr_hidden"
for ctx in (no_recorded, adversarial):
- result = _blocked_result(ctx, OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK)
+ result = _blocked_result(ctx, OutputPolicyReason.PERSISTENCE_STATE_MISMATCH)
assert (
result.user_response
== "I could not safely return that chat reply. Please adjust the request and try again."
diff --git a/tests/unit/test_copilot_output_policy.py b/tests/unit/test_copilot_output_policy.py
index bae8591a1..1f9f68a8f 100644
--- a/tests/unit/test_copilot_output_policy.py
+++ b/tests/unit/test_copilot_output_policy.py
@@ -23,7 +23,10 @@ from skyvern.forge.sdk.copilot.author_time_block import (
CREDENTIAL_SCOUT_BLOCK_ID,
AuthorTimeBlock,
)
-from skyvern.forge.sdk.copilot.blocker_signal import CopilotToolBlockerSignal
+from skyvern.forge.sdk.copilot.blocker_signal import (
+ CopilotToolBlockerSignal,
+ contains_internal_machinery_leak,
+)
from skyvern.forge.sdk.copilot.context import CopilotContext
from skyvern.forge.sdk.copilot.loop_detection import tool_step_identity
from skyvern.forge.sdk.copilot.output_policy import (
@@ -44,6 +47,7 @@ from skyvern.forge.sdk.copilot.tools import (
_WORKFLOW_YAML_OUTPUT_POLICY_GUARDRAIL,
NATIVE_TOOLS,
)
+from skyvern.forge.sdk.copilot.tools.run_execution import _watchdog_error_message
from skyvern.forge.sdk.schemas.copilot_turn_outcome import ResponseKind, TurnOutcome
# Assembled at runtime so the source never contains a token-shaped literal for secret scanners to flag.
@@ -324,14 +328,6 @@ def test_normalize_scaffolding_preserves_wrapped_ordinary_reply_sentence() -> No
"Then call update_and_run_blocks with a smaller chain.",
id="call-update-and-run-blocks-instruction",
),
- pytest.param(
- "Do NOT retry this tool call; wait for the current run result.",
- id="do-not-retry-tool-call",
- ),
- pytest.param(
- "Do NOT re-invoke the tool until the user responds.",
- id="do-not-reinvoke-tool",
- ),
pytest.param(
'I\'ll call get_run_results(workflow_run_id="wr_123") and report back.',
id="call-get-run-results-report-back",
@@ -352,34 +348,24 @@ def test_normalize_scaffolding_preserves_wrapped_ordinary_reply_sentence() -> No
"Falling back to list_credentials since the user did not specify one.",
id="list-credentials-fallback",
),
- pytest.param(
- "Less than 90 seconds remain in this Copilot turn after the previous workflow run failed. "
- "Do NOT retry block-running tools.",
- id="late-block-running-timer-do-not-retry",
- ),
],
)
-def test_rejects_internal_tool_instruction_leak_in_user_response(user_response: str) -> None:
- verdict = evaluate_output_policy(
- request_policy=_policy(),
- response_type="REPLY",
- user_response=user_response,
- )
+def test_machine_format_machinery_leak_predicate_matches(user_response: str) -> None:
+ assert contains_internal_machinery_leak(user_response) is True
- assert not verdict.allowed
- assert OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK in verdict.reason_codes
- assert OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK in hard_block_output_policy_verdict(verdict).reason_codes
-
-def test_allows_benign_do_not_retry_user_guidance() -> None:
+def test_watchdog_model_facing_text_is_allowed_as_a_run_result_reply() -> None:
verdict = evaluate_output_policy(
- request_policy=_policy(),
+ request_policy=None,
response_type="REPLY",
- user_response="Do not retry until the account lockout clears.",
+ user_response=asyncio.run(
+ _watchdog_error_message("stagnation", SimpleNamespace(), "wr_123", None, 300, dispatch_to_worker=True)
+ ),
+ output_kind=CopilotOutputKind.WORKFLOW_RUN_RESULT,
)
assert verdict.allowed
- assert OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK not in verdict.reason_codes
+ assert verdict.reason_codes == []
@pytest.mark.parametrize(
@@ -1035,27 +1021,6 @@ def test_extended_taxonomy_leak_skipped_on_ask_question(user_response: str) -> N
assert OutputPolicyReason.INTERNAL_BLOCK_TAXONOMY_LEAK not in verdict.reason_codes
- "output_kind",
- [
- CopilotOutputKind.WORKFLOW_DRAFT_PROPOSAL,
- CopilotOutputKind.WORKFLOW_UPDATE_PROPOSAL,
- CopilotOutputKind.WORKFLOW_RUN_RESULT,
- ],
-)
-def test_tool_name_leak_hard_blocks_across_output_kinds(
- output_kind: CopilotOutputKind,
-) -> None:
- verdict = evaluate_output_policy(
- request_policy=_policy(),
- response_type="REPLY",
- user_response="Use `update_workflow` to apply that change.",
- output_kind=output_kind,
- )
-
- assert OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK in verdict.reason_codes
-
-
@pytest.mark.parametrize(
"user_response",
[
@@ -1657,7 +1622,7 @@ def test_output_policy_block_preserves_already_gated_workflow_proposal() -> None
result = agent_module._build_output_policy_blocked_result(
ctx,
OutputPolicyVerdict(
- reason_codes=[OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK],
+ reason_codes=[OutputPolicyReason.PERSISTENCE_STATE_MISMATCH],
),
prior_global_llm_context="{}",
prior_workflow_yaml="title: Prior",
@@ -2009,7 +1974,7 @@ def test_translate_to_agent_result_blocks_raw_secret_final_text() -> None:
assert "DO NOT PROVIDE RAW LOGIN/PASSWORD" in agent_result.user_response
-def test_translate_scrubs_late_block_running_leak_and_preserves_draft() -> None:
+def test_translate_preserves_draft_on_late_block_running_blocker() -> None:
ctx = _ctx()
saved_workflow = object()
ctx.last_workflow = saved_workflow
@@ -2047,8 +2012,6 @@ def test_translate_scrubs_late_block_running_leak_and_preserves_draft() -> None:
assert agent_result.updated_workflow is saved_workflow
assert agent_result.clear_proposed_workflow is False
assert agent_result.proposal_disposition == "review_untested"
- assert "Do NOT retry" not in agent_result.user_response
- assert "workflow draft is still saved" in agent_result.user_response
def test_translate_to_agent_result_rewrites_unbacked_workflow_claim() -> None:
@@ -2157,27 +2120,6 @@ def test_translate_to_agent_result_rewrites_internal_classifier_vocab_leak() ->
assert diagnostics["contained_failure"] is True
-def test_translate_to_agent_result_hard_blocks_extended_taxonomy_tool_name_leak() -> None:
- leak = "Trace shows `get_run_results` was the last tool dispatched on this turn."
- result = _fake_run_result({"type": "REPLY", "user_response": leak})
-
- agent_result = asyncio.run(
- agent_module._translate_to_agent_result(
- result,
- _ctx(),
- global_llm_context=None,
- chat_request=_chat_request(),
- organization_id="org-1",
- )
- )
-
- assert "get_run_results" not in agent_result.user_response
- assert "I could not safely return" in agent_result.user_response
- diagnostics = agent_result.output_policy_diagnostics or {}
- assert "internal_tool_instruction_leak" in diagnostics["hard_block_reason_codes"]
- assert "internal_block_taxonomy_leak" not in diagnostics["raw_reason_codes"]
-
-
def test_translate_to_agent_result_rewrites_self_prescriptive_phrase_leak() -> None:
leak = "Please send 'continue debugging' next and I'll keep going."
result = _fake_run_result({"type": "REPLY", "user_response": leak})
@@ -2222,18 +2164,18 @@ def test_translate_to_agent_result_unbacked_workflow_wins_over_self_prescriptive
def test_sdk_output_guardrail_records_raw_soft_reason_alongside_hard_block() -> None:
- leak = "Call get_run_results(workflow_run_id='wr_123') and do not retry. Saw [copilot:nudge] in the trace."
+ leak = f"Use the key {_FAKE_OPENAI_KEY} to authenticate. Saw [copilot:nudge] in the trace."
verdict, response_type, diagnostics = agent_module._evaluate_copilot_final_output_policy(
_ctx(),
{"type": "REPLY", "user_response": leak},
)
assert not verdict.allowed
- assert "internal_tool_instruction_leak" in diagnostics["hard_block_reason_codes"]
+ assert "raw_secret_leak" in diagnostics["hard_block_reason_codes"]
assert "internal_block_taxonomy_leak" not in diagnostics["hard_block_reason_codes"]
assert diagnostics["soft_rewrite_reason_codes"] == []
raw_reason_codes = diagnostics["raw_reason_codes"]
- assert "internal_tool_instruction_leak" in raw_reason_codes
+ assert "raw_secret_leak" in raw_reason_codes
assert "internal_block_taxonomy_leak" in raw_reason_codes
@@ -2256,7 +2198,6 @@ def test_evaluate_output_policy_skips_new_detectors_on_ask_question() -> None:
def test_evaluate_output_policy_runs_new_detectors_on_replace_workflow() -> None:
classifier_leak = "RequestPolicy blocked this turn, safe_reason_code=request_policy_clarification."
self_prescriptive_leak = "Please send 'continue debugging' next and I'll keep going."
- tool_name_leak = "Use `get_run_results` to fetch the prior run output."
classifier_verdict = evaluate_output_policy(
request_policy=_policy(),
@@ -2272,13 +2213,6 @@ def test_evaluate_output_policy_runs_new_detectors_on_replace_workflow() -> None
)
assert OutputPolicyReason.SELF_PRESCRIPTIVE_PHRASE_LEAK in self_prescriptive_verdict.reason_codes
- tool_name_verdict = evaluate_output_policy(
- request_policy=_policy(),
- response_type="REPLACE_WORKFLOW",
- user_response=tool_name_leak,
- )
- assert OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK in tool_name_verdict.reason_codes
-
@pytest.mark.parametrize(
"user_response,expected",
@@ -2786,7 +2720,6 @@ _AUTHORING_SEAM_REFUSAL_SOURCES: dict[str, str] = {
"unbacked_workflow_delivery_claim": _FINDING,
"missing_proposal_state": _FINDING,
"persistence_state_mismatch": _FINDING,
- "internal_tool_instruction_leak": _FINDING,
"output_policy_context_missing": _FINDING,
"internal_block_taxonomy_leak": _FINDING,
"internal_classifier_vocab_leak": _FINDING,
diff --git a/tests/unit/test_copilot_terminal_halt_narrative.py b/tests/unit/test_copilot_terminal_halt_narrative.py
index 695e4898d..e4660dc88 100644
--- a/tests/unit/test_copilot_terminal_halt_narrative.py
+++ b/tests/unit/test_copilot_terminal_halt_narrative.py
@@ -17,11 +17,6 @@ from skyvern.forge.sdk.copilot.agent import (
)
from skyvern.forge.sdk.copilot.blocker_signal import contains_internal_machinery_leak
from skyvern.forge.sdk.copilot.context import CopilotContext
-from skyvern.forge.sdk.copilot.output_policy import (
- CopilotOutputKind,
- OutputPolicyReason,
- evaluate_output_policy,
-)
_ANTI_RERUN_GUARD_TEXT = (
"The prior PER_TOOL_BUDGET run for run wr_538488327000571062 advanced the live browser at "
@@ -72,15 +67,6 @@ class TestInternalMachineryLeakPredicate:
def test_product_language_is_clean(self, text: str) -> None:
assert contains_internal_machinery_leak(text) is False
- def test_output_policy_hard_blocks_guard_text(self) -> None:
- verdict = evaluate_output_policy(
- request_policy=None,
- response_type="REPLY",
- user_response=_ANTI_RERUN_GUARD_TEXT,
- output_kind=CopilotOutputKind.INFORMATIONAL_ANSWER,
- )
- assert OutputPolicyReason.INTERNAL_TOOL_INSTRUCTION_LEAK in verdict.reason_codes
-
class TestRecordedFailureReply:
def test_guard_text_renders_observed_facts_not_test_failed(self) -> None:
diff --git a/tests/unit/test_workflow_copilot_route.py b/tests/unit/test_workflow_copilot_route.py
index 7b8ef1b00..10ba23e04 100644
--- a/tests/unit/test_workflow_copilot_route.py
+++ b/tests/unit/test_workflow_copilot_route.py
@@ -2874,7 +2874,7 @@ async def test_output_policy_block_preserves_unvalidated_prior_proposal_under_au
unvalidated=False,
output_policy_diagnostics={
"final_output_policy_allowed": False,
- "hard_block_reason_codes": ["internal_tool_instruction_leak"],
+ "hard_block_reason_codes": ["raw_secret_leak"],
},
turn_outcome=None,
)