| {"args": {"key": "OPS-143"}, "ok": true, "result": "{\"assignee\": \"\", \"description\": \"\", \"key\": \"OPS-143\", \"priority\": \"high\", \"service\": \"\", \"status\": \"open\", \"ticket_id\": 9181, \"title\": \"Implement per-client rate limiting at the edge\", \"type\": \"feature\"}", "tool": "get_ticket"} |
| {"args": {"path": "src/gateway/token_bucket.py"}, "ok": true, "result": "{\"current_content\": \"\\\"\\\"\\\"Per-client rate limiting at the API gateway edge.\\\"\\\"\\\"\\n\\n\\nclass TokenBucket:\\n def __init__(self, capacity, refill_per_sec):\\n raise NotImplementedError\\n\\n def allow(self, now_ms):\\n \\\"\\\"\\\"True if a request may proceed, consuming one token.\\\"\\\"\\\"\\n raise NotImplementedError\\n\", \"function\": \"TokenBucket\", \"note\": \"hidden tests also run at verification time and are not shown\", \"path\": \"src/gateway/token_bucket.py\", \"service\": \"api-gateway\", \"spec\": \"Implement class TokenBucket(capacity, refill_per_sec) with one method,\\nallow(now_ms), returning True if a request may proceed and False otherwise.\\n\\nA bucket starts full. Each allowed request consumes exactly one token; a\\nrefused request consumes none. Tokens refill continuously at refill_per_sec\\nand the bucket never holds more than capacity.\\n\\nRefill is continuous, not stepwise: two calls 500ms apart at 1 token/sec must\\ntogether restore one whole token, so partial time must not be discarded. The\\nfirst call establishes the clock and refills nothing.\\n\\nnow_ms comes from a wall clock that is occasionally stepped backwards by NTP.\\nA backwards jump must never grant tokens and must never make the bucket\\npermanently unable to refill: treat time as not having advanced, and take the\\nnew reading as the current clock.\", \"visible_tests\": [\"a full bucket allows up to capacity\", \"waiting restores a token\"]}", "tool": "read_exercise"} |
| {"args": {"content": "\"\"\"Per-client rate limiting at the API gateway edge.\"\"\"\n\n\nclass TokenBucket:\n def __init__(self, capacity, refill_per_sec):\n self.capacity = float(capacity)\n self.refill_per_sec = float(refill_per_sec)\n self.tokens = float(capacity)\n self.last_ms = None\n\n def allow(self, now_ms):\n if self.last_ms is None:\n self.last_ms = now_ms\n elif now_ms > self.last_ms:\n elapsed = (now_ms - self.last_ms) / 1000.0\n self.tokens = min(self.capacity,\n self.tokens + elapsed * self.refill_per_sec)\n self.last_ms = now_ms\n else:\n self.last_ms = now_ms\n if self.tokens >= 1.0:\n self.tokens -= 1.0\n return True\n return False\n", "path": "src/gateway/token_bucket.py"}, "ok": true, "result": "{\"chars\": 782, \"next\": \"run_exercise_tests to execute it\", \"ok\": true, \"path\": \"src/gateway/token_bucket.py\"}", "tool": "write_implementation"} |
| {"args": {"path": "src/gateway/token_bucket.py"}, "ok": true, "result": "{\"note\": \"all visible tests pass; hidden tests also ran and are not shown\", \"ok\": true, \"passed\": 2, \"path\": \"src/gateway/token_bucket.py\", \"tests\": [{\"error\": \"\", \"name\": \"a full bucket allows up to capacity\", \"passed\": true}, {\"error\": \"\", \"name\": \"waiting restores a token\", \"passed\": true}], \"total\": 2}", "tool": "run_exercise_tests"} |
| {"args": {"key": "OPS-143", "status": "done"}, "ok": true, "result": "{\"assignee\": \"\", \"key\": \"OPS-143\", \"ok\": true, \"status\": \"done\"}", "tool": "update_ticket"} |
| {"verdict": {"passed": true, "reward": 1.0, "score": 1.0}} |
|
|