{
  "filename": "lua/queue_receipt.lua",
  "rule": "- name: timer-admission-must-succeed\n  where: \"lua/queue_receipt.lua\"\n  ensure: >-\n    enqueue must handle ngx.timer.at failure with a service-unavailable response before reporting accepted.",
  "corrected": "local function enqueue(order_id, tenant_id, deliver)\n    local ok, err = ngx.timer.at(0, function(premature, order, tenant)\n        if premature then return end\n        deliver(order, tenant)\n    end, order_id, tenant_id)\n    if not ok then\n        ngx.status = ngx.HTTP_SERVICE_UNAVAILABLE\n        ngx.say(\"background capacity unavailable\")\n        return ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE)\n    end\n    ngx.status = ngx.HTTP_ACCEPTED\n    ngx.say(\"accepted\")\nend\n\nreturn enqueue\n",
  "broken": "local function enqueue(order_id, tenant_id, deliver)\n    local ok, err = ngx.timer.at(0, function(premature, order, tenant)\n        if premature then return end\n        deliver(order, tenant)\n    end, order_id, tenant_id)\n    if false then\n        ngx.status = ngx.HTTP_SERVICE_UNAVAILABLE\n        ngx.say(\"background capacity unavailable\")\n        return ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE)\n    end\n    ngx.status = ngx.HTTP_ACCEPTED\n    ngx.say(\"accepted\")\nend\n\nreturn enqueue\n",
  "regression": [
    "    if not ok then",
    "    if false then"
  ],
  "test_scenarios": [
    [
      "Timer admitted",
      "202"
    ],
    [
      "Pending timer limit reached",
      "503"
    ],
    [
      "Worker shuts down",
      "premature path exits"
    ],
    [
      "Delivery raises",
      "Separate logged retry/dead-letter policy handles it"
    ]
  ],
  "test_source": null,
  "test_command": "resty tests/queue_receipt_spec.lua"
}