Skip to content

Automate browser based workflows with AI

[SKY-12553] Add per-gate Copilot author-time log-only registry (#7503)

Andrew Neilson19fe76108da4
diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py
index df2df3898..9c3d02ea8 100644
--- a/skyvern/forge/agent_functions.py
+++ b/skyvern/forge/agent_functions.py
@@ -803,6 +803,14 @@ class AgentFunction:
) -> bool:
return request_override if request_override is not None else settings.MCP_CODE_ONLY_MODE
+ async def resolve_copilot_author_time_gate_log_only_ids(
+ self,
+ *,
+ turn_id: str,
+ organization_id: str,
+ ) -> frozenset[str]:
+ return frozenset()
+
async def should_use_codeblock_runner(
self,
*,
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.py
index 719d70405..2290104a2 100644
--- a/skyvern/forge/sdk/copilot/agent.py
+++ b/skyvern/forge/sdk/copilot/agent.py
@@ -163,7 +163,10 @@ from skyvern.forge.sdk.copilot.request_policy import (
redact_raw_secrets_for_prompt,
)
from skyvern.forge.sdk.copilot.run_outcome import RecordedRunOutcome, run_outcome_display_reason
-from skyvern.forge.sdk.copilot.runtime import _browser_context_is_attachable
+from skyvern.forge.sdk.copilot.runtime import (
+ _browser_context_is_attachable,
+ cache_copilot_author_time_gate_log_only_ids,
+)
from skyvern.forge.sdk.copilot.streaming_adapter import (
emit_turn_start,
emit_workflow_draft,
@@ -4499,6 +4502,29 @@ def _reconcile_turn_end_ownership(
return result
+async def _cache_copilot_author_time_gate_log_only_ids(ctx: CopilotContext) -> None:
+ try:
+ resolved_ids = await app.AGENT_FUNCTION.resolve_copilot_author_time_gate_log_only_ids(
+ turn_id=ctx.turn_id,
+ organization_id=ctx.organization_id,
+ )
+ except Exception:
+ LOG.warning(
+ "Failed to resolve Copilot author-time gate log-only registry",
+ turn_id=ctx.turn_id,
+ organization_id=ctx.organization_id,
+ exc_info=True,
+ )
+ resolved_ids = frozenset()
+ cache_copilot_author_time_gate_log_only_ids(ctx, resolved_ids)
+ selected_gate_ids = sorted(ctx.author_time_gate_log_only_ids)
+ LOG.info(
+ "copilot_author_time_gate_log_only_registry_resolved",
+ selected_gate_ids=selected_gate_ids,
+ selected_gate_count=len(selected_gate_ids),
+ )
+
+
async def run_copilot_agent(
stream: EventSourceStream,
organization_id: str,
@@ -4716,6 +4742,7 @@ async def _run_copilot_turn_impl(
raise RuntimeError(
f"CopilotContext.turn_id ({ctx.turn_id!r}) diverged from route-supplied turn_id ({turn_id!r})"
)
+ await _cache_copilot_author_time_gate_log_only_ids(ctx)
if ctx_sink is not None:
ctx_sink.append(ctx)
policy_inputs = RequestPolicyGuardrailInputs(
diff --git a/skyvern/forge/sdk/copilot/runtime.py b/skyvern/forge/sdk/copilot/runtime.py
index e84b382ec..07efbd1f7 100644
--- a/skyvern/forge/sdk/copilot/runtime.py
+++ b/skyvern/forge/sdk/copilot/runtime.py
@@ -74,6 +74,24 @@ _SESSION_CLEANUP_TIMEOUT_SECONDS = 5.0
_BROWSER_BOOT_WAIT_SECONDS = 30.0
_BROWSER_BOOT_POLL_INTERVAL_SECONDS = 0.25
_FINAL_BROWSER_SESSION_STATUSES: frozenset[str] = frozenset({"completed", "failed", "timeout"})
+DEFINITION_CONTRACT_UNSATISFIED_GATE_ID = "definition_contract_unsatisfied"
+RECORDED_OUTCOME_GROUNDING_BINDER_CEILING_GATE_ID = "recorded_outcome_grounding_binder_ceiling"
+SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID = "synthesized_parameter_binding_ambiguous"
+_POSTHOG_AUTHOR_TIME_GATE_LOG_ONLY_IDS = frozenset(
+ {
+ DEFINITION_CONTRACT_UNSATISFIED_GATE_ID,
+ RECORDED_OUTCOME_GROUNDING_BINDER_CEILING_GATE_ID,
+ SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID,
+ }
+)
+_LOCAL_AUTHOR_TIME_GATE_LOG_ONLY_IDS = frozenset(
+ {
+ "output_contract_actuation",
+ "metadata_run_preflight_reject",
+ "uncovered_output_rescout_steer",
+ "recorded_outcome_grounding",
+ }
+)
CodeArtifactMetadataValue: TypeAlias = (
str | int | float | bool | None | list["CodeArtifactMetadataValue"] | dict[str, "CodeArtifactMetadataValue"]
)
@@ -535,6 +553,7 @@ class AgentContext:
# extraction_schema declares fields that map to no output the block produces.
# Surfaced into the persisted TurnOutcome so a later turn can report it.
latest_schema_incompatibility: SchemaIncompatibility | None = None
+ author_time_gate_log_only_ids: frozenset[str] = frozenset()
author_time_gate_ablation_events: list[AuthorTimeGateAblationEvent] = field(default_factory=list)
# Single-owner turn-precedence contract. One mechanism owns a turn's steering
# at a time; a contradicting weaker claim is recorded here and yields.
@@ -545,8 +564,20 @@ class AgentContext:
blocker_signal_claimant: TurnClaimant | None = None
-def copilot_author_time_gate_log_only_enabled() -> bool:
- return not settings.is_cloud_environment() and settings.WORKFLOW_COPILOT_AUTHOR_TIME_GATE_LOG_ONLY
+def cache_copilot_author_time_gate_log_only_ids(ctx: AgentContext, resolved_ids: frozenset[str]) -> None:
+ ineligible_ids = resolved_ids - _POSTHOG_AUTHOR_TIME_GATE_LOG_ONLY_IDS
+ for gate_id in sorted(ineligible_ids):
+ LOG.info("copilot_gate_log_only_ineligible", gate_id=gate_id)
+ ctx.author_time_gate_log_only_ids = resolved_ids & _POSTHOG_AUTHOR_TIME_GATE_LOG_ONLY_IDS
+
+
+def copilot_author_time_gate_log_only_enabled(ctx: AgentContext, gate_id: str) -> bool:
+ local_blanket_enabled = (
+ not settings.is_cloud_environment()
+ and settings.WORKFLOW_COPILOT_AUTHOR_TIME_GATE_LOG_ONLY
+ and gate_id in _LOCAL_AUTHOR_TIME_GATE_LOG_ONLY_IDS
+ )
+ return local_blanket_enabled or gate_id in ctx.author_time_gate_log_only_ids
def record_author_time_gate_ablation_event(
@@ -558,7 +589,7 @@ def record_author_time_gate_ablation_event(
blocked_tool: str | None = None,
payload: AuthorTimeGateAblationPayload | None = None,
) -> bool:
- if not copilot_author_time_gate_log_only_enabled():
+ if not copilot_author_time_gate_log_only_enabled(ctx, gate_id):
return False
event = AuthorTimeGateAblationEvent(
gate_id=gate_id,
diff --git a/skyvern/forge/sdk/copilot/tools/workflow_update.py b/skyvern/forge/sdk/copilot/tools/workflow_update.py
index c9bed6061..056b66415 100644
--- a/skyvern/forge/sdk/copilot/tools/workflow_update.py
+++ b/skyvern/forge/sdk/copilot/tools/workflow_update.py
@@ -168,6 +168,9 @@ from skyvern.forge.sdk.copilot.request_policy import (
)
from skyvern.forge.sdk.copilot.result_evidence import loaded_result_source_producible
from skyvern.forge.sdk.copilot.runtime import (
+ DEFINITION_CONTRACT_UNSATISFIED_GATE_ID,
+ RECORDED_OUTCOME_GROUNDING_BINDER_CEILING_GATE_ID,
+ SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID,
AgentContext,
AuthorTimeGateAblationPayload,
ScoutedFieldParameterBinding,
@@ -2155,6 +2158,31 @@ def _record_definition_plane_reject(
)
+def _record_definition_plane_ablation_event(
+ ctx: AgentContext,
+ workflow_yaml: str,
+ rejection: _DefinitionPlaneReject,
+ *,
+ code_artifact_metadata: object = None,
+) -> bool:
+ fingerprint = authored_structure_signature_from_workflow(workflow_yaml, code_artifact_metadata)
+ if fingerprint is None:
+ return False
+ payload: AuthorTimeGateAblationPayload = {
+ "criterion_ids": list(rejection.criterion_ids),
+ "definition_reason_codes": list(rejection.reason_codes),
+ "unreferenced_parameter_keys": list(rejection.unreferenced_parameter_keys),
+ }
+ return record_author_time_gate_ablation_event(
+ ctx,
+ gate_id=DEFINITION_CONTRACT_UNSATISFIED_GATE_ID,
+ reason_code="definition_contract_unsatisfied",
+ fingerprint=fingerprint,
+ blocked_tool="update_workflow",
+ payload=payload,
+ )
+
+
def _stash_unresolved_recorded_outcome_grounding_halt(
ctx: AgentContext,
unresolved_parameter_keys: Iterable[str],
@@ -2176,6 +2204,22 @@ def _stash_unresolved_recorded_outcome_grounding_halt(
keys = sorted(set(unresolved_parameter_keys))
if not keys:
return False
+ payload: AuthorTimeGateAblationPayload = {
+ "phase": requirement.phase,
+ "outcome_reason_code": requirement.reason_code,
+ "workflow_run_id": requirement.workflow_run_id,
+ "block_labels": list(requirement.block_labels),
+ "unresolved_parameter_keys": keys,
+ }
+ if record_author_time_gate_ablation_event(
+ ctx,
+ gate_id=RECORDED_OUTCOME_GROUNDING_BINDER_CEILING_GATE_ID,
+ reason_code="definition_contract_unsatisfied",
+ fingerprint=requirement.structural_key,
+ blocked_tool="update_workflow",
+ payload=payload,
+ ):
+ return False
signal = build_definition_contract_unsatisfied_blocker_signal(
unresolved_parameter_keys=keys,
grounding_unresolved=True,
@@ -4604,7 +4648,10 @@ def _stash_output_source_unobservable_terminal(
"canonical_required_child_paths": sorted(required_paths),
"spine_split_blockers": list(blockers),
}
- if copilot_author_time_gate_log_only_enabled() and ctx.output_contract_bail_actuated_this_call:
+ if (
+ copilot_author_time_gate_log_only_enabled(ctx, _OUTPUT_CONTRACT_ABLATION_GATE_ID)
+ and ctx.output_contract_bail_actuated_this_call
+ ):
return
if record_author_time_gate_ablation_event(
ctx,
@@ -5170,7 +5217,7 @@ def _impose_output_contract_envelope_after_steering(
return workflow_yaml, raw_code_artifact_metadata, declaration_stamped
if actuation.kind == OutputContractActuationKind.ADVISORY_RUN:
return workflow_yaml, raw_code_artifact_metadata, declaration_stamped
- if copilot_author_time_gate_log_only_enabled():
+ if copilot_author_time_gate_log_only_enabled(ctx, _OUTPUT_CONTRACT_ABLATION_GATE_ID):
return workflow_yaml, raw_code_artifact_metadata, declaration_stamped
attempt_key = _output_contract_spine_directive_attempt_key(
signature=signature, block_label=label, workflow_yaml=workflow_yaml
@@ -5338,24 +5385,41 @@ def _metadata_contract_run_preflight_reject(
ctx,
definition_reject.unreferenced_parameter_keys,
)
- if not halted:
+ if halted:
+ return {
+ "ok": False,
+ "error": _definition_plane_reject_error(definition_reject),
+ "user_facing_summary": _compiled_authoring_user_summary(),
+ "data": {
+ "reason_code": "definition_contract_unsatisfied",
+ "definition_criterion_ids": list(definition_reject.criterion_ids),
+ "definition_reason_codes": list(definition_reject.reason_codes),
+ "unreferenced_parameter_keys": list(definition_reject.unreferenced_parameter_keys),
+ },
+ }
+ if not _record_definition_plane_ablation_event(
+ ctx,
+ workflow_yaml,
+ definition_reject,
+ code_artifact_metadata=raw_code_artifact_metadata,
+ ):
_record_definition_plane_reject(
ctx,
workflow_yaml,
definition_reject,
code_artifact_metadata=raw_code_artifact_metadata,
)
- return {
- "ok": False,
- "error": _definition_plane_reject_error(definition_reject),
- "user_facing_summary": _compiled_authoring_user_summary(),
- "data": {
- "reason_code": "definition_contract_unsatisfied",
- "definition_criterion_ids": list(definition_reject.criterion_ids),
- "definition_reason_codes": list(definition_reject.reason_codes),
- "unreferenced_parameter_keys": list(definition_reject.unreferenced_parameter_keys),
- },
- }
+ return {
+ "ok": False,
+ "error": _definition_plane_reject_error(definition_reject),
+ "user_facing_summary": _compiled_authoring_user_summary(),
+ "data": {
+ "reason_code": "definition_contract_unsatisfied",
+ "definition_criterion_ids": list(definition_reject.criterion_ids),
+ "definition_reason_codes": list(definition_reject.reason_codes),
+ "unreferenced_parameter_keys": list(definition_reject.unreferenced_parameter_keys),
+ },
+ }
convergence_reject = _recorded_outcome_convergence_reject(
ctx,
workflow_yaml=workflow_yaml,
@@ -6592,6 +6656,7 @@ class _SynthesizedCodeImpositionResult:
selected_extraction_metadata_disposition: SelectedExtractionMetadataDisposition = "none"
minted_parameter_keys: list[str] = dataclass_field(default_factory=list)
metadata_repair_contract: dict[str, object] | None = None
+ ablation_gate_id: str | None = None
_SUBMITTED_LITERAL_METHODS = frozenset({"fill", "type"})
@@ -9103,6 +9168,31 @@ def _apply_parameter_reconciliation_to_code(code: str, reconciliation: _Synthesi
_SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_REASON_CODE = "synthesized_parameter_binding_ambiguous"
+def _record_synthesized_parameter_binding_ablation_event(
+ ctx: AgentContext,
+ workflow_yaml: str,
+ repair_context: CodeAuthoringRepairContext,
+) -> bool:
+ fingerprint = authored_structure_signature_from_workflow(workflow_yaml, ctx.raw_code_artifact_metadata)
+ if fingerprint is None:
+ return False
+ payload: AuthorTimeGateAblationPayload = {
+ "block_label": repair_context.block_label,
+ "unresolved_names": list(repair_context.unresolved_names),
+ "parameter_keys": list(repair_context.parameter_keys),
+ "available_parameter_keys": list(repair_context.available_parameter_keys),
+ "binding_candidates": list(repair_context.binding_candidates),
+ }
+ return record_author_time_gate_ablation_event(
+ ctx,
+ gate_id=SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID,
+ reason_code=_SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_REASON_CODE,
+ fingerprint=fingerprint,
+ blocked_tool="update_workflow",
+ payload=payload,
+ )
+
+
def _synthesized_parameter_binding_repair_context(
*,
parsed: Mapping[str, Any],
@@ -9760,6 +9850,7 @@ def _maybe_impose_synthesized_code_block(
synthesized_parameters=synthesized.parameters,
scout_trajectory=scout_trajectory,
)
+ parameter_binding_is_only_violation = not violations and bool(parameter_reconciliation.violations)
violations.extend(parameter_reconciliation.violations)
if repair_context is None:
repair_context = parameter_reconciliation.repair_context
@@ -9776,6 +9867,13 @@ def _maybe_impose_synthesized_code_block(
violations=violations,
repair_context=repair_context,
metadata_repair_contract=_co_computed_metadata_repair_contract(ctx, workflow_yaml, raw_metadata),
+ ablation_gate_id=(
+ SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID
+ if parameter_binding_is_only_violation
+ and repair_context is not None
+ and repair_context.reason_code == _SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_REASON_CODE
+ else None
+ ),
)
metadata_declares_goal_values = bool(raw_metadata) and _raw_metadata_declares_goal_values_for_block(
@@ -11090,37 +11188,48 @@ async def _update_workflow(
ctx.synthesized_block_reopened_for_credential_scout = False
if imposition.violations:
if (
- imposition.repair_context is not None
- and imposition.repair_context.reason_code == _SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_REASON_CODE
- ):
- required_paths = _output_contract_required_paths_source(ctx).union
- _record_output_contract_family_reject(
+ imposition.ablation_gate_id == SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID
+ and imposition.repair_context is not None
+ and _record_synthesized_parameter_binding_ablation_event(
ctx,
- required_paths,
- reject_family=_SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_REASON_CODE,
+ workflow_yaml,
+ imposition.repair_context,
)
- if (
- imposition.repair_context is not None
- and imposition.repair_context.reason_code in _SCOUTED_SPINE_REASON_CODES
):
- _set_code_authoring_repair_context(ctx, imposition.repair_context)
- _record_code_authoring_guardrail_reject(ctx)
+ imposition = _SynthesizedCodeImpositionResult(workflow_yaml=workflow_yaml)
+ else:
+ if (
+ imposition.repair_context is not None
+ and imposition.repair_context.reason_code == _SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_REASON_CODE
+ ):
+ required_paths = _output_contract_required_paths_source(ctx).union
+ _record_output_contract_family_reject(
+ ctx,
+ required_paths,
+ reject_family=_SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_REASON_CODE,
+ )
+ if (
+ imposition.repair_context is not None
+ and imposition.repair_context.reason_code in _SCOUTED_SPINE_REASON_CODES
+ ):
+ _set_code_authoring_repair_context(ctx, imposition.repair_context)
+ _record_code_authoring_guardrail_reject(ctx)
+ return reject(
+ error="\n".join(imposition.violations),
+ user_facing_summary=_compiled_authoring_user_summary(),
+ data=_code_repair_progress_data(imposition.repair_context),
+ repair_context=imposition.repair_context,
+ record_repair_context_outcome=False,
+ )
return reject(
error="\n".join(imposition.violations),
user_facing_summary=_compiled_authoring_user_summary(),
- data=_code_repair_progress_data(imposition.repair_context),
+ data=_code_repair_progress_data(
+ imposition.repair_context,
+ metadata_repair_contract=imposition.metadata_repair_contract,
+ ),
repair_context=imposition.repair_context,
- record_repair_context_outcome=False,
)
- return reject(
- error="\n".join(imposition.violations),
- user_facing_summary=_compiled_authoring_user_summary(),
- data=_code_repair_progress_data(
- imposition.repair_context,
- metadata_repair_contract=imposition.metadata_repair_contract,
- ),
- repair_context=imposition.repair_context,
- )
workflow_yaml = imposition.workflow_yaml
if imposition.substitutions is None:
seam_under_build = _persist_seam_spine_under_build_result(workflow_yaml, ctx)
@@ -11179,23 +11288,39 @@ async def _update_workflow(
ctx,
definition_reject.unreferenced_parameter_keys,
)
- if not halted:
+ if halted:
+ return reject(
+ error=_definition_plane_reject_error(definition_reject),
+ user_facing_summary=_compiled_authoring_user_summary(),
+ data={
+ "reason_code": "definition_contract_unsatisfied",
+ "definition_criterion_ids": list(definition_reject.criterion_ids),
+ "definition_reason_codes": list(definition_reject.reason_codes),
+ "unreferenced_parameter_keys": list(definition_reject.unreferenced_parameter_keys),
+ },
+ )
+ if not _record_definition_plane_ablation_event(
+ ctx,
+ workflow_yaml,
+ definition_reject,
+ code_artifact_metadata=ctx.raw_code_artifact_metadata,
+ ):
_record_definition_plane_reject(
ctx,
workflow_yaml,
definition_reject,
code_artifact_metadata=ctx.raw_code_artifact_metadata,
)
- return reject(
- error=_definition_plane_reject_error(definition_reject),
- user_facing_summary=_compiled_authoring_user_summary(),
- data={
- "reason_code": "definition_contract_unsatisfied",
- "definition_criterion_ids": list(definition_reject.criterion_ids),
- "definition_reason_codes": list(definition_reject.reason_codes),
- "unreferenced_parameter_keys": list(definition_reject.unreferenced_parameter_keys),
- },
- )
+ return reject(
+ error=_definition_plane_reject_error(definition_reject),
+ user_facing_summary=_compiled_authoring_user_summary(),
+ data={
+ "reason_code": "definition_contract_unsatisfied",
+ "definition_criterion_ids": list(definition_reject.criterion_ids),
+ "definition_reason_codes": list(definition_reject.reason_codes),
+ "unreferenced_parameter_keys": list(definition_reject.unreferenced_parameter_keys),
+ },
+ )
params["workflow_yaml"] = workflow_yaml
metadata_scrubbed_by_imposition = False
if (
diff --git a/tests/unit/test_copilot_author_time_gate_log_only.py b/tests/unit/test_copilot_author_time_gate_log_only.py
new file mode 100644
index 000000000..890e71354
--- /dev/null
+++ b/tests/unit/test_copilot_author_time_gate_log_only.py
@@ -0,0 +1,329 @@
+from __future__ import annotations
+
+from types import SimpleNamespace
+from unittest.mock import AsyncMock
+
+import pytest
+from structlog.testing import capture_logs
+
+from skyvern.config import settings
+from skyvern.forge.sdk.copilot import agent
+from skyvern.forge.sdk.copilot.build_test_outcome import (
+ RecordedBuildTestOutcome,
+ RecordedOutcomeBindingConstraint,
+ RecordedOutcomeGroundingRequirement,
+)
+from skyvern.forge.sdk.copilot.config import BlockAuthoringPolicy
+from skyvern.forge.sdk.copilot.context import CodeAuthoringRepairContext, CopilotContext
+from skyvern.forge.sdk.copilot.request_policy import CompletionCriterion, RequestPolicy
+from skyvern.forge.sdk.copilot.runtime import (
+ DEFINITION_CONTRACT_UNSATISFIED_GATE_ID,
+ RECORDED_OUTCOME_GROUNDING_BINDER_CEILING_GATE_ID,
+ SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID,
+ cache_copilot_author_time_gate_log_only_ids,
+ copilot_author_time_gate_log_only_enabled,
+ record_author_time_gate_ablation_event,
+)
+from skyvern.forge.sdk.copilot.tools import workflow_update as wu
+from tests.unit.copilot_test_helpers import make_copilot_ctx
+
+_UNREFERENCED_DEFINITION_YAML = """\
+title: Submit reusable request
+workflow_definition:
+ parameters:
+ - {parameter_type: workflow, key: account_name, workflow_parameter_type: string}
+ blocks:
+ - block_type: code
+ label: submit_request
+ parameter_keys: []
+ code: |
+ await page.locator("#submit").click()
+"""
+
+
+def _definition_ctx() -> CopilotContext:
+ ctx = make_copilot_ctx()
+ ctx.block_authoring_policy = BlockAuthoringPolicy.CODE_ONLY_BROWSER
+ ctx.request_policy = RequestPolicy(
+ completion_criteria=[
+ CompletionCriterion(
+ id="definition-1",
+ outcome="The workflow uses account name as a reusable input.",
+ level="definition",
+ output_path="workflow.parameters",
+ )
+ ]
+ )
+ return ctx
+
+
+def _stub_successful_update(monkeypatch: pytest.MonkeyPatch) -> None:
+ async def fake_process_workflow_yaml(**_kwargs: object) -> SimpleNamespace:
+ return SimpleNamespace(
+ workflow_definition=SimpleNamespace(blocks=[SimpleNamespace(label="submit_request")]),
+ proxy_location=None,
+ )
+
+ async def fake_get_prior_workflow(_ctx: object) -> None:
+ return None
+
+ monkeypatch.setattr(wu, "_process_workflow_yaml", fake_process_workflow_yaml)
+ monkeypatch.setattr(wu, "_get_prior_workflow", fake_get_prior_workflow)
+ monkeypatch.setattr(wu, "composition_page_evidence_error", lambda *_args, **_kwargs: None)
+
+
[email protected](autouse=True)
+def _cloud_environment(monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(settings, "ENV", "prod")
+ monkeypatch.setattr(settings, "WORKFLOW_COPILOT_AUTHOR_TIME_GATE_LOG_ONLY", False)
+
+
+def test_oss_policy_filters_ineligible_ids_and_preserves_legacy_blanket(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ ctx = make_copilot_ctx()
+ with capture_logs() as logs:
+ cache_copilot_author_time_gate_log_only_ids(
+ ctx,
+ frozenset({DEFINITION_CONTRACT_UNSATISFIED_GATE_ID, "credential_reference_presence"}),
+ )
+
+ assert ctx.author_time_gate_log_only_ids == frozenset({DEFINITION_CONTRACT_UNSATISFIED_GATE_ID})
+ assert copilot_author_time_gate_log_only_enabled(ctx, DEFINITION_CONTRACT_UNSATISFIED_GATE_ID) is True
+ assert copilot_author_time_gate_log_only_enabled(ctx, "credential_reference_presence") is False
+ assert any(
+ log["event"] == "copilot_gate_log_only_ineligible" and log["gate_id"] == "credential_reference_presence"
+ for log in logs
+ )
+
+ monkeypatch.setattr(settings, "ENV", "local")
+ monkeypatch.setattr(settings, "WORKFLOW_COPILOT_AUTHOR_TIME_GATE_LOG_ONLY", True)
+ assert copilot_author_time_gate_log_only_enabled(ctx, "output_contract_actuation") is True
+ assert copilot_author_time_gate_log_only_enabled(ctx, DEFINITION_CONTRACT_UNSATISFIED_GATE_ID) is True
+ assert copilot_author_time_gate_log_only_enabled(ctx, "credential_reference_presence") is False
+
+
+async def test_turn_setup_resolves_once_and_gate_checks_use_cached_ids(monkeypatch: pytest.MonkeyPatch) -> None:
+ resolver = AsyncMock(return_value=frozenset({DEFINITION_CONTRACT_UNSATISFIED_GATE_ID}))
+ monkeypatch.setattr(
+ agent.app, "AGENT_FUNCTION", SimpleNamespace(resolve_copilot_author_time_gate_log_only_ids=resolver)
+ )
+ ctx = make_copilot_ctx(turn_id="turn-1")
+
+ with capture_logs() as logs:
+ await agent._cache_copilot_author_time_gate_log_only_ids(ctx)
+ for _ in range(4):
+ assert copilot_author_time_gate_log_only_enabled(ctx, DEFINITION_CONTRACT_UNSATISFIED_GATE_ID) is True
+
+ resolver.assert_awaited_once_with(turn_id="turn-1", organization_id="org-1")
+ assert [log for log in logs if log["event"] == "copilot_author_time_gate_log_only_registry_resolved"] == [
+ {
+ "event": "copilot_author_time_gate_log_only_registry_resolved",
+ "log_level": "info",
+ "selected_gate_ids": [DEFINITION_CONTRACT_UNSATISFIED_GATE_ID],
+ "selected_gate_count": 1,
+ }
+ ]
+
+
+def test_definition_gate_replay_records_one_event_per_suppression() -> None:
+ ctx = make_copilot_ctx()
+ cache_copilot_author_time_gate_log_only_ids(ctx, frozenset({DEFINITION_CONTRACT_UNSATISFIED_GATE_ID}))
+ rejection = wu._DefinitionPlaneReject(
+ criterion_ids=("criterion-1",),
+ reason_codes=("definition_parameters_unreferenced",),
+ unreferenced_parameter_keys=("account_name",),
+ )
+ workflow_yaml = _UNREFERENCED_DEFINITION_YAML
+
+ for _ in range(16):
+ assert wu._record_definition_plane_ablation_event(ctx, workflow_yaml, rejection) is True
+
+ assert len(ctx.author_time_gate_ablation_events) == 16
+ assert {event.gate_id for event in ctx.author_time_gate_ablation_events} == {
+ DEFINITION_CONTRACT_UNSATISFIED_GATE_ID
+ }
+ assert len({event.fingerprint for event in ctx.author_time_gate_ablation_events}) == 1
+
+
+async def test_selected_definition_reject_persists_without_reject_state(monkeypatch: pytest.MonkeyPatch) -> None:
+ _stub_successful_update(monkeypatch)
+ ctx = _definition_ctx()
+ cache_copilot_author_time_gate_log_only_ids(ctx, frozenset({DEFINITION_CONTRACT_UNSATISFIED_GATE_ID}))
+
+ result = await wu._update_workflow(
+ {"workflow_yaml": _UNREFERENCED_DEFINITION_YAML},
+ ctx,
+ allow_missing_credentials=True,
+ allow_static_output_uncertainty=True,
+ )
+
+ assert result["ok"] is True
+ assert ctx.latest_recorded_build_test_outcome is None
+ assert ctx.blocker_signal is None
+ assert ctx.turn_halt is None
+ assert [event.gate_id for event in ctx.author_time_gate_ablation_events] == [
+ DEFINITION_CONTRACT_UNSATISFIED_GATE_ID
+ ]
+
+
+def test_selected_definition_reject_strict_run_preflight_records_ablation_event() -> None:
+ ctx = _definition_ctx()
+ cache_copilot_author_time_gate_log_only_ids(ctx, frozenset({DEFINITION_CONTRACT_UNSATISFIED_GATE_ID}))
+
+ result = wu._metadata_contract_run_preflight_reject(
+ ctx,
+ _UNREFERENCED_DEFINITION_YAML,
+ [],
+ enforce_untagged_declared_inputs=True,
+ )
+
+ assert result is None
+ assert ctx.latest_recorded_build_test_outcome is None
+ assert [event.gate_id for event in ctx.author_time_gate_ablation_events] == [
+ DEFINITION_CONTRACT_UNSATISFIED_GATE_ID
+ ]
+
+
+def test_binder_ceiling_suppression_does_not_stash_reject_state(monkeypatch: pytest.MonkeyPatch) -> None:
+ ctx = make_copilot_ctx()
+ cache_copilot_author_time_gate_log_only_ids(ctx, frozenset({RECORDED_OUTCOME_GROUNDING_BINDER_CEILING_GATE_ID}))
+ outcome = RecordedBuildTestOutcome(
+ phase="author_time_reject",
+ verdict="authoring_rejected",
+ reason_code="definition_contract_unsatisfied",
+ structural_failure_identity="definition-fingerprint",
+ )
+ assert outcome.structural_key is not None
+ ctx.latest_recorded_build_test_outcome = outcome
+ ctx.recorded_outcome_grounding_requirement = RecordedOutcomeGroundingRequirement(
+ phase="author_time_reject",
+ reason_code="definition_contract_unsatisfied",
+ structural_key=outcome.structural_key,
+ satisfied=True,
+ )
+ ctx.recorded_outcome_binding_constraint = RecordedOutcomeBindingConstraint(
+ repeated_structural_key=outcome.structural_key,
+ phase="author_time_reject",
+ reason_code="definition_contract_unsatisfied",
+ frontier_facet="value_shape",
+ )
+ monkeypatch.setattr(wu, "latest_recorded_build_test_outcome_repeated", lambda _ctx: True)
+
+ assert wu._stash_unresolved_recorded_outcome_grounding_halt(ctx, ["account_name"]) is False
+ assert ctx.turn_halt is None
+ assert ctx.blocker_signal is None
+ assert ctx.latest_recorded_build_test_outcome is outcome
+ assert ctx.author_time_gate_ablation_events[-1].gate_id == RECORDED_OUTCOME_GROUNDING_BINDER_CEILING_GATE_ID
+
+
+def test_synthesized_binding_suppression_records_bounded_structural_event() -> None:
+ ctx = make_copilot_ctx()
+ cache_copilot_author_time_gate_log_only_ids(ctx, frozenset({SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID}))
+ repair_context = CodeAuthoringRepairContext(
+ block_label="submit_request",
+ reason_code="synthesized_parameter_binding_ambiguous",
+ unresolved_names=["account_name"],
+ parameter_keys=["account_name"],
+ available_parameter_keys=["customer_name"],
+ binding_candidates=["account_name", "customer_name"],
+ )
+
+ assert (
+ wu._record_synthesized_parameter_binding_ablation_event(
+ ctx,
+ _UNREFERENCED_DEFINITION_YAML,
+ repair_context,
+ )
+ is True
+ )
+ event = ctx.author_time_gate_ablation_events[-1]
+ assert event.gate_id == SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID
+ assert event.reason_code == "synthesized_parameter_binding_ambiguous"
+ assert event.payload["unresolved_names"] == ["account_name"]
+
+
+def test_structural_gate_suppression_fails_closed_without_fingerprint(monkeypatch: pytest.MonkeyPatch) -> None:
+ ctx = make_copilot_ctx()
+ cache_copilot_author_time_gate_log_only_ids(
+ ctx,
+ frozenset(
+ {
+ DEFINITION_CONTRACT_UNSATISFIED_GATE_ID,
+ SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID,
+ }
+ ),
+ )
+ rejection = wu._DefinitionPlaneReject(
+ criterion_ids=("criterion-1",),
+ reason_codes=("definition_parameters_unreferenced",),
+ unreferenced_parameter_keys=("account_name",),
+ )
+ repair_context = CodeAuthoringRepairContext(
+ block_label="submit_request",
+ reason_code="synthesized_parameter_binding_ambiguous",
+ unresolved_names=["account_name"],
+ parameter_keys=["account_name"],
+ available_parameter_keys=["customer_name"],
+ binding_candidates=["account_name", "customer_name"],
+ )
+ monkeypatch.setattr(wu, "authored_structure_signature_from_workflow", lambda *_args: None)
+
+ assert wu._record_definition_plane_ablation_event(ctx, "invalid", rejection) is False
+ assert wu._record_synthesized_parameter_binding_ablation_event(ctx, "invalid", repair_context) is False
+ assert ctx.author_time_gate_ablation_events == []
+
+
+async def test_selected_synthesized_binding_reject_persists_without_repair_state(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ _stub_successful_update(monkeypatch)
+ ctx = make_copilot_ctx()
+ cache_copilot_author_time_gate_log_only_ids(ctx, frozenset({SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID}))
+ repair_context = CodeAuthoringRepairContext(
+ block_label="submit_request",
+ reason_code="synthesized_parameter_binding_ambiguous",
+ unresolved_names=["account_name"],
+ parameter_keys=["account_name"],
+ available_parameter_keys=["customer_name"],
+ binding_candidates=["account_name", "customer_name"],
+ )
+ monkeypatch.setattr(
+ wu,
+ "_maybe_impose_synthesized_code_block",
+ lambda *_args, **_kwargs: wu._SynthesizedCodeImpositionResult(
+ workflow_yaml=_UNREFERENCED_DEFINITION_YAML,
+ violations=["Unable to bind synthesized parameter."],
+ repair_context=repair_context,
+ ablation_gate_id=SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID,
+ ),
+ )
+
+ result = await wu._update_workflow(
+ {"workflow_yaml": _UNREFERENCED_DEFINITION_YAML},
+ ctx,
+ allow_missing_credentials=True,
+ allow_static_output_uncertainty=True,
+ )
+
+ assert result["ok"] is True
+ assert ctx.latest_recorded_build_test_outcome is None
+ assert ctx.last_code_authoring_repair_context is None
+ assert ctx.author_time_gate_ablation_events[-1].gate_id == SYNTHESIZED_PARAMETER_BINDING_AMBIGUOUS_GATE_ID
+
+
+def test_unselected_new_gate_keeps_enforcing() -> None:
+ ctx = make_copilot_ctx()
+ assert (
+ record_author_time_gate_ablation_event(
+ ctx,
+ gate_id=DEFINITION_CONTRACT_UNSATISFIED_GATE_ID,
+ reason_code="definition_contract_unsatisfied",
+ fingerprint="fingerprint",
+ )
+ is False
+ )
+ assert ctx.author_time_gate_ablation_events == []
diff --git a/tests/unit/test_copilot_enforcement_pruning.py b/tests/unit/test_copilot_enforcement_pruning.py
index e9f854daa..75dcc040a 100644
--- a/tests/unit/test_copilot_enforcement_pruning.py
+++ b/tests/unit/test_copilot_enforcement_pruning.py
@@ -155,6 +155,7 @@ class _Ctx:
self.last_run_blocks_workflow_run_id = None
self.completion_criteria_turn_state = None
self.reached_download_target: ReachedDownloadTarget | None = None
+ self.author_time_gate_log_only_ids: frozenset[str] = frozenset()
self.author_time_gate_ablation_events = []
self.request_policy = None
self.blocker_signal = None
diff --git a/tests/unit/test_copilot_output_contract_actuation.py b/tests/unit/test_copilot_output_contract_actuation.py
index f3f4acd96..351915d3a 100644
--- a/tests/unit/test_copilot_output_contract_actuation.py
+++ b/tests/unit/test_copilot_output_contract_actuation.py
@@ -553,6 +553,7 @@ def _advisory_ctx() -> SimpleNamespace:
output_contract_run_output_observed_by_signature={},
output_contract_run_bound_required_path_by_signature={},
output_contract_bail_actuated_this_call=False,
+ author_time_gate_log_only_ids=frozenset(),
author_time_gate_ablation_events=[],
latest_recorded_build_test_outcome=None,
recorded_build_test_outcome_history=[],