{
  "schema": 1,
  "sqlstate": "40001",
  "condition_name": "serialization_failure",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "serializable_stale_update",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "Two sessions using SERIALIZABLE",
        "Both read the same row before either writes"
      ],
      "trigger": "Commit one writer, then update the row from the stale serializable transaction.",
      "assertions": [
        "The stale writer receives 40001",
        "Its transaction is rolled back",
        "The first committed value remains before retry",
        "A fresh serializable snapshot is read, applied, and committed as a complete retry"
      ],
      "repair": "Retry the complete serializable transaction with bounded backoff and an idempotency policy; begin from a fresh snapshot and verify the final business result.",
      "cleanup": "Roll back workers and drop the case schema."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "serializable_stale_update",
      "case_id": "serializable_stale_update",
      "language": "sql",
      "statements": {
        "create": "CREATE TABLE serial_rows(id integer PRIMARY KEY, value integer NOT NULL)",
        "seed": "INSERT INTO serial_rows VALUES (1, 0)",
        "first_begin": "BEGIN ISOLATION LEVEL SERIALIZABLE",
        "stale_begin": "BEGIN ISOLATION LEVEL SERIALIZABLE",
        "first_select": "SELECT value FROM serial_rows WHERE id = 1",
        "stale_select": "SELECT value FROM serial_rows WHERE id = 1",
        "first_update": "UPDATE serial_rows SET value = 1 WHERE id = 1",
        "first_commit": "COMMIT",
        "stale_update": "UPDATE serial_rows SET value = 2 WHERE id = 1",
        "stale_rollback": "ROLLBACK",
        "retry_begin": "BEGIN ISOLATION LEVEL SERIALIZABLE",
        "retry_select": "SELECT value FROM serial_rows WHERE id = 1",
        "retry_update": "UPDATE serial_rows SET value = 2 WHERE id = 1",
        "retry_commit": "COMMIT",
        "final_select": "SELECT value FROM serial_rows WHERE id = 1"
      }
    }
  ],
  "runtime": [
    {
      "cases": [
        "serializable_stale_update"
      ],
      "id": "runtime.40001-registry-final-20260909.latest",
      "observed": {
        "diagnostic": {
          "message_primary": "could not serialize access due to concurrent update",
          "severity": "ERROR",
          "source_file": "nodeModifyTable.c",
          "source_function": "ExecUpdate",
          "source_line": "2604",
          "sqlstate": "40001"
        },
        "final_value": 2,
        "reads": {
          "first": 0,
          "retry": 1,
          "stale": 0
        },
        "statuses": {
          "first_after_commit": "IDLE",
          "retry": "IDLE",
          "stale_after_error": "INERROR",
          "stale_after_rollback": "IDLE"
        }
      },
      "raw_sha256": "6a0f6ba16f654c5a3513a19647a5ef3a3e6908802133414d1a8ccd09de6a39ac",
      "run_id": "40001-registry-final-20260909",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "snippet_registry": {
        "sha256": "7ed0b0bf4dc0bb2a2141a1cf9b223b61d80c9817ca041355d1f6527fbbb98007"
      },
      "status": "passed",
      "summary_sha256": "d4d8fdec585ef6fbe571940646d91cda6568befc64e12211ee17888a6c5b2433",
      "target": "latest",
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 28944,
          "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": "both read 0",
                "name": "both serializable reads completed",
                "observed": {
                  "first": 0,
                  "stale": 0
                },
                "passed": true
              },
              {
                "expected": "40001",
                "name": "stale writer sqlstate",
                "observed": "40001",
                "passed": true
              },
              {
                "expected": "INERROR",
                "name": "stale transaction is inerror",
                "observed": "INERROR",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "rollback restores stale connection",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "first commit remains before retry",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "read 1, commit at IDLE, final value 2",
                "name": "complete retry uses a fresh snapshot",
                "observed": {
                  "retry_read": 1,
                  "retry_status": "IDLE",
                  "value": 2
                },
                "passed": true
              },
              {
                "expected": "error",
                "name": "natural serialization failure was raised",
                "observed": "error",
                "passed": true
              }
            ],
            "case_id": "serializable_stale_update",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.017,
            "observed": {
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "SerializationFailure",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "could not serialize access due to concurrent update",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "nodeModifyTable.c",
                "source_function": "ExecUpdate",
                "source_line": "2604",
                "sqlstate": "40001",
                "statement_position": null,
                "table_name": null,
                "text": "could not serialize access due to concurrent update"
              },
              "final_value": 2,
              "reads": {
                "first": 0,
                "retry": 1,
                "stale": 0
              },
              "statuses": {
                "first_after_commit": "IDLE",
                "retry": "IDLE",
                "stale_after_error": "INERROR",
                "stale_after_rollback": "IDLE"
              }
            },
            "schema": "c40001_serializable_stale_update",
            "status": "passed"
          }
        ]
      }
    },
    {
      "cases": [
        "serializable_stale_update"
      ],
      "id": "runtime.40001-registry-final-20260909.pg10",
      "image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
      "observed": {
        "diagnostic": {
          "message_primary": "could not serialize access due to concurrent update",
          "severity": "ERROR",
          "source_file": "nodeModifyTable.c",
          "source_function": "ExecUpdate",
          "source_line": "1012",
          "sqlstate": "40001"
        },
        "final_value": 2,
        "reads": {
          "first": 0,
          "retry": 1,
          "stale": 0
        },
        "statuses": {
          "first_after_commit": "IDLE",
          "retry": "IDLE",
          "stale_after_error": "INERROR",
          "stale_after_rollback": "IDLE"
        }
      },
      "raw_sha256": "85985ffb3f1599df3bc38d65651cb2a532b329e10ab2029481733b3e8a501867",
      "run_id": "40001-registry-final-20260909",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "snippet_registry": {
        "sha256": "7ed0b0bf4dc0bb2a2141a1cf9b223b61d80c9817ca041355d1f6527fbbb98007"
      },
      "status": "passed",
      "summary_sha256": "45e3f031aa5d5cb02adc714c3cbfcb27e9d166bf884c6d8405559a60b840ba45",
      "target": "pg10",
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Etc/UTC",
          "backend_pid": 78,
          "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": "both read 0",
                "name": "both serializable reads completed",
                "observed": {
                  "first": 0,
                  "stale": 0
                },
                "passed": true
              },
              {
                "expected": "40001",
                "name": "stale writer sqlstate",
                "observed": "40001",
                "passed": true
              },
              {
                "expected": "INERROR",
                "name": "stale transaction is inerror",
                "observed": "INERROR",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "rollback restores stale connection",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "first commit remains before retry",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "read 1, commit at IDLE, final value 2",
                "name": "complete retry uses a fresh snapshot",
                "observed": {
                  "retry_read": 1,
                  "retry_status": "IDLE",
                  "value": 2
                },
                "passed": true
              },
              {
                "expected": "error",
                "name": "natural serialization failure was raised",
                "observed": "error",
                "passed": true
              }
            ],
            "case_id": "serializable_stale_update",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.032,
            "observed": {
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "SerializationFailure",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "could not serialize access due to concurrent update",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "nodeModifyTable.c",
                "source_function": "ExecUpdate",
                "source_line": "1012",
                "sqlstate": "40001",
                "statement_position": null,
                "table_name": null,
                "text": "could not serialize access due to concurrent update"
              },
              "final_value": 2,
              "reads": {
                "first": 0,
                "retry": 1,
                "stale": 0
              },
              "statuses": {
                "first_after_commit": "IDLE",
                "retry": "IDLE",
                "stale_after_error": "INERROR",
                "stale_after_rollback": "IDLE"
              }
            },
            "schema": "c40001_serializable_stale_update",
            "status": "passed"
          }
        ]
      }
    },
    {
      "cases": [
        "serializable_stale_update"
      ],
      "id": "runtime.40001-manual-boundary-final-20260909.latest",
      "observed": {
        "connections_autocommit": {
          "first": true,
          "retry": true,
          "stale": true
        },
        "diagnostic": {
          "message_primary": "could not serialize access due to concurrent update",
          "severity": "ERROR",
          "source_file": "nodeModifyTable.c",
          "source_function": "ExecUpdate",
          "source_line": "2604",
          "sqlstate": "40001"
        },
        "final_value": 2,
        "reads": {
          "first": 0,
          "retry": 1,
          "stale": 0
        },
        "retry_semantics": "Fresh retry read 1, then fixed SET value=2; this case does not test a business calculation.",
        "statuses": {
          "first_after_commit": "IDLE",
          "retry": "IDLE",
          "stale_after_error": "INERROR",
          "stale_after_rollback": "IDLE"
        },
        "transaction_control": "Registry BEGIN/COMMIT/ROLLBACK statements run with autocommit=True; no driver implicit BEGIN participates."
      },
      "raw_sha256": "befdfdf94a5577983557d64cecdd013f3e63c4e439388d1fc54e218937378b4f",
      "run_id": "40001-manual-boundary-final-20260909",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "snippet_registry": {
        "sha256": "7ed0b0bf4dc0bb2a2141a1cf9b223b61d80c9817ca041355d1f6527fbbb98007"
      },
      "status": "passed",
      "summary_sha256": "6bbcb014add8ea24c8b6ba7663dade8b26a6ed6b2f95f544f9c8dc11a90cbcdf",
      "target": "latest",
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 90415,
          "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": "both read 0",
                "name": "both serializable reads completed",
                "observed": {
                  "first": 0,
                  "stale": 0
                },
                "passed": true
              },
              {
                "expected": "40001",
                "name": "stale writer sqlstate",
                "observed": "40001",
                "passed": true
              },
              {
                "expected": "INERROR",
                "name": "stale transaction is inerror",
                "observed": "INERROR",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "rollback restores stale connection",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "first commit remains before retry",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "read 1, commit at IDLE, final value 2",
                "name": "complete retry uses a fresh snapshot",
                "observed": {
                  "retry_read": 1,
                  "retry_status": "IDLE",
                  "value": 2
                },
                "passed": true
              },
              {
                "expected": "error",
                "name": "natural serialization failure was raised",
                "observed": "error",
                "passed": true
              }
            ],
            "case_id": "serializable_stale_update",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.018,
            "observed": {
              "connections_autocommit": {
                "first": true,
                "retry": true,
                "stale": true
              },
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "SerializationFailure",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "could not serialize access due to concurrent update",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "nodeModifyTable.c",
                "source_function": "ExecUpdate",
                "source_line": "2604",
                "sqlstate": "40001",
                "statement_position": null,
                "table_name": null,
                "text": "could not serialize access due to concurrent update"
              },
              "final_value": 2,
              "reads": {
                "first": 0,
                "retry": 1,
                "stale": 0
              },
              "retry_semantics": "Fresh retry read 1, then fixed SET value=2; this case does not test a business calculation.",
              "statuses": {
                "first_after_commit": "IDLE",
                "retry": "IDLE",
                "stale_after_error": "INERROR",
                "stale_after_rollback": "IDLE"
              },
              "transaction_control": "Registry BEGIN/COMMIT/ROLLBACK statements run with autocommit=True; no driver implicit BEGIN participates."
            },
            "schema": "c40001_serializable_stale_update",
            "status": "passed"
          }
        ]
      }
    },
    {
      "cases": [
        "serializable_stale_update"
      ],
      "id": "runtime.40001-manual-boundary-final-20260909.pg10",
      "image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
      "observed": {
        "connections_autocommit": {
          "first": true,
          "retry": true,
          "stale": true
        },
        "diagnostic": {
          "message_primary": "could not serialize access due to concurrent update",
          "severity": "ERROR",
          "source_file": "nodeModifyTable.c",
          "source_function": "ExecUpdate",
          "source_line": "1012",
          "sqlstate": "40001"
        },
        "final_value": 2,
        "reads": {
          "first": 0,
          "retry": 1,
          "stale": 0
        },
        "retry_semantics": "Fresh retry read 1, then fixed SET value=2; this case does not test a business calculation.",
        "statuses": {
          "first_after_commit": "IDLE",
          "retry": "IDLE",
          "stale_after_error": "INERROR",
          "stale_after_rollback": "IDLE"
        },
        "transaction_control": "Registry BEGIN/COMMIT/ROLLBACK statements run with autocommit=True; no driver implicit BEGIN participates."
      },
      "raw_sha256": "3d761eff0e571682ef5ea48bdd8ae8c355480f8775387e667c4db707f31d715f",
      "run_id": "40001-manual-boundary-final-20260909",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "snippet_registry": {
        "sha256": "7ed0b0bf4dc0bb2a2141a1cf9b223b61d80c9817ca041355d1f6527fbbb98007"
      },
      "status": "passed",
      "summary_sha256": "156c4129cf0b1b6a1108cf73353cca11425dbf353c4aa695261aeb7d8db1d992",
      "target": "pg10",
      "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": "both read 0",
                "name": "both serializable reads completed",
                "observed": {
                  "first": 0,
                  "stale": 0
                },
                "passed": true
              },
              {
                "expected": "40001",
                "name": "stale writer sqlstate",
                "observed": "40001",
                "passed": true
              },
              {
                "expected": "INERROR",
                "name": "stale transaction is inerror",
                "observed": "INERROR",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "rollback restores stale connection",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "first commit remains before retry",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": "read 1, commit at IDLE, final value 2",
                "name": "complete retry uses a fresh snapshot",
                "observed": {
                  "retry_read": 1,
                  "retry_status": "IDLE",
                  "value": 2
                },
                "passed": true
              },
              {
                "expected": "error",
                "name": "natural serialization failure was raised",
                "observed": "error",
                "passed": true
              }
            ],
            "case_id": "serializable_stale_update",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.038,
            "observed": {
              "connections_autocommit": {
                "first": true,
                "retry": true,
                "stale": true
              },
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "SerializationFailure",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "could not serialize access due to concurrent update",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "nodeModifyTable.c",
                "source_function": "ExecUpdate",
                "source_line": "1012",
                "sqlstate": "40001",
                "statement_position": null,
                "table_name": null,
                "text": "could not serialize access due to concurrent update"
              },
              "final_value": 2,
              "reads": {
                "first": 0,
                "retry": 1,
                "stale": 0
              },
              "retry_semantics": "Fresh retry read 1, then fixed SET value=2; this case does not test a business calculation.",
              "statuses": {
                "first_after_commit": "IDLE",
                "retry": "IDLE",
                "stale_after_error": "INERROR",
                "stale_after_rollback": "IDLE"
              },
              "transaction_control": "Registry BEGIN/COMMIT/ROLLBACK statements run with autocommit=True; no driver implicit BEGIN participates."
            },
            "schema": "c40001_serializable_stale_update",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
