skyware-js / bot

A framework for building bots on Bluesky.
Mozilla Public License 2.0
43 stars 6 forks source link

Rate Limit Exceeded #12

Open ledlamp opened 1 month ago

ledlamp commented 1 month ago

Thought this library was supposed to handle rate limits but I got "Failed to send message(s)." errors after using bot.sendMessages() a bunch of times.

Error: Failed to send message.
    at file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:971:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Bot.sendMessage (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:959:26)
    at async Bot.<anonymous> (file:///home/ubuntu/bskychatbot/index.mjs:42:3) {
  [cause]: XRPCError: RateLimitExceeded > Rate Limit Exceeded
      at RateLimitedAgent.request (file:///home/ubuntu/bskychatbot/node_modules/@atcute/client/dist/rpc.js:82:19)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Bot.sendMessage (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:959:26)
      at async Bot.<anonymous> (file:///home/ubuntu/bskychatbot/index.mjs:42:3) {
    status: 429,
    kind: 'RateLimitExceeded',
    description: 'Rate Limit Exceeded',
    headers: {
      'access-control-allow-origin': '*',
      'cache-control': 'private',
      'content-length': '61',
      'content-type': 'application/json; charset=utf-8',
      date: 'Fri, 25 Oct 2024 20:59:10 GMT',
      etag: 'W/"3d-egyFOcXCrKQFzoI7522/4+PpxIk"',
      'keep-alive': 'timeout=90',
      'ratelimit-limit': '3000',
      'ratelimit-policy': '3000;w=300',
      'ratelimit-remaining': '2902',
      'ratelimit-reset': '1729889985',
      'strict-transport-security': 'max-age=63072000',
      vary: 'Authorization, Accept-Encoding',
      'x-powered-by': 'Express'
    },
    [cause]: undefined
  }
}
futurGH commented 1 month ago

Are you on 0.3.6? I fixed some ratelimit-related issues in the latest update. If not, try updating and let me know if you still run into this.

ledlamp commented 1 month ago

Yes, it is 0.3.6.

futurGH commented 1 month ago

Got it, can you try 0.3.7-beta.0 and see if this continues to happen?

ledlamp commented 1 month ago

Still happening

Error: Failed to send messages.
    at file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1019:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Bot.sendMessages (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1016:26)
    at async Bot.<anonymous> (file:///home/ubuntu/bskychatbot/index.mjs:61:3) {
  [cause]: XRPCError: RateLimitExceeded > Rate Limit Exceeded
      at RateLimitedAgent.request (file:///home/ubuntu/bskychatbot/node_modules/@atcute/client/dist/rpc.js:82:19)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Bot.sendMessages (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1016:26)
      at async Bot.<anonymous> (file:///home/ubuntu/bskychatbot/index.mjs:61:3) {
    status: 429,
    kind: 'RateLimitExceeded',
    description: 'Rate Limit Exceeded',
    headers: {
      'access-control-allow-origin': '*',
      'cache-control': 'private',
      'content-length': '61',
      'content-type': 'application/json; charset=utf-8',
      date: 'Sat, 26 Oct 2024 04:06:11 GMT',
      etag: 'W/"3d-egyFOcXCrKQFzoI7522/4+PpxIk"', 
      'keep-alive': 'timeout=90',
      'ratelimit-limit': '3000',
      'ratelimit-policy': '3000;w=300',
      'ratelimit-remaining': '2995',
      'ratelimit-reset': '1729915865',
      'strict-transport-security': 'max-age=63072000',
      vary: 'Authorization, Accept-Encoding',
      'x-powered-by': 'Express'
    },
    [cause]: undefined
  }
}
Error: Failed to send messages.
    at file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1019:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Bot.sendMessages (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1016:26)
    at async Bot.<anonymous> (file:///home/ubuntu/bskychatbot/index.mjs:61:3) {
  [cause]: XRPCError: RateLimitExceeded > Rate Limit Exceeded
      at RateLimitedAgent.request (file:///home/ubuntu/bskychatbot/node_modules/@atcute/client/dist/rpc.js:82:19)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Bot.sendMessages (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1016:26)
      at async Bot.<anonymous> (file:///home/ubuntu/bskychatbot/index.mjs:61:3) {
    status: 429,
    kind: 'RateLimitExceeded',
    description: 'Rate Limit Exceeded',
    headers: {
      'access-control-allow-origin': '*',
      'cache-control': 'private',
      'content-length': '61',
      'content-type': 'application/json; charset=utf-8',
      date: 'Sat, 26 Oct 2024 04:06:11 GMT',
      etag: 'W/"3d-egyFOcXCrKQFzoI7522/4+PpxIk"',
      'keep-alive': 'timeout=90',
      'ratelimit-limit': '3000',
      'ratelimit-policy': '3000;w=300',
      'ratelimit-remaining': '2994',
      'ratelimit-reset': '1729915865',
      'strict-transport-security': 'max-age=63072000',
      vary: 'Authorization, Accept-Encoding',
      'x-powered-by': 'Express'
    },
    [cause]: undefined
  }
}
futurGH commented 1 month ago

Weird, I'll have to see if I can reproduce.

futurGH commented 1 month ago

Can you give beta.1 a shot? Apologies, this is tough to pin down.

futurGH commented 1 month ago

Fix is published in 0.3.7, let me know if you continue to run into this.

ledlamp commented 3 weeks ago

Happened again

2024-11-04T20:52:52.712Z,did:plc:icwasmy7mggrjaw4k5yam2nt,luizzeroxis,luizzeroxis.bsky.social,that before might not happen because you could assume people didnt see the thin
g at all at least
Error: Failed to send messages.
    at file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1017:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Bot.sendMessages (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1014:26)
    at async Bot.<anonymous> (file:///home/ubuntu/bskychatbot/index.mjs:94:3) {
  [cause]: XRPCError: RateLimitExceeded > Rate Limit Exceeded
      at RateLimitedAgent.request (file:///home/ubuntu/bskychatbot/node_modules/@atcute/client/dist/rpc.js:82:19)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Bot.sendMessages (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:1014:26)
      at async Bot.<anonymous> (file:///home/ubuntu/bskychatbot/index.mjs:94:3) {
    status: 429,
    kind: 'RateLimitExceeded',
    description: 'Rate Limit Exceeded',
    headers: {
      'access-control-allow-origin': '*',
      'cache-control': 'private',
      'content-length': '61',
      'content-type': 'application/json; charset=utf-8',
      date: 'Mon, 04 Nov 2024 20:52:56 GMT',
      etag: 'W/"3d-egyFOcXCrKQFzoI7522/4+PpxIk"',
      'keep-alive': 'timeout=90',
      'ratelimit-limit': '3000',
      'ratelimit-policy': '3000;w=300',
      'ratelimit-remaining': '2950',
      'ratelimit-reset': '1730753700',
      'strict-transport-security': 'max-age=63072000',
      vary: 'Authorization, Accept-Encoding',
      'x-powered-by': 'Express'
    },
    [cause]: undefined
  }
}
Error: Failed to send message.
    at file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:968:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Bot.sendMessage (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:956:26) {
  [cause]: XRPCError: RateLimitExceeded > Rate Limit Exceeded
      at RateLimitedAgent.request (file:///home/ubuntu/bskychatbot/node_modules/@atcute/client/dist/rpc.js:82:19)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Bot.sendMessage (file:///home/ubuntu/bskychatbot/node_modules/@skyware/bot/dist/bot/Bot.js:956:26) {
    status: 429,
    kind: 'RateLimitExceeded',
    description: 'Rate Limit Exceeded',
    headers: {
      'access-control-allow-origin': '*',
      'cache-control': 'private',
      'content-length': '61',
      'content-type': 'application/json; charset=utf-8',
      date: 'Mon, 04 Nov 2024 20:52:56 GMT',
      etag: 'W/"3d-egyFOcXCrKQFzoI7522/4+PpxIk"',
      'keep-alive': 'timeout=90',
      'ratelimit-limit': '3000',
      'ratelimit-policy': '3000;w=300',
      'ratelimit-remaining': '2949',
      'ratelimit-reset': '1730753700',
      'strict-transport-security': 'max-age=63072000',
      vary: 'Authorization, Accept-Encoding',
      'x-powered-by': 'Express'
    },
    [cause]: undefined
  }
}

Version was 0.3.7-beta.1, but it's the same right?

futurGH commented 3 weeks ago

Weird, the headers indicate you've still got 2950 requests remaining. What's the other process running on your server (i.e. is it also running @skyware bot? Is it only using chat endpoints or others as well?)

ledlamp commented 3 weeks ago

it's running in my house so the other client would be me using the bluesky chat

ledlamp commented 2 weeks ago

Actually, I'm on a different network with different IP so it must be just the bot but it still happens.

I'm using .sendMessages() with more than a dozen people, could it be that this rate limit is for the individual messages and not the HTTP requests? https://gitea.moe/lamp/bluesky-groupchat-bot/src/commit/da34c1012123a6f8d536a24625eec1d8b5cad975/index.mjs#L97

ledlamp commented 1 week ago

Well I don't know, I changed it to use separate sendMessage but it works the same.

2024-11-22_22-35-43 203_ubuntu@dev_~

I don't understand these ratelimit headers.. Policy is 3000 requests per 300 seconds? 2722 remaining? Quota resets in 1732343848 seconds? What?

futurGH commented 1 week ago

That's a timestamp, not a length of time. Really not sure though, my best guess is that the chat service has its own rate limits that aren't actually being exposed — will need to ask about it.