Skip to content

feat(integrations): rate-limit incoming webhook calls - #102

Merged
itsskofficial merged 2 commits into
existence-master:mainfrom
anushkaanair:feat/webhook-rate-limit
Oct 8, 2026
Merged

itsskofficial merged 2 commits into
existence-master:mainfrom
anushkaanair:feat/webhook-rate-limit

Conversation

@anushkaanair

Copy link
Copy Markdown
Contributor

What and why

Webhook calls to Sentient are now rate limited, so a leaked webhook URL can no longer flood Sentient with task runs. Each hook accepts 30 calls a minute by default; extra calls get a 429 with a Retry-After header.

Closes #91

  • New setting integrations.webhook_rate_limit_per_minute (default 30, 0 turns the limit off), with a description like the settings around it.
  • Each hook has its own token bucket (HookStore.rate_limited). An idle hook can take a burst the size of the limit, and a steady caller is held to it.
  • The check in POST /hooks/{id} runs after the secret check. That way someone who only knows the URL can't use up a real caller's budget, and a call without the secret still gets 401, not 429.
  • A refused call is not published and does not count towards calls.
  • A deleted hook drops its bucket.
  • The LAN listener mounts the same route and shares the same HookStore, so it gets the same limit. A test covers that.
  • docs/API.md section 16 documents the setting and the 429.

How I tested it

.venv/bin/python -m pytest tests/integrations/test_hooks.py  # 10 passed (4 existing + 6 new)
.venv/bin/python -m pytest  # 530 passed, 1 skipped (before the last test was added)
.venv/bin/ruff check sentient tests  # All checks passed

The new behaviour tests fail when the check in the route is removed. They use a movable clock (sentient.integrations.hooks._monotonic), so they never sleep. I didn't run the desktop app; nothing in desktop/ changed.

Checklist

  • Tests added or updated, and pytest / npm run typecheck pass locally for what I touched
  • ruff check sentient tests is clean
  • docs/API.md updated if the desktop ↔ engine contract changed
  • No keys, tokens or personal data in the code, tests or screenshots

POST /hooks/{id} checked the secret and a body size limit but had no rate
limit, so a leaked webhook URL could flood Sentient with task runs.

Each hook now has a token bucket. `integrations.webhook_rate_limit_per_minute`
(default 30, 0 turns it off) sets its size, and a call over the limit gets
a 429 with a `Retry-After` header. The check runs after the secret check, so
callers without the secret can't use up a real caller's budget, and a refused
call is neither published nor counted. A deleted hook drops its bucket.

Closes existence-master#91
@github-actions github-actions Bot added documentation Improvements or additions to documentation area: engine Agent loop, models, approvals, storage, gateway area: integrations App integrations, change feeds, webhooks labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@anushkaanair

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 8, 2026
@itsskofficial
itsskofficial merged commit 7e4fcfd into existence-master:main Oct 8, 2026
7 of 8 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 8, 2026
@itsskofficial

Copy link
Copy Markdown
Contributor

Merged, thank you @anushkaanair! Clean change, good tests, and the contract update in API.md was exactly right. If you'd like another one, #92 (IMAP STARTTLS and folders) is a nice next step in the same area.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: engine Agent loop, models, approvals, storage, gateway area: integrations App integrations, change feeds, webhooks documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rate-limit incoming webhook calls

2 participants