{
  "schema": 1,
  "sqlstate": "25P02",
  "condition_name": "in_failed_sql_transaction",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "failed_transaction_recovery",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "A runner-owned disposable target is provisioned."
      ],
      "trigger": "Raise a root unique violation, then issue a query before ROLLBACK.",
      "assertions": [
        "The root duplicate is 23505",
        "The follow-up command reports 25P02",
        "The failed transaction remains INERROR until ROLLBACK",
        "A new explicit transaction commits the repaired row"
      ],
      "repair": "Follow the explicit transaction or source boundary described by the case.",
      "cleanup": "Drop the case schema with an owner connection."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "failed_transaction",
      "case_id": "failed_transaction_recovery",
      "language": "sql",
      "statements": {
        "create": "CREATE TABLE items(id integer PRIMARY KEY, note text UNIQUE NOT NULL)",
        "seed": "INSERT INTO items VALUES (1, 'seed')",
        "begin": "BEGIN",
        "trigger": "INSERT INTO items VALUES (2, 'seed')",
        "followup": "SELECT 1 AS ignored",
        "rollback": "ROLLBACK",
        "repair_begin": "BEGIN",
        "repair": "INSERT INTO items VALUES (2, 'repaired')",
        "commit": "COMMIT",
        "verify": "SELECT id, note FROM items ORDER BY id"
      }
    }
  ],
  "runtime": [
    {
      "id": "runtime.25P02-batch2-latest-20260909.latest",
      "run_id": "25P02-batch2-latest-20260909",
      "target": "latest",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "status": "passed",
      "case_status": "passed",
      "target_status": "passed",
      "cases": [
        "failed_transaction_recovery"
      ],
      "summary_sha256": "6c06ba72ebf7ce12c171d8a45ceec233b03eedc0db98796221d00c8b0e34732d",
      "raw_sha256": "f03391117a5430c0611c72a1fa03ee6169f72575e69733a98023b0c9fb255788",
      "case_manifest": {
        "sha256": "dc6dea41ff7dc64f413c290151ee8200b11d66050eb5de499c64ef7aaf87f88c"
      },
      "snippet_registry": {
        "sha256": "04da3240dcf3c03fe60d13715f8187350fadf5b8d1f10e5b837acd45289759cd"
      },
      "observed": {
        "root_sqlstate": "23505",
        "root_primary": "duplicate key value violates unique constraint \"items_note_key\"",
        "sqlstate": "25P02",
        "primary": "current transaction is aborted, commands ignored until end of transaction block",
        "after_root_error": "INERROR",
        "after_25P02": "INERROR",
        "after_rollback": "IDLE",
        "final_status": "IDLE",
        "rows_after_retry": [
          [
            1,
            "seed"
          ],
          [
            2,
            "repaired"
          ]
        ]
      },
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 77667,
          "binary": {
            "bindir": "/opt/homebrew/Cellar/postgresql@18/18.6/bin",
            "pg_config": "/opt/homebrew/bin/pg_config",
            "pg_config_version": "PostgreSQL 18.6 (Homebrew)",
            "postgres": "/opt/homebrew/Cellar/postgresql@18/18.6/bin/postgres"
          },
          "connection_scope": "runner-owned localhost port",
          "current_user": "runner",
          "docker": {},
          "lc_messages": "C",
          "libpq_version": "18.6",
          "locale": "en_US.UTF-8",
          "log_destination": "csvlog,jsonlog",
          "log_error_verbosity": "verbose",
          "log_min_error_statement": "error",
          "log_min_messages": "error",
          "logging_collector": "on",
          "machine": "arm64",
          "max_connections": "100",
          "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
          "psycopg_version": "3.3.5",
          "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
          "server_encoding": "UTF8",
          "server_version": "18.6 (Homebrew)",
          "server_version_num": "180006",
          "target_kind": "latest",
          "wal_level": "logical"
        },
        "cases": [
          {
            "assertions": [
              {
                "expected": "23505",
                "name": "root error is unique violation",
                "observed": "23505",
                "passed": true
              },
              {
                "expected": "25P02",
                "name": "failed-transaction sqlstate",
                "observed": "25P02",
                "passed": true
              },
              {
                "expected": "current transaction is aborted, commands ignored until end of transaction block",
                "name": "failed-transaction diagnostic",
                "observed": "current transaction is aborted, commands ignored until end of transaction block",
                "passed": true
              },
              {
                "expected": "INERROR",
                "name": "failed transaction remains in error",
                "observed": {
                  "after_first": "INERROR",
                  "after_second": "INERROR"
                },
                "passed": true
              },
              {
                "expected": "rollback, valid retry, committed rows and IDLE",
                "name": "rollback and retry restore data path",
                "observed": {
                  "after_rollback": "IDLE",
                  "final": "IDLE",
                  "rows": [
                    [
                      1,
                      "seed"
                    ],
                    [
                      2,
                      "repaired"
                    ]
                  ]
                },
                "passed": true
              }
            ],
            "case_id": "failed_transaction_recovery",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.013,
            "observed": {
              "connection_autocommit": true,
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "InFailedSqlTransaction",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "current transaction is aborted, commands ignored until end of transaction block",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "postgres.c",
                "source_function": "exec_simple_query",
                "source_line": "1140",
                "sqlstate": "25P02",
                "statement_position": null,
                "table_name": null,
                "text": "current transaction is aborted, commands ignored until end of transaction block"
              },
              "root_diagnostic": {
                "column_name": null,
                "constraint_name": "items_note_key",
                "context": null,
                "datatype_name": null,
                "exception_type": "UniqueViolation",
                "internal_position": null,
                "internal_query": null,
                "message_detail": "Key (note)=(seed) already exists.",
                "message_hint": null,
                "message_primary": "duplicate key value violates unique constraint \"items_note_key\"",
                "schema_name": "c25p02_failed_transaction_recovery",
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "nbtinsert.c",
                "source_function": "_bt_check_unique",
                "source_line": "673",
                "sqlstate": "23505",
                "statement_position": null,
                "table_name": "items",
                "text": "duplicate key value violates unique constraint \"items_note_key\"\nDETAIL:  Key (note)=(seed) already exists."
              },
              "rows": [
                [
                  1,
                  "seed"
                ],
                [
                  2,
                  "repaired"
                ]
              ],
              "statuses": {
                "after_25P02": "INERROR",
                "after_rollback": "IDLE",
                "after_root_error": "INERROR",
                "final": "IDLE"
              },
              "transaction_control": [
                "BEGIN",
                "ROLLBACK",
                "BEGIN",
                "COMMIT"
              ]
            },
            "schema": "c25p02_failed_transaction_recovery",
            "status": "passed"
          }
        ]
      }
    },
    {
      "id": "runtime.25P02-batch2-pg10-20260909.pg10",
      "run_id": "25P02-batch2-pg10-20260909",
      "target": "pg10",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "status": "passed",
      "case_status": "passed",
      "target_status": "passed",
      "cases": [
        "failed_transaction_recovery"
      ],
      "summary_sha256": "722e8d8c8ddc1301c1c7acb98d9e6442dde6f3a2020246b30775dec8c98a3847",
      "raw_sha256": "97d4ce9f816c98c09408bd00921a97e33708ccf52ca10da0682ab7238ef377a6",
      "case_manifest": {
        "sha256": "dc6dea41ff7dc64f413c290151ee8200b11d66050eb5de499c64ef7aaf87f88c"
      },
      "snippet_registry": {
        "sha256": "04da3240dcf3c03fe60d13715f8187350fadf5b8d1f10e5b837acd45289759cd"
      },
      "observed": {
        "root_sqlstate": "23505",
        "root_primary": "duplicate key value violates unique constraint \"items_note_key\"",
        "sqlstate": "25P02",
        "primary": "current transaction is aborted, commands ignored until end of transaction block",
        "after_root_error": "INERROR",
        "after_25P02": "INERROR",
        "after_rollback": "IDLE",
        "final_status": "IDLE",
        "rows_after_retry": [
          [
            1,
            "seed"
          ],
          [
            2,
            "repaired"
          ]
        ]
      },
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Etc/UTC",
          "backend_pid": 79,
          "binary": {},
          "connection_scope": "runner-owned localhost port",
          "current_user": "postgres",
          "docker": {
            "architecture": "arm64",
            "command": "/usr/local/bin/docker",
            "id": "sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "image": "postgres:10",
            "image_created": "2022-06-23T09:11:18.374607054Z",
            "os": "linux",
            "repo_digests": [
              "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc"
            ]
          },
          "lc_messages": "en_US.utf8",
          "libpq_version": "18.6",
          "locale": "en_US.UTF-8",
          "log_destination": "csvlog",
          "log_error_verbosity": "verbose",
          "log_min_error_statement": "error",
          "log_min_messages": "error",
          "logging_collector": "on",
          "machine": "arm64",
          "max_connections": "100",
          "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
          "psycopg_version": "3.3.5",
          "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
          "server_encoding": "UTF8",
          "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
          "server_version_num": "100021",
          "target_kind": "pg10",
          "wal_level": "logical"
        },
        "cases": [
          {
            "assertions": [
              {
                "expected": "23505",
                "name": "root error is unique violation",
                "observed": "23505",
                "passed": true
              },
              {
                "expected": "25P02",
                "name": "failed-transaction sqlstate",
                "observed": "25P02",
                "passed": true
              },
              {
                "expected": "current transaction is aborted, commands ignored until end of transaction block",
                "name": "failed-transaction diagnostic",
                "observed": "current transaction is aborted, commands ignored until end of transaction block",
                "passed": true
              },
              {
                "expected": "INERROR",
                "name": "failed transaction remains in error",
                "observed": {
                  "after_first": "INERROR",
                  "after_second": "INERROR"
                },
                "passed": true
              },
              {
                "expected": "rollback, valid retry, committed rows and IDLE",
                "name": "rollback and retry restore data path",
                "observed": {
                  "after_rollback": "IDLE",
                  "final": "IDLE",
                  "rows": [
                    [
                      1,
                      "seed"
                    ],
                    [
                      2,
                      "repaired"
                    ]
                  ]
                },
                "passed": true
              }
            ],
            "case_id": "failed_transaction_recovery",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.02,
            "observed": {
              "connection_autocommit": true,
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "InFailedSqlTransaction",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "current transaction is aborted, commands ignored until end of transaction block",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "postgres.c",
                "source_function": "exec_simple_query",
                "source_line": "1022",
                "sqlstate": "25P02",
                "statement_position": null,
                "table_name": null,
                "text": "current transaction is aborted, commands ignored until end of transaction block"
              },
              "root_diagnostic": {
                "column_name": null,
                "constraint_name": "items_note_key",
                "context": null,
                "datatype_name": null,
                "exception_type": "UniqueViolation",
                "internal_position": null,
                "internal_query": null,
                "message_detail": "Key (note)=(seed) already exists.",
                "message_hint": null,
                "message_primary": "duplicate key value violates unique constraint \"items_note_key\"",
                "schema_name": "c25p02_failed_transaction_recovery",
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "nbtinsert.c",
                "source_function": "_bt_check_unique",
                "source_line": "434",
                "sqlstate": "23505",
                "statement_position": null,
                "table_name": "items",
                "text": "duplicate key value violates unique constraint \"items_note_key\"\nDETAIL:  Key (note)=(seed) already exists."
              },
              "rows": [
                [
                  1,
                  "seed"
                ],
                [
                  2,
                  "repaired"
                ]
              ],
              "statuses": {
                "after_25P02": "INERROR",
                "after_rollback": "IDLE",
                "after_root_error": "INERROR",
                "final": "IDLE"
              },
              "transaction_control": [
                "BEGIN",
                "ROLLBACK",
                "BEGIN",
                "COMMIT"
              ]
            },
            "schema": "c25p02_failed_transaction_recovery",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
