{
"id": "288",
"prompt": "A notification rate-limit tester: a BUZZ ME button calls host::agent::notify, which returns 1 when the notification actually posted and 0 when it was dropped - it never prompts for permission and is rate-limited to roughly one per 3 seconds. Count POSTED and DROPPED separately, remember the frame of the last success in a slot so a cooldown bar can drain over 180 frames, and print on screen why drops are normal.",
"solution_rl": "fn frame(t: i32) {\n host::display::clear(0x101014);\n host::display::draw_string(120, 40, \"NOTIFY TESTER\", 0xffffff, 2);\n\n host::display::fill_rect(156, 120, 200, 90, 0xdddddd);\n host::display::draw_string(202, 155, \"BUZZ ME\", 0x000000, 2);\n\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(0);\n host::display::state_set(0, down);\n if down == 1 && prev == 0 {\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n if px >= 156 && px < 356 && py >= 120 && py < 210 {\n let ok: i32 = host::agent::notify(\"Cartridge ping\", \"You tapped the buzz button.\");\n if ok == 1 {\n host::display::state_set(1, host::display::state_get(1) + 1);\n host::display::state_set(3, t);\n } else {\n host::display::state_set(2, host::display::state_get(2) + 1);\n }\n }\n }\n\n host::display::draw_string(80, 270, \"POSTED\", 0x22bb44, 2);\n host::display::draw_number(80, 300, host::display::state_get(1), 0xffffff, 4);\n host::display::draw_string(320, 270, \"DROPPED\", 0xbb5533, 2);\n host::display::draw_number(320, 300, host::display::state_get(2), 0xffffff, 4);\n\n let last: i32 = host::display::state_get(3);\n let mut cool: i32 = 180 - (t - last);\n if last == 0 || cool < 0 {\n cool = 0;\n }\n host::display::draw_string(80, 400, \"RATE LIMIT COOLDOWN\", 0x888888, 1);\n host::display::fill_rect(80, 420, cool * 2, 10, 0xaa7700);\n host::display::draw_string(80, 450, \"DROPS ARE NORMAL: PERMISSION-GATED\", 0x556677, 1);\n host::display::draw_string(80, 464, \"AND LIMITED TO ROUGHLY ONE PER 3S\", 0x556677, 1);\n host::display::present();\n}\n",
"tags": [
"agent",
"notify",
"rate-limit"
]
}