{
  "schema": 1,
  "sqlstate": "57014",
  "condition_name": "query_canceled",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "statement_timeout_cancel",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "A dedicated connection",
        "statement_timeout set to 100 ms"
      ],
      "trigger": "Run pg_sleep(1) and let the server cancel the statement at the configured timeout.",
      "assertions": [
        "SQLSTATE is 57014",
        "The message identifies statement timeout",
        "The autocommit connection is usable for a subsequent query"
      ],
      "repair": "Classify timeout by operation and budget; tune the timeout or query, and do not treat cancellation as proof that all server work has stopped without checking the operation.",
      "cleanup": "Drop the case schema with an owner connection."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "statement_timeout_cancel",
      "case_id": "statement_timeout_cancel",
      "language": "sql",
      "statements": {
        "set_timeout": "SET statement_timeout = '100ms'",
        "cancel": "SELECT pg_sleep(1)",
        "followup": "SELECT 1"
      }
    }
  ],
  "runtime": [
    {
      "cases": [
        "statement_timeout_cancel"
      ],
      "id": "runtime.57014-registry-final-20260909.latest",
      "observed": {
        "diagnostic": {
          "message_primary": "canceling statement due to statement timeout",
          "severity": "ERROR",
          "source_file": "postgres.c",
          "source_function": "ProcessInterrupts",
          "source_line": "3446",
          "sqlstate": "57014"
        },
        "followup": 1,
        "statuses": {
          "after_cancel": "IDLE",
          "after_followup": "IDLE"
        }
      },
      "raw_sha256": "dabaaf0b01d0c45133ea2d3e85ba3272e436cf75b95c7681b608b1b96cb9a99f",
      "run_id": "57014-registry-final-20260909",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "snippet_registry": {
        "sha256": "f6cf9d26837aae084280538fc4283418b23f160838b581c67eaf0e22d8c6715d"
      },
      "status": "passed",
      "summary_sha256": "8e310974fb6160095bd37df9c259419289e44a2c62ab42d72218e906a2ef8bbc",
      "target": "latest",
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 29077,
          "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": "57014",
                "name": "query-canceled sqlstate",
                "observed": "57014",
                "passed": true
              },
              {
                "expected": "statement timeout",
                "name": "timeout message is identified",
                "observed": "canceling statement due to statement timeout",
                "passed": true
              },
              {
                "expected": "error, IDLE, SELECT 1",
                "name": "autocommit connection remains usable",
                "observed": {
                  "error": true,
                  "final_status": "IDLE",
                  "status": "IDLE",
                  "valid": 1
                },
                "passed": true
              }
            ],
            "case_id": "statement_timeout_cancel",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.109,
            "observed": {
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "QueryCanceled",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "canceling statement due to statement timeout",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "postgres.c",
                "source_function": "ProcessInterrupts",
                "source_line": "3446",
                "sqlstate": "57014",
                "statement_position": null,
                "table_name": null,
                "text": "canceling statement due to statement timeout"
              },
              "followup": 1,
              "statuses": {
                "after_cancel": "IDLE",
                "after_followup": "IDLE"
              }
            },
            "schema": "c57014_statement_timeout_cancel",
            "status": "passed"
          }
        ]
      }
    },
    {
      "cases": [
        "statement_timeout_cancel"
      ],
      "id": "runtime.57014-registry-final-20260909.pg10",
      "image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
      "observed": {
        "diagnostic": {
          "message_primary": "canceling statement due to statement timeout",
          "severity": "ERROR",
          "source_file": "postgres.c",
          "source_function": "ProcessInterrupts",
          "source_line": "3018",
          "sqlstate": "57014"
        },
        "followup": 1,
        "statuses": {
          "after_cancel": "IDLE",
          "after_followup": "IDLE"
        }
      },
      "raw_sha256": "85c6bb64d7e6178c4b2300d5f24d15c356339662f40573180dd230b2c65a3b80",
      "run_id": "57014-registry-final-20260909",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "snippet_registry": {
        "sha256": "f6cf9d26837aae084280538fc4283418b23f160838b581c67eaf0e22d8c6715d"
      },
      "status": "passed",
      "summary_sha256": "fa02b6c80d94c75f63912def8ffd13dd794792d403749f57de45dd6f860d2dbb",
      "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": "57014",
                "name": "query-canceled sqlstate",
                "observed": "57014",
                "passed": true
              },
              {
                "expected": "statement timeout",
                "name": "timeout message is identified",
                "observed": "canceling statement due to statement timeout",
                "passed": true
              },
              {
                "expected": "error, IDLE, SELECT 1",
                "name": "autocommit connection remains usable",
                "observed": {
                  "error": true,
                  "final_status": "IDLE",
                  "status": "IDLE",
                  "valid": 1
                },
                "passed": true
              }
            ],
            "case_id": "statement_timeout_cancel",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.113,
            "observed": {
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "QueryCanceled",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "canceling statement due to statement timeout",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "postgres.c",
                "source_function": "ProcessInterrupts",
                "source_line": "3018",
                "sqlstate": "57014",
                "statement_position": null,
                "table_name": null,
                "text": "canceling statement due to statement timeout"
              },
              "followup": 1,
              "statuses": {
                "after_cancel": "IDLE",
                "after_followup": "IDLE"
              }
            },
            "schema": "c57014_statement_timeout_cancel",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
