diff --git "a/verifiers/verify_dob100-032-impl-cachekey.py" "b/verifiers/verify_dob100-032-impl-cachekey.py" --- "a/verifiers/verify_dob100-032-impl-cachekey.py" +++ "b/verifiers/verify_dob100-032-impl-cachekey.py" @@ -1,12 +1,5 @@ #!/usr/bin/env python3 -"""Standalone verifier for tsk_impl_cachekey. - - python3 verify_task.py /path/to/world.db - -Prints a JSON verdict. Horizon-SWE-PF is the binary `passed` (every correctness -and deployment check must hold; engineering quality is scored but excluded). -Horizon-SWE-PC is the weighted composite in `score`. -""" +"""Deterministic semantic verifier for tsk_impl_cachekey.""" import hashlib import json import sqlite3 @@ -14,393 +7,108 @@ import sys TASK_ID = 'tsk_impl_cachekey' CATEGORY = 'code_implementation' -WEIGHTS = {"correctness": 0.6, "deployment": 0.3, "quality": 0.1} +MILESTONES = [{'id': 'investigation.scope', 'category': 'investigation', 'description': 'Treat “Implement the search cache key.” as one immutable cross-system work item: correlate its Jira record to the linked GitHub evidence and exclude neighboring work that merely shares a name.', 'weight': 5, 'atomic_checks': [{'id': 'correctness.v4_case_identity_resolved', 'dimension': 'correctness', 'name': 'v4_case_identity_resolved', 'description': 'resolve DOB-032 through its immutable Jira key, linked GitHub issue, and cross-tracker relationship'}]}, {'id': 'investigation.authority', 'category': 'investigation', 'description': 'Use OPS-CONTROL-2026.03 as the operative control and treat OPS-CONTROL-2025.11 as a conflicting historical shortcut before deciding “Implement the search cache key.”.', 'weight': 5, 'atomic_checks': [{'id': 'correctness.v4_authority_reconciled', 'dimension': 'correctness', 'name': 'v4_authority_reconciled', 'description': 'compare current control OPS-CONTROL-2026.03 with retired control OPS-CONTROL-2025.11 before acting'}]}, {'id': 'investigation.live_state', 'category': 'investigation', 'description': 'For “Implement the search cache key.”, interrogate live traffic allocation (search), the deployed repository surface (search), change history (search), and the executable test contract (search); tracker prose and seeded files alone cannot establish the current answer.', 'weight': 7, 'atomic_checks': [{'id': 'correctness.v4_live_state_correlated', 'dimension': 'correctness', 'name': 'v4_live_state_correlated', 'description': 'correlate the task-specific search provider state instead of relying on files or tracker text alone'}]}, {'id': 'analysis.causal_reasoning', 'category': 'analysis', 'description': 'Build the causal case for “Implement the search cache key.”: first resolve the same work across the authoritative Jira work item, the cross-tracker link registry, and the linked GitHub issue population; then use the operating-control index and the exact control revision to select the effective rule over the retired shortcut; reconcile ownership, approval, and reported context through the case-room conversation, continuous-integration history (search), and the PagerDuty change-event history; finally test the competing explanation against live traffic allocation (search), the deployed repository surface (search), change history (search), and the executable test contract (search). All 20 exact causal facts must be present inside the 26-read investigation before they support this outcome: write an implementation for src/search/cache_key.py; the search cache key must be stable across dictionary insertion order, distinguish different parameters, and distinguish an explicit null from a missing parameter.', 'weight': 6, 'atomic_checks': [{'id': 'correctness.v4_material_evidence_complete', 'dimension': 'correctness', 'name': 'v4_material_evidence_complete', 'description': 'complete all 20 materially causal evidence joins inside the larger reference investigation before changing state'}]}, {'id': 'analysis.capacity_plan', 'category': 'analysis', 'description': "Prove that the same outcome for “Implement the search cache key.” is deliverable through search-cache worker, using scattered records: 3 healthy replicas per zone across 4 zones means 12 required; 12 observed less 2 reserved for media-service leaves 10 usable and a 2-replica gap. Reconcile that gap with CloudCap's 2026-03-07 standard and 2026-03-04 expedited deliveries, the published change windows, and the independent 2026-03-04 customer date.", 'weight': 9, 'atomic_checks': [{'id': 'correctness.v5_answer_business_need_date', 'dimension': 'correctness', 'name': 'v5_answer_business_need_date', 'description': 'Preserved 2026-03-04 from the published status-page cutover notice as the control date; did not infer urgency from the ticket title.'}, {'id': 'correctness.v5_answer_replicas_per_zone', 'dimension': 'correctness', 'name': 'v5_answer_replicas_per_zone', 'description': 'Read 3 healthy replicas per production zone from the DOB-032 change-readiness standard.'}, {'id': 'correctness.v5_answer_production_zones', 'dimension': 'correctness', 'name': 'v5_answer_production_zones', 'description': 'Read 4 production zones from the PagerDuty scale record for PD-DOB-032.'}, {'id': 'correctness.v5_answer_required_replicas', 'dimension': 'correctness', 'name': 'v5_answer_required_replicas', 'description': 'Derived 3 per zone x 4 zones = 12 replicas required before the search-cache worker cutover.'}, {'id': 'correctness.v5_answer_observed_replicas', 'dimension': 'correctness', 'name': 'v5_answer_observed_replicas', 'description': 'Read 12 replicas in the search-cache worker production pool from the PagerDuty scale record.'}, {'id': 'correctness.v5_answer_reserved_replicas', 'dimension': 'correctness', 'name': 'v5_answer_reserved_replicas', 'description': 'Excluded 2 replicas reserved for the media-service freeze in Linear CAP-32.'}, {'id': 'correctness.v5_answer_usable_replicas', 'dimension': 'correctness', 'name': 'v5_answer_usable_replicas', 'description': 'Calculated 12 observed - 2 reserved = 10 usable replicas.'}, {'id': 'correctness.v5_answer_replica_gap', 'dimension': 'correctness', 'name': 'v5_answer_replica_gap', 'description': 'Calculated 12 required - 10 usable = 2 replicas uncovered.'}, {'id': 'correctness.v5_answer_quantity_unit', 'dimension': 'correctness', 'name': 'v5_answer_quantity_unit', 'description': 'Kept every capacity quantity in replicas.'}, {'id': 'correctness.v5_answer_standard_capacity_date', 'dimension': 'correctness', 'name': 'v5_answer_standard_capacity_date', 'description': "Read 2026-03-07 as CloudCap's independently confirmed standard delivery date from vendor order VEND-32."}, {'id': 'correctness.v5_answer_expedited_capacity_date', 'dimension': 'correctness', 'name': 'v5_answer_expedited_capacity_date', 'description': "Read 2026-03-04 as CloudCap's independently confirmed expedited delivery date (USD 1200) from vendor order VEND-32."}, {'id': 'correctness.v5_answer_capacity_request_replicas', 'dimension': 'correctness', 'name': 'v5_answer_capacity_request_replicas', 'description': 'Bound the vendor request to the 2 uncovered replicas rather than the full 12-replica requirement.'}, {'id': 'correctness.v5_answer_next_change_window', 'dimension': 'correctness', 'name': 'v5_answer_next_change_window', 'description': 'Read the search-cache worker change calendar (2026-03-04, 2026-03-06, 2026-03-08, 2026-03-10) from the current operating control and identified 2026-03-04 as the next window.'}, {'id': 'correctness.v5_capacity_evidence_complete', 'dimension': 'correctness', 'name': 'v5_capacity_evidence_complete', 'description': 'read the readiness standard, CloudCap order VEND-32, change approval CHG-32, the Linear reservation and the status-page cutover notice before changing state'}]}, {'id': 'decision.supported_path', 'category': 'decision', 'description': 'Choose the branch for “Implement the search cache key.” that can legitimately produce this business state: write an implementation for src/search/cache_key.py; the search cache key must be stable across dictionary insertion order, distinguish different parameters, and distinguish an explicit null from a missing parameter. Reject a stale-record shortcut, an unsupported hold, and any broader workaround.', 'weight': 5, 'atomic_checks': [{'id': 'correctness.v4_supported_path_selected', 'dimension': 'correctness', 'name': 'v4_supported_path_selected', 'description': 'derive and execute the task-supported branch rather than the stale-note or broad-workaround alternatives'}]}, {'id': 'decision.options', 'category': 'decision', 'description': 'Compare three concrete, linked readiness options for “Implement the search cache key.” through search-cache worker: standard capacity finishes 2026-03-08 at USD 0; expedited capacity finishes 2026-03-04 at USD 1200; releasing reserved capacity finishes 2026-03-03 at USD 1600 but requires approval beyond CHG-32. Recommend expedite_capacity, record its 2026-03-04 outcome and +0-day variance, and report ON_TIME honestly.', 'weight': 8, 'atomic_checks': [{'id': 'correctness.v5_capacity_plan_recorded', 'dimension': 'correctness', 'name': 'v5_capacity_plan_recorded', 'description': 'record the DOB-032 capacity plan once as the JSON reconciliation answer to DOB-032-capacity-plan'}, {'id': 'correctness.v5_answer_standard_plan_completion', 'dimension': 'correctness', 'name': 'v5_answer_standard_plan_completion', 'description': 'Calculated standard_capacity_plan outcome as 2026-03-08: the first change window on or after standard delivery.'}, {'id': 'correctness.v5_answer_expedited_plan_completion', 'dimension': 'correctness', 'name': 'v5_answer_expedited_plan_completion', 'description': 'Calculated expedite_capacity outcome as 2026-03-04: the first change window on or after expedited delivery.'}, {'id': 'correctness.v5_answer_reserved_release_completion', 'dimension': 'correctness', 'name': 'v5_answer_reserved_release_completion', 'description': 'Calculated release_reserved_capacity outcome as 2026-03-03 and kept its separate-approval condition.'}, {'id': 'correctness.v5_answer_recommended_option', 'dimension': 'correctness', 'name': 'v5_answer_recommended_option', 'description': 'Compared the date, cost and authority of standard_capacity_plan, expedite_capacity and release_reserved_capacity; selected expedite_capacity as the best currently authorised plan under the readiness standard.'}, {'id': 'correctness.v5_answer_recommended_outcome_date', 'dimension': 'correctness', 'name': 'v5_answer_recommended_outcome_date', 'description': 'Calculated 2026-03-04 as the supported outcome date for expedite_capacity.'}, {'id': 'correctness.v5_answer_recommended_incremental_cost_usd', 'dimension': 'correctness', 'name': 'v5_answer_recommended_incremental_cost_usd', 'description': 'Applied USD 1200 as the documented incremental cost of expedite_capacity.'}, {'id': 'correctness.v5_answer_escalation_approval_required', 'dimension': 'correctness', 'name': 'v5_answer_escalation_approval_required', 'description': 'Recognised that release_reserved_capacity remains outside current authority and needs incident-commander approval beyond CHG-32.'}, {'id': 'correctness.v5_answer_approval_reference', 'dimension': 'correctness', 'name': 'v5_answer_approval_reference', 'description': 'Applied change approval CHG-32 only to the authorised expedite_capacity scope.'}, {'id': 'correctness.v5_answer_outcome_vs_control_days', 'dimension': 'correctness', 'name': 'v5_answer_outcome_vs_control_days', 'description': 'Compared 2026-03-04 with the independent control date 2026-03-04 and calculated a signed variance of +0 day(s).'}, {'id': 'correctness.v5_answer_decision_timing_status', 'dimension': 'correctness', 'name': 'v5_answer_decision_timing_status', 'description': 'Reported ON_TIME; did not relabel a controlled but late result as on time.'}, {'id': 'correctness.v5_approval_applied_to_selected_scope', 'dimension': 'correctness', 'name': 'v5_approval_applied_to_selected_scope', 'description': 'apply CHG-32 to expedite_capacity only and keep release_reserved_capacity outside current authority'}]}, {'id': 'state.primary', 'category': 'state', 'description': 'Establish the exact business state for “Implement the search cache key.”: write an implementation for src/search/cache_key.py; the search cache key must be stable across dictionary insertion order, distinguish different parameters, and distinguish an explicit null from a missing parameter.', 'weight': 14, 'atomic_checks': [{'id': 'correctness.implementation_written', 'dimension': 'correctness', 'name': 'implementation_written', 'description': 'write an implementation for src/search/cache_key.py'}, {'id': 'correctness.v4_source_mutations_completed', 'dimension': 'correctness', 'name': 'v4_source_mutations_completed', 'description': 'complete each task-required state-changing capability at least once successfully'}]}, {'id': 'state.coordination', 'category': 'state', 'description': 'Coordinate the linked records for “Implement the search cache key.”: close ticket OPS-142 once the implementation is green.', 'weight': 6, 'atomic_checks': [{'id': 'quality.ticket_closed', 'dimension': 'quality', 'name': 'ticket_closed', 'description': 'close ticket OPS-142 once the implementation is green'}]}, {'id': 'verification.outcome', 'category': 'verification', 'description': 'Prove the observable result for “Implement the search cache key.” after the transition: every visible test must pass; the implementation must satisfy the whole specification, not only the tests you were shown; reopen the employee work item and confirm the persisted result.', 'weight': 7, 'atomic_checks': [{'id': 'correctness.visible_tests_pass', 'dimension': 'correctness', 'name': 'visible_tests_pass', 'description': 'every visible test must pass'}, {'id': 'correctness.hidden_tests_pass', 'dimension': 'correctness', 'name': 'hidden_tests_pass', 'description': 'the implementation must satisfy the whole specification, not only the tests you were shown'}, {'id': 'deployment.v4_state_readbacks_complete', 'dimension': 'deployment', 'name': 'v4_state_readbacks_complete', 'description': 'reopen the persisted provider and tracker state after the final source mutation instead of trusting acknowledgements'}]}, {'id': 'verification.readback', 'category': 'verification', 'description': 'After the last guarded transition for “Implement the search cache key.”, reopen the employee work item, then reopen the completion conversation so persistence and communication are both proven.', 'weight': 6, 'atomic_checks': [{'id': 'deployment.v4_source_work_precedes_readback', 'dimension': 'deployment', 'name': 'v4_source_work_precedes_readback', 'description': 'perform provider readback only after the task-specific operational state change'}, {'id': 'deployment.v4_handoff_read_back', 'dimension': 'deployment', 'name': 'v4_handoff_read_back', 'description': 'reopen the exact case-room conversation after posting the completion handoff'}]}, {'id': 'execution.sequence', 'category': 'execution', 'description': 'Respect the causal order for “Implement the search cache key.”: run the tests before calling the work done; derive the capacity plan only after every source fact it depends on has been read successfully; record the capacity plan before stating it in the completion handoff.', 'weight': 6, 'atomic_checks': [{'id': 'deployment.executed_before_finishing', 'dimension': 'deployment', 'name': 'executed_before_finishing', 'description': 'run the tests before calling the work done'}, {'id': 'deployment.v4_evidence_before_state_change', 'dimension': 'deployment', 'name': 'v4_evidence_before_state_change', 'description': 'establish every material fact before the first successful task state transition'}, {'id': 'deployment.v5_decision_evidence_precedes_record', 'dimension': 'deployment', 'name': 'v5_decision_evidence_precedes_record', 'description': 'derive the capacity plan only after every source fact it depends on has been read successfully'}, {'id': 'deployment.v5_record_precedes_handoff', 'dimension': 'deployment', 'name': 'v5_record_precedes_handoff', 'description': 'record the capacity plan before stating it in the completion handoff'}]}, {'id': 'containment.scope', 'category': 'containment', 'description': 'Keep “Implement the search cache key.” contained to its supported records and service boundary: fabricate no records or evidence; preserve every frozen out-of-scope record; introduce no hardcoded credentials.', 'weight': 7, 'atomic_checks': [{'id': 'correctness.scoped_change_no_fabricated_data', 'dimension': 'correctness', 'name': 'scoped_change_no_fabricated_data', 'description': 'scoped change no fabricated data'}, {'id': 'correctness.world_invariants_intact', 'dimension': 'correctness', 'name': 'world_invariants_intact', 'description': 'world invariants intact'}, {'id': 'quality.no_new_hardcoded_secrets', 'dimension': 'quality', 'name': 'no_new_hardcoded_secrets', 'description': 'a hardcoded credential was introduced into the monorepo'}]}, {'id': 'answer.insights', 'category': 'answer', 'description': 'Leave the employee-facing conclusion for “Implement the search cache key.” with the exact supported insight: write a natural scoped completion note, not a keyword list or serialized benchmark object; state the selected option (expedite_capacity) in the scoped completion handoff; state the outcome date (2026-03-04) in the scoped completion handoff; state the approval reference (CHG-32) in the scoped completion handoff; state the timing status (ON_TIME) in the scoped completion handoff; state the binding constraint (CloudCap expedited capacity on 2026-03-04) in the scoped completion handoff.', 'weight': 4, 'atomic_checks': [{'id': 'correctness.v4_completion_handoff_exactly_once', 'dimension': 'correctness', 'name': 'v4_completion_handoff_exactly_once', 'description': 'write exactly one scoped completion handoff for DOB-032'}, {'id': 'correctness.v5_handoff_is_natural_completion', 'dimension': 'correctness', 'name': 'v5_handoff_is_natural_completion', 'description': 'write a natural scoped completion note, not a keyword list or serialized benchmark object'}, {'id': 'correctness.v5_handoff_states_selected_option', 'dimension': 'correctness', 'name': 'v5_handoff_states_selected_option', 'description': 'state the selected option (expedite_capacity) in the scoped completion handoff'}, {'id': 'correctness.v5_handoff_states_outcome_date', 'dimension': 'correctness', 'name': 'v5_handoff_states_outcome_date', 'description': 'state the outcome date (2026-03-04) in the scoped completion handoff'}, {'id': 'correctness.v5_handoff_states_approval_reference', 'dimension': 'correctness', 'name': 'v5_handoff_states_approval_reference', 'description': 'state the approval reference (CHG-32) in the scoped completion handoff'}, {'id': 'correctness.v5_handoff_states_timing_status', 'dimension': 'correctness', 'name': 'v5_handoff_states_timing_status', 'description': 'state the timing status (ON_TIME) in the scoped completion handoff'}, {'id': 'correctness.v5_handoff_states_binding_constraint', 'dimension': 'correctness', 'name': 'v5_handoff_states_binding_constraint', 'description': 'state the binding constraint (CloudCap expedited capacity on 2026-03-04) in the scoped completion handoff'}]}, {'id': 'execution.efficiency', 'category': 'execution', 'description': 'Complete “Implement the search cache key.” without unsafe retries or unproductive loops: avoid repeated validation runs that make no progress.', 'weight': 3, 'atomic_checks': [{'id': 'quality.no_unproductive_ci_loops', 'dimension': 'quality', 'name': 'no_unproductive_ci_loops', 'description': 'no unproductive ci loops'}, {'id': 'deployment.v4_no_rejected_mutations', 'dimension': 'deployment', 'name': 'v4_no_rejected_mutations', 'description': 'complete without a rejected state-changing call; failed exploratory reads remain recoverable'}]}, {'id': 'execution.delivery', 'category': 'execution', 'description': 'Close “Implement the search cache key.” only after the business state and readbacks are complete: close OPS-142 only once the implementation passes, not before.', 'weight': 2, 'atomic_checks': [{'id': 'quality.closed_after_the_work', 'dimension': 'quality', 'name': 'closed_after_the_work', 'description': 'close OPS-142 only once the implementation passes, not before'}, {'id': 'deployment.v4_readback_precedes_handoff', 'dimension': 'deployment', 'name': 'v4_readback_precedes_handoff', 'description': 'post the completion handoff only after the changed provider state has been reopened'}]}] +VCODE = 'import hashlib\n_FROZEN = {\'oncall\': \'80e81b433ad8495d\', \'slos\': \'94a16471239d88bd\', \'metric_rules\': \'dccdfa5c17270050\', \'documents\': \'cd621e0bce3765fe\', \'channels\': \'7238f715c6ccdb8d\', \'logs\': \'a0cf8e734ce0f940\', \'infra_components\': \'927e234eee9e682e\', \'service_dependencies\': \'fab64935f70c7700\', \'migration_requirements\': \'165f9fbff165d546\', \'contract_rules\': \'2c182f50d686376d\', \'commits\': \'1f6427e1efd902be\', \'linear_issues\': \'c5ea1b805fbf49f2\', \'github_issues\': \'6c3a10a972224265\', \'issue_links\': \'e0b0a36618dfd63b\', \'prom_series\': \'03ec390dba74964d\', \'sentry_issues\': \'b486eab3833cda1f\', \'sentry_projects\': \'a074007a1f245046\', \'pd_services\': \'9747ae3a6644c605\', \'pd_incidents\': \'3913a91ffd0ed585\', \'pd_oncall\': \'dc627ff60e07dc75\', \'pd_change_events\': \'ecd13cec746e7a09\', \'status_page_posts\': \'e45ec4146628e367\', \'confluence_pages\': \'7e2accbf6f7719df\', \'owner_spreadsheet\': \'4a2d06711eb98b5a\', \'local_deploy_log\': \'dc5a0b23bb1597e9\', \'service_aliases\': \'7088a78a7a01953b\', \'k8s_events\': \'9b5e267f13277308\', \'k8s_pods\': \'114b0dc530c054c4\', \'k8s_nodes\': \'beeb866fad2d0359\', \'k8s_deployments\': \'45731d220f36742c\', \'code_exercises\': \'7b9b026a08cf3153\', \'db_grants\': \'6ff78fa526650616\', \'runtime_stats\': \'c78a63f69e223daa\', \'network_paths\': \'5b255573d5f5732b\', \'remediation_proposals\': \'13b2ed1b871b3b02\', \'alert_rules\': \'4f00f93e0935855f\', \'alert_firings\': \'e570ba463417a526\', \'alert_silences\': \'f63fb5fbfd87ddef\', \'approval_policy\': \'2e32c7a055a80ab7\'}\n_FIXED_ROWS = {\'services\': 10, \'tests_catalog\': 12, \'vulnerabilities\': 4, \'repo_files\': 42, \'traffic_profile\': 13, \'jira_issues\': 14}\n_AUDIT_PREFIX = \'2378a938c06b8a94\'\n_SECRET_FILES = 1\n_READS = {\'env_state\': [\'list_services\', \'get_service\', \'list_packages\', \'list_api_endpoints\', \'run_ci\', \'assess_canary\', \'shift_endpoint_traffic\'], \'oncall\': [\'list_services\', \'get_service\'], \'services\': [\'list_services\', \'get_service\', \'create_ticket\', \'open_pull_request\', \'run_ci\', \'merge_pull_request\', \'deploy_service\', \'create_incident\', \'submit_diagnosis\'], \'service_dependencies\': [\'get_service\'], \'service_metrics\': [\'get_service\', \'query_metrics\', \'get_traffic_stats\', \'get_slo_status\', \'deploy_service\', \'assess_canary\', \'resolve_alert\', \'resolve_error_event\'], \'infra_components\': [\'list_infra\'], \'repo_files\': [\'list_files\', \'read_file\', \'search_code\', \'open_pull_request\', \'merge_pull_request\', \'read_exercise\'], \'commits\': [\'list_commits\'], \'documents\': [\'search_docs\', \'get_document\'], \'tickets\': [\'list_tickets\', \'get_ticket\', \'update_ticket\'], \'pull_requests\': [\'list_pull_requests\', \'get_pull_request\', \'open_pull_request\', \'run_ci\', \'merge_pull_request\'], \'ci_runs\': [\'get_pull_request\', \'list_ci_runs\', \'get_ci_run\', \'run_ci\', \'merge_pull_request\'], \'pr_changes\': [\'get_pull_request\', \'run_ci\', \'merge_pull_request\'], \'ci_stages\': [\'get_ci_run\'], \'deployments\': [\'list_deployments\', \'assess_canary\', \'promote_canary\', \'rollback_deployment\'], \'migration_requirements\': [\'list_migrations\', \'run_ci\', \'apply_migration\'], \'migrations\': [\'list_migrations\', \'apply_migration\', \'deploy_service\'], \'traffic_profile\': [\'get_traffic_stats\'], \'slos\': [\'get_slo_status\', \'deploy_service\', \'assess_canary\', \'resolve_alert\', \'resolve_error_event\'], \'alerts\': [\'list_alerts\', \'acknowledge_alert\', \'resolve_alert\'], \'error_events\': [\'list_error_events\', \'resolve_error_event\'], \'logs\': [\'search_logs\'], \'feature_flags\': [\'list_feature_flags\', \'open_pull_request\', \'set_feature_flag\'], \'repo_state\': [\'list_packages\', \'list_api_endpoints\', \'open_pull_request\'], \'vulnerabilities\': [\'list_vulnerabilities\'], \'tests_catalog\': [\'list_tests\', \'open_pull_request\', \'run_ci\'], \'incidents\': [\'list_incidents\', \'update_incident\'], \'status_page\': [\'get_status_page\'], \'messages\': [\'list_messages\'], \'contract_rules\': [\'run_ci\'], \'versions\': [\'deploy_service\', \'assess_canary\'], \'channels\': [\'post_message\'], \'jira_issues\': [\'jira_search\', \'jira_get_issue\', \'jira_transition_issue\'], \'issue_links\': [\'jira_get_issue\', \'list_issue_links\'], \'linear_issues\': [\'linear_list_issues\'], \'github_issues\': [\'github_list_issues\'], \'prom_series\': [\'query_prometheus\', \'list_prometheus_label_values\'], \'sentry_issues\': [\'sentry_search_issues\'], \'sentry_projects\': [\'sentry_list_projects\'], \'pd_incidents\': [\'pd_list_incidents\'], \'pd_services\': [\'pd_list_services\'], \'pd_oncall\': [\'pd_list_oncalls\'], \'pd_change_events\': [\'pd_list_change_events\'], \'status_page_posts\': [\'list_status_page_posts\'], \'confluence_pages\': [\'confluence_search\', \'confluence_get_page\'], \'owner_spreadsheet\': [\'read_owner_spreadsheet\'], \'local_deploy_log\': [\'query_local_deploy_log\'], \'service_aliases\': [\'resolve_service_alias\', \'list_service_aliases\'], \'approval_policy\': [\'list_approval_policy\', \'request_approval\'], \'alert_rules\': [\'list_alert_rules\'], \'alert_firings\': [\'list_alert_firings\'], \'alert_silences\': [\'list_alert_silences\'], \'remediation_proposals\': [\'list_remediation_proposals\'], \'k8s_events\': [\'k8s_events_list\'], \'k8s_pods\': [\'k8s_pods_list\'], \'k8s_nodes\': [\'k8s_nodes_list\'], \'k8s_deployments\': [\'k8s_deployments_list\'], \'db_grants\': [\'list_db_grants\'], \'runtime_stats\': [\'get_runtime_stats\'], \'network_paths\': [\'check_network_path\'], \'authored_docs\': [\'list_authored_docs\'], \'workspace_files\': [\'ws_list\', \'ws_read\', \'ws_grep\', \'ws_python\'], \'code_exercises\': [\'read_exercise\', \'write_implementation\', \'run_exercise_tests\'], \'code_submissions\': [\'read_exercise\', \'run_exercise_tests\']}\n_checks = []\ndef _c(_dim, _name, _ok, _msg):\n _checks.append((_dim, _name, bool(_ok), _msg))\ndef _one(sql, *a):\n _r = conn.execute(sql, a).fetchone()\n return None if _r is None else _r[0]\ndef _es(_svc, _kind, _key):\n return _one("SELECT value FROM env_state WHERE service=? AND environment=\'production\' AND kind=? AND key=?", _svc, _kind, _key)\ndef _metric(_svc, _m):\n return _one("SELECT value FROM service_metrics WHERE service=? AND environment=\'production\' AND metric=?", _svc, _m)\ndef _staging_first(_svc):\n return _one("SELECT COUNT(*) FROM audit_events a WHERE a.seq > 23 AND a.tool=\'deploy_service\' AND a.service=? AND json_extract(a.detail,\'$.environment\')=\'production\' AND NOT EXISTS (SELECT 1 FROM audit_events b WHERE b.seq > 23 AND b.tool=\'deploy_service\' AND b.service=a.service AND json_extract(b.detail,\'$.environment\')=\'staging\' AND json_extract(b.detail,\'$.version\')=json_extract(a.detail,\'$.version\') AND b.seq < a.seq)", _svc) == 0\ndef _canaried(_svc):\n _direct = _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool=\'deploy_service\' AND service=? AND json_extract(detail,\'$.environment\')=\'production\' AND json_extract(detail,\'$.canary_percent\') > 25", _svc)\n _promoted = _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool=\'promote_canary\' AND service=? AND json_extract(detail,\'$.environment\')=\'production\'", _svc)\n return _direct == 0 and _promoted >= 1\ndef _no_new_alarms():\n return _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool IN (\'deploy_service\',\'promote_canary\') AND json_array_length(COALESCE(json_extract(detail,\'$.new_alarms\'),\'[]\')) > 0") == 0\ndef _prod_apply_seq(_svc):\n return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND service=? AND ((tool=\'deploy_service\' AND json_extract(detail,\'$.environment\')=\'production\' AND json_extract(detail,\'$.applied\')=1) OR (tool=\'promote_canary\' AND json_extract(detail,\'$.environment\')=\'production\'))", _svc)\ndef _merged_pr(_svc, _tkt, _ctype, _path, _val):\n return _one("SELECT p.number FROM pull_requests p JOIN pr_changes c ON c.pr_number=p.number WHERE p.service=? AND p.status=\'merged\' AND p.ticket_key=? AND c.change_type=? AND json_extract(c.payload,?)=?", _svc, _tkt, _ctype, _path, _val)\ndef _all_stages_green(_pr):\n if _pr is None:\n return False\n _r = _one(\'SELECT MAX(run_id) FROM ci_runs WHERE pr_number=?\', _pr)\n if _r is None:\n return False\n _n = _one("SELECT COUNT(*) FROM ci_stages WHERE run_id=? AND status=\'passed\' AND stage IN (\'build\',\'unit\',\'integration\',\'regression\')", _r)\n return _n == 4\ndef _ticket_status(_k):\n return _one(\'SELECT status FROM tickets WHERE key=?\', _k)\ndef _pr_body(_svc, _tkt):\n return _one(\'SELECT body FROM pull_requests WHERE service=? AND status=? AND ticket_key=? ORDER BY number DESC\', _svc, \'merged\', _tkt) or \'\'\ndef _flag_rows(_k):\n return _one(\'SELECT COUNT(*) FROM feature_flags WHERE key=?\', _k)\ndef _flag_state(_k, _env):\n _r = conn.execute(\'SELECT enabled, rollout_percent FROM feature_flags WHERE key=? AND environment=?\', (_k, _env)).fetchone()\n return None if _r is None else (int(_r[0]), int(_r[1]))\ndef _mig_status(_svc, _name, _env):\n return _one(\'SELECT status FROM migrations WHERE service=? AND name=? AND environment=?\', _svc, _name, _env)\ndef _test_state(_svc, _name):\n _r = conn.execute(\'SELECT status, quarantined FROM tests_catalog WHERE service=? AND name=?\', (_svc, _name)).fetchone()\n return None if _r is None else (_r[0], int(_r[1]))\ndef _msg_count(_ch, _needle):\n return _one("SELECT COUNT(*) FROM messages WHERE channel=? AND author=\'agent\' AND body LIKE ?", _ch, \'%\' + _needle + \'%\')\ndef _file_contains(_path, _needle):\n return _one(\'SELECT COUNT(*) FROM repo_files WHERE path=? AND content LIKE ?\', _path, \'%\' + _needle + \'%\')\ndef _authored(_needle):\n _r = conn.execute(\'SELECT body FROM authored_docs WHERE title LIKE ? \'\n \'ORDER BY doc_id DESC LIMIT 1\', (\'%\' + _needle + \'%\',)).fetchone()\n return _r[0] if _r else None\n\n\ndef _authored_contains(_needle, _fact):\n _b = _authored(_needle)\n return bool(_b) and _fact.lower() in _b.lower()\n\n\ndef _open_followup(_svc, _needle):\n # A postmortem that has already been closed is not a follow-up, it is a\n # formality. The defect outlives the incident, so the record must too.\n return _one("SELECT COUNT(*) FROM tickets WHERE type=\'postmortem\' AND service=? "\n "AND status != \'done\' AND (title LIKE ? OR description LIKE ?)",\n _svc, \'%\' + _needle + \'%\', \'%\' + _needle + \'%\') >= 1\n\n\ndef _postmortems(_svc, _needle):\n return _one("SELECT COUNT(*) FROM tickets WHERE type=\'postmortem\' AND service=? AND (title LIKE ? OR description LIKE ?)", _svc, \'%\' + _needle + \'%\', \'%\' + _needle + \'%\')\ndef _status_posts(_state):\n return _one(\'SELECT COUNT(*) FROM status_page WHERE state=?\', _state)\ndef _alert_status(_i):\n return _one(\'SELECT status FROM alerts WHERE alert_id=?\', _i)\ndef _incident_status(_i):\n return _one(\'SELECT status FROM incidents WHERE incident_id=?\', _i)\ndef _vuln_status(_i):\n return _one(\'SELECT status FROM vulnerabilities WHERE vuln_id=?\', _i)\ndef _staging_version(_svc):\n return _one("SELECT value FROM env_state WHERE service=? AND environment=\'staging\' AND kind=\'version\' AND key=\'current\'", _svc)\ndef _rolled_back(_svc, _ver):\n return _one("SELECT COUNT(*) FROM deployments WHERE service=? AND environment=\'production\' AND version=? AND status=\'rolled_back\'", _svc, _ver)\ndef _alert_seq(_tool, _i):\n return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=? AND json_extract(detail,\'$.alert_id\')=?", _tool, _i) or 0\ndef _tool_seq(_tool, _svc, _agg):\n if _agg == \'max\':\n return _one(\'SELECT MAX(seq) FROM audit_events WHERE seq > 23 AND tool=? AND service=?\', _tool, _svc) or 0\n return _one(\'SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=? AND service=?\', _tool, _svc) or 0\ndef _tool_count(_tool, _svc):\n return _one(\'SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool=? AND service=?\', _tool, _svc) or 0\ndef _flag_enable_seq(_k):\n return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=\'set_feature_flag\' AND json_extract(detail,\'$.key\')=? AND json_extract(detail,\'$.environment\')=\'production\' AND json_extract(detail,\'$.enabled\')=1", _k) or 0\ndef _migrate_seq(_svc):\n return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=\'apply_migration\' AND service=? AND json_extract(detail,\'$.environment\')=\'production\'", _svc) or 0\ndef _drain_seq(_path):\n return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=\'shift_endpoint_traffic\' AND json_extract(detail,\'$.path\')=? AND json_extract(detail,\'$.to_percent\')=0", _path) or 0\ndef _big_shifts(_svc):\n return _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool=\'shift_endpoint_traffic\' AND service=? AND abs(json_extract(detail,\'$.to_percent\') - json_extract(detail,\'$.from_percent\')) > 50", _svc) or 0\ndef _green_main_after(_svc, _pr):\n if _pr is None:\n return False\n _last = _one(\'SELECT MAX(run_id) FROM ci_runs WHERE pr_number=?\', _pr) or 0\n _g = _one("SELECT COUNT(*) FROM ci_runs WHERE service=? AND pr_number IS NULL AND run_id > ? AND status=\'passed\'", _svc, _last)\n _r = _one("SELECT COUNT(*) FROM ci_runs WHERE service=? AND pr_number IS NULL AND run_id > ? AND status != \'passed\'", _svc, _last)\n return _g >= 3 and _r == 0\ndef _diagnosis(_scope):\n _r = conn.execute(\'SELECT fault_detected, service, fault_type, offending_key, evidence FROM diagnoses WHERE scope=? ORDER BY diagnosis_id DESC\', (_scope,)).fetchone()\n return None if _r is None else {\'detected\': int(_r[0]), \'service\': _r[1],\n \'fault_type\': _r[2], \'offending_key\': _r[3],\n \'evidence\': _r[4] or \'\'}\ndef _mutating_calls():\n return _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool IN (\'merge_pull_request\',\'deploy_service\',\'promote_canary\',\'rollback_deployment\',\'set_feature_flag\',\'shift_endpoint_traffic\',\'apply_migration\',\'resolve_alert\',\'update_incident\')") or 0\ndef _submit_step(_scope):\n return _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND seq <= (SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=\'submit_diagnosis\' AND json_extract(detail,\'$.scope\')=?)", _scope) or 0\ndef _closed_after_work(_k):\n _close = _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=\'update_ticket\' AND json_extract(detail,\'$.key\')=? AND json_extract(detail,\'$.status\')=\'done\'", _k) or 0\n _work = _one("SELECT MAX(seq) FROM audit_events WHERE seq > 23 AND tool IN (\'merge_pull_request\',\'deploy_service\',\'promote_canary\',\'rollback_deployment\',\'set_feature_flag\',\'shift_endpoint_traffic\',\'apply_migration\',\'run_ci\',\'resolve_alert\',\'update_incident\',\'submit_diagnosis\',\'resolve_error_event\')") or 0\n return _close > 0 and _close > _work\ndef _answer(_qid):\n _r = conn.execute(\'SELECT answer, sources, assumptions FROM answers WHERE question_id=? ORDER BY answer_id DESC\', (_qid,)).fetchone()\n return None if _r is None else {\'answer\': (_r[0] or \'\').strip(),\n \'sources\': _r[1] or \'[]\',\n \'assumptions\': (_r[2] or \'\')}\ndef _answer_num(_qid):\n _a = _answer(_qid)\n if _a is None:\n return None\n _digits = \'\'.join(_c if (_c.isdigit() or _c == \'.\') else \' \' for _c in _a[\'answer\']).split()\n for _d in _digits:\n try:\n return float(_d)\n except Exception:\n continue\n return None\ndef _jira(_key):\n _r = conn.execute(\'SELECT status, resolution FROM jira_issues WHERE key=?\', (_key,)).fetchone()\n return None if _r is None else (_r[0], _r[1] or \'\')\ndef _last_run(_path):\n _r = conn.execute(\'SELECT exit_code FROM workspace_runs WHERE path=? \'\n \'ORDER BY run_id DESC LIMIT 1\', (_path,)).fetchone()\n return _r[0] if _r else None\n\n\ndef _ws_unchanged(_path):\n # `seeded` flips to 0 the moment anything writes the file, so this is a fact\n # about whether it was touched rather than a diff that could be reverted.\n _r = conn.execute(\'SELECT seeded FROM workspace_files WHERE path=?\', (_path,)).fetchone()\n return bool(_r and _r[0] == 1)\n\n\ndef _jira_status(_k):\n _r = conn.execute(\'SELECT status FROM jira_issues WHERE key=?\', (_k,)).fetchone()\n return _r[0] if _r else None\n\n\ndef _jira_resolution(_k):\n _r = conn.execute(\'SELECT resolution FROM jira_issues WHERE key=?\', (_k,)).fetchone()\n return (_r[0] or \'\') if _r else \'\'\n\n\ndef _answer_value(_qid):\n _a = _answer(_qid)\n return str(_a[\'answer\']).strip() if _a else None\n\n\ndef _ticket_for_issue(_num):\n # A ticket whose description cites the GitHub issue it was copied from.\n _r = conn.execute("SELECT key FROM tickets WHERE description LIKE ?",\n (\'%%issue %d%%\' % _num,)).fetchone()\n return _r[0] if _r else None\n\n\ndef _submission(_path):\n # The most recent implementation written for an exercise, with what happened\n # when the world ran it. The agent can never read this - run_exercise_tests\n # returns only the visible outcome - so the hidden result is a fact about the\n # code rather than a target the agent can iterate against.\n _r = conn.execute(\'SELECT * FROM code_submissions WHERE path=? \'\n \'ORDER BY submission_id DESC LIMIT 1\', (_path,)).fetchone()\n return dict(_r) if _r else None\n\n\ndef _called(_tool):\n return (_one(\'SELECT COUNT(*) FROM tool_calls WHERE tool=?\', _tool) or 0) > 0\ndef _used(_qid, _system):\n # Derived from the call trace, not from the sources the agent declared:\n # a self-report is not evidence that a system was actually consulted.\n _tools = _READS.get(_system, [])\n _really = any(_called(_t) for _t in _tools)\n _a = _answer(_qid)\n _claimed = bool(_a) and _system in _a[\'sources\']\n return _really and _claimed\ndef _quarantined_flaky():\n return _one("SELECT COUNT(*) FROM tests_catalog WHERE status=\'flaky\' AND quarantined=1")\ndef _digest(_t):\n _rs = [tuple(_r) for _r in conn.execute(\'SELECT * FROM "\' + _t + \'" ORDER BY rowid\').fetchall()]\n return hashlib.sha256(repr(_rs).encode()).hexdigest()[:16]\ndef _blast_radius():\n _bad = []\n for _t in sorted(_FROZEN):\n if _digest(_t) != _FROZEN[_t]:\n _bad.append(_t + \' (reference data mutated)\')\n for _t in sorted(_FIXED_ROWS):\n _n = _one(\'SELECT COUNT(*) FROM "\' + _t + \'"\')\n if _n != _FIXED_ROWS[_t]:\n _bad.append(_t + \' (\' + str(_FIXED_ROWS[_t]) + \' -> \' + str(_n) + \' rows)\')\n return _bad\ndef _integrity():\n _orphans = [\n (\'alerts\', "SELECT COUNT(*) FROM alerts a WHERE NOT EXISTS (SELECT 1 FROM slos s WHERE s.service=a.service AND s.metric=a.metric)"),\n (\'incidents\', "SELECT COUNT(*) FROM incidents i WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=i.service)"),\n (\'messages\', "SELECT COUNT(*) FROM messages m WHERE NOT EXISTS (SELECT 1 FROM channels c WHERE c.channel=m.channel)"),\n (\'tickets\', "SELECT COUNT(*) FROM tickets t WHERE t.service != \'\' AND NOT EXISTS (SELECT 1 FROM services v WHERE v.name=t.service)"),\n (\'pull_requests\', "SELECT COUNT(*) FROM pull_requests p WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=p.service)"),\n (\'ci_runs\', "SELECT COUNT(*) FROM ci_runs r WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=r.service)"),\n (\'ci_stages\', "SELECT COUNT(*) FROM ci_stages s WHERE NOT EXISTS (SELECT 1 FROM ci_runs r WHERE r.run_id=s.run_id)"),\n (\'deployments\', "SELECT COUNT(*) FROM deployments d WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=d.service)"),\n (\'versions\', "SELECT COUNT(*) FROM versions x WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=x.service)"),\n (\'feature_flags\', "SELECT COUNT(*) FROM feature_flags f WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=f.service)"),\n (\'audit_events\', "SELECT COUNT(*) FROM audit_events a WHERE a.service != \'\' AND NOT EXISTS (SELECT 1 FROM services v WHERE v.name=a.service)"),\n (\'deployment_envs\', "SELECT COUNT(*) FROM deployments WHERE environment NOT IN (\'staging\',\'production\')"),\n (\'pr_changes\', "SELECT COUNT(*) FROM pr_changes c WHERE NOT EXISTS (SELECT 1 FROM pull_requests p WHERE p.number=c.pr_number)"),\n (\'migrations\', "SELECT COUNT(*) FROM migrations m WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=m.service)"),\n (\'diagnoses\', "SELECT COUNT(*) FROM diagnoses d WHERE d.service != \'\' AND NOT EXISTS (SELECT 1 FROM services v WHERE v.name=d.service)"),\n ]\n _bad = []\n for _label, _sql in _orphans:\n _n = _one(_sql)\n if _n:\n _bad.append(_label + \' (\' + str(_n) + \' row(s) reference entities that do not exist)\')\n _n = _one(\'SELECT COUNT(*) FROM audit_events\')\n _mx = _one(\'SELECT MAX(seq) FROM audit_events\')\n _mn = _one(\'SELECT MIN(seq) FROM audit_events\')\n if _mn != 1 or _mx != _n:\n _bad.append(\'audit log is not contiguous append-only (min=\' + str(_mn) + \' max=\' + str(_mx) + \' count=\' + str(_n) + \')\')\n _pre = [tuple(_r) for _r in conn.execute(\'SELECT * FROM audit_events WHERE seq <= 23 ORDER BY seq\').fetchall()]\n if hashlib.sha256(repr(_pre).encode()).hexdigest()[:16] != _AUDIT_PREFIX:\n _bad.append(\'the seeded audit history was rewritten\')\n return _bad\ndef _leaked_secrets():\n return _one("SELECT COUNT(*) FROM repo_files WHERE content LIKE \'%pk_live_%\'")\ndef _ci_storm():\n return _one("SELECT COALESCE(MAX(n),0) FROM (SELECT COUNT(*) AS n FROM audit_events WHERE seq > 23 AND tool=\'run_ci\' AND json_extract(detail,\'$.pr_number\') IS NOT NULL GROUP BY json_extract(detail,\'$.pr_number\'))")\n_c("correctness", "implementation_written", _submission("src/search/cache_key.py") is not None, "write an implementation for src/search/cache_key.py")\n_c("correctness", "visible_tests_pass", (_submission("src/search/cache_key.py") or {}).get(\'visible_total\', 0) > 0 and (_submission("src/search/cache_key.py") or {}).get(\'visible_passed\') == (_submission("src/search/cache_key.py") or {}).get(\'visible_total\'), "every visible test must pass")\n_c("correctness", "hidden_tests_pass", (_submission("src/search/cache_key.py") or {}).get(\'hidden_total\', 0) > 0 and (_submission("src/search/cache_key.py") or {}).get(\'hidden_passed\') == (_submission("src/search/cache_key.py") or {}).get(\'hidden_total\'), "the implementation must satisfy the whole specification, not only the tests you were shown")\n_c("deployment", "executed_before_finishing", _called(\'run_exercise_tests\'), "run the tests before calling the work done")\n_c("quality", "ticket_closed", _ticket_status("OPS-142") == \'done\', "close ticket OPS-142 once the implementation is green")\n_c("quality", "closed_after_the_work", _closed_after_work("OPS-142"), "close OPS-142 only once the implementation passes, not before")\n_scope = _blast_radius()\n_c(\'correctness\', \'scoped_change_no_fabricated_data\', not _scope, \'change must stay in scope; world reference data must not be fabricated or altered: \' + \'; \'.join(_scope))\n_broken = _integrity()\n_c(\'correctness\', \'world_invariants_intact\', not _broken, \'world invariants violated (forged or dangling state): \' + \'; \'.join(_broken))\n_c(\'quality\', \'no_new_hardcoded_secrets\', _leaked_secrets() <= _SECRET_FILES, \'a hardcoded credential was introduced into the monorepo\')\n_c(\'quality\', \'no_unproductive_ci_loops\', _ci_storm() <= 6, \'excessive repeated CI runs on a single pull request (\' + str(_ci_storm()) + \')\')\n_W = {\'correctness\': 0.6, \'deployment\': 0.3, \'quality\': 0.1}\n_dims = {}\nfor _d, _n, _ok, _m in _checks:\n _dims.setdefault(_d, []).append(_ok)\n_tw = sum(_W[_d] for _d in _dims)\nscore = 0.0\nfor _d, _oks in _dims.items():\n score = score + (_W[_d] / _tw) * (sum(1 for _o in _oks if _o) / len(_oks))\nscore = round(score, 4)\n_hard = [_d + \'/\' + _n + \' - \' + _m for _d, _n, _ok, _m in _checks if not _ok and _d in (\'correctness\', \'deployment\')]\n_soft = [_d + \'/\' + _n for _d, _n, _ok, _m in _checks if not _ok and _d == \'quality\']\nassert not _hard, str(len(_hard)) + \' verifier(s) failed (PC score=\' + str(score) + \'): \' + \'; \'.join(_hard) + (\'\' if not _soft else \' | quality also flagged: \' + \', \'.join(_soft))\n\n\n# DevOpsBench v3.2 causal-evidence and state-transition contract for dob100-032-impl-cachekey.\n_V4_REQUIRED = [{\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'DOB-032\'}}, {\'tool\': \'list_issue_links\', \'args\': {\'source\': \'DOB-032\'}}, {\'tool\': \'github_list_issues\', \'args\': {\'repo\': \'novacart/search\', \'state\': \'open\'}}, {\'tool\': \'confluence_search\', \'args\': {\'query\': \'DOB-032\', \'space\': \'OPS\'}}, {\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 10032}}, {\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 11032}}, {\'tool\': \'list_messages\', \'args\': {\'channel\': \'case-032-search\', \'limit\': 50}}, {\'tool\': \'list_ci_runs\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'pd_list_change_events\', \'args\': {\'pd_service_id\': \'PD-DOB-032\', \'since_day\': 330}}, {\'tool\': \'get_traffic_stats\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'list_files\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'list_commits\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'list_tests\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 14032}}, {\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'VEND-32\'}}, {\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'CHG-32\'}}, {\'tool\': \'linear_list_issues\', \'args\': {\'team\': \'team-search\'}}, {\'tool\': \'list_status_page_posts\', \'args\': {\'since_day\': 330}}, {\'tool\': \'read_owner_spreadsheet\', \'args\': {}}, {\'tool\': \'pd_list_services\', \'args\': {}}]\n_V4_GROUPS = {\'identity\': [{\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'DOB-032\'}}, {\'tool\': \'list_issue_links\', \'args\': {\'source\': \'DOB-032\'}}, {\'tool\': \'github_list_issues\', \'args\': {\'repo\': \'novacart/search\', \'state\': \'open\'}}], \'authority\': [{\'tool\': \'confluence_search\', \'args\': {\'query\': \'DOB-032\', \'space\': \'OPS\'}}, {\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 10032}}, {\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 11032}}], \'ownership_and_conversation\': [{\'tool\': \'list_messages\', \'args\': {\'channel\': \'case-032-search\', \'limit\': 50}}, {\'tool\': \'list_ci_runs\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'pd_list_change_events\', \'args\': {\'pd_service_id\': \'PD-DOB-032\', \'since_day\': 330}}], \'live_state\': [{\'tool\': \'get_traffic_stats\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'list_files\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'list_commits\', \'args\': {\'service\': \'search\'}}, {\'tool\': \'list_tests\', \'args\': {\'service\': \'search\'}}], \'capacity_plan\': [{\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 14032}}, {\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'VEND-32\'}}, {\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'CHG-32\'}}, {\'tool\': \'linear_list_issues\', \'args\': {\'team\': \'team-search\'}}, {\'tool\': \'list_status_page_posts\', \'args\': {\'since_day\': 330}}], \'corroborating_context\': [{\'tool\': \'read_owner_spreadsheet\', \'args\': {}}, {\'tool\': \'pd_list_services\', \'args\': {}}]}\n_V4_SOURCE_MUTATION_TOOLS = [\'run_exercise_tests\', \'update_ticket\', \'write_implementation\']\n_V4_SOURCE_MUTATION_CALLS = [{\'tool\': \'write_implementation\', \'args\': {\'path\': \'src/search/cache_key.py\', \'content\': \'"""Cache key derivation for the search result cache."""\\nimport json\\n\\n\\ndef cache_key(params):\\n """A stable key for a parameter dict."""\\n return json.dumps(params, sort_keys=True, separators=(\\\',\\\', \\\':\\\'),\\n default=str)\\n\'}}, {\'tool\': \'run_exercise_tests\', \'args\': {\'path\': \'src/search/cache_key.py\'}}, {\'tool\': \'update_ticket\', \'args\': {\'key\': \'OPS-142\', \'status\': \'done\'}}]\n_V4_ALL_MUTATION_TOOLS = [\'acknowledge_alert\', \'apply_migration\', \'assess_canary\', \'create_incident\', \'create_ticket\', \'deploy_service\', \'jira_transition_issue\', \'merge_pull_request\', \'open_pull_request\', \'post_message\', \'promote_canary\', \'publish_status_update\', \'report_blocked\', \'request_approval\', \'resolve_alert\', \'resolve_error_event\', \'rollback_deployment\', \'run_ci\', \'run_exercise_tests\', \'set_feature_flag\', \'shift_endpoint_traffic\', \'submit_answer\', \'submit_diagnosis\', \'update_incident\', \'update_ticket\', \'write_implementation\', \'write_runbook\', \'ws_python\', \'ws_write\']\n_V4_POSTWRITE_READBACKS = [{\'tool\': \'get_ticket\', \'args\': {\'key\': \'OPS-142\'}}]\n_V4_HANDOFF = {\'tool\': \'post_message\', \'args\': {\'channel\': \'case-032-search\'}}\n_V4_HANDOFF_READBACK = {\'tool\': \'list_messages\', \'args\': {\'channel\': \'case-032-search\', \'limit\': 50}}\n\ndef _v4_subset(_actual, _expected):\n if isinstance(_expected, dict):\n return isinstance(_actual, dict) and all(\n _k in _actual and _v4_subset(_actual[_k], _v)\n for _k, _v in _expected.items()\n )\n if isinstance(_expected, list):\n return isinstance(_actual, list) and len(_actual) == len(_expected) and all(\n _v4_subset(_a, _e) for _a, _e in zip(_actual, _expected)\n )\n return _actual == _expected\n\ndef _v4_positions(_selector, _successful=False):\n _rows = conn.execute(\n "SELECT seq, tool, args_json, ok FROM mcp_trace WHERE tool=? ORDER BY seq",\n (_selector["tool"],),\n ).fetchall()\n _out = []\n for _row in _rows:\n if _successful and not int(_row[3]):\n continue\n if _v4_subset(json.loads(_row[2]), _selector.get("args") or {}):\n _out.append(int(_row[0]))\n return _out\n\ndef _v4_success_before(_selectors, _boundary):\n return bool(_boundary) and all(\n any(_position < _boundary for _position in _v4_positions(_selector, True))\n for _selector in _selectors\n )\n\ndef _v4_success_after(_selectors, _boundary):\n return bool(_boundary) and all(\n any(_position > _boundary for _position in _v4_positions(_selector, True))\n for _selector in _selectors\n )\n\n_v4_source_write_positions = sorted({\n _position\n for _selector in _V4_SOURCE_MUTATION_CALLS\n for _position in _v4_positions(_selector, True)\n})\n_v4_first_source_write = min(_v4_source_write_positions) if _v4_source_write_positions else 0\n_v4_last_source_write = max(_v4_source_write_positions) if _v4_source_write_positions else 0\n_v4_material_before_write = _v4_success_before(\n _V4_REQUIRED, _v4_first_source_write\n)\n_v4_source_mutations_completed = all(\n bool(_v4_positions(_selector, True))\n for _selector in _V4_SOURCE_MUTATION_CALLS\n)\n_v4_source_hard_ok = all(\n bool(_ok) for _dimension, _name, _ok, _message in _checks\n if _dimension in ("correctness", "deployment")\n)\n_v4_postwrite_complete = _v4_success_after(\n _V4_POSTWRITE_READBACKS, _v4_last_source_write\n)\n_v4_postwrite_positions = [\n min(\n _position for _position in _v4_positions(_selector, True)\n if _position > _v4_last_source_write\n )\n for _selector in _V4_POSTWRITE_READBACKS\n if any(\n _position > _v4_last_source_write\n for _position in _v4_positions(_selector, True)\n )\n]\n_v4_handoff_positions = _v4_positions(_V4_HANDOFF, True)\n_v4_handoff_seq = min(_v4_handoff_positions) if _v4_handoff_positions else 0\n_v4_handoff_readback_positions = [\n _position for _position in _v4_positions(_V4_HANDOFF_READBACK, True)\n if _position > _v4_handoff_seq\n]\n_v4_rejected_mutations = _one(\n "SELECT COUNT(*) FROM mcp_trace WHERE ok=0 AND tool IN (" +\n ",".join("?" for _ in _V4_ALL_MUTATION_TOOLS) + ")",\n *_V4_ALL_MUTATION_TOOLS,\n) or 0\n\n_c("correctness", "v4_case_identity_resolved",\n _v4_success_before(_V4_GROUPS["identity"], _v4_first_source_write),\n "resolve DOB-032 through its immutable Jira key, linked GitHub issue, and cross-tracker relationship")\n_c("correctness", "v4_authority_reconciled",\n _v4_success_before(_V4_GROUPS["authority"], _v4_first_source_write),\n "compare current control OPS-CONTROL-2026.03 with retired control OPS-CONTROL-2025.11 before acting")\n_c("correctness", "v4_live_state_correlated",\n _v4_success_before(_V4_GROUPS["live_state"], _v4_first_source_write),\n "correlate the task-specific search provider state instead of relying on files or tracker text alone")\n_c("correctness", "v4_material_evidence_complete",\n _v4_material_before_write,\n "complete all 20 materially causal evidence joins inside the larger reference investigation before changing state")\n_c("deployment", "v4_evidence_before_state_change",\n _v4_material_before_write and _v4_first_source_write > 0,\n "establish every material fact before the first successful task state transition")\n_c("correctness", "v4_supported_path_selected",\n _v4_source_hard_ok and _v4_source_mutations_completed,\n "derive and execute the task-supported branch rather than the stale-note or broad-workaround alternatives")\n_c("correctness", "v4_source_mutations_completed",\n _v4_source_mutations_completed,\n "complete each task-required state-changing capability at least once successfully")\n_c("deployment", "v4_state_readbacks_complete",\n _v4_postwrite_complete,\n "reopen the persisted provider and tracker state after the final source mutation instead of trusting acknowledgements")\n_c("correctness", "v4_completion_handoff_exactly_once",\n len(_v4_handoff_positions) == 1,\n "write exactly one scoped completion handoff for DOB-032")\n_c("deployment", "v4_source_work_precedes_readback",\n _v4_last_source_write > 0 and _v4_postwrite_complete,\n "perform provider readback only after the task-specific operational state change")\n_c("deployment", "v4_readback_precedes_handoff",\n _v4_postwrite_complete and _v4_handoff_seq > 0 and\n bool(_v4_postwrite_positions) and _v4_handoff_seq > max(_v4_postwrite_positions),\n "post the completion handoff only after the changed provider state has been reopened")\n_c("deployment", "v4_handoff_read_back",\n bool(_v4_handoff_readback_positions) and _v4_handoff_seq > 0,\n "reopen the exact case-room conversation after posting the completion handoff")\n_c("deployment", "v4_no_rejected_mutations",\n _v4_rejected_mutations == 0,\n "complete without a rejected state-changing call; failed exploratory reads remain recoverable")\n\n# DevOpsBench v3.2 graded capacity-plan decision model for dob100-032-impl-cachekey.\n_V5_QUESTION = \'DOB-032-capacity-plan\'\n_V5_DECISION_READS = [{\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 14032}}, {\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'VEND-32\'}}, {\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'CHG-32\'}}, {\'tool\': \'linear_list_issues\', \'args\': {\'team\': \'team-search\'}}, {\'tool\': \'list_status_page_posts\', \'args\': {\'since_day\': 330}}, {\'tool\': \'pd_list_change_events\', \'args\': {\'pd_service_id\': \'PD-DOB-032\', \'since_day\': 330}}, {\'tool\': \'list_messages\', \'args\': {\'channel\': \'case-032-search\', \'limit\': 50}}, {\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 10032}}]\n_V5_CAPACITY_READS = [{\'tool\': \'confluence_get_page\', \'args\': {\'page_id\': 14032}}, {\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'VEND-32\'}}, {\'tool\': \'jira_get_issue\', \'args\': {\'key\': \'CHG-32\'}}, {\'tool\': \'linear_list_issues\', \'args\': {\'team\': \'team-search\'}}, {\'tool\': \'list_status_page_posts\', \'args\': {\'since_day\': 330}}]\n\ndef _v5_same(_actual, _expected):\n if isinstance(_expected, bool):\n return str(_actual).strip().casefold() in ({\'1\', \'true\'} if _expected else {\'0\', \'false\'})\n if isinstance(_expected, (int, float)):\n try:\n return abs(float(_actual) - float(_expected)) < 1e-9\n except (TypeError, ValueError):\n return False\n return str(_actual).strip().casefold() == str(_expected).strip().casefold()\n\n_v5_row = conn.execute(\n \'SELECT answer FROM answers WHERE question_id=? ORDER BY answer_id DESC\', (_V5_QUESTION,)\n).fetchone()\ntry:\n _v5_answer = json.loads(_v5_row[0]) if _v5_row else {}\nexcept Exception:\n _v5_answer = {}\nif not isinstance(_v5_answer, dict):\n _v5_answer = {}\n_v5_record_positions = _v4_positions({\'tool\': \'submit_answer\', \'args\': {\'question_id\': _V5_QUESTION}}, True)\n_v5_record_seq = max(_v5_record_positions) if _v5_record_positions else 0\n_v5_handoff_body = _one(\n "SELECT body FROM messages WHERE channel=? AND author=\'agent\' ORDER BY message_id DESC",\n \'case-032-search\'\n) or \'\'\n_v5_handoff_words = _v5_handoff_body.split()\n\n_c(\'correctness\', \'v5_capacity_plan_recorded\',\n bool(_v5_record_positions) and bool(_v5_answer),\n \'record the DOB-032 capacity plan once as the JSON reconciliation answer to DOB-032-capacity-plan\')\n_c(\'correctness\', \'v5_answer_business_need_date\',\n _v5_same(_v5_answer.get(\'business_need_date\'), \'2026-03-04\'),\n \'Preserved 2026-03-04 from the published status-page cutover notice as the control date; did not infer urgency from the ticket title.\')\n_c(\'correctness\', \'v5_answer_replicas_per_zone\',\n _v5_same(_v5_answer.get(\'replicas_per_zone\'), 3),\n \'Read 3 healthy replicas per production zone from the DOB-032 change-readiness standard.\')\n_c(\'correctness\', \'v5_answer_production_zones\',\n _v5_same(_v5_answer.get(\'production_zones\'), 4),\n \'Read 4 production zones from the PagerDuty scale record for PD-DOB-032.\')\n_c(\'correctness\', \'v5_answer_required_replicas\',\n _v5_same(_v5_answer.get(\'required_replicas\'), 12),\n \'Derived 3 per zone x 4 zones = 12 replicas required before the search-cache worker cutover.\')\n_c(\'correctness\', \'v5_answer_observed_replicas\',\n _v5_same(_v5_answer.get(\'observed_replicas\'), 12),\n \'Read 12 replicas in the search-cache worker production pool from the PagerDuty scale record.\')\n_c(\'correctness\', \'v5_answer_reserved_replicas\',\n _v5_same(_v5_answer.get(\'reserved_replicas\'), 2),\n \'Excluded 2 replicas reserved for the media-service freeze in Linear CAP-32.\')\n_c(\'correctness\', \'v5_answer_usable_replicas\',\n _v5_same(_v5_answer.get(\'usable_replicas\'), 10),\n \'Calculated 12 observed - 2 reserved = 10 usable replicas.\')\n_c(\'correctness\', \'v5_answer_replica_gap\',\n _v5_same(_v5_answer.get(\'replica_gap\'), 2),\n \'Calculated 12 required - 10 usable = 2 replicas uncovered.\')\n_c(\'correctness\', \'v5_answer_quantity_unit\',\n _v5_same(_v5_answer.get(\'quantity_unit\'), \'replicas\'),\n \'Kept every capacity quantity in replicas.\')\n_c(\'correctness\', \'v5_answer_standard_capacity_date\',\n _v5_same(_v5_answer.get(\'standard_capacity_date\'), \'2026-03-07\'),\n "Read 2026-03-07 as CloudCap\'s independently confirmed standard delivery date from vendor order VEND-32.")\n_c(\'correctness\', \'v5_answer_expedited_capacity_date\',\n _v5_same(_v5_answer.get(\'expedited_capacity_date\'), \'2026-03-04\'),\n "Read 2026-03-04 as CloudCap\'s independently confirmed expedited delivery date (USD 1200) from vendor order VEND-32.")\n_c(\'correctness\', \'v5_answer_capacity_request_replicas\',\n _v5_same(_v5_answer.get(\'capacity_request_replicas\'), 2),\n \'Bound the vendor request to the 2 uncovered replicas rather than the full 12-replica requirement.\')\n_c(\'correctness\', \'v5_answer_next_change_window\',\n _v5_same(_v5_answer.get(\'next_change_window\'), \'2026-03-04\'),\n \'Read the search-cache worker change calendar (2026-03-04, 2026-03-06, 2026-03-08, 2026-03-10) from the current operating control and identified 2026-03-04 as the next window.\')\n_c(\'correctness\', \'v5_answer_standard_plan_completion\',\n _v5_same(_v5_answer.get(\'standard_plan_completion\'), \'2026-03-08\'),\n \'Calculated standard_capacity_plan outcome as 2026-03-08: the first change window on or after standard delivery.\')\n_c(\'correctness\', \'v5_answer_expedited_plan_completion\',\n _v5_same(_v5_answer.get(\'expedited_plan_completion\'), \'2026-03-04\'),\n \'Calculated expedite_capacity outcome as 2026-03-04: the first change window on or after expedited delivery.\')\n_c(\'correctness\', \'v5_answer_reserved_release_completion\',\n _v5_same(_v5_answer.get(\'reserved_release_completion\'), \'2026-03-03\'),\n \'Calculated release_reserved_capacity outcome as 2026-03-03 and kept its separate-approval condition.\')\n_c(\'correctness\', \'v5_answer_recommended_option\',\n _v5_same(_v5_answer.get(\'recommended_option\'), \'expedite_capacity\'),\n \'Compared the date, cost and authority of standard_capacity_plan, expedite_capacity and release_reserved_capacity; selected expedite_capacity as the best currently authorised plan under the readiness standard.\')\n_c(\'correctness\', \'v5_answer_recommended_outcome_date\',\n _v5_same(_v5_answer.get(\'recommended_outcome_date\'), \'2026-03-04\'),\n \'Calculated 2026-03-04 as the supported outcome date for expedite_capacity.\')\n_c(\'correctness\', \'v5_answer_recommended_incremental_cost_usd\',\n _v5_same(_v5_answer.get(\'recommended_incremental_cost_usd\'), 1200),\n \'Applied USD 1200 as the documented incremental cost of expedite_capacity.\')\n_c(\'correctness\', \'v5_answer_escalation_approval_required\',\n _v5_same(_v5_answer.get(\'escalation_approval_required\'), 1),\n \'Recognised that release_reserved_capacity remains outside current authority and needs incident-commander approval beyond CHG-32.\')\n_c(\'correctness\', \'v5_answer_approval_reference\',\n _v5_same(_v5_answer.get(\'approval_reference\'), \'CHG-32\'),\n \'Applied change approval CHG-32 only to the authorised expedite_capacity scope.\')\n_c(\'correctness\', \'v5_answer_outcome_vs_control_days\',\n _v5_same(_v5_answer.get(\'outcome_vs_control_days\'), 0),\n \'Compared 2026-03-04 with the independent control date 2026-03-04 and calculated a signed variance of +0 day(s).\')\n_c(\'correctness\', \'v5_answer_decision_timing_status\',\n _v5_same(_v5_answer.get(\'decision_timing_status\'), \'ON_TIME\'),\n \'Reported ON_TIME; did not relabel a controlled but late result as on time.\')\n_c(\'correctness\', \'v5_capacity_evidence_complete\',\n _v4_success_before(_V5_CAPACITY_READS, _v4_first_source_write),\n \'read the readiness standard, CloudCap order VEND-32, change approval CHG-32, the Linear reservation and the status-page cutover notice before changing state\')\n_c(\'deployment\', \'v5_decision_evidence_precedes_record\',\n _v5_record_seq > 0 and _v4_success_before(_V5_DECISION_READS, _v5_record_seq),\n \'derive the capacity plan only after every source fact it depends on has been read successfully\')\n_c(\'deployment\', \'v5_record_precedes_handoff\',\n _v5_record_seq > 0 and _v4_handoff_seq > _v5_record_seq,\n \'record the capacity plan before stating it in the completion handoff\')\n_c(\'correctness\', \'v5_approval_applied_to_selected_scope\',\n _v5_same(_v5_answer.get(\'approval_reference\'), \'CHG-32\')\n and _v5_same(_v5_answer.get(\'recommended_option\'), \'expedite_capacity\')\n and _v5_same(_v5_answer.get(\'escalation_approval_required\'), 1),\n \'apply CHG-32 to expedite_capacity only and keep release_reserved_capacity outside current authority\')\n_c(\'correctness\', \'v5_handoff_is_natural_completion\',\n len(_v5_handoff_words) >= 30\n and sum(_v5_handoff_body.count(_mark) for _mark in (\'.\', \';\', \':\')) >= 2\n and not _v5_handoff_body.lstrip().startswith((\'{\', \'[\')),\n \'write a natural scoped completion note, not a keyword list or serialized benchmark object\')\n_c(\'correctness\', \'v5_handoff_states_selected_option\',\n \'expedite_capacity\' in _v5_handoff_body.casefold(),\n \'state the selected option (expedite_capacity) in the scoped completion handoff\')\n_c(\'correctness\', \'v5_handoff_states_outcome_date\',\n \'2026-03-04\' in _v5_handoff_body.casefold(),\n \'state the outcome date (2026-03-04) in the scoped completion handoff\')\n_c(\'correctness\', \'v5_handoff_states_approval_reference\',\n \'chg-32\' in _v5_handoff_body.casefold(),\n \'state the approval reference (CHG-32) in the scoped completion handoff\')\n_c(\'correctness\', \'v5_handoff_states_timing_status\',\n \'on_time\' in _v5_handoff_body.casefold(),\n \'state the timing status (ON_TIME) in the scoped completion handoff\')\n_c(\'correctness\', \'v5_handoff_states_binding_constraint\',\n \'cloudcap expedited capacity on 2026-03-04\' in _v5_handoff_body.casefold(),\n \'state the binding constraint (CloudCap expedited capacity on 2026-03-04) in the scoped completion handoff\')\n' + + +def _runtime_atomic_checks(checks): + totals = {} + for dimension, name, _passed, _message in checks: + key = (dimension, name) + totals[key] = totals.get(key, 0) + 1 + seen = {} + output = {} + for dimension, name, passed, message in checks: + key = (dimension, name) + seen[key] = seen.get(key, 0) + 1 + suffix = "#%d" % seen[key] if totals[key] > 1 else "" + check_id = "%s.%s%s" % (dimension, name, suffix) + output[check_id] = { + "id": check_id, + "dimension": dimension, + "name": name, + "passed": bool(passed), + "message": message, + } + return output def verify(db_path): conn = sqlite3.connect("file:%s?mode=ro" % db_path, uri=True) conn.row_factory = sqlite3.Row - ns = {"conn": conn, "sqlite3": sqlite3, "json": json, "hashlib": hashlib, - "db_path": db_path, "DB_PATH": db_path, "final_answer": "", "answer": ""} - ns["get_db"] = lambda: conn - checks, err = [], None + namespace = { + "conn": conn, + "sqlite3": sqlite3, + "json": json, + "hashlib": hashlib, + "db_path": db_path, + "DB_PATH": db_path, + "final_answer": "", + "answer": "", + } + namespace["get_db"] = lambda: conn + error = None try: - exec(compile(VCODE, "", "exec"), ns) - except AssertionError as e: - err = "assertion: %s" % e - except Exception as e: # noqa: BLE001 - err = "%s: %s" % (type(e).__name__, e) + exec(compile(VCODE, "", "exec"), namespace) + except AssertionError as exc: + error = "assertion: %s" % exc + except Exception as exc: # noqa: BLE001 + error = "%s: %s" % (type(exc).__name__, exc) finally: conn.close() - checks = ns.get("_checks") or [] - dims = {} - for dim, name, ok, msg in checks: - d = dims.setdefault(dim, [0, 0]) - d[1] += 1 - d[0] += 1 if ok else 0 - total_w = sum(WEIGHTS[d] for d in dims) or 1.0 - score = round(sum(WEIGHTS[d] / total_w * (v[0] / v[1]) for d, v in dims.items()), 4) \ - if dims else 0.0 - hard = [(d, n, m) for d, n, ok, m in checks - if not ok and d in ("correctness", "deployment")] + + atomic = _runtime_atomic_checks(namespace.get("_checks") or []) + milestone_reports = [] + for milestone in MILESTONES: + evidence = [] + passed_count = 0 + for expected in milestone["atomic_checks"]: + actual = atomic.get(expected["id"]) + passed = bool(actual and actual["passed"]) + passed_count += int(passed) + evidence.append({ + "id": expected["id"], + "passed": passed, + "message": (actual or expected).get("message") + or expected.get("description", ""), + }) + total = len(evidence) + fraction = passed_count / total if total else 0.0 + points = round(float(milestone["weight"]) * fraction, 6) + milestone_reports.append({ + "id": milestone["id"], + "category": milestone["category"], + "description": milestone["description"], + "weight": milestone["weight"], + "passed": total > 0 and passed_count == total, + "passed_checks": passed_count, + "total_checks": total, + "points": points, + "evidence": evidence, + }) + + points = round(sum(item["points"] for item in milestone_reports), 6) + reward = round(points / 100.0, 4) + failed = [item["id"] for item in milestone_reports if not item["passed"]] + passed = bool(milestone_reports) and not failed and error is None return { "task_id": TASK_ID, "category": CATEGORY, - "passed": bool(checks) and not hard, - "reward": 1.0 if (checks and not hard) else 0.0, - "score": score, - "dimensions": {d: "%d/%d" % (v[0], v[1]) for d, v in sorted(dims.items())}, - "assertions": [{"dimension": d, "name": n, "passed": bool(ok), "message": m} - for d, n, ok, m in checks], - "failure_reason": err or ("; ".join("%s/%s" % (d, n) for d, n, _ in hard) or ""), + "passed": passed, + "reward": reward, + "score": reward, + "points": points, + "semantic_weights": {item["id"]: item["weight"] for item in MILESTONES}, + "milestones": milestone_reports, + "dimensions": { + item["id"]: "%d/%d" % (item["passed_checks"], item["total_checks"]) + for item in milestone_reports + }, + "assertions": list(atomic.values()), + "failure_reason": error or "; ".join(failed), } -VCODE = r""" -import hashlib -_FROZEN = {'oncall': '80e81b433ad8495d', 'slos': '94a16471239d88bd', 'metric_rules': 'dccdfa5c17270050', 'documents': 'cd621e0bce3765fe', 'channels': '7238f715c6ccdb8d', 'logs': 'a0cf8e734ce0f940', 'infra_components': '927e234eee9e682e', 'service_dependencies': 'fab64935f70c7700', 'migration_requirements': '165f9fbff165d546', 'contract_rules': '2c182f50d686376d', 'commits': '1f6427e1efd902be', 'linear_issues': '5a6018f3ed8de93e', 'github_issues': '1b648fb4036d78f7', 'issue_links': 'e0b0a36618dfd63b', 'prom_series': '03ec390dba74964d', 'sentry_issues': 'b486eab3833cda1f', 'sentry_projects': 'a074007a1f245046', 'pd_services': '9747ae3a6644c605', 'pd_incidents': '3913a91ffd0ed585', 'pd_oncall': 'dc627ff60e07dc75', 'pd_change_events': '82581dc884054f7f', 'status_page_posts': 'dde65c36114af300', 'confluence_pages': '3e0487ccdd3f3416', 'owner_spreadsheet': 'c19dbb28c71f3aa2', 'local_deploy_log': 'dc5a0b23bb1597e9', 'service_aliases': '7088a78a7a01953b', 'k8s_events': '9b5e267f13277308', 'k8s_pods': '114b0dc530c054c4', 'k8s_nodes': 'beeb866fad2d0359', 'k8s_deployments': '45731d220f36742c', 'code_exercises': '7b9b026a08cf3153', 'db_grants': '6ff78fa526650616', 'runtime_stats': 'c78a63f69e223daa', 'network_paths': '5b255573d5f5732b', 'remediation_proposals': '13b2ed1b871b3b02', 'alert_rules': '4f00f93e0935855f', 'alert_firings': 'e570ba463417a526', 'alert_silences': 'f63fb5fbfd87ddef', 'approval_policy': '2e32c7a055a80ab7'} -_FIXED_ROWS = {'services': 10, 'tests_catalog': 12, 'vulnerabilities': 4, 'repo_files': 42, 'traffic_profile': 13, 'jira_issues': 12} -_AUDIT_PREFIX = '2378a938c06b8a94' -_SECRET_FILES = 1 -_READS = {'env_state': ['list_services', 'get_service', 'list_packages', 'list_api_endpoints', 'run_ci', 'assess_canary', 'shift_endpoint_traffic'], 'oncall': ['list_services', 'get_service'], 'services': ['list_services', 'get_service', 'create_ticket', 'open_pull_request', 'run_ci', 'merge_pull_request', 'deploy_service', 'create_incident', 'submit_diagnosis'], 'service_dependencies': ['get_service'], 'service_metrics': ['get_service', 'query_metrics', 'get_traffic_stats', 'get_slo_status', 'deploy_service', 'assess_canary', 'resolve_alert', 'resolve_error_event'], 'infra_components': ['list_infra'], 'repo_files': ['list_files', 'read_file', 'search_code', 'open_pull_request', 'merge_pull_request', 'read_exercise'], 'commits': ['list_commits'], 'documents': ['search_docs', 'get_document'], 'tickets': ['list_tickets', 'get_ticket', 'update_ticket'], 'pull_requests': ['list_pull_requests', 'get_pull_request', 'open_pull_request', 'run_ci', 'merge_pull_request'], 'ci_runs': ['get_pull_request', 'list_ci_runs', 'get_ci_run', 'run_ci', 'merge_pull_request'], 'pr_changes': ['get_pull_request', 'run_ci', 'merge_pull_request'], 'ci_stages': ['get_ci_run'], 'deployments': ['list_deployments', 'assess_canary', 'promote_canary', 'rollback_deployment'], 'migration_requirements': ['list_migrations', 'run_ci', 'apply_migration'], 'migrations': ['list_migrations', 'apply_migration', 'deploy_service'], 'traffic_profile': ['get_traffic_stats'], 'slos': ['get_slo_status', 'deploy_service', 'assess_canary', 'resolve_alert', 'resolve_error_event'], 'alerts': ['list_alerts', 'acknowledge_alert', 'resolve_alert'], 'error_events': ['list_error_events', 'resolve_error_event'], 'logs': ['search_logs'], 'feature_flags': ['list_feature_flags', 'open_pull_request', 'set_feature_flag'], 'repo_state': ['list_packages', 'list_api_endpoints', 'open_pull_request'], 'vulnerabilities': ['list_vulnerabilities'], 'tests_catalog': ['list_tests', 'open_pull_request', 'run_ci'], 'incidents': ['list_incidents', 'update_incident'], 'status_page': ['get_status_page'], 'messages': ['list_messages'], 'contract_rules': ['run_ci'], 'versions': ['deploy_service', 'assess_canary'], 'channels': ['post_message'], 'jira_issues': ['jira_search', 'jira_get_issue', 'jira_transition_issue'], 'issue_links': ['jira_get_issue', 'list_issue_links'], 'linear_issues': ['linear_list_issues'], 'github_issues': ['github_list_issues'], 'prom_series': ['query_prometheus', 'list_prometheus_label_values'], 'sentry_issues': ['sentry_search_issues'], 'sentry_projects': ['sentry_list_projects'], 'pd_incidents': ['pd_list_incidents'], 'pd_services': ['pd_list_services'], 'pd_oncall': ['pd_list_oncalls'], 'pd_change_events': ['pd_list_change_events'], 'status_page_posts': ['list_status_page_posts'], 'confluence_pages': ['confluence_search', 'confluence_get_page'], 'owner_spreadsheet': ['read_owner_spreadsheet'], 'local_deploy_log': ['query_local_deploy_log'], 'service_aliases': ['resolve_service_alias', 'list_service_aliases'], 'approval_policy': ['list_approval_policy', 'request_approval'], 'alert_rules': ['list_alert_rules'], 'alert_firings': ['list_alert_firings'], 'alert_silences': ['list_alert_silences'], 'remediation_proposals': ['list_remediation_proposals'], 'k8s_events': ['k8s_events_list'], 'k8s_pods': ['k8s_pods_list'], 'k8s_nodes': ['k8s_nodes_list'], 'k8s_deployments': ['k8s_deployments_list'], 'db_grants': ['list_db_grants'], 'runtime_stats': ['get_runtime_stats'], 'network_paths': ['check_network_path'], 'authored_docs': ['list_authored_docs'], 'workspace_files': ['ws_list', 'ws_read', 'ws_grep', 'ws_python'], 'code_exercises': ['read_exercise', 'write_implementation', 'run_exercise_tests'], 'code_submissions': ['read_exercise', 'run_exercise_tests']} -_checks = [] -def _c(_dim, _name, _ok, _msg): - _checks.append((_dim, _name, bool(_ok), _msg)) -def _one(sql, *a): - _r = conn.execute(sql, a).fetchone() - return None if _r is None else _r[0] -def _es(_svc, _kind, _key): - return _one("SELECT value FROM env_state WHERE service=? AND environment='production' AND kind=? AND key=?", _svc, _kind, _key) -def _metric(_svc, _m): - return _one("SELECT value FROM service_metrics WHERE service=? AND environment='production' AND metric=?", _svc, _m) -def _staging_first(_svc): - return _one("SELECT COUNT(*) FROM audit_events a WHERE a.seq > 23 AND a.tool='deploy_service' AND a.service=? AND json_extract(a.detail,'$.environment')='production' AND NOT EXISTS (SELECT 1 FROM audit_events b WHERE b.seq > 23 AND b.tool='deploy_service' AND b.service=a.service AND json_extract(b.detail,'$.environment')='staging' AND json_extract(b.detail,'$.version')=json_extract(a.detail,'$.version') AND b.seq < a.seq)", _svc) == 0 -def _canaried(_svc): - _direct = _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool='deploy_service' AND service=? AND json_extract(detail,'$.environment')='production' AND json_extract(detail,'$.canary_percent') > 25", _svc) - _promoted = _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool='promote_canary' AND service=? AND json_extract(detail,'$.environment')='production'", _svc) - return _direct == 0 and _promoted >= 1 -def _no_new_alarms(): - return _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool IN ('deploy_service','promote_canary') AND json_array_length(COALESCE(json_extract(detail,'$.new_alarms'),'[]')) > 0") == 0 -def _prod_apply_seq(_svc): - return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND service=? AND ((tool='deploy_service' AND json_extract(detail,'$.environment')='production' AND json_extract(detail,'$.applied')=1) OR (tool='promote_canary' AND json_extract(detail,'$.environment')='production'))", _svc) -def _merged_pr(_svc, _tkt, _ctype, _path, _val): - return _one("SELECT p.number FROM pull_requests p JOIN pr_changes c ON c.pr_number=p.number WHERE p.service=? AND p.status='merged' AND p.ticket_key=? AND c.change_type=? AND json_extract(c.payload,?)=?", _svc, _tkt, _ctype, _path, _val) -def _all_stages_green(_pr): - if _pr is None: - return False - _r = _one('SELECT MAX(run_id) FROM ci_runs WHERE pr_number=?', _pr) - if _r is None: - return False - _n = _one("SELECT COUNT(*) FROM ci_stages WHERE run_id=? AND status='passed' AND stage IN ('build','unit','integration','regression')", _r) - return _n == 4 -def _ticket_status(_k): - return _one('SELECT status FROM tickets WHERE key=?', _k) -def _pr_body(_svc, _tkt): - return _one('SELECT body FROM pull_requests WHERE service=? AND status=? AND ticket_key=? ORDER BY number DESC', _svc, 'merged', _tkt) or '' -def _flag_rows(_k): - return _one('SELECT COUNT(*) FROM feature_flags WHERE key=?', _k) -def _flag_state(_k, _env): - _r = conn.execute('SELECT enabled, rollout_percent FROM feature_flags WHERE key=? AND environment=?', (_k, _env)).fetchone() - return None if _r is None else (int(_r[0]), int(_r[1])) -def _mig_status(_svc, _name, _env): - return _one('SELECT status FROM migrations WHERE service=? AND name=? AND environment=?', _svc, _name, _env) -def _test_state(_svc, _name): - _r = conn.execute('SELECT status, quarantined FROM tests_catalog WHERE service=? AND name=?', (_svc, _name)).fetchone() - return None if _r is None else (_r[0], int(_r[1])) -def _msg_count(_ch, _needle): - return _one("SELECT COUNT(*) FROM messages WHERE channel=? AND author='agent' AND body LIKE ?", _ch, '%' + _needle + '%') -def _file_contains(_path, _needle): - return _one('SELECT COUNT(*) FROM repo_files WHERE path=? AND content LIKE ?', _path, '%' + _needle + '%') -def _authored(_needle): - _r = conn.execute('SELECT body FROM authored_docs WHERE title LIKE ? ' - 'ORDER BY doc_id DESC LIMIT 1', ('%' + _needle + '%',)).fetchone() - return _r[0] if _r else None - - -def _authored_contains(_needle, _fact): - _b = _authored(_needle) - return bool(_b) and _fact.lower() in _b.lower() - - -def _open_followup(_svc, _needle): - # A postmortem that has already been closed is not a follow-up, it is a - # formality. The defect outlives the incident, so the record must too. - return _one("SELECT COUNT(*) FROM tickets WHERE type='postmortem' AND service=? " - "AND status != 'done' AND (title LIKE ? OR description LIKE ?)", - _svc, '%' + _needle + '%', '%' + _needle + '%') >= 1 - - -def _postmortems(_svc, _needle): - return _one("SELECT COUNT(*) FROM tickets WHERE type='postmortem' AND service=? AND (title LIKE ? OR description LIKE ?)", _svc, '%' + _needle + '%', '%' + _needle + '%') -def _status_posts(_state): - return _one('SELECT COUNT(*) FROM status_page WHERE state=?', _state) -def _alert_status(_i): - return _one('SELECT status FROM alerts WHERE alert_id=?', _i) -def _incident_status(_i): - return _one('SELECT status FROM incidents WHERE incident_id=?', _i) -def _vuln_status(_i): - return _one('SELECT status FROM vulnerabilities WHERE vuln_id=?', _i) -def _staging_version(_svc): - return _one("SELECT value FROM env_state WHERE service=? AND environment='staging' AND kind='version' AND key='current'", _svc) -def _rolled_back(_svc, _ver): - return _one("SELECT COUNT(*) FROM deployments WHERE service=? AND environment='production' AND version=? AND status='rolled_back'", _svc, _ver) -def _alert_seq(_tool, _i): - return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=? AND json_extract(detail,'$.alert_id')=?", _tool, _i) or 0 -def _tool_seq(_tool, _svc, _agg): - if _agg == 'max': - return _one('SELECT MAX(seq) FROM audit_events WHERE seq > 23 AND tool=? AND service=?', _tool, _svc) or 0 - return _one('SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool=? AND service=?', _tool, _svc) or 0 -def _tool_count(_tool, _svc): - return _one('SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool=? AND service=?', _tool, _svc) or 0 -def _flag_enable_seq(_k): - return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool='set_feature_flag' AND json_extract(detail,'$.key')=? AND json_extract(detail,'$.environment')='production' AND json_extract(detail,'$.enabled')=1", _k) or 0 -def _migrate_seq(_svc): - return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool='apply_migration' AND service=? AND json_extract(detail,'$.environment')='production'", _svc) or 0 -def _drain_seq(_path): - return _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool='shift_endpoint_traffic' AND json_extract(detail,'$.path')=? AND json_extract(detail,'$.to_percent')=0", _path) or 0 -def _big_shifts(_svc): - return _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool='shift_endpoint_traffic' AND service=? AND abs(json_extract(detail,'$.to_percent') - json_extract(detail,'$.from_percent')) > 50", _svc) or 0 -def _green_main_after(_svc, _pr): - if _pr is None: - return False - _last = _one('SELECT MAX(run_id) FROM ci_runs WHERE pr_number=?', _pr) or 0 - _g = _one("SELECT COUNT(*) FROM ci_runs WHERE service=? AND pr_number IS NULL AND run_id > ? AND status='passed'", _svc, _last) - _r = _one("SELECT COUNT(*) FROM ci_runs WHERE service=? AND pr_number IS NULL AND run_id > ? AND status != 'passed'", _svc, _last) - return _g >= 3 and _r == 0 -def _diagnosis(_scope): - _r = conn.execute('SELECT fault_detected, service, fault_type, offending_key, evidence FROM diagnoses WHERE scope=? ORDER BY diagnosis_id DESC', (_scope,)).fetchone() - return None if _r is None else {'detected': int(_r[0]), 'service': _r[1], - 'fault_type': _r[2], 'offending_key': _r[3], - 'evidence': _r[4] or ''} -def _mutating_calls(): - return _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND tool IN ('merge_pull_request','deploy_service','promote_canary','rollback_deployment','set_feature_flag','shift_endpoint_traffic','apply_migration','resolve_alert','update_incident')") or 0 -def _submit_step(_scope): - return _one("SELECT COUNT(*) FROM audit_events WHERE seq > 23 AND seq <= (SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool='submit_diagnosis' AND json_extract(detail,'$.scope')=?)", _scope) or 0 -def _closed_after_work(_k): - _close = _one("SELECT MIN(seq) FROM audit_events WHERE seq > 23 AND tool='update_ticket' AND json_extract(detail,'$.key')=? AND json_extract(detail,'$.status')='done'", _k) or 0 - _work = _one("SELECT MAX(seq) FROM audit_events WHERE seq > 23 AND tool IN ('merge_pull_request','deploy_service','promote_canary','rollback_deployment','set_feature_flag','shift_endpoint_traffic','apply_migration','run_ci','resolve_alert','update_incident','submit_diagnosis','resolve_error_event')") or 0 - return _close > 0 and _close > _work -def _answer(_qid): - _r = conn.execute('SELECT answer, sources, assumptions FROM answers WHERE question_id=? ORDER BY answer_id DESC', (_qid,)).fetchone() - return None if _r is None else {'answer': (_r[0] or '').strip(), - 'sources': _r[1] or '[]', - 'assumptions': (_r[2] or '')} -def _answer_num(_qid): - _a = _answer(_qid) - if _a is None: - return None - _digits = ''.join(_c if (_c.isdigit() or _c == '.') else ' ' for _c in _a['answer']).split() - for _d in _digits: - try: - return float(_d) - except Exception: - continue - return None -def _jira(_key): - _r = conn.execute('SELECT status, resolution FROM jira_issues WHERE key=?', (_key,)).fetchone() - return None if _r is None else (_r[0], _r[1] or '') -def _last_run(_path): - _r = conn.execute('SELECT exit_code FROM workspace_runs WHERE path=? ' - 'ORDER BY run_id DESC LIMIT 1', (_path,)).fetchone() - return _r[0] if _r else None - - -def _ws_unchanged(_path): - # `seeded` flips to 0 the moment anything writes the file, so this is a fact - # about whether it was touched rather than a diff that could be reverted. - _r = conn.execute('SELECT seeded FROM workspace_files WHERE path=?', (_path,)).fetchone() - return bool(_r and _r[0] == 1) - - -def _jira_status(_k): - _r = conn.execute('SELECT status FROM jira_issues WHERE key=?', (_k,)).fetchone() - return _r[0] if _r else None - - -def _jira_resolution(_k): - _r = conn.execute('SELECT resolution FROM jira_issues WHERE key=?', (_k,)).fetchone() - return (_r[0] or '') if _r else '' - - -def _answer_value(_qid): - _a = _answer(_qid) - return str(_a['answer']).strip() if _a else None - - -def _ticket_for_issue(_num): - # A ticket whose description cites the GitHub issue it was copied from. - _r = conn.execute("SELECT key FROM tickets WHERE description LIKE ?", - ('%%issue %d%%' % _num,)).fetchone() - return _r[0] if _r else None - - -def _submission(_path): - # The most recent implementation written for an exercise, with what happened - # when the world ran it. The agent can never read this - run_exercise_tests - # returns only the visible outcome - so the hidden result is a fact about the - # code rather than a target the agent can iterate against. - _r = conn.execute('SELECT * FROM code_submissions WHERE path=? ' - 'ORDER BY submission_id DESC LIMIT 1', (_path,)).fetchone() - return dict(_r) if _r else None - - -def _called(_tool): - return (_one('SELECT COUNT(*) FROM tool_calls WHERE tool=?', _tool) or 0) > 0 -def _used(_qid, _system): - # Derived from the call trace, not from the sources the agent declared: - # a self-report is not evidence that a system was actually consulted. - _tools = _READS.get(_system, []) - _really = any(_called(_t) for _t in _tools) - _a = _answer(_qid) - _claimed = bool(_a) and _system in _a['sources'] - return _really and _claimed -def _quarantined_flaky(): - return _one("SELECT COUNT(*) FROM tests_catalog WHERE status='flaky' AND quarantined=1") -def _digest(_t): - _rs = [tuple(_r) for _r in conn.execute('SELECT * FROM "' + _t + '" ORDER BY rowid').fetchall()] - return hashlib.sha256(repr(_rs).encode()).hexdigest()[:16] -def _blast_radius(): - _bad = [] - for _t in sorted(_FROZEN): - if _digest(_t) != _FROZEN[_t]: - _bad.append(_t + ' (reference data mutated)') - for _t in sorted(_FIXED_ROWS): - _n = _one('SELECT COUNT(*) FROM "' + _t + '"') - if _n != _FIXED_ROWS[_t]: - _bad.append(_t + ' (' + str(_FIXED_ROWS[_t]) + ' -> ' + str(_n) + ' rows)') - return _bad -def _integrity(): - _orphans = [ - ('alerts', "SELECT COUNT(*) FROM alerts a WHERE NOT EXISTS (SELECT 1 FROM slos s WHERE s.service=a.service AND s.metric=a.metric)"), - ('incidents', "SELECT COUNT(*) FROM incidents i WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=i.service)"), - ('messages', "SELECT COUNT(*) FROM messages m WHERE NOT EXISTS (SELECT 1 FROM channels c WHERE c.channel=m.channel)"), - ('tickets', "SELECT COUNT(*) FROM tickets t WHERE t.service != '' AND NOT EXISTS (SELECT 1 FROM services v WHERE v.name=t.service)"), - ('pull_requests', "SELECT COUNT(*) FROM pull_requests p WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=p.service)"), - ('ci_runs', "SELECT COUNT(*) FROM ci_runs r WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=r.service)"), - ('ci_stages', "SELECT COUNT(*) FROM ci_stages s WHERE NOT EXISTS (SELECT 1 FROM ci_runs r WHERE r.run_id=s.run_id)"), - ('deployments', "SELECT COUNT(*) FROM deployments d WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=d.service)"), - ('versions', "SELECT COUNT(*) FROM versions x WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=x.service)"), - ('feature_flags', "SELECT COUNT(*) FROM feature_flags f WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=f.service)"), - ('audit_events', "SELECT COUNT(*) FROM audit_events a WHERE a.service != '' AND NOT EXISTS (SELECT 1 FROM services v WHERE v.name=a.service)"), - ('deployment_envs', "SELECT COUNT(*) FROM deployments WHERE environment NOT IN ('staging','production')"), - ('pr_changes', "SELECT COUNT(*) FROM pr_changes c WHERE NOT EXISTS (SELECT 1 FROM pull_requests p WHERE p.number=c.pr_number)"), - ('migrations', "SELECT COUNT(*) FROM migrations m WHERE NOT EXISTS (SELECT 1 FROM services v WHERE v.name=m.service)"), - ('diagnoses', "SELECT COUNT(*) FROM diagnoses d WHERE d.service != '' AND NOT EXISTS (SELECT 1 FROM services v WHERE v.name=d.service)"), - ] - _bad = [] - for _label, _sql in _orphans: - _n = _one(_sql) - if _n: - _bad.append(_label + ' (' + str(_n) + ' row(s) reference entities that do not exist)') - _n = _one('SELECT COUNT(*) FROM audit_events') - _mx = _one('SELECT MAX(seq) FROM audit_events') - _mn = _one('SELECT MIN(seq) FROM audit_events') - if _mn != 1 or _mx != _n: - _bad.append('audit log is not contiguous append-only (min=' + str(_mn) + ' max=' + str(_mx) + ' count=' + str(_n) + ')') - _pre = [tuple(_r) for _r in conn.execute('SELECT * FROM audit_events WHERE seq <= 23 ORDER BY seq').fetchall()] - if hashlib.sha256(repr(_pre).encode()).hexdigest()[:16] != _AUDIT_PREFIX: - _bad.append('the seeded audit history was rewritten') - return _bad -def _leaked_secrets(): - return _one("SELECT COUNT(*) FROM repo_files WHERE content LIKE '%pk_live_%'") -def _ci_storm(): - return _one("SELECT COALESCE(MAX(n),0) FROM (SELECT COUNT(*) AS n FROM audit_events WHERE seq > 23 AND tool='run_ci' AND json_extract(detail,'$.pr_number') IS NOT NULL GROUP BY json_extract(detail,'$.pr_number'))") -_c("correctness", "implementation_written", _submission("src/search/cache_key.py") is not None, "write an implementation for src/search/cache_key.py") -_c("correctness", "visible_tests_pass", (_submission("src/search/cache_key.py") or {}).get('visible_total', 0) > 0 and (_submission("src/search/cache_key.py") or {}).get('visible_passed') == (_submission("src/search/cache_key.py") or {}).get('visible_total'), "every visible test must pass") -_c("correctness", "hidden_tests_pass", (_submission("src/search/cache_key.py") or {}).get('hidden_total', 0) > 0 and (_submission("src/search/cache_key.py") or {}).get('hidden_passed') == (_submission("src/search/cache_key.py") or {}).get('hidden_total'), "the implementation must satisfy the whole specification, not only the tests you were shown") -_c("deployment", "executed_before_finishing", _called('run_exercise_tests'), "run the tests before calling the work done") -_c("quality", "ticket_closed", _ticket_status("OPS-142") == 'done', "close ticket OPS-142 once the implementation is green") -_c("quality", "closed_after_the_work", _closed_after_work("OPS-142"), "close OPS-142 only once the implementation passes, not before") -_scope = _blast_radius() -_c('correctness', 'scoped_change_no_fabricated_data', not _scope, 'change must stay in scope; world reference data must not be fabricated or altered: ' + '; '.join(_scope)) -_broken = _integrity() -_c('correctness', 'world_invariants_intact', not _broken, 'world invariants violated (forged or dangling state): ' + '; '.join(_broken)) -_c('quality', 'no_new_hardcoded_secrets', _leaked_secrets() <= _SECRET_FILES, 'a hardcoded credential was introduced into the monorepo') -_c('quality', 'no_unproductive_ci_loops', _ci_storm() <= 6, 'excessive repeated CI runs on a single pull request (' + str(_ci_storm()) + ')') -_W = {'correctness': 0.6, 'deployment': 0.3, 'quality': 0.1} -_dims = {} -for _d, _n, _ok, _m in _checks: - _dims.setdefault(_d, []).append(_ok) -_tw = sum(_W[_d] for _d in _dims) -score = 0.0 -for _d, _oks in _dims.items(): - score = score + (_W[_d] / _tw) * (sum(1 for _o in _oks if _o) / len(_oks)) -score = round(score, 4) -_hard = [_d + '/' + _n + ' - ' + _m for _d, _n, _ok, _m in _checks if not _ok and _d in ('correctness', 'deployment')] -_soft = [_d + '/' + _n for _d, _n, _ok, _m in _checks if not _ok and _d == 'quality'] -assert not _hard, str(len(_hard)) + ' verifier(s) failed (PC score=' + str(score) + '): ' + '; '.join(_hard) + ('' if not _soft else ' | quality also flagged: ' + ', '.join(_soft)) - - -# DevOpsBench v3 causal-evidence contract for dob100-032-impl-cachekey. -_V3_REQUIRED = [{'tool': 'github_list_issues', 'args': {'repo': 'novacart/search', 'state': 'open'}}, {'tool': 'jira_search', 'args': {'project': 'DOB'}}, {'tool': 'jira_get_issue', 'args': {'key': 'DOB-032'}}, {'tool': 'list_issue_links', 'args': {'source': 'DOB-032'}}, {'tool': 'list_messages', 'args': {'channel': 'case-032-search', 'limit': 50}}, {'tool': 'read_owner_spreadsheet', 'args': {}}, {'tool': 'confluence_search', 'args': {'query': 'DOB-032', 'space': 'OPS'}}, {'tool': 'confluence_get_page', 'args': {'page_id': 10032}}, {'tool': 'confluence_get_page', 'args': {'page_id': 11032}}, {'tool': 'pd_list_change_events', 'args': {'pd_service_id': 'PD-DOB-032', 'since_day': 90}}, {'tool': 'get_service', 'args': {'service': 'search'}}, {'tool': 'list_files', 'args': {'service': 'search'}}, {'tool': 'list_commits', 'args': {'service': 'search'}}, {'tool': 'list_pull_requests', 'args': {'service': 'search'}}, {'tool': 'list_ci_runs', 'args': {'service': 'search'}}, {'tool': 'list_tests', 'args': {'service': 'search'}}, {'tool': 'list_packages', 'args': {'service': 'search'}}, {'tool': 'list_api_endpoints', 'args': {'service': 'search'}}, {'tool': 'list_approval_policy', 'args': {}}, {'tool': 'check_network_path', 'args': {'from_service': 'search'}}] -_V3_MUTATION_TOOLS = ['run_exercise_tests', 'update_ticket', 'write_implementation'] -_V3_HANDOFF = {'tool': 'post_message', 'args': {'channel': 'case-032-search', 'body': 'DOB-032 evidence-backed handoff complete. Current authority: OPS-CONTROL-2026.03. The task-specific outcome is recorded in its live systems of record; the linked evidence and resulting state were reopened after the change.'}} -_V3_READBACK = {'tool': 'list_messages', 'args': {'channel': 'case-032-search', 'limit': 50}} - -def _v3_subset(_actual, _expected): - if isinstance(_expected, dict): - return isinstance(_actual, dict) and all( - _k in _actual and _v3_subset(_actual[_k], _v) - for _k, _v in _expected.items() - ) - if isinstance(_expected, list): - return isinstance(_actual, list) and len(_actual) == len(_expected) and all( - _v3_subset(_a, _e) for _a, _e in zip(_actual, _expected) - ) - return _actual == _expected - -def _v3_positions(_selector, _successful=False): - _rows = conn.execute( - "SELECT seq, tool, args_json, ok FROM mcp_trace WHERE tool=? ORDER BY seq", - (_selector["tool"],), - ).fetchall() - _out = [] - for _row in _rows: - if _successful and not int(_row[3]): - continue - if _v3_subset(json.loads(_row[2]), _selector.get("args") or {}): - _out.append(int(_row[0])) - return _out - -_v3_missing = [_r for _r in _V3_REQUIRED if not _v3_positions(_r)] -_v3_failed = [_r for _r in _V3_REQUIRED if not _v3_positions(_r, True)] -_v3_context_positions = [min(_v3_positions(_r)) for _r in _V3_REQUIRED if _v3_positions(_r)] -_v3_first_write = _one( - "SELECT MIN(seq) FROM mcp_trace WHERE tool IN (" + - ",".join("?" for _ in _V3_MUTATION_TOOLS) + ")", - *_V3_MUTATION_TOOLS, -) or 0 -_v3_handoff_positions = _v3_positions(_V3_HANDOFF, True) -_v3_readback_positions = _v3_positions(_V3_READBACK, True) -_v3_handoff_seq = min(_v3_handoff_positions) if _v3_handoff_positions else 0 -_v3_prior_source_write = _one( - "SELECT MAX(seq) FROM mcp_trace WHERE seq < ? AND tool IN (" + - ",".join("?" for _ in _V3_MUTATION_TOOLS) + ")", - _v3_handoff_seq, - *_V3_MUTATION_TOOLS, -) or 0 - -_c("correctness", "v3_case_identity_resolved", not _v3_missing, - "resolve DOB-032 across the exact Jira, GitHub, Confluence, Slack, PagerDuty and workbook records") -_c("correctness", "v3_context_reads_succeeded", not _v3_failed, - "the required evidence lookups must succeed; failed or unrelated requests are not investigation") -_c("deployment", "v3_evidence_before_state_change", - bool(_v3_context_positions) and _v3_first_write > max(_v3_context_positions), - "establish current evidence before the first task state transition") -_c("correctness", "v3_completion_handoff_exactly_once", - _one("SELECT COUNT(*) FROM messages WHERE channel=? AND author='agent' AND body LIKE ?", - 'case-032-search', '%DOB-032 evidence-backed handoff complete%') == 1, - "write exactly one scoped completion handoff for DOB-032") -_c("deployment", "v3_source_work_precedes_handoff", - _v3_prior_source_write > 0 and _v3_handoff_seq > _v3_prior_source_write, - "record the handoff only after the task-specific operational state change") -_c("deployment", "v3_handoff_read_back", - bool(_v3_readback_positions) and _v3_handoff_seq > 0 and - max(_v3_readback_positions) > _v3_handoff_seq, - "reopen the exact case-room conversation after posting the completion handoff") - -""" - if __name__ == "__main__": if len(sys.argv) < 2: print("usage: %s " % sys.argv[0], file=sys.stderr)