Skip to content

Automate browser based workflows with AI

fix(SKY-11952): force-persist waits for the full credential flow before grading a login goal-complete (#7315)

Andrew Neilsondcdf769ab5d5
diff --git a/skyvern/forge/sdk/copilot/code_block_synthesis.py b/skyvern/forge/sdk/copilot/code_block_synthesis.py
index 5ef20fc67..5808d5fdd 100644
--- a/skyvern/forge/sdk/copilot/code_block_synthesis.py
+++ b/skyvern/forge/sdk/copilot/code_block_synthesis.py
@@ -17,8 +17,9 @@ import re
import textwrap
import tokenize
from collections.abc import Mapping, Sequence
+from collections.abc import Set as AbstractSet
from dataclasses import dataclass, field
-from typing import Any
+from typing import Any, NamedTuple
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
from skyvern.forge.sdk.copilot.composition_evidence import SCOUT_INTERACTION_EVIDENCE_TOOL
@@ -66,6 +67,108 @@ _CREDENTIAL_FIELDS = frozenset({"username", "password", "totp"})
# accessor ``.fill(await <param>.otp())`` — distinguishes a login fill from a plain
# ``.fill(str(<key>))`` text input.
CREDENTIAL_FILL_CODE_PATTERN = re.compile(r"\.fill\(\s*(?:[A-Za-z_]\w*\.\w+|await\s+[A-Za-z_]\w*\.otp\(\))\s*\)")
+# Credential fields the scout must fill live before a code block reading them may persist;
+# `.otp()` resolves at runtime only, so totp never requires (or credits) a live scout fill.
+LIVE_SCOUT_CREDENTIAL_FIELDS = frozenset({"username", "password"})
+_CREDENTIAL_FIELD_ACCESS_RE = re.compile(
+ r"\b(?P<parameter>[A-Za-z_][A-Za-z0-9_]*)\.(?:(?P<field>username|password|totp)\b|(?P<otp_method>otp)\s*\()"
+)
+_CODE_SUBMIT_ACTION_RE = re.compile(r"\.(?:click|press)\s*\(")
+_SCOUT_SUBMIT_TOOL_NAMES = frozenset({"click", "press_key"})
+
+
+class CredentialFieldAccess(NamedTuple):
+ parameter_key: str
+ field: str
+ requires_live_scout: bool
+
+
+def _credential_field_accesses(code: str) -> list[CredentialFieldAccess]:
+ accesses: list[CredentialFieldAccess] = []
+ for match in _CREDENTIAL_FIELD_ACCESS_RE.finditer(code):
+ field = match.group("field")
+ if field:
+ accesses.append(
+ CredentialFieldAccess(
+ parameter_key=match.group("parameter"),
+ field=field,
+ requires_live_scout=True,
+ )
+ )
+ continue
+ if match.group("otp_method"):
+ accesses.append(
+ CredentialFieldAccess(
+ parameter_key=match.group("parameter"),
+ field="totp",
+ requires_live_scout=False,
+ )
+ )
+ return accesses
+
+
+class ScoutGap(NamedTuple):
+ missing_fields: list[str]
+ missing_submit: bool
+
+
+def first_matched_post_fill_submit_index(
+ trajectory: Sequence[Mapping[str, Any]],
+ latest_fill_index: int,
+ matched_source_urls: AbstractSet[str],
+) -> int | None:
+ for index, interaction in enumerate(trajectory):
+ if index <= latest_fill_index:
+ continue
+ if str(interaction.get("tool_name") or "").strip() not in _SCOUT_SUBMIT_TOOL_NAMES:
+ continue
+ source_url = str(interaction.get("source_url") or "").strip()
+ if matched_source_urls and source_url not in matched_source_urls:
+ continue
+ return index
+ return None
+
+
+def credential_scout_gap(
+ trajectory: Sequence[Mapping[str, Any]],
+ requirements: Sequence[tuple[AbstractSet[str], AbstractSet[str]]],
+ *,
+ requires_submit: bool,
+) -> ScoutGap:
+ """Match one block's credential requirements — (allowed_credential_ids, required_fields) tuples —
+ against the scout trajectory: fill indexes and source urls accumulate across requirement tuples, and
+ a single post-latest-fill submit on a matched source url satisfies ``requires_submit`` globally."""
+ matched_fill_indexes: list[int] = []
+ matched_source_urls: set[str] = set()
+ missing_fields: list[str] = []
+ for allowed_credential_ids, required_fields in requirements:
+ matched_fields: set[str] = set()
+ for index, interaction in enumerate(trajectory):
+ if str(interaction.get("tool_name") or "").strip() != CREDENTIAL_FILL_TOOL_NAME:
+ continue
+ if str(interaction.get("credential_id") or "").strip() not in allowed_credential_ids:
+ continue
+ field = str(interaction.get("credential_field") or "").strip()
+ if field not in required_fields:
+ continue
+ matched_fields.add(field)
+ matched_fill_indexes.append(index)
+ source_url = str(interaction.get("source_url") or "").strip()
+ if source_url:
+ matched_source_urls.add(source_url)
+ for field in sorted(required_fields - matched_fields):
+ missing_fields.append(field)
+
+ missing_submit = False
+ if requires_submit:
+ latest_fill_index = max(matched_fill_indexes, default=-1)
+ missing_submit = (
+ latest_fill_index < 0
+ or first_matched_post_fill_submit_index(trajectory, latest_fill_index, matched_source_urls) is None
+ )
+ return ScoutGap(missing_fields=missing_fields, missing_submit=missing_submit)
+
+
_ENTRY_TARGET_TOOLS = frozenset({"click", "type_text", CREDENTIAL_FILL_TOOL_NAME, "select_option", "press_key"})
_DURABLE_FALLBACK_ENTRY_TARGET_TOOLS = frozenset({"type_text", CREDENTIAL_FILL_TOOL_NAME, "select_option"})
_OPTIONAL_DISMISSAL_NAME_PATTERN = re.compile(
diff --git a/skyvern/forge/sdk/copilot/context.py b/skyvern/forge/sdk/copilot/context.py
index 4239dca21..d8c7fb959 100644
--- a/skyvern/forge/sdk/copilot/context.py
+++ b/skyvern/forge/sdk/copilot/context.py
@@ -168,6 +168,7 @@ class FillCarry(BaseModel):
control_value_satisfied: bool | None = None
credential_id: str = ""
credential_field: str = ""
+ available_fields: list[str] | None = None
class LoadedResultTargetContext(BaseModel):
@@ -417,7 +418,10 @@ def _carry_bool(value: FillCarryPrimitive) -> bool | None:
return value if isinstance(value, bool) else None
-def _fill_carry_from_scout_trajectory(trajectory: Sequence[Mapping[str, FillCarryPrimitive]]) -> list[FillCarry]:
+def _fill_carry_from_scout_trajectory(
+ trajectory: Sequence[Mapping[str, FillCarryPrimitive]],
+ credential_field_inventory: Mapping[str, frozenset[str]] | None = None,
+) -> list[FillCarry]:
carry: list[FillCarry] = []
for interaction in trajectory:
tool_name = _carry_text(interaction.get("tool_name"), max_chars=40)
@@ -460,6 +464,7 @@ def _fill_carry_from_scout_trajectory(trajectory: Sequence[Mapping[str, FillCarr
credential_id = _carry_text(interaction.get("credential_id"))
credential_field = _carry_text(interaction.get("credential_field"), max_chars=20)
if credential_id and credential_field in _FILL_CARRY_CREDENTIAL_FIELDS:
+ inventory = (credential_field_inventory or {}).get(credential_id)
carry.append(
FillCarry(
source_url=source_url,
@@ -470,6 +475,7 @@ def _fill_carry_from_scout_trajectory(trajectory: Sequence[Mapping[str, FillCarr
typed_length=typed_length,
credential_id=credential_id,
credential_field=credential_field,
+ available_fields=sorted(inventory) if inventory else None,
)
)
return carry[-_MAX_FILL_CARRY:]
@@ -536,8 +542,10 @@ def finalize_discovery_counter_in_global_llm_context(ctx: Any, raw_context: str
)
raw_scout_trajectory = getattr(ctx, "scout_trajectory", None)
scout_trajectory = raw_scout_trajectory if isinstance(raw_scout_trajectory, Sequence) else ()
+ raw_inventory = getattr(ctx, "scouted_credential_field_inventory_by_credential_id", None)
fill_carry = _fill_carry_from_scout_trajectory(
- [interaction for interaction in scout_trajectory if isinstance(interaction, Mapping)]
+ [interaction for interaction in scout_trajectory if isinstance(interaction, Mapping)],
+ credential_field_inventory=raw_inventory if isinstance(raw_inventory, Mapping) else None,
)
if (
not raw_context
diff --git a/skyvern/forge/sdk/copilot/enforcement.py b/skyvern/forge/sdk/copilot/enforcement.py
index 677f1cfc2..cfd020726 100644
--- a/skyvern/forge/sdk/copilot/enforcement.py
+++ b/skyvern/forge/sdk/copilot/enforcement.py
@@ -37,7 +37,11 @@ from skyvern.forge.sdk.copilot.build_test_outcome import (
)
from skyvern.forge.sdk.copilot.challenge_evidence import composition_challenge_carrier
from skyvern.forge.sdk.copilot.code_block_synthesis import (
+ CREDENTIAL_FILL_TOOL_NAME,
+ LIVE_SCOUT_CREDENTIAL_FIELDS,
SCOUTED_SPINE_UNDER_BUILD_REASON_CODE,
+ credential_scout_gap,
+ first_matched_post_fill_submit_index,
freeze_requested_output_extraction_candidate,
is_durable_fallback_entry_target,
is_generic_entry_opener_click,
@@ -2339,6 +2343,8 @@ def synthesized_persistence_reopened_after_failed_run(ctx: Any) -> bool:
def synthesized_persistence_reopened(ctx: AgentContext) -> bool:
if ctx.synthesized_block_reopened_for_output_coverage:
return True
+ if ctx.synthesized_block_reopened_for_credential_scout:
+ return True
return synthesized_persistence_reopened_after_failed_run(ctx)
@@ -2477,10 +2483,80 @@ def record_scouted_output_coverage(ctx: AgentContext, page_evidence: dict[str, A
)
+def _credential_flow_filled_fields_by_credential(interactions: list[dict[str, Any]]) -> dict[str, set[str]]:
+ filled: dict[str, set[str]] = {}
+ for item in interactions:
+ if str(item.get("tool_name") or "").strip() != CREDENTIAL_FILL_TOOL_NAME:
+ continue
+ field_name = str(item.get("credential_field") or "").strip()
+ if field_name not in LIVE_SCOUT_CREDENTIAL_FIELDS:
+ continue
+ credential_id = str(item.get("credential_id") or "").strip()
+ if not credential_id:
+ continue
+ filled.setdefault(credential_id, set()).add(field_name)
+ return filled
+
+
+def _credential_password_demand_holds(ctx: Any, interactions: list[dict[str, Any]], credential_id: str) -> bool:
+ """The password requirement stands until a page observation lands after a post-fill submit that
+ ``credential_scout_gap`` itself would credit (fill-source-url matched), and stays whenever that
+ latest observed page still shows a password-type control."""
+ latest_fill_index = -1
+ fill_source_urls: set[str] = set()
+ for index, item in enumerate(interactions):
+ if (
+ str(item.get("tool_name") or "").strip() != CREDENTIAL_FILL_TOOL_NAME
+ or str(item.get("credential_id") or "").strip() != credential_id
+ or str(item.get("credential_field") or "").strip() not in LIVE_SCOUT_CREDENTIAL_FIELDS
+ ):
+ continue
+ latest_fill_index = index
+ source_url = str(item.get("source_url") or "").strip()
+ if source_url:
+ fill_source_urls.add(source_url)
+ submit_index = first_matched_post_fill_submit_index(interactions, latest_fill_index, fill_source_urls)
+ if submit_index is None:
+ return True
+ submit_trajectory_index = interactions[submit_index].get("trajectory_index")
+ observed_index = getattr(ctx, "last_scout_observation_trajectory_index", None)
+ if (
+ not isinstance(submit_trajectory_index, int)
+ or not isinstance(observed_index, int)
+ or observed_index < submit_trajectory_index
+ ):
+ return True
+ return bool(getattr(ctx, "last_scout_observation_has_password_control", False))
+
+
+def _credential_flow_scout_gap_incomplete(ctx: Any, trajectory: list[Any]) -> bool:
+ """Trajectory- and inventory-scoped mirror of the persist seam's credential scout gate: engaged
+ credentials (username/password fills) must have every required field filled plus a post-fill
+ submit before the synthesized trajectory may grade goal-complete."""
+ interactions = [item for item in trajectory if isinstance(item, dict)]
+ filled_by_credential = _credential_flow_filled_fields_by_credential(interactions)
+ if not filled_by_credential:
+ return False
+ raw_inventory = getattr(ctx, "scouted_credential_field_inventory_by_credential_id", None)
+ inventory: Mapping[str, frozenset[str]] = raw_inventory if isinstance(raw_inventory, Mapping) else {}
+ requirements: list[tuple[frozenset[str], frozenset[str]]] = []
+ for credential_id, filled_fields in filled_by_credential.items():
+ required_fields = set(filled_fields)
+ if "password" in inventory.get(credential_id, frozenset()) and _credential_password_demand_holds(
+ ctx, interactions, credential_id
+ ):
+ required_fields.add("password")
+ requirements.append((frozenset({credential_id}), frozenset(required_fields)))
+ # requires_submit is always True here: the predicate is deliberately stricter than the persist
+ # gate, which demands a submit only when the block's code itself performs one.
+ gap = credential_scout_gap(interactions, requirements, requires_submit=True)
+ return bool(gap.missing_fields) or gap.missing_submit
+
+
def synthesized_trajectory_is_goal_complete(ctx: Any) -> bool:
"""Complete once the scout trajectory covers a durable entry followed by a commit (or a reached download target)
- with no requested-output path left uncovered; an empty requested-output set falls through to the shape heuristic
- byte-identically, so an entry ``synthesize_code_block`` would drop never counts as complete."""
+ with no requested-output path left uncovered and no engaged credential flow left unscouted; empty requested-output
+ and credential-fill sets fall through to the shape heuristic byte-identically."""
if uncovered_requested_output_paths(ctx):
return False
requested_paths = _requested_output_paths_for_ctx(ctx)
@@ -2490,6 +2566,8 @@ def synthesized_trajectory_is_goal_complete(ctx: Any) -> bool:
trajectory = getattr(ctx, "scout_trajectory", None)
if not isinstance(trajectory, list) or not trajectory:
return False
+ if _credential_flow_scout_gap_incomplete(ctx, trajectory):
+ return False
download = getattr(ctx, "reached_download_target", None)
if isinstance(download, ReachedDownloadTarget) and download.selector:
return True
@@ -2555,6 +2633,8 @@ def _should_block_mutating_tool_after_synthesized_offer(ctx: Any, tool_name: str
return False
if uncovered_requested_output_paths(ctx):
return False
+ if _credential_flow_scout_gap_incomplete(ctx, getattr(ctx, "scout_trajectory", None) or []):
+ return False
if getattr(ctx, "update_workflow_called", False) and not synthesized_persistence_reopened(ctx):
return False
if not _turn_intent_can_update_and_run_without_user_input(getattr(ctx, "turn_intent", None)):
@@ -2667,6 +2747,21 @@ def _actuation_obligation_admits_required_fill_tool(ctx: CopilotContext, tool_na
return tool_name == _actuation_obligation_required_fill_tool(ctx)
+def arm_credential_scout_reopen(ctx: AgentContext, identity_digest: str) -> bool:
+ """Arm a one-shot scout-window reopen for the first author-time credential-scout reject per
+ (structural identity + credential binding) digest. A repeat identical reject returns False and
+ falls through so it counts normally toward the repair ceiling."""
+ if ctx.credential_scout_rescout_context_key == identity_digest:
+ return False
+ ctx.credential_scout_rescout_context_key = identity_digest
+ ctx.synthesized_block_reopened_for_credential_scout = True
+ return True
+
+
+def _credential_scout_reopen_admits_evaluate(ctx: CopilotContext, tool_name: str) -> bool:
+ return tool_name == "evaluate" and bool(ctx.synthesized_block_reopened_for_credential_scout)
+
+
def consume_uncovered_output_reopen_event(ctx: CopilotContext) -> bool:
"""Arm a one-shot scout-window reopen for the first author-time reject citing an uncovered
requested-output path. Returns True only on that first reject per structural identity; a
@@ -2774,6 +2869,8 @@ def synthesized_block_persistence_signal(ctx: Any, tool_name: str) -> CopilotToo
return None
if _uncovered_output_reject_admits_evaluate(ctx, tool_name):
return None
+ if _credential_scout_reopen_admits_evaluate(ctx, tool_name):
+ return None
if _actuation_obligation_admits_required_fill_tool(ctx, tool_name):
return None
if (
diff --git a/skyvern/forge/sdk/copilot/mcp_adapter.py b/skyvern/forge/sdk/copilot/mcp_adapter.py
index dca6cbacf..26129174c 100644
--- a/skyvern/forge/sdk/copilot/mcp_adapter.py
+++ b/skyvern/forge/sdk/copilot/mcp_adapter.py
@@ -71,6 +71,8 @@ _POST_HOOK_CONTEXT_ROLLBACK_FIELDS = (
"code_only_target_page_evidence_seen",
"last_evaluate_actionable_signature",
"last_evaluate_actionable_url",
+ "last_scout_observation_trajectory_index",
+ "last_scout_observation_has_password_control",
"latest_evaluate_result_composition_steer",
"latest_evaluate_result_composition_signature",
"last_auto_acted_signature",
diff --git a/skyvern/forge/sdk/copilot/runtime.py b/skyvern/forge/sdk/copilot/runtime.py
index 8e2e0a166..c7979b0da 100644
--- a/skyvern/forge/sdk/copilot/runtime.py
+++ b/skyvern/forge/sdk/copilot/runtime.py
@@ -348,7 +348,7 @@ class AgentContext:
# flow_evidence does not cover it (closes the spent-inspection-budget
# deadlock). Each item: {url, had_bounded_schema, reached_via}.
prior_observed_acted_pages: list[dict[str, Any]] = field(default_factory=list)
- prior_fill_carry: list[dict[str, str | int | bool | None]] = field(default_factory=list)
+ prior_fill_carry: list[dict[str, str | int | bool | list[str] | None]] = field(default_factory=list)
fill_carry_rebound_done: bool = False
post_budget_page_inspection_required: bool = False
post_budget_page_inspection_url: str | None = None
@@ -432,9 +432,18 @@ class AgentContext:
requested_output_extraction_candidate: FrozenRequestedOutputExtractionCandidate | None = None
synthesized_block_reopened_after_failed_run: bool = False
synthesized_block_reopened_for_output_coverage: bool = False
+ synthesized_block_reopened_for_credential_scout: bool = False
scouted_output_covered_paths: set[str] = field(default_factory=set)
uncovered_output_rescout_context_key: str | None = None
uncovered_output_rescout_steer_key: str | None = None
+ credential_scout_rescout_context_key: str | None = None
+ # Which requires-live-scout fields (username/password, non-empty) each scouted credential
+ # carries; recorded at credential resolve time and rehydrated from FillCarry across turns.
+ scouted_credential_field_inventory_by_credential_id: dict[str, frozenset[str]] = field(default_factory=dict)
+ # Highest trajectory_index visible at the latest parsed evaluate observation and whether that page
+ # showed a password-type control; orders page evidence against post-fill submits across evictions.
+ last_scout_observation_trajectory_index: int | None = None
+ last_scout_observation_has_password_control: bool = False
# Count of times the scout-act download gate rejected a download-intent block this turn. Bounds
# the author->scout->re-author cycle so a genuinely un-scoutable affordance halts honestly.
download_scout_required_rejections: int = 0
diff --git a/skyvern/forge/sdk/copilot/tools/credential_fill.py b/skyvern/forge/sdk/copilot/tools/credential_fill.py
index f7e4ac02c..fd8aef126 100644
--- a/skyvern/forge/sdk/copilot/tools/credential_fill.py
+++ b/skyvern/forge/sdk/copilot/tools/credential_fill.py
@@ -160,6 +160,11 @@ async def _resolve_credential_fill_value(
register_secret_scrub_value(copilot_ctx, value)
if not value:
return None, "", f"Credential `{credential_id}` has no `{field}` value."
+ copilot_ctx.scouted_credential_field_inventory_by_credential_id[credential_id] = frozenset(
+ field_name
+ for field_name, field_value in (("username", credential.username), ("password", credential.password))
+ if field_value
+ )
return value, credential_item.name, None
diff --git a/skyvern/forge/sdk/copilot/tools/scouting.py b/skyvern/forge/sdk/copilot/tools/scouting.py
index 4e3321445..a5cdefa0c 100644
--- a/skyvern/forge/sdk/copilot/tools/scouting.py
+++ b/skyvern/forge/sdk/copilot/tools/scouting.py
@@ -330,6 +330,16 @@ def _capped_with_eviction_accounting(
return items[-_MAX_SCOUTED_INTERACTIONS:]
+def _next_trajectory_index(trajectory: list[ScoutedInteraction]) -> int:
+ # len() regresses once eviction trims the list, so the next index continues from the highest recorded one.
+ highest = -1
+ for item in trajectory:
+ index = item.get("trajectory_index")
+ if isinstance(index, int) and index > highest:
+ highest = index
+ return highest + 1 if highest >= 0 else len(trajectory)
+
+
def _record_scouted_interaction(
ctx: AgentContext,
*,
@@ -408,7 +418,7 @@ def _record_scouted_interaction(
trajectory = list(ctx.scout_trajectory)
trajectory_artifact = cast(ScoutedInteraction, artifact.copy())
- trajectory_artifact["trajectory_index"] = len(trajectory)
+ trajectory_artifact["trajectory_index"] = _next_trajectory_index(trajectory)
trajectory.append(trajectory_artifact)
ctx.scout_trajectory = _capped_with_eviction_accounting(trajectory, collection="scout_trajectory")
@@ -529,6 +539,13 @@ async def _maybe_rebind_prior_fill_carry(
if not prior:
ctx.fill_carry_rebound_done = True
return
+ # Inventory is credential metadata, not page state: rehydrate it even when page
+ # validation below drops the carried fills themselves.
+ for carry in prior:
+ if carry.tool_name == "fill_credential_field" and carry.credential_id and carry.available_fields:
+ ctx.scouted_credential_field_inventory_by_credential_id.setdefault(
+ carry.credential_id, frozenset(carry.available_fields)
+ )
rebound: list[FillCarry] = []
for carry in prior:
failure = await _fill_carry_validation_failure(ctx, carry, page_evidence=page_evidence, url=url)
@@ -546,7 +563,7 @@ async def _maybe_rebind_prior_fill_carry(
ctx.fill_carry_rebound_done = True
trajectory = list(ctx.scout_trajectory)
for carry in rebound:
- trajectory.append(_fill_carry_to_interaction(carry, len(trajectory)))
+ trajectory.append(_fill_carry_to_interaction(carry, _next_trajectory_index(trajectory)))
ctx.scout_trajectory = _capped_with_eviction_accounting(trajectory, collection="scout_trajectory")
LOG.info(
"copilot_fill_carry_rebound",
@@ -1213,6 +1230,34 @@ class _UnsetEvidence:
_EVIDENCE_UNSET = _UnsetEvidence()
+def _page_evidence_has_password_control(page_evidence: dict[str, Any]) -> bool:
+ forms = page_evidence.get("forms")
+ if not isinstance(forms, list):
+ return False
+ for form in forms:
+ if not isinstance(form, dict):
+ continue
+ fields = form.get("fields")
+ if not isinstance(fields, list):
+ continue
+ for form_field in fields:
+ if isinstance(form_field, dict) and str(form_field.get("type") or "").strip().lower() == "password":
+ return True
+ return False
+
+
+def _record_scout_page_observation(ctx: AgentContext, page_evidence: dict[str, Any]) -> None:
+ observed_index: int | None = None
+ for item in ctx.scout_trajectory:
+ if not isinstance(item, dict):
+ continue
+ index = item.get("trajectory_index")
+ if isinstance(index, int) and (observed_index is None or index > observed_index):
+ observed_index = index
+ ctx.last_scout_observation_trajectory_index = observed_index
+ ctx.last_scout_observation_has_password_control = _page_evidence_has_password_control(page_evidence)
+
+
async def _maybe_steer_evaluate_to_action(
ctx: AgentContext,
result: dict[str, Any],
@@ -1233,6 +1278,7 @@ async def _maybe_steer_evaluate_to_action(
_reset_evaluate_tracker(ctx)
return False
record_scouted_output_coverage(ctx, parsed)
+ _record_scout_page_observation(ctx, parsed)
loaded_results = _mint_current_loaded_result_source(ctx, parsed, url=url)
if loaded_results is not None:
_reset_evaluate_tracker(ctx)
diff --git a/skyvern/forge/sdk/copilot/tools/workflow_update.py b/skyvern/forge/sdk/copilot/tools/workflow_update.py
index c1714ceff..6d1da5552 100644
--- a/skyvern/forge/sdk/copilot/tools/workflow_update.py
+++ b/skyvern/forge/sdk/copilot/tools/workflow_update.py
@@ -35,6 +35,7 @@ from skyvern.forge.sdk.copilot.build_test_outcome import (
BuildTestOutcomeReasonCode,
RecordedBuildTestOutcome,
RecordedOutcomeBindingConstraint,
+ _stable_hash,
authored_block_signatures_from_workflow,
authored_structure_signature_from_workflow,
record_build_test_outcome,
@@ -53,17 +54,20 @@ from skyvern.forge.sdk.copilot.code_block_security import CodeBlockSecurityError
from skyvern.forge.sdk.copilot.code_block_steps import apply_derived_code_block_steps, fill_code_block_prompts_in_yaml
from skyvern.forge.sdk.copilot.code_block_synthesis import (
_BARE_TAG_RE,
+ _CODE_SUBMIT_ACTION_RE,
_INTERNAL_SCOUT_VARS,
_SYNTHESIZED_BLOCK_LABEL,
CREDENTIAL_FILL_TOOL_NAME,
SCOUTED_SPINE_UNDER_BUILD_REASON_CODE,
SynthesisDiagnostics,
SynthesizedCodeBlock,
+ _credential_field_accesses,
_get_by_role_expr_strict,
_is_positional_selector,
_parse_role_name,
artifact_dependency_id,
artifact_observation_ref_id,
+ credential_scout_gap,
freeze_requested_output_extraction_candidate,
locator_selector_literals,
missing_rung_text,
@@ -90,6 +94,7 @@ from skyvern.forge.sdk.copilot.enforcement import (
_CHURN_REASON_CODES,
_record_code_authoring_guardrail_reject,
_scouted_spine_open_obligation,
+ arm_credential_scout_reopen,
requested_output_extraction_plan,
requested_output_extraction_plan_changed,
synthesized_persistence_reopened,
@@ -385,41 +390,6 @@ _CODE_ARTIFACT_REQUIRED_LIST_FIELDS = (
"completion_criteria",
"terminal_verifier_expectations",
)
-_CREDENTIAL_FIELD_ACCESS_RE = re.compile(
- r"\b(?P<parameter>[A-Za-z_][A-Za-z0-9_]*)\.(?:(?P<field>username|password|totp)\b|(?P<otp_method>otp)\s*\()"
-)
-_CODE_SUBMIT_ACTION_RE = re.compile(r"\.(?:click|press)\s*\(")
-_SCOUT_SUBMIT_TOOL_NAMES = frozenset({"click", "press_key"})
-
-
-class CredentialFieldAccess(NamedTuple):
- parameter_key: str
- field: str
- requires_live_scout: bool
-
-
-def _credential_field_accesses(code: str) -> list[CredentialFieldAccess]:
- accesses: list[CredentialFieldAccess] = []
- for match in _CREDENTIAL_FIELD_ACCESS_RE.finditer(code):
- field = match.group("field")
- if field:
- accesses.append(
- CredentialFieldAccess(
- parameter_key=match.group("parameter"),
- field=field,
- requires_live_scout=True,
- )
- )
- continue
- if match.group("otp_method"):
- accesses.append(
- CredentialFieldAccess(
- parameter_key=match.group("parameter"),
- field="totp",
- requires_live_scout=False,
- )
- )
- return accesses
def _code_artifact_metadata_as_tool_argument(
@@ -1302,6 +1272,24 @@ def _credential_scout_reject_payload(workflow_yaml: str) -> Mapping[str, object]
return {"credential_scout_requirements": entries}
+def _credential_scout_reopen_identity_digest(workflow_yaml: str) -> str:
+ structural_identity = "author_time:" + _stable_hash(_credential_scout_reject_payload(workflow_yaml) or {})
+ accessed_parameter_keys: set[str] = set()
+ for block in _workflow_yaml_code_blocks_by_label(workflow_yaml).values():
+ code = str(block.get("code") or "")
+ accessed_parameter_keys.update(
+ access.parameter_key for access in _credential_field_accesses(code) if access.requires_live_scout
+ )
+ credential_params_by_key: dict[str, set[str]] = {}
+ parsed = parse_workflow_yaml(workflow_yaml)
+ if isinstance(parsed, dict):
+ workflow_definition = parsed.get("workflow_definition")
+ if isinstance(workflow_definition, dict):
+ credential_params_by_key = credential_param_ids(workflow_definition.get("parameters"))
+ binding = {key: sorted(ids) for key, ids in credential_params_by_key.items() if key in accessed_parameter_keys}
+ return f"{structural_identity}|{_stable_hash(binding)}"
+
+
def _code_artifact_metadata_reject_payload(
*,
workflow_yaml: str,
@@ -5457,6 +5445,7 @@ def _should_impose_after_update_attempt(ctx: AgentContext) -> bool:
return (
(isinstance(target, ReachedDownloadTarget) and not target.already_registered and bool(target.selector.strip()))
or synthesized_persistence_reopened_after_failed_run(ctx)
+ or ctx.synthesized_block_reopened_for_credential_scout
or _author_time_reject_reopens_synthesized_imposition(ctx)
)
@@ -8891,45 +8880,13 @@ def _credentialed_code_block_scout_gate_errors(
if not required_fields_by_parameter:
continue
- matched_fill_indexes: list[int] = []
- matched_source_urls: set[str] = set()
- missing_fields: list[str] = []
- for allowed_credential_ids, required_fields in required_fields_by_parameter.values():
- matched_fields: set[str] = set()
- for index, interaction in enumerate(scout_trajectory):
- if str(interaction.get("tool_name") or "").strip() != "fill_credential_field":
- continue
- if str(interaction.get("credential_id") or "").strip() not in allowed_credential_ids:
- continue
- field = str(interaction.get("credential_field") or "").strip()
- if field not in required_fields:
- continue
- matched_fields.add(field)
- matched_fill_indexes.append(index)
- source_url = str(interaction.get("source_url") or "").strip()
- if source_url:
- matched_source_urls.add(source_url)
- for field in sorted(required_fields - matched_fields):
- missing_fields.append(field)
-
- requires_submit = bool(_CODE_SUBMIT_ACTION_RE.search(code))
- missing_submit = False
- if requires_submit:
- latest_fill_index = max(matched_fill_indexes, default=-1)
- if latest_fill_index < 0:
- missing_submit = True
- else:
- missing_submit = True
- for index, interaction in enumerate(scout_trajectory):
- if index <= latest_fill_index:
- continue
- if str(interaction.get("tool_name") or "").strip() not in _SCOUT_SUBMIT_TOOL_NAMES:
- continue
- source_url = str(interaction.get("source_url") or "").strip()
- if matched_source_urls and source_url not in matched_source_urls:
- continue
- missing_submit = False
- break
+ gap = credential_scout_gap(
+ scout_trajectory,
+ list(required_fields_by_parameter.values()),
+ requires_submit=bool(_CODE_SUBMIT_ACTION_RE.search(code)),
+ )
+ missing_fields = gap.missing_fields
+ missing_submit = gap.missing_submit
if not missing_fields and not missing_submit:
continue
@@ -9053,6 +9010,8 @@ async def _update_workflow(
ctx.raw_code_artifact_metadata = params.get("raw_code_artifact_metadata", params.get("code_artifact_metadata"))
# Imposition reconciles synthesized aliases/parameters before the persisted YAML contract is checked.
imposition = _maybe_impose_synthesized_code_block(workflow_yaml, ctx)
+ # Consume the one-shot credential-scout reopen before the gate below so a fresh reject can re-arm it.
+ ctx.synthesized_block_reopened_for_credential_scout = False
if imposition.violations:
if (
imposition.repair_context is not None
@@ -9407,6 +9366,7 @@ async def _update_workflow(
repair_context=code_authoring_repair_context,
)
if credential_scout_errors and code_safety_errors and code_artifact_metadata_error is None:
+ arm_credential_scout_reopen(ctx, _credential_scout_reopen_identity_digest(workflow_yaml))
return reject(
error=_credential_scout_reject_error_text(ctx, credential_scout_errors),
user_facing_summary=CREDENTIAL_SCOUT_VERIFY_REPLY,
@@ -9447,6 +9407,7 @@ async def _update_workflow(
structural_payload=_credential_scout_reject_payload(workflow_yaml),
)
_record_code_authoring_guardrail_reject(ctx, defer_churn_stop=True)
+ arm_credential_scout_reopen(ctx, _credential_scout_reopen_identity_digest(workflow_yaml))
return reject(
error=_credential_scout_reject_error_text(ctx, credential_scout_errors),
user_facing_summary=CREDENTIAL_SCOUT_VERIFY_REPLY,
diff --git a/tests/unit/test_copilot_code_block_persist_seam.py b/tests/unit/test_copilot_code_block_persist_seam.py
index 26e5a9094..8c086ca0d 100644
--- a/tests/unit/test_copilot_code_block_persist_seam.py
+++ b/tests/unit/test_copilot_code_block_persist_seam.py
@@ -41,10 +41,12 @@ from skyvern.forge.sdk.copilot.code_block_preflight import (
)
from skyvern.forge.sdk.copilot.code_block_security import CodeBlockSecurityError
from skyvern.forge.sdk.copilot.code_block_synthesis import (
+ ScoutGap,
SynthesisDiagnostics,
SynthesizedCodeBlock,
_get_by_role_expr,
_get_by_role_expr_strict,
+ credential_scout_gap,
)
from skyvern.forge.sdk.copilot.completion_verification import CompletionVerificationResult, CriterionVerdict
from skyvern.forge.sdk.copilot.config import BlockAuthoringPolicy, CopilotConfig
@@ -13212,6 +13214,18 @@ class TestScoutCaptureParityAccounting:
assert len(ctx.scout_trajectory) == scouting_module._MAX_SCOUTED_INTERACTIONS
assert ctx.scouted_interactions[0]["selector"] == "#item-1"
+ def test_trajectory_index_stays_monotonic_across_evictions(self) -> None:
+ ctx = _code_only_ctx()
+ ctx.scouted_interactions = []
+ ctx.scout_trajectory = []
+ for index in range(scouting_module._MAX_SCOUTED_INTERACTIONS + 2):
+ scouting_module._record_scouted_interaction(
+ ctx, tool_name="click", selector=f"#item-{index}", source_url="https://example.com/list"
+ )
+
+ indexes = [item["trajectory_index"] for item in ctx.scout_trajectory]
+ assert indexes == list(range(2, scouting_module._MAX_SCOUTED_INTERACTIONS + 2))
+
def test_dedup_replacement_is_not_an_eviction(self) -> None:
ctx = _code_only_ctx()
ctx.scouted_interactions = []
@@ -14004,3 +14018,220 @@ class TestAmbiguousRejectCarriesOpenObligationArtifact:
assert any("ambiguous browser action" in violation for violation in result.violations)
assert not any("reuse verbatim" in violation for violation in result.violations)
+
+
+class TestCredentialScoutGapMatcher:
+ _PAGE_ONE = "https://portal.example.test/step-one"
+ _PAGE_TWO = "https://portal.example.test/step-two"
+
+ @staticmethod
+ def _fill(credential_id: str, field: str, source_url: str) -> dict[str, object]:
+ return {
+ "tool_name": "fill_credential_field",
+ "credential_id": credential_id,
+ "credential_field": field,
+ "selector": f"#{field}",
+ "source_url": source_url,
+ }
+
+ @staticmethod
+ def _click(source_url: str) -> dict[str, object]:
+ return {"tool_name": "click", "selector": "input[type='submit']", "source_url": source_url}
+
+ def test_missing_fields_reported_sorted_per_requirement(self) -> None:
+ gap = credential_scout_gap(
+ [self._fill("cred_a", "username", self._PAGE_ONE)],
+ [(frozenset({"cred_a"}), frozenset({"username", "password"}))],
+ requires_submit=False,
+ )
+ assert gap == ScoutGap(missing_fields=["password"], missing_submit=False)
+
+ def test_no_matched_fill_means_missing_submit(self) -> None:
+ gap = credential_scout_gap(
+ [self._click(self._PAGE_ONE)],
+ [(frozenset({"cred_a"}), frozenset({"username"}))],
+ requires_submit=True,
+ )
+ assert gap == ScoutGap(missing_fields=["username"], missing_submit=True)
+
+ def test_cross_requirement_accumulation_accepts_submit_on_either_matched_page(self) -> None:
+ trajectory = [
+ self._fill("cred_a", "username", self._PAGE_ONE),
+ self._fill("cred_b", "password", self._PAGE_TWO),
+ self._click(self._PAGE_ONE),
+ ]
+ gap = credential_scout_gap(
+ trajectory,
+ [
+ (frozenset({"cred_a"}), frozenset({"username"})),
+ (frozenset({"cred_b"}), frozenset({"password"})),
+ ],
+ requires_submit=True,
+ )
+ assert gap == ScoutGap(missing_fields=[], missing_submit=False)
+
+ def test_submit_on_unmatched_page_stays_missing(self) -> None:
+ trajectory = [
+ self._fill("cred_a", "username", self._PAGE_ONE),
+ self._click("https://portal.example.test/elsewhere"),
+ ]
+ gap = credential_scout_gap(
+ trajectory,
+ [(frozenset({"cred_a"}), frozenset({"username"}))],
+ requires_submit=True,
+ )
+ assert gap == ScoutGap(missing_fields=[], missing_submit=True)
+
+ def test_submit_before_latest_fill_stays_missing(self) -> None:
+ trajectory = [
+ self._click(self._PAGE_ONE),
+ self._fill("cred_a", "username", self._PAGE_ONE),
+ ]
+ gap = credential_scout_gap(
+ trajectory,
+ [(frozenset({"cred_a"}), frozenset({"username"}))],
+ requires_submit=True,
+ )
+ assert gap == ScoutGap(missing_fields=[], missing_submit=True)
+
+ def test_sourceless_fill_accepts_any_later_submit(self) -> None:
+ trajectory = [
+ self._fill("cred_a", "username", ""),
+ self._click("https://portal.example.test/elsewhere"),
+ ]
+ gap = credential_scout_gap(
+ trajectory,
+ [(frozenset({"cred_a"}), frozenset({"username"}))],
+ requires_submit=True,
+ )
+ assert gap == ScoutGap(missing_fields=[], missing_submit=False)
+
+
+class TestCredentialScoutGatePredicateCoherence:
+ _TWO_FIELD_LOGIN_YAML = _credential_code_yaml(
+ code="""
+ await page.locator("#user").fill(login_credential.username)
+ await page.locator("#pass").fill(login_credential.password)
+ await page.locator("button[type='submit']").click()
+ """,
+ credential_id="cred_1",
+ )
+
+ @staticmethod
+ def _trajectory(*steps: dict[str, object]) -> list[dict[str, object]]:
+ return list(steps)
+
+ def _gate_ctx(self, trajectory: list[dict[str, object]]) -> CopilotContext:
+ ctx = _code_only_ctx()
+ ctx.scout_trajectory = trajectory
+ ctx.scouted_credential_field_inventory_by_credential_id = {"cred_1": frozenset({"username", "password"})}
+ return ctx
+
+ def test_predicate_complete_trajectory_passes_the_real_gate(self) -> None:
+ helper = TestCredentialScoutGapMatcher
+ trajectory = self._trajectory(
+ helper._fill("cred_1", "username", helper._PAGE_ONE),
+ helper._click(helper._PAGE_ONE),
+ helper._fill("cred_1", "password", helper._PAGE_TWO),
+ helper._click(helper._PAGE_TWO),
+ )
+ ctx = self._gate_ctx(trajectory)
+ assert enforcement_module.synthesized_trajectory_is_goal_complete(ctx) is True
+ assert workflow_update_module._credentialed_code_block_scout_gate_errors(self._TWO_FIELD_LOGIN_YAML, ctx) == []
+
+ def test_predicate_incomplete_half_login_is_also_gate_rejected(self) -> None:
+ helper = TestCredentialScoutGapMatcher
+ trajectory = self._trajectory(
+ helper._fill("cred_1", "username", helper._PAGE_ONE),
+ helper._click(helper._PAGE_ONE),
+ )
+ ctx = self._gate_ctx(trajectory)
+ assert enforcement_module.synthesized_trajectory_is_goal_complete(ctx) is False
+ errors = workflow_update_module._credentialed_code_block_scout_gate_errors(self._TWO_FIELD_LOGIN_YAML, ctx)
+ assert errors
+ assert "password" in errors[0]
+
+
+class TestCredentialScoutReopenSeam:
+ @pytest.mark.asyncio
+ async def test_pure_credential_reject_arms_then_same_identity_does_not_re_arm(self) -> None:
+ ctx = _code_only_ctx()
+ ctx.scout_trajectory = []
+ yaml_text = TestCredentialScoutPersistGate._SUBMIT_CODE_YAML
+
+ result = await _update_workflow({"workflow_yaml": yaml_text}, ctx)
+
+ assert result["ok"] is False
+ assert result["data"]["failure_type"] == "missing_credential_or_init"
+ assert ctx.synthesized_block_reopened_for_credential_scout is True
+ first_key = ctx.credential_scout_rescout_context_key
+ assert first_key
+
+ result = await _update_workflow({"workflow_yaml": yaml_text}, ctx)
+
+ assert result["ok"] is False
+ assert ctx.synthesized_block_reopened_for_credential_scout is False
+ assert ctx.credential_scout_rescout_context_key == first_key
+
+ @pytest.mark.asyncio
+ async def test_new_binding_identity_re_arms_reopen(self) -> None:
+ ctx = _code_only_ctx()
+ ctx.scout_trajectory = []
+
+ await _update_workflow({"workflow_yaml": TestCredentialScoutPersistGate._SUBMIT_CODE_YAML}, ctx)
+ first_key = ctx.credential_scout_rescout_context_key
+ assert ctx.synthesized_block_reopened_for_credential_scout is True
+
+ rebound_yaml = _credential_code_yaml(
+ code="""
+ await page.locator("#email").fill(login_credential.username)
+ await page.locator("input[type='password']").fill(login_credential.password)
+ await page.locator("#totpmfa").fill(login_credential.totp)
+ await page.locator("input[type='submit']").click()
+ await page.wait_for_load_state("load")
+ """,
+ credential_id="cred_rebound",
+ )
+ result = await _update_workflow({"workflow_yaml": rebound_yaml}, ctx)
+
+ assert result["ok"] is False
+ assert ctx.synthesized_block_reopened_for_credential_scout is True
+ assert ctx.credential_scout_rescout_context_key != first_key
+
+ @pytest.mark.asyncio
+ async def test_combined_credential_and_code_safety_reject_arms_reopen(self) -> None:
+ ctx = _code_only_ctx()
+ ctx.scout_trajectory = []
+
+ result = await _update_workflow({"workflow_yaml": TestCredentialScoutPersistGate._UNSAFE_SUBMIT_CODE_YAML}, ctx)
+
+ assert result["ok"] is False
+ assert result["data"]["failure_type"] == "missing_credential_or_init"
+ assert ctx.synthesized_block_reopened_for_credential_scout is True
+ assert ctx.credential_scout_rescout_context_key
+
+ @pytest.mark.asyncio
+ async def test_gate_passing_attempt_leaves_window_closed(self) -> None:
+ ctx = _code_only_ctx()
+ ctx.scout_trajectory = []
+
+ await _update_workflow({"workflow_yaml": TestCredentialScoutPersistGate._SUBMIT_CODE_YAML}, ctx)
+ assert ctx.synthesized_block_reopened_for_credential_scout is True
+
+ ctx.scout_trajectory = [
+ _credential_fill_interaction("username"),
+ _credential_fill_interaction("password"),
+ _credential_fill_interaction("totp"),
+ _submit_interaction(),
+ ]
+ result = await _update_workflow({"workflow_yaml": TestCredentialScoutPersistGate._SUBMIT_CODE_YAML}, ctx)
+
+ assert ctx.synthesized_block_reopened_for_credential_scout is False
+ error_text = str(result.get("error") or "")
+ assert "fill_credential_field" not in error_text
+
+ def test_should_impose_after_update_attempt_honors_reopen_flag(self) -> None:
+ ctx = _code_only_ctx()
+ assert workflow_update_module._should_impose_after_update_attempt(ctx) is False
+ ctx.synthesized_block_reopened_for_credential_scout = True
+ assert workflow_update_module._should_impose_after_update_attempt(ctx) is True
diff --git a/tests/unit/test_copilot_context.py b/tests/unit/test_copilot_context.py
index 4ec689ddc..5cc7ba613 100644
--- a/tests/unit/test_copilot_context.py
+++ b/tests/unit/test_copilot_context.py
@@ -359,6 +359,72 @@ def test_finalize_context_persists_fill_carry() -> None:
]
+def test_fill_carry_records_credential_field_inventory() -> None:
+ carry = _fill_carry_from_scout_trajectory(
+ [
+ {
+ "tool_name": "fill_credential_field",
+ "selector": "#user",
+ "source_url": "https://portal.example.test/login",
+ "typed_length": 10,
+ "credential_id": "cred_123",
+ "credential_field": "username",
+ }
+ ],
+ credential_field_inventory={"cred_123": frozenset({"username", "password"})},
+ )
+
+ assert [item.available_fields for item in carry] == [["password", "username"]]
+
+
+def test_fill_carry_without_inventory_serializes_like_legacy_payload() -> None:
+ carry = _fill_carry_from_scout_trajectory(
+ [
+ {
+ "tool_name": "fill_credential_field",
+ "selector": "#user",
+ "source_url": "https://portal.example.test/login",
+ "credential_id": "cred_123",
+ "credential_field": "username",
+ }
+ ]
+ )
+
+ assert [item.available_fields for item in carry] == [None]
+ serialized = StructuredContext(fill_carry=carry).to_json_str()
+ assert "available_fields" not in serialized
+ legacy_round_trip = StructuredContext.from_json_str(serialized)
+ assert legacy_round_trip.fill_carry[0].available_fields is None
+
+
+def test_finalize_context_persists_credential_inventory_on_fill_carry() -> None:
+ ctx = SimpleNamespace(
+ prior_discovery_calls_made=0,
+ discovery_calls_this_turn=0,
+ prior_page_inspection_calls_made=0,
+ page_inspection_calls_this_turn=0,
+ flow_evidence=[],
+ latest_evaluate_result_composition_steer=None,
+ scout_trajectory=[
+ {
+ "tool_name": "fill_credential_field",
+ "selector": "#user",
+ "source_url": "https://portal.example.test/login",
+ "typed_length": 10,
+ "credential_id": "cred_123",
+ "credential_field": "username",
+ }
+ ],
+ scouted_credential_field_inventory_by_credential_id={"cred_123": frozenset({"username", "password"})},
+ )
+
+ raw = finalize_discovery_counter_in_global_llm_context(ctx, None)
+
+ assert raw is not None
+ parsed = StructuredContext.from_json_str(raw)
+ assert parsed.fill_carry[0].available_fields == ["password", "username"]
+
+
def test_finalize_context_clears_fill_carry_when_current_turn_has_no_fills() -> None:
inbound = StructuredContext(
fill_carry=[
diff --git a/tests/unit/test_copilot_enforcement_pruning.py b/tests/unit/test_copilot_enforcement_pruning.py
index 931ae2e41..f0686f420 100644
--- a/tests/unit/test_copilot_enforcement_pruning.py
+++ b/tests/unit/test_copilot_enforcement_pruning.py
@@ -49,6 +49,7 @@ from skyvern.forge.sdk.copilot.enforcement import (
_should_force_synthesized_block_persistence,
_summarize_tool_output,
_uncovered_output_reject_admits_evaluate,
+ arm_credential_scout_reopen,
consume_uncovered_output_reopen_event,
record_scouted_output_coverage,
run_with_enforcement,
@@ -78,6 +79,11 @@ from skyvern.forge.sdk.copilot.tools import (
_record_run_blocks_result,
_record_workflow_update_result,
)
+from skyvern.forge.sdk.copilot.tools.scouting import (
+ _MAX_SCOUTED_INTERACTIONS,
+ _capped_with_eviction_accounting,
+ _record_scout_page_observation,
+)
from skyvern.forge.sdk.copilot.turn_halt import stash_turn_halt_from_blocker_signal
from skyvern.forge.sdk.copilot.turn_intent import RequiredContextKey, TurnIntent, TurnIntentAuthority, TurnIntentMode
from skyvern.forge.sdk.copilot.verification_evidence import WorkflowVerificationEvidence
@@ -126,6 +132,8 @@ class _Ctx:
self.last_code_authoring_repair_context = None
self.synthesized_block_reopened_after_failed_run = False
self.synthesized_block_reopened_for_output_coverage = False
+ self.synthesized_block_reopened_for_credential_scout = False
+ self.credential_scout_rescout_context_key = None
self.scouted_output_covered_paths: set[str] = set()
self.flow_evidence: list[dict[str, object]] = []
self.copilot_config: CopilotConfig | None = None
@@ -2689,3 +2697,306 @@ class TestAdvisoryRunDispatchForceLane:
assert ctx.turn_halt is None
assert ctx.output_contract_actuation_by_signature["sig_a"] == OutputContractAdvisoryState.GRANTED
assert _should_force_advisory_run_dispatch(ctx) is True
+
+
+class TestCredentialFlowGoalComplete:
+ _LOGIN_URL = "https://portal.example.test/login"
+ _PASSWORD_URL = "https://portal.example.test/password"
+
+ @staticmethod
+ def _username_fill(source_url: str = "https://portal.example.test/login") -> dict[str, object]:
+ return {
+ "tool_name": "fill_credential_field",
+ "credential_id": "cred_1",
+ "credential_field": "username",
+ "selector": "#user",
+ "source_url": source_url,
+ }
+
+ @staticmethod
+ def _password_fill(source_url: str = "https://portal.example.test/password") -> dict[str, object]:
+ return {
+ "tool_name": "fill_credential_field",
+ "credential_id": "cred_1",
+ "credential_field": "password",
+ "selector": "#pass",
+ "source_url": source_url,
+ }
+
+ @staticmethod
+ def _submit(source_url: str, accessible_name: str) -> dict[str, object]:
+ return {
+ "tool_name": "click",
+ "selector": "button[type='submit']",
+ "accessible_name": accessible_name,
+ "source_url": source_url,
+ }
+
+ def _two_screen_first_page(self) -> list[dict[str, object]]:
+ return [self._username_fill(), self._submit(self._LOGIN_URL, "Continue")]
+
+ def _two_screen_full_login(self) -> list[dict[str, object]]:
+ return [*self._two_screen_first_page(), self._password_fill(), self._submit(self._PASSWORD_URL, "Sign in")]
+
+ def _ctx_with_inventory(
+ self,
+ trajectory: list[dict[str, object]],
+ *,
+ inventory: dict[str, frozenset[str]] | None = None,
+ observed_at_index: int | None = None,
+ observed_password_control: bool = False,
+ ) -> _Ctx:
+ ctx = _Ctx()
+ ctx.turn_intent = TurnIntent(
+ mode=TurnIntentMode.BUILD,
+ authority=TurnIntentAuthority(may_update_workflow=True, may_run_blocks=True),
+ )
+ ctx.block_authoring_policy = BlockAuthoringPolicy.CODE_ONLY_BROWSER
+ for position, item in enumerate(trajectory):
+ item.setdefault("trajectory_index", position)
+ ctx.scout_trajectory = trajectory
+ ctx.scouted_credential_field_inventory_by_credential_id = inventory or {}
+ ctx.last_scout_observation_trajectory_index = observed_at_index
+ ctx.last_scout_observation_has_password_control = observed_password_control
+ ctx.synthesized_block_offered = True
+ ctx.synthesized_block_offered_trajectory_len = len(trajectory)
+ ctx.synthesized_block_offered_goal_complete = synthesized_trajectory_is_goal_complete(ctx)
+ return ctx
+
+ def test_half_login_with_unobserved_second_screen_is_incomplete(self) -> None:
+ ctx = self._ctx_with_inventory(
+ self._two_screen_first_page(),
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+ assert _should_force_synthesized_block_persistence(ctx) is False
+ assert synthesized_block_persistence_signal(ctx, "evaluate") is None
+
+ def test_full_login_with_post_fill_submit_is_complete(self) -> None:
+ ctx = self._ctx_with_inventory(
+ self._two_screen_full_login(),
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is True
+ assert _should_force_synthesized_block_persistence(ctx) is True
+ assert synthesized_block_persistence_signal(ctx, "evaluate") is not None
+
+ def test_username_only_flow_completes_after_no_password_control_observation(self) -> None:
+ trajectory = self._two_screen_first_page()
+ ctx = self._ctx_with_inventory(
+ trajectory,
+ inventory={"cred_1": frozenset({"username", "password"})},
+ observed_at_index=len(trajectory) - 1,
+ observed_password_control=False,
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is True
+ assert _should_force_synthesized_block_persistence(ctx) is True
+
+ def test_observed_password_screen_keeps_flow_incomplete(self) -> None:
+ trajectory = self._two_screen_first_page()
+ ctx = self._ctx_with_inventory(
+ trajectory,
+ inventory={"cred_1": frozenset({"username", "password"})},
+ observed_at_index=len(trajectory) - 1,
+ observed_password_control=True,
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+
+ def test_observation_before_submit_does_not_drop_password_requirement(self) -> None:
+ trajectory = self._two_screen_first_page()
+ ctx = self._ctx_with_inventory(
+ trajectory,
+ inventory={"cred_1": frozenset({"username", "password"})},
+ observed_at_index=0,
+ observed_password_control=False,
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+
+ def test_unmatched_incidental_click_before_observation_keeps_password_demand(self) -> None:
+ trajectory = [
+ self._username_fill(),
+ {
+ "tool_name": "click",
+ "selector": "#cookie-accept",
+ "accessible_name": "Accept",
+ "source_url": "https://consent.example.test/banner",
+ },
+ self._submit(self._LOGIN_URL, "Continue"),
+ ]
+ ctx = self._ctx_with_inventory(
+ trajectory,
+ inventory={"cred_1": frozenset({"username", "password"})},
+ observed_at_index=1,
+ observed_password_control=False,
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+
+ def test_non_dict_trajectory_entry_does_not_release_demand_early(self) -> None:
+ trajectory: list[Any] = [{**self._username_fill(), "trajectory_index": 0}, "scout-note"]
+ ctx = self._ctx_with_inventory(
+ [self._username_fill()],
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ ctx.scout_trajectory = trajectory
+ _record_scout_page_observation(ctx, {"forms": [{"fields": [{"selector": "#user", "type": "text"}]}]})
+ trajectory.append({**self._submit(self._LOGIN_URL, "Continue"), "trajectory_index": 2})
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+
+ def test_observation_after_submit_with_non_dict_entry_releases_demand(self) -> None:
+ trajectory: list[Any] = [
+ {**self._username_fill(), "trajectory_index": 0},
+ "scout-note",
+ {**self._submit(self._LOGIN_URL, "Continue"), "trajectory_index": 2},
+ ]
+ ctx = self._ctx_with_inventory(
+ [self._username_fill()],
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ ctx.scout_trajectory = trajectory
+ _record_scout_page_observation(ctx, {"forms": [{"fields": [{"selector": "#user", "type": "text"}]}]})
+ assert synthesized_trajectory_is_goal_complete(ctx) is True
+
+ def test_eviction_does_not_reorder_observation_past_submit(self) -> None:
+ fill_index = _MAX_SCOUTED_INTERACTIONS - 1
+ trajectory: list[dict[str, object]] = [
+ {
+ "tool_name": "click",
+ "selector": f"#step-{index}",
+ "source_url": "https://portal.example.test/browse",
+ "trajectory_index": index,
+ }
+ for index in range(fill_index)
+ ]
+ trajectory.append({**self._username_fill(), "trajectory_index": fill_index})
+ ctx = self._ctx_with_inventory([], inventory={"cred_1": frozenset({"username", "password"})})
+ ctx.scout_trajectory = trajectory
+ _record_scout_page_observation(ctx, {"forms": [{"fields": [{"selector": "#user", "type": "text"}]}]})
+ trajectory = list(trajectory)
+ trajectory.append({**self._submit(self._LOGIN_URL, "Continue"), "trajectory_index": fill_index + 1})
+ ctx.scout_trajectory = _capped_with_eviction_accounting(trajectory, collection="scout_trajectory")
+ assert len(ctx.scout_trajectory) == _MAX_SCOUTED_INTERACTIONS
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+
+ def test_password_only_reauth_completes(self) -> None:
+ ctx = self._ctx_with_inventory(
+ [self._password_fill(), self._submit(self._PASSWORD_URL, "Sign in")],
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is True
+
+ def test_username_only_credential_without_password_completes(self) -> None:
+ ctx = self._ctx_with_inventory(
+ self._two_screen_first_page(),
+ inventory={"cred_1": frozenset({"username"})},
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is True
+
+ def test_legacy_session_without_inventory_degrades_to_filled_fields(self) -> None:
+ ctx = self._ctx_with_inventory(self._two_screen_first_page(), inventory={})
+ assert synthesized_trajectory_is_goal_complete(ctx) is True
+
+ def test_totp_only_continuation_falls_through_to_shape_heuristic(self) -> None:
+ trajectory = [
+ {
+ "tool_name": "fill_credential_field",
+ "credential_id": "cred_1",
+ "credential_field": "totp",
+ "selector": "#totp",
+ "source_url": self._PASSWORD_URL,
+ },
+ self._submit(self._PASSWORD_URL, "Verify"),
+ ]
+ ctx = self._ctx_with_inventory(trajectory, inventory={"cred_1": frozenset({"username", "password"})})
+ assert synthesized_trajectory_is_goal_complete(ctx) is True
+
+ def test_filled_password_without_post_fill_submit_is_incomplete(self) -> None:
+ ctx = self._ctx_with_inventory(
+ [self._username_fill(), self._submit(self._LOGIN_URL, "Continue"), self._password_fill()],
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+
+ def test_mixed_credentials_incomplete_until_both_flows_finish(self) -> None:
+ second_fill = {
+ "tool_name": "fill_credential_field",
+ "credential_id": "cred_2",
+ "credential_field": "username",
+ "selector": "#user2",
+ "source_url": self._PASSWORD_URL,
+ }
+ trajectory = [*self._two_screen_full_login(), second_fill, self._submit(self._PASSWORD_URL, "Next")]
+ ctx = self._ctx_with_inventory(
+ trajectory,
+ inventory={
+ "cred_1": frozenset({"username", "password"}),
+ "cred_2": frozenset({"username", "password"}),
+ },
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+
+ def test_download_target_does_not_bypass_credential_flow(self) -> None:
+ ctx = self._ctx_with_inventory(
+ self._two_screen_first_page(),
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ ctx.reached_download_target = ReachedDownloadTarget(
+ selector="a.report",
+ affordance_text="Report",
+ download_kind="extension",
+ source_step="trajectory_recency",
+ already_registered=False,
+ )
+ assert synthesized_trajectory_is_goal_complete(ctx) is False
+
+ def test_mutating_tools_admitted_while_credential_flow_incomplete(self) -> None:
+ ctx = self._ctx_with_inventory(
+ self._two_screen_first_page(),
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ assert _should_block_mutating_tool_after_synthesized_offer(ctx, "click") is False
+ assert synthesized_block_persistence_signal(ctx, "click") is None
+ assert synthesized_block_persistence_signal(ctx, "type_text") is None
+
+ def test_mutating_tools_blocked_again_once_flow_completes(self) -> None:
+ ctx = self._ctx_with_inventory(
+ self._two_screen_full_login(),
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+ assert _should_block_mutating_tool_after_synthesized_offer(ctx, "click") is True
+ assert synthesized_block_persistence_signal(ctx, "click") is not None
+
+
+class TestCredentialScoutReopen:
+ def _offered_complete_ctx(self) -> _Ctx:
+ helper = TestCredentialFlowGoalComplete()
+ return helper._ctx_with_inventory(
+ helper._two_screen_full_login(),
+ inventory={"cred_1": frozenset({"username", "password"})},
+ )
+
+ def test_arm_is_one_shot_per_identity_digest(self) -> None:
+ ctx = make_copilot_context()
+ assert arm_credential_scout_reopen(ctx, "identity-1") is True
+ assert ctx.synthesized_block_reopened_for_credential_scout is True
+ assert synthesized_persistence_reopened(ctx) is True
+
+ ctx.synthesized_block_reopened_for_credential_scout = False
+ assert arm_credential_scout_reopen(ctx, "identity-1") is False
+ assert ctx.synthesized_block_reopened_for_credential_scout is False
+ assert synthesized_persistence_reopened(ctx) is False
+
+ assert arm_credential_scout_reopen(ctx, "identity-2") is True
+ assert ctx.synthesized_block_reopened_for_credential_scout is True
+
+ def test_reopen_admits_evaluate_while_offer_is_goal_complete(self) -> None:
+ ctx = self._offered_complete_ctx()
+ assert synthesized_block_persistence_signal(ctx, "evaluate") is not None
+ ctx.synthesized_block_reopened_for_credential_scout = True
+ assert synthesized_block_persistence_signal(ctx, "evaluate") is None
+
+ def test_reopen_reopens_offer_refresh_window(self) -> None:
+ ctx = self._offered_complete_ctx()
+ ctx.update_workflow_called = True
+ assert _should_force_synthesized_block_persistence(ctx) is False
+ ctx.synthesized_block_reopened_for_credential_scout = True
+ assert _should_force_synthesized_block_persistence(ctx) is True
diff --git a/tests/unit/test_copilot_fill_credential_field.py b/tests/unit/test_copilot_fill_credential_field.py
index e148292c9..49acf9dd7 100644
--- a/tests/unit/test_copilot_fill_credential_field.py
+++ b/tests/unit/test_copilot_fill_credential_field.py
@@ -55,6 +55,7 @@ def _ctx(**overrides: Any) -> SimpleNamespace:
pending_browser_interaction_observation=None,
discovery_mcp_server=None,
secret_scrub_values=[],
+ scouted_credential_field_inventory_by_credential_id={},
)
for key, value in overrides.items():
setattr(ns, key, value)
@@ -134,6 +135,33 @@ class TestResolveCredentialFillValue:
value, _, error = await tools_module._resolve_credential_fill_value(_ctx(), "cred_123", "password")
assert (value, error) == (_FAKE_PASSWORD, None)
+ @pytest.mark.asyncio
+ async def test_resolve_records_live_scout_field_inventory(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ self._wire_vault(monkeypatch, PasswordCredential(username=_FAKE_USERNAME, password=_FAKE_PASSWORD, totp=None))
+ ctx = _ctx()
+ _, _, error = await tools_module._resolve_credential_fill_value(ctx, "cred_123", "username")
+ assert error is None
+ assert ctx.scouted_credential_field_inventory_by_credential_id == {
+ "cred_123": frozenset({"username", "password"})
+ }
+
+ @pytest.mark.asyncio
+ async def test_resolve_inventory_excludes_empty_password(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ self._wire_vault(monkeypatch, PasswordCredential(username=_FAKE_USERNAME, password="", totp=None))
+ ctx = _ctx()
+ _, _, error = await tools_module._resolve_credential_fill_value(ctx, "cred_123", "username")
+ assert error is None
+ assert ctx.scouted_credential_field_inventory_by_credential_id == {"cred_123": frozenset({"username"})}
+
+ @pytest.mark.asyncio
+ async def test_resolve_error_records_no_inventory(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ self._wire_vault(monkeypatch, PasswordCredential(username=_FAKE_USERNAME, password="", totp=None))
+ ctx = _ctx()
+ value, _, error = await tools_module._resolve_credential_fill_value(ctx, "cred_123", "password")
+ assert value is None
+ assert error is not None
+ assert ctx.scouted_credential_field_inventory_by_credential_id == {}
+
@pytest.mark.asyncio
async def test_totp_mints_fresh_code_not_the_seed(self, monkeypatch: pytest.MonkeyPatch) -> None:
self._wire_vault(
diff --git a/tests/unit/test_copilot_scout_act_observe.py b/tests/unit/test_copilot_scout_act_observe.py
index 6f063d4d3..0a4f3ff24 100644
--- a/tests/unit/test_copilot_scout_act_observe.py
+++ b/tests/unit/test_copilot_scout_act_observe.py
@@ -20,7 +20,11 @@ from skyvern.forge.sdk.copilot.composition_evidence import (
_auto_credit_interaction_observation,
has_bounded_page_schema,
)
-from skyvern.forge.sdk.copilot.context import FillCarry
+from skyvern.forge.sdk.copilot.context import (
+ FillCarry,
+ StructuredContext,
+ finalize_discovery_counter_in_global_llm_context,
+)
from skyvern.forge.sdk.copilot.enforcement import (
_RECENT_TOOL_OUTPUT_CHAR_CAP,
MAX_NO_PROGRESS_INTERACTION_ATTEMPTS,
@@ -1224,3 +1228,142 @@ class TestClickReperceptionHardening:
assert ctx.last_scout_act_observe_outcome == "attached"
assert ctx.consecutive_no_progress_interaction_count == 0
+
+
+class TestCredentialInventoryCarry:
+ @staticmethod
+ def _credential_carry(available_fields: list[str] | None) -> dict[str, Any]:
+ return FillCarry(
+ source_url=_LANDING_URL,
+ selector="#password",
+ tool_name="fill_credential_field",
+ credential_id="cred_123",
+ credential_field="username",
+ available_fields=available_fields,
+ ).model_dump()
+
+ @pytest.mark.asyncio
+ async def test_rebind_rehydrates_inventory_alongside_carried_fills(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(scouting_module, "_selector_live_match_count", _selector_count_one)
+ ctx = _ctx()
+ ctx.scouted_credential_field_inventory_by_credential_id = {}
+ ctx.prior_fill_carry = [self._credential_carry(["password", "username"])]
+ evidence = {
+ "current_url": _LANDING_URL,
+ "forms": [{"fields": [{"selector": "#password", "label": "Password"}]}],
+ }
+
+ await _maybe_rebind_prior_fill_carry(ctx, page_evidence=evidence, url=_LANDING_URL)
+
+ assert ctx.scouted_credential_field_inventory_by_credential_id == {
+ "cred_123": frozenset({"username", "password"})
+ }
+ assert ctx.scout_trajectory[-1]["credential_id"] == "cred_123"
+
+ @pytest.mark.asyncio
+ async def test_page_mismatch_drops_carry_but_keeps_inventory(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(scouting_module, "_selector_live_match_count", _selector_count_one)
+ ctx = _ctx()
+ ctx.scouted_credential_field_inventory_by_credential_id = {}
+ ctx.prior_fill_carry = [self._credential_carry(["password", "username"])]
+ mismatched = {"current_url": "https://example.com/elsewhere", "forms": [{"fields": []}]}
+
+ await _maybe_rebind_prior_fill_carry(ctx, page_evidence=mismatched, url="https://example.com/elsewhere")
+
+ assert ctx.scout_trajectory == []
+ assert ctx.scouted_credential_field_inventory_by_credential_id == {
+ "cred_123": frozenset({"username", "password"})
+ }
+
+ @pytest.mark.asyncio
+ async def test_legacy_carry_without_available_fields_rehydrates_nothing(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ monkeypatch.setattr(scouting_module, "_selector_live_match_count", _selector_count_one)
+ ctx = _ctx()
+ ctx.scouted_credential_field_inventory_by_credential_id = {}
+ ctx.prior_fill_carry = [self._credential_carry(None)]
+ evidence = {
+ "current_url": _LANDING_URL,
+ "forms": [{"fields": [{"selector": "#password", "label": "Password"}]}],
+ }
+
+ await _maybe_rebind_prior_fill_carry(ctx, page_evidence=evidence, url=_LANDING_URL)
+
+ assert ctx.scouted_credential_field_inventory_by_credential_id == {}
+ assert ctx.scout_trajectory[-1]["credential_id"] == "cred_123"
+
+ @pytest.mark.asyncio
+ async def test_inventory_round_trips_through_structured_context_and_agent_hydration(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ first_turn = SimpleNamespace(
+ prior_discovery_calls_made=0,
+ discovery_calls_this_turn=0,
+ prior_page_inspection_calls_made=0,
+ page_inspection_calls_this_turn=0,
+ flow_evidence=[],
+ latest_evaluate_result_composition_steer=None,
+ scout_trajectory=[
+ {
+ "tool_name": "fill_credential_field",
+ "selector": "#password",
+ "source_url": _LANDING_URL,
+ "typed_length": 10,
+ "credential_id": "cred_123",
+ "credential_field": "username",
+ }
+ ],
+ scouted_credential_field_inventory_by_credential_id={"cred_123": frozenset({"username", "password"})},
+ )
+ raw = finalize_discovery_counter_in_global_llm_context(first_turn, None)
+ assert raw is not None
+
+ monkeypatch.setattr(scouting_module, "_selector_live_match_count", _selector_count_one)
+ next_turn = _ctx()
+ next_turn.scouted_credential_field_inventory_by_credential_id = {}
+ next_turn.prior_fill_carry = [carry.model_dump() for carry in StructuredContext.from_json_str(raw).fill_carry]
+ evidence = {
+ "current_url": _LANDING_URL,
+ "forms": [{"fields": [{"selector": "#password", "label": "Password"}]}],
+ }
+
+ await _maybe_rebind_prior_fill_carry(next_turn, page_evidence=evidence, url=_LANDING_URL)
+
+ assert next_turn.scouted_credential_field_inventory_by_credential_id == {
+ "cred_123": frozenset({"username", "password"})
+ }
+ assert next_turn.scout_trajectory[-1]["credential_field"] == "username"
+
+
+class TestScoutPageObservationSignal:
+ def test_password_control_detected_in_forms(self) -> None:
+ evidence = {
+ "forms": [{"fields": [{"selector": "#user", "type": "text"}, {"selector": "#pass", "type": "password"}]}]
+ }
+ assert scouting_module._page_evidence_has_password_control(evidence) is True
+
+ def test_no_password_control_in_forms(self) -> None:
+ evidence = {"forms": [{"fields": [{"selector": "#user", "type": "text"}]}]}
+ assert scouting_module._page_evidence_has_password_control(evidence) is False
+ assert scouting_module._page_evidence_has_password_control({}) is False
+
+ def test_record_scout_page_observation_captures_stable_index_and_signal(self) -> None:
+ ctx = _ctx()
+ ctx.scout_trajectory = [
+ {"tool_name": "click", "selector": "#go", "source_url": _LANDING_URL, "trajectory_index": 4},
+ "scout-note",
+ ]
+ ctx.last_scout_observation_trajectory_index = None
+ ctx.last_scout_observation_has_password_control = False
+
+ scouting_module._record_scout_page_observation(
+ ctx, {"forms": [{"fields": [{"selector": "#pass", "type": "password"}]}]}
+ )
+
+ assert ctx.last_scout_observation_trajectory_index == 4
+ assert ctx.last_scout_observation_has_password_control is True
+
+ scouting_module._record_scout_page_observation(ctx, {"forms": [{"fields": [{"selector": "#name"}]}]})
+
+ assert ctx.last_scout_observation_has_password_control is False
diff --git a/tests/unit/test_evaluate_actionable_target.py b/tests/unit/test_evaluate_actionable_target.py
index 1069b77d7..c10805bfe 100644
--- a/tests/unit/test_evaluate_actionable_target.py
+++ b/tests/unit/test_evaluate_actionable_target.py
@@ -107,7 +107,9 @@ def _single_max_structural_loaded_result_packet() -> dict:
def _ctx() -> AgentContext:
- return AgentContext.__new__(AgentContext)
+ ctx = AgentContext.__new__(AgentContext)
+ ctx.scout_trajectory = []
+ return ctx
@pytest.mark.asyncio