@devries-cameron20 / composio Mirror · read-only / commits / bd26f3283
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

fix(python): match the trigger toolkit filter for underscore toolkit slugs (#4954)

## Summary Python side of #4947, the follow-up I offered in #4948 (TypeScript). `@subscription.handle(toolkit="one_drive")` never calls the callback. V3 trigger frames don't carry a toolkit slug, so `_build_trigger_event_from_v3` takes the first `_` segment of the trigger slug: `ONE_DRIVE_FILE_CREATED_TRIGGER` gives `ONE`. `_filters_match` then compares `one_drive` with `one` and skips the event. That covers `one_drive` (9 triggers), `launch_darkly` (16) and `agent_mail` (1), so 26 of the 671 triggers in `docs/public/data/toolkits.json`. Fixes #4947 Designated PR reviewer: @jkomyno ## Changes - `_filters_match`: the `toolkit` filter still matches when it equals the derived `toolkit_slug`, and now also when the trigger slug starts with `<toolkit>_`, case-insensitively. Same rule as #4948. An empty filter value doesn't take the prefix path, so the existing "empty never matches" behaviour is unchanged. - Three tests in `tests/test_triggers.py` that go through `_parse_payload` with a real V3 frame: `one_drive` and `ONE_DRIVE` both match a `ONE_DRIVE_FILE_CREATED_TRIGGER` event, and `one_drive` does not match `ONE_DRIVEX_FILE_CREATED`. Like the TS PR, I left the derived `toolkit_slug` on the event alone (it is still `ONE`). Getting that right needs the toolkit slug from the backend, since it isn't in the V3 metadata. No changeset: `.changeset` only covers the TS packages, and I didn't see a per-change changelog for the Python package (`python/docs/release.md` bumps versions at release time). Happy to add one if there's somewhere it should go. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? - New tests without the fix: `pytest tests/test_triggers.py` gives 2 failed, 130 passed (`assert False is True`, the event's `toolkit_slug` is `'ONE'`). - With the fix: 132 passed in `tests/test_triggers.py`, and 187 passed across `test_triggers.py`, `test_webhooks.py` and `test_verify_webhook_integration.py`. - Full `pytest tests` (minus `test_provider.py`, providers not installed): 2292 passed. The 8 failures and 4 errors are in `test_cross_sdk_compatibility.py` (needs the `ts/` fixtures, which weren't in my sparse checkout), `test_schema_semantic_regressions.py` and `test_url_safety_pinning.py` (local sockets blocked in my environment). They fail the same way on `next` without this change. - `ruff --config config/ruff.toml check composio/ tests/`: clean. `ruff format --check` on the two files: clean. - `mypy --config-file config/mypy.ini composio/ tests/test_triggers.py`: no issues in 64 files. Python 3.12.12, ruff 0.17.1, mypy 2.3.1, pydantic 2.12.5 (from `uv.lock`). ## Screenshots (if applicable) n/a ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I have read and understand every line of this diff, including any LLM-generated code - [x] Any third-party docs links or promotional content follow the [third-party links policy](https://github.com/ComposioHQ/composio/blob/next/CONTRIBUTING.md#third-party-links-in-docs) - [x] I ran linters/tests locally and they passed - [x] I updated documentation as needed - [x] I added tests or explain why not applicable - [ ] I added a changeset if this change affects published packages ## Additional context Every trigger slug in `toolkits.json` starts with `<TOOLKIT>_`, which is what the prefix match relies on. The `ONE_DRIVEX_` test is there so a longer slug that only shares the prefix doesn't match. --------- Co-authored-by: jkomyno <alberto@composio.dev>

Abhishek B R committed Nov 13, 2026 at 19:11 UTC bd26f3283e843d1c8b5212458a8bf155e0201db0
3 files changed +59
.changeset/python-trigger-toolkit-filter-underscore.md new
+7
@@ -0,0 +1,7 @@
1 +---
2 +'@composio/python-sdk': patch
3 +---
4 +
5 +Match the `toolkit` filter of trigger subscriptions for toolkits whose slug contains an underscore
6 +
7 +The toolkit of an incoming event is derived from the first `_` segment of its trigger slug, so `ONE_DRIVE_FILE_CREATED_TRIGGER` was attributed to `ONE` and `handle(toolkit="one_drive")` skipped every OneDrive event. The same happened to `launch_darkly` and `agent_mail`. A `toolkit` filter now also matches when the trigger slug starts with `<toolkit>_`.
python/composio/core/models/triggers.py
+14
@@ -749,6 +749,20 @@ class TriggerSubscription(Resource):
749 if check_str and str(value).lower() == check_str.lower():
750 continue
751
752 + # Payloads don't carry the toolkit slug, so ``toolkit_slug`` is the
753 + # trigger slug's first ``_`` segment, which is wrong for toolkits
754 + # whose slug contains an underscore (``ONE_DRIVE_FILE_CREATED_TRIGGER``
755 + # gives ``ONE``). Trigger slugs start with ``<TOOLKIT>_``, so the
756 + # toolkit filter also matches on that prefix.
757 + if (
758 + name == "toolkit"
759 + and str(value)
760 + and str(data["trigger_slug"])
761 + .lower()
762 + .startswith(f"{str(value).lower()}_")
763 + ):
764 + continue
765 +
766 self.logger.debug(
767 f"Skipping `{callback}` since "
768 f"`{name}` filter does not match the event metadata",
python/tests/test_triggers.py
+38
@@ -1615,6 +1615,44 @@ class TestTriggerSubscriptionParsing:
1615 event = self._make_event(user_id="")
1616 assert subscription._filters_match(event, {"user_id": ""}, "cb") is False
1617
1618 + # Toolkit slugs such as `one_drive`, `launch_darkly` and `agent_mail` contain
1619 + # an underscore, so the toolkit derived from the trigger slug's first segment
1620 + # is `ONE`, not `ONE_DRIVE`.
1621 + @staticmethod
1622 + def _v3_frame(trigger_slug):
1623 + return json.dumps(
1624 + {
1625 + "id": "evt-1",
1626 + "type": "composio.trigger.message",
1627 + "metadata": {
1628 + "trigger_slug": trigger_slug,
1629 + "trigger_id": "ti_abc",
1630 + "connected_account_id": "ca_abc",
1631 + "auth_config_id": "ac_abc",
1632 + "user_id": "user-1",
1633 + "log_id": "log-1",
1634 + },
1635 + "data": {},
1636 + }
1637 + )
1638 +
1639 + @pytest.mark.parametrize("toolkit", ["one_drive", "ONE_DRIVE"])
1640 + def test_filters_match_toolkit_slug_with_underscore(self, subscription, toolkit):
1641 + """A `toolkit` filter matches events of a toolkit whose slug has an underscore."""
1642 + event = subscription._parse_payload(
1643 + self._v3_frame("ONE_DRIVE_FILE_CREATED_TRIGGER")
1644 + )
1645 + assert event is not None
1646 + assert subscription._filters_match(event, {"toolkit": toolkit}, "cb") is True
1647 +
1648 + def test_filters_match_toolkit_prefix_needs_full_segment(self, subscription):
1649 + """A `toolkit` filter that only shares a prefix with the trigger slug does not match."""
1650 + event = subscription._parse_payload(self._v3_frame("ONE_DRIVEX_FILE_CREATED"))
1651 + assert event is not None
1652 + assert (
1653 + subscription._filters_match(event, {"toolkit": "one_drive"}, "cb") is False
1654 + )
1655 +
1656 def test_truncate_frame_bounds_long_frames(self):
1657 """A long raw frame is truncated so PII-bearing frames aren't dumped."""
1658 short = "x" * 10