{
  "filename": "orders/lookup.go",
  "rule": "- name: database-observes-request-context\n  where: \"orders/lookup.go\"\n  ensure: >-\n    The order query must use QueryRowContext with c.Request().Context(), so a canceled request or deadline can cancel database work.",
  "corrected": "package orders\nimport (\n    \"database/sql\"\n    \"net/http\"\n    \"github.com/labstack/echo/v5\"\n)\n\nfunc Lookup(db *sql.DB) echo.HandlerFunc {\n    return func(c *echo.Context) error {\n        tenant, ok := c.Get(\"tenant_id\").(string)\n        if !ok || tenant == \"\" { return echo.NewHTTPError(http.StatusUnauthorized) }\n        var status string\n        err := db.QueryRowContext(c.Request().Context(),\n            \"SELECT status FROM orders WHERE id=$1 AND tenant_id=$2\", c.Param(\"id\"), tenant).Scan(&status)\n        if err == sql.ErrNoRows { return echo.NewHTTPError(http.StatusNotFound) }\n        if err != nil { return err }\n        return c.JSON(http.StatusOK, map[string]string{\"status\":status})\n    }\n}\n",
  "broken": "package orders\nimport (\n    \"database/sql\"\n    \"net/http\"\n    \"github.com/labstack/echo/v5\"\n)\n\nfunc Lookup(db *sql.DB) echo.HandlerFunc {\n    return func(c *echo.Context) error {\n        tenant, ok := c.Get(\"tenant_id\").(string)\n        if !ok || tenant == \"\" { return echo.NewHTTPError(http.StatusUnauthorized) }\n        var status string\n        err := db.QueryRow(\n            \"SELECT status FROM orders WHERE id=$1 AND tenant_id=$2\", c.Param(\"id\"), tenant).Scan(&status)\n        if err == sql.ErrNoRows { return echo.NewHTTPError(http.StatusNotFound) }\n        if err != nil { return err }\n        return c.JSON(http.StatusOK, map[string]string{\"status\":status})\n    }\n}\n",
  "regression": [
    "db.QueryRowContext(c.Request().Context(),",
    "db.QueryRow("
  ],
  "test_scenarios": [
    [
      "Normal query",
      "Tenant-scoped result"
    ],
    [
      "Context deadline expires",
      "Query cancellation propagates"
    ],
    [
      "Client disconnects",
      "Request-owned database work stops when driver supports it"
    ],
    [
      "Background job",
      "Uses its own worker context, not a retained Echo context"
    ]
  ],
  "test_source": null,
  "test_command": "go test ./orders -run TestLookupCancellation"
}