Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Save the workflow instead of giving up when Copilot already found the value (SKY-12907) (#7703)
Andrew Neilsond95cf91bd490
diff --git a/skyvern/forge/sdk/copilot/tools/workflow_update.py b/skyvern/forge/sdk/copilot/tools/workflow_update.pyindex fee0df361..2577eb3da 100644--- a/skyvern/forge/sdk/copilot/tools/workflow_update.py+++ b/skyvern/forge/sdk/copilot/tools/workflow_update.py@@ -4096,7 +4096,12 @@ def _evaluate_output_contract_for_code_block(*,allow_static_return_advisory: bool = False,enforce_value_bearing_liveness: bool = False,+ credit_convergence_ceiling: bool = False,) -> _OutputContractEvaluation | None:+ """`credit_convergence_ceiling` inverts the liveness benefit of the doubt once the steer loop+ has consumed its budget: a root envelope the static prover reports as "unknown" is credited+ instead of refused, and the separated-spine structure steer no longer blocks. Provably absent+ or empty bindings and missing metadata/schema/return coverage keep rejecting unchanged."""if _copilot_block_authoring_policy(ctx) != BlockAuthoringPolicy.CODE_ONLY_BROWSER:return Noneruntime_contract = _runtime_output_repair_contract_from_recorded_outcome(ctx)@@ -4133,24 +4138,23 @@ def _evaluate_output_contract_for_code_block(missing_declaration_return_paths = sorted(declaration_paths - submitted_code_paths)shape_violations: list[str] = []declaration_only_contract = bool(declaration_paths) and not observation_paths++ def _root_envelope_unproved(paths: set[str]) -> bool:+ if paths != {_VALUE_BEARING_ROOT_GUIDANCE_PATH}:+ return False+ state = _root_output_envelope_state(target_code)+ return state == "absent" if credit_convergence_ceiling else state != "proven"+if enforce_value_bearing_liveness:if contract.liveness is _OutputContractLiveness.DEGRADED_EMPTY or declaration_only_contract:- root_envelope_unproved = (- required_paths == {_VALUE_BEARING_ROOT_GUIDANCE_PATH}- and _root_output_envelope_state(target_code) != "proven"- )if (target_block is None- or root_envelope_unproved+ or _root_envelope_unproved(required_paths)or _statically_lacks_value_bearing_observation_paths(target_code, required_paths)):shape_violations.append(_OUTPUT_CONTRACT_VALUE_REQUIRED_REASON_CODE)elif target_block is not None:- root_envelope_unproved = (- observation_paths == {_VALUE_BEARING_ROOT_GUIDANCE_PATH}- and _root_output_envelope_state(target_code) != "proven"- )- if root_envelope_unproved or _statically_lacks_value_bearing_observation_paths(+ if _root_envelope_unproved(observation_paths) or _statically_lacks_value_bearing_observation_paths(target_code, observation_paths):shape_violations.append(_OUTPUT_CONTRACT_VALUE_REQUIRED_REASON_CODE)@@ -4158,7 +4162,7 @@ def _evaluate_output_contract_for_code_block(shape_violations.append("ambiguous_output_owner" if owner_labels else "missing_output_owner")elif target_block is None:shape_violations.append("missing_output_block")- elif required_paths and _scout_spine_requires_separated_blocks(ctx):+ elif required_paths and not credit_convergence_ceiling and _scout_spine_requires_separated_blocks(ctx):synthesized = synthesize_code_block(ctx.scout_trajectory,strict_selectors=True,@@ -5105,6 +5109,226 @@ def _stash_output_contract_reject_budget_terminal()+@dataclass(frozen=True)+class _OutputContractCeilingResolution:+ """Outcome of the impose-or-credit move at the convergence ceiling: the draft (possibly+ rewritten server-side) plus the crediting re-evaluation that admits it."""++ workflow_yaml: str+ code_artifact_metadata: object+ evaluation: _OutputContractEvaluation+ mode: Literal["credited", "imposed"]+++def _output_contract_binding_source_on_record(+ ctx: AgentContext,+ evaluation: _OutputContractEvaluation,+ workflow_yaml: str,+) -> bool:+ """Whether the recorded exploration already pins where the requested value lives: either the+ scout observed the required paths, or a producible loaded-result composition anchors the+ target block's selectors. Imposition is only justified when this is on record."""+ binding_paths = evaluation.observation_paths or evaluation.required_paths+ if binding_paths and _observed_required_output_values(ctx, binding_paths):+ return True+ target_block = _workflow_yaml_code_blocks_by_label(workflow_yaml).get(evaluation.block_label)+ if target_block is None:+ return False+ return loaded_result_source_producible(+ ctx.latest_evaluate_result_composition_steer,+ target_code=str(target_block.get("code") or ""),+ )+++def _impose_output_contract_binding_at_ceiling(+ ctx: AgentContext,+ workflow_yaml: str,+ raw_code_artifact_metadata: object,+ evaluation: _OutputContractEvaluation,+) -> tuple[str, object] | None:+ """Compose the required output binding onto the submitted draft using the same static-return+ and metadata-scaffold composers the steer directives describe to the model. Abstains (returns+ None) when no value-bearing envelope can be composed, leaving the reject path byte-identical."""+ label = evaluation.block_label+ parsed = parse_workflow_yaml(workflow_yaml)+ if not isinstance(parsed, dict):+ return None+ target_block = _workflow_yaml_code_blocks_by_label(workflow_yaml).get(label)+ if target_block is None:+ return None+ target_code = str(target_block.get("code") or "")+ contract = _output_contract_required_paths_source(ctx)+ binding_paths = set(contract.union) or _value_bearing_directive_paths(contract)+ if not binding_paths:+ return None+ keyed_code, violations = _extraction_code_with_value_bearing_static_return(+ target_code,+ required_paths=binding_paths,+ declaration_paths=contract.declaration_paths,+ )+ if violations:+ return None+ imposed_yaml = workflow_yaml+ if keyed_code != textwrap.dedent(target_code).strip():+ applied = False+ for block in _workflow_code_blocks(parsed):+ if str(block.get("label") or "").strip() == label:+ block["code"] = keyed_code.rstrip() + "\n"+ applied = True+ break+ if not applied:+ return None+ imposed_yaml = yaml.safe_dump(parsed, sort_keys=False)+ scaffolded_metadata = _apply_metadata_contract_scaffold(+ ctx,+ imposed_yaml,+ raw_code_artifact_metadata,+ required_paths=contract.observation_paths or (binding_paths - contract.declaration_paths),+ source=contract.source or evaluation.source,+ reason_code=contract.reason_code or evaluation.reason_code,+ declaration_paths=contract.declaration_paths,+ allow_missing_static_return=True,+ )+ return imposed_yaml, scaffolded_metadata+++def _output_contract_ceiling_reached(ctx: AgentContext, evaluation: _OutputContractEvaluation) -> bool:+ if not evaluation.canonical_signature or not evaluation.block_label:+ return False+ if copilot_author_time_gate_log_only_enabled(ctx, _OUTPUT_CONTRACT_ABLATION_GATE_ID):+ return False+ return _output_contract_reject_count(ctx, evaluation.canonical_signature) + 1 >= _MAX_OUTPUT_CONTRACT_REJECTS+++def _credit_output_contract_submission(+ ctx: AgentContext,+ evaluation: _OutputContractEvaluation,+ *,+ workflow_yaml: str,+ raw_metadata: object,+ actuation_entry: str,+) -> _OutputContractEvaluation | None:+ """Credit move: re-adjudicate the submission with static uncertainty credited, so a draft+ that binds the required paths but that the liveness prover can only call "unknown" ships+ instead of looping. Returns the crediting evaluation when the strict rejection was+ over-strict, None when the deficiency is genuine."""+ credited = _evaluate_output_contract_for_code_block(+ ctx,+ workflow_yaml,+ raw_metadata,+ enforce_value_bearing_liveness=True,+ credit_convergence_ceiling=True,+ )+ if credited is None or credited.has_deficiencies:+ return None+ LOG.info(+ "copilot_output_contract_submission_credited_at_ceiling",+ block_label=evaluation.block_label,+ canonical_output_contract_signature=evaluation.canonical_signature,+ steering_reject_count=_output_contract_reject_count(ctx, evaluation.canonical_signature),+ credited_shape_violations=list(evaluation.shape_violations),+ credited_missing_code_return_paths=list(evaluation.missing_return_paths),+ actuation_entry=actuation_entry,+ )+ return credited+++def _credit_output_contract_submission_at_ceiling(+ ctx: AgentContext,+ evaluation: _OutputContractEvaluation,+ *,+ workflow_yaml: str,+ raw_metadata: object,+) -> _OutputContractEvaluation | None:+ if not _output_contract_ceiling_reached(ctx, evaluation):+ return None+ return _credit_output_contract_submission(+ ctx,+ evaluation,+ workflow_yaml=workflow_yaml,+ raw_metadata=raw_metadata,+ actuation_entry="reject_ceiling",+ )+++def _credit_or_impose_output_contract_at_ceiling(+ ctx: AgentContext,+ evaluation: _OutputContractEvaluation,+ *,+ workflow_yaml: str,+ raw_metadata: object,+) -> _OutputContractCeilingResolution | None:+ """Impose-or-credit at the convergence ceiling (SKY-12907): once steering has consumed the+ reject budget on one canonical contract signature, the server stops asking the model."""+ if not _output_contract_ceiling_reached(ctx, evaluation):+ return None+ return _credit_or_impose_output_contract(+ ctx,+ evaluation,+ workflow_yaml=workflow_yaml,+ raw_metadata=raw_metadata,+ actuation_entry="reject_ceiling",+ )+++def _credit_or_impose_output_contract(+ ctx: AgentContext,+ evaluation: _OutputContractEvaluation,+ *,+ workflow_yaml: str,+ raw_metadata: object,+ actuation_entry: str,+) -> _OutputContractCeilingResolution | None:+ """Credit first — is the strict rejection over-strict for this submission? Impose second —+ when the recorded exploration pins the value's source, compose the return envelope and+ metadata scaffold server-side from the same templates the steer directives quote. Returns+ None when neither move is justified, leaving the caller's reject/ablation path untouched.+ Armed by the reject ceiling in enforcing mode and by the ablation seam in log-only mode."""+ credited = _credit_output_contract_submission(+ ctx,+ evaluation,+ workflow_yaml=workflow_yaml,+ raw_metadata=raw_metadata,+ actuation_entry=actuation_entry,+ )+ if credited is not None:+ return _OutputContractCeilingResolution(+ workflow_yaml=workflow_yaml,+ code_artifact_metadata=raw_metadata,+ evaluation=credited,+ mode="credited",+ )+ if not _output_contract_binding_source_on_record(ctx, evaluation, workflow_yaml):+ return None+ imposed = _impose_output_contract_binding_at_ceiling(ctx, workflow_yaml, raw_metadata, evaluation)+ if imposed is None:+ return None+ imposed_yaml, imposed_metadata = imposed+ reevaluated = _evaluate_output_contract_for_code_block(+ ctx,+ imposed_yaml,+ imposed_metadata,+ enforce_value_bearing_liveness=True,+ credit_convergence_ceiling=True,+ )+ if reevaluated is None or reevaluated.has_deficiencies:+ return None+ _mark_output_contract_imposed(ctx, evaluation.canonical_signature)+ LOG.info(+ "copilot_output_contract_binding_imposed_at_ceiling",+ block_label=evaluation.block_label,+ canonical_output_contract_signature=evaluation.canonical_signature,+ steering_reject_count=_output_contract_reject_count(ctx, evaluation.canonical_signature),+ actuation_entry=actuation_entry,+ )+ return _OutputContractCeilingResolution(+ workflow_yaml=imposed_yaml,+ code_artifact_metadata=imposed_metadata,+ evaluation=reevaluated,+ mode="imposed",+ )++def _capture_rejected_code_artifact_metadata(ctx: AgentContext) -> None:snapshot = ctx.submitted_code_artifact_metadata_snapshotif snapshot is None:@@ -6830,6 +7054,18 @@ def _metadata_contract_run_preflight_reject()if evaluation is None or not evaluation.has_deficiencies:return None+ if (+ _credit_output_contract_submission_at_ceiling(+ ctx,+ evaluation,+ workflow_yaml=workflow_yaml,+ raw_metadata=raw_code_artifact_metadata,+ )+ is not None+ ):+ # The steer loop consumed its budget on this contract and the submission satisfies it+ # under ceiling crediting: let the run proceed instead of re-emitting the directive.+ return Noneif _OUTPUT_CONTRACT_VALUE_REQUIRED_REASON_CODE in evaluation.shape_violations:_revoke_output_contract_advisory_run(ctx, evaluation.canonical_signature)authored_fingerprint = _output_contract_structural_fingerprint(workflow_yaml, evaluation.canonical_signature)@@ -13569,10 +13805,41 @@ async def _update_workflow(output_contract_static_advisory_allowed = (output_contract_evaluation is not None and output_contract_evaluation.can_attempt_run)+ output_contract_ceiling_resolution: _OutputContractCeilingResolution | None = Noneif (output_contract_evaluation is not Noneand output_contract_evaluation.has_deficienciesand not output_contract_static_advisory_allowed+ ):+ output_contract_ceiling_resolution = _credit_or_impose_output_contract_at_ceiling(+ ctx,+ output_contract_evaluation,+ workflow_yaml=workflow_yaml,+ raw_metadata=params.get("code_artifact_metadata"),+ )+ # Under log-only the reject ceiling never arms (no rejects are counted), so the deficient+ # draft would persist as-is; arm the same composer at the ablation seam instead.+ if output_contract_ceiling_resolution is None and copilot_author_time_gate_log_only_enabled(+ ctx, _OUTPUT_CONTRACT_ABLATION_GATE_ID+ ):+ output_contract_ceiling_resolution = _credit_or_impose_output_contract(+ ctx,+ output_contract_evaluation,+ workflow_yaml=workflow_yaml,+ raw_metadata=params.get("code_artifact_metadata"),+ actuation_entry="log_only_ablation",+ )+ if output_contract_ceiling_resolution is not None:+ workflow_yaml = output_contract_ceiling_resolution.workflow_yaml+ params["workflow_yaml"] = workflow_yaml+ params["code_artifact_metadata"] = output_contract_ceiling_resolution.code_artifact_metadata+ params["raw_code_artifact_metadata"] = output_contract_ceiling_resolution.code_artifact_metadata+ ctx.raw_code_artifact_metadata = output_contract_ceiling_resolution.code_artifact_metadata+ output_contract_evaluation = output_contract_ceiling_resolution.evaluation+ elif (+ output_contract_evaluation is not None+ and output_contract_evaluation.has_deficiencies+ and not output_contract_static_advisory_allowed):authored_fingerprint = _output_contract_structural_fingerprint(workflow_yaml, output_contract_evaluation.canonical_signature@@ -13790,7 +14057,8 @@ async def _update_workflow(verified_runtime_output_paths_by_label=_verified_runtime_output_contract_paths_by_label(ctx, workflow_yaml),advisory_declared_output_return_shape_labels=({output_contract_evaluation.block_label}- if output_contract_static_advisory_allowed and output_contract_evaluation is not None+ if output_contract_evaluation is not None+ and (output_contract_static_advisory_allowed or output_contract_ceiling_resolution is not None)else None),)diff --git a/tests/unit/test_copilot_output_contract_actuation.py b/tests/unit/test_copilot_output_contract_actuation.pyindex 503040349..9fec26a2d 100644--- a/tests/unit/test_copilot_output_contract_actuation.py+++ b/tests/unit/test_copilot_output_contract_actuation.py@@ -7,8 +7,10 @@ OSS-synced: only synthetic labels and RFC-2606 placeholder identifiers.from __future__ import annotations+import hashlibimport itertoolsimport json+from pathlib import Pathfrom types import SimpleNamespaceimport pytest@@ -2680,3 +2682,340 @@ def test_deficient_candidate_still_rejected_by_gate() -> None:assert evaluation.has_deficiencies is Trueassert "output.record_id" in evaluation.missing_return_pathsassert "output.record_id" in evaluation.missing_metadata_paths+++# ---------------------------------------------------------------------------+# SKY-12907: impose-or-credit at the convergence ceiling.+# ---------------------------------------------------------------------------+++def _record_criterion_ctx() -> CopilotContext:+ ctx = _antecedent_ctx(+ CompletionCriterion(+ id="c_record", outcome="The returned record includes record id.", output_path="output.record_id"+ )+ )+ ctx.turn_id = "turn_ceiling_record"+ return ctx+++def _record_contract_metadata() -> list[dict[str, object]]:+ return [+ wu._metadata_contract_template(+ block_label="extract_record",+ required_paths={"output.record_id"},+ source="requested_output_contract",+ reason_code="requested_output_contract_missing_output_coverage",+ )+ ]+++_UNCERTAIN_ROOT_ENVELOPE_CODE = 'envelope = {"output": {"blocker": None}}\nenvelope.update(status)\nreturn envelope'+++def _declaration_only_root_contract() -> tuple[CopilotContext, str, list[dict[str, object]]]:+ ctx = _antecedent_ctx(_blocker_contingent_criterion())+ ctx.turn_id = "turn_ceiling_root"+ workflow_yaml = _declaration_waiver_yaml(_UNCERTAIN_ROOT_ENVELOPE_CODE)+ metadata = [+ wu._metadata_contract_template(+ block_label="extract_record",+ required_paths={"output"},+ source="requested_output_contract",+ reason_code="requested_output_contract_missing_output_coverage",+ declaration_paths={"output.blocker"},+ )+ ]+ return ctx, workflow_yaml, metadata+++def test_credit_flag_admits_uncertain_root_envelope_and_keeps_absent_rejected() -> None:+ ctx, workflow_yaml, metadata = _declaration_only_root_contract()++ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None+ assert wu._OUTPUT_CONTRACT_VALUE_REQUIRED_REASON_CODE in strict.shape_violations++ credited = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True, credit_convergence_ceiling=True+ )+ assert credited is not None+ assert credited.has_deficiencies is False++ # A provably output-less envelope stays rejected even with crediting on.+ absent_yaml = _declaration_waiver_yaml('return {"status": "done"}')+ absent = wu._evaluate_output_contract_for_code_block(+ ctx, absent_yaml, metadata, enforce_value_bearing_liveness=True, credit_convergence_ceiling=True+ )+ assert absent is not None+ assert wu._OUTPUT_CONTRACT_VALUE_REQUIRED_REASON_CODE in absent.shape_violations+++def test_ceiling_credits_uncertain_but_bound_submission() -> None:+ ctx, workflow_yaml, metadata = _declaration_only_root_contract()+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None and strict.has_deficiencies++ # Below the ceiling the server keeps steering: no credit, no imposition.+ assert (+ wu._credit_or_impose_output_contract_at_ceiling(ctx, strict, workflow_yaml=workflow_yaml, raw_metadata=metadata)+ is None+ )++ ctx.output_contract_reject_count_by_signature[strict.canonical_signature] = wu._MAX_OUTPUT_CONTRACT_REJECTS - 1+ with capture_logs() as logs:+ resolution = wu._credit_or_impose_output_contract_at_ceiling(+ ctx, strict, workflow_yaml=workflow_yaml, raw_metadata=metadata+ )+ assert resolution is not None+ assert resolution.mode == "credited"+ assert resolution.workflow_yaml == workflow_yaml+ assert resolution.code_artifact_metadata is metadata+ assert resolution.evaluation.has_deficiencies is False+ assert ctx.output_contract_imposed_since_last_reject_by_signature.get(strict.canonical_signature) is not True+ assert any(log.get("event") == "copilot_output_contract_submission_credited_at_ceiling" for log in logs)+++def test_credit_preserves_reject_streak_so_downstream_reject_keeps_ceiling() -> None:+ ctx, workflow_yaml, metadata = _declaration_only_root_contract()+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None and strict.has_deficiencies+ ctx.output_contract_reject_count_by_signature[strict.canonical_signature] = wu._MAX_OUTPUT_CONTRACT_REJECTS - 1++ credited = wu._credit_output_contract_submission_at_ceiling(+ ctx, strict, workflow_yaml=workflow_yaml, raw_metadata=metadata+ )+ assert credited is not None++ downstream = wu._record_output_contract_family_reject(+ ctx,+ strict.required_paths,+ reject_family="requested_output_contract_missing_output_coverage",+ authored_structural_fingerprint="fp_downstream",+ )+ assert downstream == wu._MAX_OUTPUT_CONTRACT_REJECTS+++def test_ceiling_imposes_binding_from_scouted_observation() -> None:+ ctx = _record_criterion_ctx()+ workflow_yaml = _declaration_waiver_yaml('record_id = await page.inner_text("#record")')+ metadata = _record_contract_metadata()+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None+ assert "output.record_id" in strict.missing_return_paths+ ctx.output_contract_reject_count_by_signature[strict.canonical_signature] = wu._MAX_OUTPUT_CONTRACT_REJECTS - 1++ # Enforcing-mode negative: without a recorded source, the reject path stays untouched.+ assert (+ wu._credit_or_impose_output_contract_at_ceiling(ctx, strict, workflow_yaml=workflow_yaml, raw_metadata=metadata)+ is None+ )++ ctx.scouted_output_covered_paths = {"output.record_id"}+ with capture_logs() as logs:+ resolution = wu._credit_or_impose_output_contract_at_ceiling(+ ctx, strict, workflow_yaml=workflow_yaml, raw_metadata=metadata+ )+ assert resolution is not None+ assert resolution.mode == "imposed"+ imposed_code = str(+ wu._workflow_yaml_code_blocks_by_label(resolution.workflow_yaml)["extract_record"].get("code") or ""+ )+ assert 'return {"output": {"record_id": record_id}}' in imposed_code+ assert resolution.evaluation.has_deficiencies is False+ assert ctx.output_contract_imposed_since_last_reject_by_signature[strict.canonical_signature] is True+ assert any(log.get("event") == "copilot_output_contract_binding_imposed_at_ceiling" for log in logs)+++def test_ceiling_abstains_when_no_binding_composable_even_with_observation() -> None:+ ctx = _record_criterion_ctx()+ workflow_yaml = _declaration_waiver_yaml('await page.click("#next")\nreturn "done"')+ metadata = _record_contract_metadata()+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None and strict.has_deficiencies+ ctx.output_contract_reject_count_by_signature[strict.canonical_signature] = wu._MAX_OUTPUT_CONTRACT_REJECTS - 1+ ctx.scouted_output_covered_paths = {"output.record_id"}++ assert (+ wu._credit_or_impose_output_contract_at_ceiling(ctx, strict, workflow_yaml=workflow_yaml, raw_metadata=metadata)+ is None+ )+ assert ctx.output_contract_imposed_since_last_reject_by_signature.get(strict.canonical_signature) is None+++def test_ceiling_hook_inert_in_log_only_mode() -> None:+ ctx, workflow_yaml, metadata = _declaration_only_root_contract()+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None+ ctx.output_contract_reject_count_by_signature[strict.canonical_signature] = wu._MAX_OUTPUT_CONTRACT_REJECTS - 1+ ctx.author_time_gate_log_only_ids = frozenset({wu._OUTPUT_CONTRACT_ABLATION_GATE_ID})++ assert (+ wu._credit_or_impose_output_contract_at_ceiling(ctx, strict, workflow_yaml=workflow_yaml, raw_metadata=metadata)+ is None+ )+++def test_log_only_ablation_entry_credits_qualifying_submission_without_any_rejects() -> None:+ ctx, workflow_yaml, metadata = _declaration_only_root_contract()+ ctx.author_time_gate_log_only_ids = frozenset({wu._OUTPUT_CONTRACT_ABLATION_GATE_ID})+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None and strict.has_deficiencies+ assert ctx.output_contract_reject_count_by_signature == {}++ with capture_logs() as logs:+ resolution = wu._credit_or_impose_output_contract(+ ctx,+ strict,+ workflow_yaml=workflow_yaml,+ raw_metadata=metadata,+ actuation_entry="log_only_ablation",+ )+ assert resolution is not None+ assert resolution.mode == "credited"+ assert resolution.evaluation.has_deficiencies is False+ credited_logs = [+ log for log in logs if log.get("event") == "copilot_output_contract_submission_credited_at_ceiling"+ ]+ assert credited_logs and credited_logs[0].get("actuation_entry") == "log_only_ablation"+++def test_log_only_ablation_entry_imposes_binding_from_scouted_observation() -> None:+ ctx = _record_criterion_ctx()+ ctx.author_time_gate_log_only_ids = frozenset({wu._OUTPUT_CONTRACT_ABLATION_GATE_ID})+ ctx.scouted_output_covered_paths = {"output.record_id"}+ workflow_yaml = _declaration_waiver_yaml('record_id = await page.inner_text("#record")')+ metadata = _record_contract_metadata()+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None and strict.has_deficiencies+ assert ctx.output_contract_reject_count_by_signature == {}++ with capture_logs() as logs:+ resolution = wu._credit_or_impose_output_contract(+ ctx,+ strict,+ workflow_yaml=workflow_yaml,+ raw_metadata=metadata,+ actuation_entry="log_only_ablation",+ )+ assert resolution is not None+ assert resolution.mode == "imposed"+ imposed_code = str(+ wu._workflow_yaml_code_blocks_by_label(resolution.workflow_yaml)["extract_record"].get("code") or ""+ )+ assert 'return {"output": {"record_id": record_id}}' in imposed_code+ imposed_logs = [log for log in logs if log.get("event") == "copilot_output_contract_binding_imposed_at_ceiling"]+ assert imposed_logs and imposed_logs[0].get("actuation_entry") == "log_only_ablation"+++def test_log_only_ablation_entry_abstains_without_observation_so_draft_persists_as_today() -> None:+ ctx = _record_criterion_ctx()+ ctx.author_time_gate_log_only_ids = frozenset({wu._OUTPUT_CONTRACT_ABLATION_GATE_ID})+ ctx.scouted_output_covered_paths = set()+ omitted_yaml = _declaration_waiver_yaml('return {"status": "done"}')+ metadata = _record_contract_metadata()+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, omitted_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None and strict.has_deficiencies++ assert (+ wu._credit_or_impose_output_contract(+ ctx,+ strict,+ workflow_yaml=omitted_yaml,+ raw_metadata=metadata,+ actuation_entry="log_only_ablation",+ )+ is None+ )+ assert ctx.output_contract_imposed_since_last_reject_by_signature.get(strict.canonical_signature) is None+++def test_ceiling_refuses_omitted_value_without_observation_byte_identically() -> None:+ ctx, _, metadata = _declaration_only_root_contract()+ ctx.scouted_output_covered_paths = set()+ omitted_yaml = _declaration_waiver_yaml('return {"status": "done"}')+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, omitted_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None and strict.has_deficiencies+ ctx.output_contract_reject_count_by_signature[strict.canonical_signature] = wu._MAX_OUTPUT_CONTRACT_REJECTS - 1++ assert (+ wu._credit_or_impose_output_contract_at_ceiling(ctx, strict, workflow_yaml=omitted_yaml, raw_metadata=metadata)+ is None+ )+ credited = wu._evaluate_output_contract_for_code_block(+ ctx, omitted_yaml, metadata, enforce_value_bearing_liveness=True, credit_convergence_ceiling=True+ )+ assert credited is not None+ assert credited.payload == strict.payload+ assert wu._OUTPUT_CONTRACT_VALUE_REQUIRED_REASON_CODE in credited.shape_violations+ assert ctx.output_contract_imposed_since_last_reject_by_signature.get(strict.canonical_signature) is None+++def test_ceiling_reached_at_final_counted_reject_not_before() -> None:+ ctx, workflow_yaml, metadata = _declaration_only_root_contract()+ strict = wu._evaluate_output_contract_for_code_block(+ ctx, workflow_yaml, metadata, enforce_value_bearing_liveness=True+ )+ assert strict is not None+ counts = ctx.output_contract_reject_count_by_signature++ counts[strict.canonical_signature] = wu._MAX_OUTPUT_CONTRACT_REJECTS - 2+ assert wu._output_contract_ceiling_reached(ctx, strict) is False++ counts[strict.canonical_signature] = wu._MAX_OUTPUT_CONTRACT_REJECTS - 1+ assert wu._output_contract_ceiling_reached(ctx, strict) is True+++_PROD_METADATA_CORPUS = Path(+ "/Users/andrewneilson/sky/.gauntlet-cache/output-contract-binder-20260722/prod_rejected_metadata_captures.json"+)+_PROD_METADATA_CORPUS_SHA256 = "0f99fa0ddb8ce52ad4d6191ea307277ff373ccfed3a647caa46d80d6ee2aa060"+++def _prod_capture_binding_dimension(payload: list[dict[str, object]]) -> tuple[bool, bool]:+ element = payload[0]+ observations = element.get("exploration_observations") or []+ statuses = {str(observation.get("status")) for observation in observations}+ binding_source_on_record = len(observations) > 0+ liveness_uncertain = bool(statuses) and statuses <= {"observed_not_verified"}+ return binding_source_on_record, liveness_uncertain++[email protected](not _PROD_METADATA_CORPUS.exists(), reason="prod evidence archive not present in this environment")+def test_prod_rejected_metadata_corpus_adjudication() -> None:+ raw = _PROD_METADATA_CORPUS.read_bytes()+ assert hashlib.sha256(raw).hexdigest() == _PROD_METADATA_CORPUS_SHA256++ captures = [+ row["attributes"]["attributes"]["rejected_code_artifact_metadata_payload"] for row in json.loads(raw)["data"]+ ]+ assert len(captures) == 6++ for payload in captures:+ element = payload[0]+ # One shared extraction block label across all captures; the exact name stays in+ # the local evidence archive (never committed — it identifies the target site).+ assert element["block_label"] == captures[0][0]["block_label"]+ binding_source_on_record, liveness_uncertain = _prod_capture_binding_dimension(payload)+ assert binding_source_on_record is True+ assert liveness_uncertain is True