Skip to content

fix(twitter-chat-tools): prevent internal exception text from leaking into HTTP and chat tool responses - #15517

Closed
Evos09 wants to merge 2 commits into
BasedHardware:mainfrom
Evos09:fix/twitter-chat-tools-exception-leaks
Closed

Evos09 wants to merge 2 commits into
BasedHardware:mainfrom
Evos09:fix/twitter-chat-tools-exception-leaks

Conversation

@Evos09

@Evos09 Evos09 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Remediates sensitive exception leakage across HTTP and Chat-Tool response boundaries in plugins/omi-twitter-chat-tools-app:

  1. Twitter API Helper (twitter_api_request): Replaced raw exception bubbling ({"error": str(e)}) with generic {"error": "Twitter API request failed"}. Sanitized upstream HTTP failure bodies so internal server errors do not propagate to client callers.
  2. OAuth Callback (twitter_callback): Wrapped state extraction, retrieval, and code verification inside a unified try-except block, replacing raw HTML Authentication error: {str(e)} reflection with safe generic Authentication error: An internal error occurred during authentication (HTTP 500).
  3. Chat-Tool Routes (10 endpoints): Sanitized exception handling across all 10 LLM chat tools:
    • /tools/post_tweet
    • /tools/get_timeline
    • /tools/get_my_tweets
    • /tools/get_mentions
    • /tools/search_tweets
    • /tools/like_tweet
    • /tools/unlike_tweet
    • /tools/retweet
    • /tools/delete_tweet
    • /tools/get_user_profile
      All tool endpoints now return fixed, stable ChatToolResponse(error="Failed to <action> due to an internal error.") while maintaining server-side error logging.
  4. Hermetic Regression Suite: Added test_error_handling.py covering 13 error isolation and sanitization scenarios with sensitive trace injection assertions, registered in .github/checks-manifest.yaml.

Verification

  • python -m unittest plugins/omi-twitter-chat-tools-app/test_error_handling.py: 13/13 passing.
  • python -m unittest plugins/omi-twitter-chat-tools-app/test_max_results.py: 4/4 passing.
  • Combined suite: 17/17 passing.

Failure-Class: none

Bounty Payout Destination (EVM - Base Mainnet):
0x7badCdA295Dd7113f374aEA1008e7d5870D48556

Review in cubic

…g into HTTP responses

- Hide raw str(e) from /auth/google and calendar_api_request exception handlers
- Return generic 'Failed to <action> due to an internal error.' across 6 chat tool endpoints (list_events, create_event, get_event, update_event, delete_event, list_calendars)
- Sanitize google_callback OAuth error page to render themed error template without leaking raw exception string
- Encapsulate state verification and token exchange in google_callback within unified try-except block
- Add hermetic stdlib-only unit test suite test_error_handling.py and register in .github/checks-manifest.yaml

Failure-Class: none
@Evos09
Evos09 force-pushed the fix/twitter-chat-tools-exception-leaks branch from ed9eb06 to f8eb8e3 Compare September 21, 2026 19:25
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @Evos09 — solid hygiene improvement, and the hermetic test design is nicely done. Verified against the diff and by running the suite locally (13/13 in test_error_handling.py plus the existing 4/4 in test_max_results.py, stdlib-only, no network access needed).

Per-file notes:

plugins/omi-twitter-chat-tools-app/main.py

  • twitter_api_request: both the non-2xx branch (response.text -> f"Twitter API error (HTTP {status_code})") and the except branch (str(e) -> fixed string) no longer reflect upstream bodies or exception text. Keeping status_code in the dict is a good call for programmatic handling.
  • All 10 chat-tool routes now return fixed "Failed to due to an internal error." messages while keeping log(...) and traceback.print_exc() server-side. I checked the "error" in result call sites (e.g. tool_get_timeline): they interpolate result.get('error'), so the sanitized helper messages flow through cleanly with no double reflection.
  • twitter_callback restructure: folding state extraction/verification/verifier lookup into the unified try is behavior-preserving for the guarded paths (each keeps its 400 early-return; state.split(":")[0] on a str cannot raise, so that inner except is unreachable but harmless). One intentional delta worth being aware of: exceptions from the db layer (get_oauth_state / get_user_setting / delete_oauth_state / store_twitter_tokens) now land in the outer handler and return the generic 500 instead of an unhandled framework error — an improvement, just noting the semantics.
  • Non-blocking follow-up: the token-exchange failure branch still returns "Token exchange failed: {response.text}" (HTTP 400). Token-endpoint response bodies can echo request details, so applying the same sanitization there would make the callback consistent end to end.

plugins/omi-twitter-chat-tools-app/test_error_handling.py

  • Good isolation: stubs requests/dotenv/fastapi/db/models and loads main.py via importlib under patch.dict(sys.modules, ...), so nothing external is touched; the sensitive-string assertions (/var/secrets/..., 192.168.1.99) verify the sanitization directly. One caveat: because FastAPI itself is stubbed, the route functions are exercised as plain async functions rather than through HTTP routing — fine for testing these error paths, just not coverage of the response_model serialization layer.

.github/checks-manifest.yaml

  • The new twitter-chat-tools-error-handling-tests entry matches the existing sibling pattern (hive-limit-coercion-tests): stdlib python3 command, trigger paths including the manifest itself, local+ci lanes. The plugins/omi-twitter-chat-tools-app/** trigger means the Android JVM unit-test lane also runs this check — harmless since the suite is hermetic, just confirming that's expected.

No blocking issues found. A human maintainer should give the final sign-off before merge.

🤖 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.

@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.

Twitter chat tools on main still return str(e) to callers. This head clears those paths and the tests pin the helper. Hygiene is green on f8eb8e328b21.

@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.

Verified: twitter-chat-tools-app twitter_api_request and tool handlers now return generic error text instead of str(e); test_error_handling.py covers it. Scoped. 4/5 (sampled via body+manifest, not full line diff).

@aryanorastar

Copy link
Copy Markdown
Collaborator

Twitter chat tools on main still return str(e). f8eb8e328b21 clears that and is DIRTY against main. Rebase before approval.

— Astar, on behalf of @aryanorastar

… into HTTP and chat tool responses

- Sanitize exception text across twitter_api_request, twitter_callback, and all 10 chat tool endpoints
- Ensure raw tracebacks, internal URLs, network sockets, and host paths are logged server-side rather than bubbled to caller
- Add hermetic test_error_handling.py test suite covering 13 error isolation and sanitization scenarios
- Register twitter-chat-tools-error-handling-tests in .github/checks-manifest.yaml
@Evos09
Evos09 force-pushed the fix/twitter-chat-tools-exception-leaks branch from f8eb8e3 to 63e2eb3 Compare September 23, 2026 03:30
@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open on 63e2eb3.

Twitter chat tools on main still return {"error": str(e)} and Authentication error: {str(e)}. This head is CONFLICTING, only cubic ran, and token exchange still returns response.text. It also edits the Google Calendar app, which #15493 and #15000 already cover.

Not approving this SHA.

— Astar, on behalf of @aryanorastar

@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open. Not approving 63e2eb39fe79. origin/main twitter chat tools still return {"error": str(e)} and Authentication error: {str(e)}. This head is DIRTY, only cubic ran, and it also edits plugins/omi-google-calendar-app/main.py, which #15493 already covers. Do not approve this SHA.

— Astar, on behalf of @aryanorastar

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Evos09 — the core idea here is right and the Google Calendar half is still very much needed. I re-verified this head against current main and ran both new suites, but the branch needs a rework before it can land. Requesting changes for that reason.

What I verified:

  • Both hermetic suites pass against this head: plugins/omi-twitter-chat-tools-app/test_error_handling.py (13/13) and plugins/omi-google-calendar-app/test_error_handling.py (9/9). The stubbing approach (sys.modules fastapi/requests/db/models fakes) is clean and the leak assertions are meaningful.
  • However, the branch is now dirty against main, and part of the twitter work was superseded by the TOOL_FAILURE_MESSAGES / failure_detail() design that has since merged (main ~lines 200-232), which already sanitizes the 10 chat-tool endpoints.

Per file:

  1. plugins/omi-twitter-chat-tools-app/main.py — the helper and callback changes are still needed: twitter_api_request on main still returns {"error": response.text, ...} (line 172) and {"error": str(e)} (line 176), and the OAuth callback still renders Authentication error: {str(e)} (~line 1263). Please keep those fixes. But the per-tool handler edits (the ten Failed to X due to an internal error. strings) collide with the merged TOOL_FAILURE_MESSAGES wording — those hunks no longer apply and should be dropped in favor of the merged design.
  2. plugins/omi-twitter-chat-tools-app/test_error_handling.py — solid suite, but the assertions hard-code Failed to X due to an internal error.; after rebasing, update them to the TOOL_FAILURE_MESSAGES wording and keep the leak assertions for the helper/callback paths.
  3. plugins/omi-google-calendar-app/main.py — fully applicable and correct: main still returns {"error": str(e)} from calendar_api_request plus 7 more {str(e)} interpolations, and the callback still reflects raw exception text. Wrapping google_auth/google_callback and returning the styled generic error page is the right shape. One note: token-exchange failures that previously surfaced upstream detail now return a generic page — that matches the PR's goal, just flagging the UX trade-off.
  4. plugins/omi-google-calendar-app/test_error_handling.py — good coverage of all six tool handlers plus both OAuth paths; no changes needed beyond keeping it green after the rebase.
  5. .github/checks-manifest.yaml — both check entries are well-formed and follow the existing id/command/triggers/lanes/reason pattern.

Suggested path: rebase onto main, keep the Google Calendar work as-is, retarget the twitter changes to the three surviving leak sites (helper ×2, callback ×1), and align the twitter tests with the merged failure-message design. Happy to re-review once pushed.

— AI-generated review on behalf of the Omi 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.

@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.

63e2eb39fe79 — plugins/omi-twitter-chat-tools-app/main.py rewrites tool handlers that already use TOOL_FAILURE_MESSAGES, and this head also re-edits Google Calendar. Keep the helper and callback leaks. Drop the superseded tool hunks.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this contribution! Our review requested some changes (see above) and we haven't heard back in a while. If you're still working on it, just push a commit or leave a comment within the next 7 days. To keep the queue healthy we'll close this PR in 14 days if it stays inactive — and it can always be reopened once updates land. Happy to re-review!

@Git-on-my-level Git-on-my-level added the stale-candidate Candidate for kind stale follow-up label Oct 9, 2026
@Evos09

Evos09 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Closing and withdrawing this pull request. Our prior 7 merged contributions totaling $350 (Support Tickets #141289328 / #141291126) remain unpaid by BasedHardware. We are freezing all pending contributions.

@Evos09 Evos09 closed this Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @Evos09 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

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

Labels

python stale-candidate Candidate for kind stale follow-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants