Skip to content

fix(plugins): bound every requests call with a timeout - #15113

Merged
kodjima33 merged 3 commits into
BasedHardware:mainfrom
singhharsh1708:fix/plugins-request-timeouts
Oct 5, 2026
Merged

kodjima33 merged 3 commits into
BasedHardware:mainfrom
singhharsh1708:fix/plugins-request-timeouts

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15112.

requests applies no default timeout, so an upstream that completes the TCP handshake and then stops answering keeps the caller waiting forever. 75 of the 108 requests calls in plugins/ have no timeout on current main (one of the original 76 picked up a literal timeout=10 in the meantime), and 19 of those sit in async def handlers, where the blocking call holds the event loop and the app stops answering everyone, not just the caller.

Every call now passes a timeout. Each file gets a REQUEST_TIMEOUT = (5, 30) constant, 5 seconds to connect and 30 between bytes, which is the value dropbox_client.py already used for its downloads. The 16 files are:

App Calls On the event loop
omi-github-app 13
omi-clickup-app 9 1
composio 9 8
omi-dropbox-app 8 1
omi-twitter-chat-tools-app 7 3
omi-google-calendar-app 7 1
omi-shopify-app 6 2
omi-shipbob-app 6 1
omi-notion-app 5 1
omi-linear-app 3 1
omi-twitter-app, omi-slack-app, import 3

The event-loop ones are mostly OAuth token exchanges: shopify_callback, linear_callback, twitter_callback, auth_callback (dropbox), handle_shipbob_callback, google_callback, notion_callback, plus composio's page extraction and clickup's create_task.

This class has been fixed one app at a time three times already: #14278 (whoop), #14255 (zapier) and #14257 (oauth). That is the trigger in AGENTS.md for a reusable guard rather than a fourth instance fix, so scripts/check_plugin_request_timeouts.py lands with it. It is stdlib only, follows requests.Session() aliases, and reports whether each finding sits in an async def. Two manifest entries run it and its own tests on plugins/**/*.py.

Verified by running, from the repo root:

$ python3 scripts/check_plugin_request_timeouts.py
plugin request timeouts: 236 file(s) checked, no unbounded calls

$ python3 scripts/check_plugin_request_timeouts.py          (with one timeout removed again)
1 requests call(s) without a timeout:
  plugins/omi-linear-app/main.py:144 requests.post()

$ python3 scripts/test_check_plugin_request_timeouts.py
Ran 4 tests in 1.051s
OK

The event-loop claim is not theory. Against a socket that accepts and never answers, with a FastAPI app whose async def /callback calls requests.get on it, an unrelated /health request on the same worker:

no timeout:        /health -> ReadTimeout after 8.0s (event loop blocked), /callback still running
timeout=(3, 3):    /health -> 200 in 2.0s,                                 /callback failed in 3.0s

Sizing: the connect budget is 5s and the read budget 30s, matching DropboxClient.DEFAULT_DOWNLOAD_TIMEOUT, which already transfers the same files. Calls that retry on requests.exceptions.Timeout (dropbox upload and download) keep their existing tenacity policy, so a slow-but-alive upstream still gets its retries instead of one unbounded wait.

Merged main in. Two follow-up commits came out of that:

Failure-Class: none

Review in cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified on this head:

  • Ran python3 scripts/check_plugin_request_timeouts.py from a checkout of this PR: 210 file(s) checked, no unbounded calls, exit 0; its own test file passes (4 tests). Both new .github/checks-manifest.yaml entries follow the same lanes/triggers pattern as the existing checks.
  • Audited the full 20-file diff for anything riding along: every removed line is a bare requests.* call and every added line is either the timeout= argument, its trailing-comma adjustment, or the new scanner/tests/manifest entries. No hidden behavior changes.
  • Checked the values per app: plugins/omi-github-app/claude_code_cli.py and plugins/omi-github-app/claude_coder.py bound get_default_branch, create_pr_with_github_api, merge_pr_with_github_api and the git-tree CRUD calls; plugins/omi-shopify-app/main.py and plugins/omi-shipbob-app/main.py route every method arm of their *_api_request dispatchers plus their OAuth callbacks through the constant; plugins/composio/src/notion.py bounds all calls including the background page extraction and the notion_callback token exchange. (5, 30) (connect, read) matches the budget dropbox_client.py already used for downloads.
  • The history claim holds: fix(omi-whoop-app): add request timeouts, null score guards, and type validation #14278, [Plugin] Harden error handling, timeouts, null guards, and webhook status handling in zapier plugin #14255 and [Plugin] Harden error handling, timeouts, null guards, and safe database validation in oauth notion plugin #14257 are the three earlier one-app-at-a-time timeout fixes, and shipping a reusable guard here matches the repo's stated rule for recurring same-cause fixes.

Two non-blocking notes:

  1. plugins/omi-dropbox-app/dropbox_client.py already declared tenacity retries on requests.exceptions.Timeout (retry_if_exception_type, stop_after_attempt(3)); without a bound those retries almost never fired in practice. Bound + retry is the right shape — just be aware the effective worst case for those calls is now up to ~3 attempts.
  2. The scanner's session_names only tracks variables assigned directly from requests.Session(), and call detection only recognizes bases named requests, x.requests, or a directly assigned session variable. An import requests as rq or a session passed through a wrapper would slip through — none exist under plugins/ today (verified), so this is future-proofing rather than a current gap.

Good reliability work — the event-loop framing in the description matches the code (19 unbounded calls inside async def handlers, mostly third-party OAuth token exchanges), and the guard should keep this class closed. The new CI checks and the checks-manifest changes need a maintainer's merge decision before this lands; leaving for human maintainer review.

🤖 Automated review on behalf of the maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior python labels Sep 20, 2026

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on 6e343d2 against origin/main 1ef3b91.

origin/main still has 76 unbounded requests calls under plugins/ (19 inside async def). scripts/check_plugin_request_timeouts.py is a real AST scanner; on this tip it reports 210 file(s) checked, no unbounded calls. plugin-request-timeouts and plugin-request-timeout-check-tests are in .github/checks-manifest.yaml. Scanner tests 4/4 OK. Production hunks are timeout=REQUEST_TIMEOUT plus the (5, 30) constants; test_clickup_client.py only updates call kwargs.

Hygiene is already green. I am not merging. #15124 stays closed as a duplicate of this vehicle.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4/5: real timeout-hardening fix (fixes #15112), tests + guard script added, CI green; diff size (368 lines/16 files) is the only soft miss.

@singhharsh1708
singhharsh1708 force-pushed the fix/plugins-request-timeouts branch from 29ed922 to 7b8b52e Compare September 20, 2026 17:35
@singhharsh1708

Copy link
Copy Markdown
Contributor Author

Rebased onto fdcae0a. Two conflicts with main, both resolved: the dropbox token refresh had picked up a literal timeout=10 on main, now using this file's REQUEST_TIMEOUT, and the checks-manifest addition sat next to a new iq-rating-score-parsing-tests entry, both kept.

The Dart Tests (Pacific/Kiritimati) failure on the previous head was not from this diff, which touches no Dart. It was the tearDown in app/test/unit/local_recordings_owner_test.dart racing the filesystem:

PathNotFoundException: Deletion failed, path = '/tmp/local_recordings_ownerESNZTD'
test/unit/local_recordings_owner_test.dart 25:39

That line does if (await dir.exists()) await dir.delete(...), so it throws when the directory goes away between the two calls.

After the rebase: scanner reports 218 files checked, no unbounded calls; scanner tests 4/4; dropbox suites pass.

@singhharsh1708

Copy link
Copy Markdown
Contributor Author

Hygiene was failing on dropbox-token-refresh-and-tools-tests with ModuleNotFoundError: No module named 'tenacity'. That is not from this diff, it is the suite itself: it stubs requests, dotenv, fastapi and db for hermetic execution but never stubs tenacity, and it imported dropbox_client outside the stub context.

Checked main's copy directly, running it under a python without requests or tenacity:

$ python3 test_token_refresh_and_tools.py   # origin/main copy
from dropbox_client import DropboxClient
ModuleNotFoundError: No module named 'tenacity'

Same failure, so the check only passes where tenacity happens to be installed. This branch triggers it because it touches the dropbox files.

Fixed in a66fadd: added a tenacity stub, bound DropboxClient from the module main.py already imported inside the stub context instead of re-importing it outside, and switched the one string patch target to the loaded module so it does not re-import either.

python3  (no requests, no tenacity): Ran 6 tests, OK
venv     (both installed):           Ran 6 tests, OK

scripts/pr-preflight now exits 0.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5/5 confidence: real bug (missing timeouts on 75+ requests calls across 16 plugin files, some blocking the async event loop), root cause well-documented with reproduction, scoped to timeout-only changes plus a reusable CI guard script, fixes referenced issue #15112, all CI green.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Verified on a66fadd899f0.

This stays the timeout vehicle for #15112. The scanner is still missing on main, and origin/main still has unbounded requests calls under plugins/.

I am not approving or merging this SHA. GitHub reports CONFLICTING/DIRTY on .github/checks-manifest.yaml and plugins/omi-dropbox-app/test_token_refresh_and_tools.py. The tenacity stub in that test file already landed via merged #15186.

Please rebase onto current main, drop test_token_refresh_and_tools.py (keep the REQUEST_TIMEOUT production hunks and the scanner), and union the manifest entry. Do not resolve those files in the web editor.

My earlier approve was on 6e343d2, not this rewrite.

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed current head a66fadd899f0 (prior APPROVE was 6e343d2bd8fb). origin/main requests calls in composio/plugins still have no timeout. Scanner + tests pin the bound. Hygiene SUCCESS. Not merging.

@aryanorastar

Copy link
Copy Markdown
Collaborator

The touched plugin clients on main still call requests with no timeout. This head adds timeout=REQUEST_TIMEOUT. a66fadd899f0 conflicts and spans 21 files, so rebase it. This stays open and unapproved.

— Astar, on behalf of @aryanorastar

requests has no default timeout, so an upstream that accepts the connection and then stops answering pins the caller. 19 of the 76 unbounded calls sat in async handlers, where the blocking call holds the event loop and the app stops answering everyone.
The same class was fixed one app at a time in BasedHardware#14278, BasedHardware#14255 and BasedHardware#14257. The scanner is stdlib only, follows requests.Session aliases, and reports which findings sit in an async handler.
@singhharsh1708
singhharsh1708 force-pushed the fix/plugins-request-timeouts branch from a66fadd to dbcc7af Compare September 22, 2026 15:46
@aryanorastar

Copy link
Copy Markdown
Collaborator

Request timeouts are the right class, but dbcc7af7ed27 touches 20 files and merge is UNSTABLE. This stays open and unapproved.

— Astar, on behalf of @aryanorastar

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slack OAuth requests.post still has no timeout. This head sets timeout= on the plugin request calls. Hygiene passed on dbcc7af7ed27.

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified this end to end from the head commit: ran scripts/test_check_plugin_request_timeouts.py (4/4 pass, including the real accept-then-stall socket test) and ran scripts/check_plugin_request_timeouts.py over all 16 changed plugin files — zero unbounded calls remain.

The plugin diffs are purely additive timeout=REQUEST_TIMEOUT kwargs plus the (5, 30) constant; no URL, auth, or payload changes anywhere, and omi-dropbox-app/main.py nicely unifies the old literal timeout=10 into the shared constant.

Two minor, non-blocking notes on the scanner for future hardening:

  1. It won't catch import requests as rq or from requests import get call sites (neither pattern is used in the changed files today).
  2. In explicit-file mode the str(path).startswith("plugins/") guard means only paths under plugins/ are honored — fine for the manifest triggers, but worth knowing if anyone runs it with absolute paths.

The new checks-manifest entries only execute the repo-local python3 scripts added here, so no CI-surface risk. Thanks for fixing the whole class and landing the guard instead of a fourth per-app patch — the AGENTS.md trigger reasoning and the PR writeup are exactly right.

workflow-review stays on for the manifest change per usual process; leaving the merge call to maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level mentioned this pull request Oct 4, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix(plugins): every requests call in plugins/ now has a (5,30) timeout to stop event-loop-blocking hangs on OAuth callbacks — root cause well documented (75/108 unbounded calls, 19 on the event loop), linked issue #15112, adds reusable CI guard script + tests, CI fully green, already approved twice each by kodjima33 and aryanorastar. Diff is large (309+62) but mechanical/repeated across files; confidence 4/5, merging.

@kodjima33
kodjima33 merged commit 566b74e into BasedHardware:main Oct 5, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty $150] reliability(plugins): 76 requests calls have no timeout, 19 of them block the event loop

4 participants