Skip to content

[Plugin] Harden error handling, timeouts, null guards, and webhook status handling in zapier plugin #14255

Closed

Description

@TheRWX

Problem Description

In plugins/zapier/, several edge cases, unbounded HTTP calls, and unhandled exceptions cause runtime crashes or hangs during normal webhook triggering and memory syncing:

  1. plugins/zapier/client.py:
    • ZapierClient.send_hook_conversation_created, OmiClient.create_conversation, and OmiClient.get_latest_conversation invoke requests.post() and requests.get() without a timeout argument, allowing requests to hang indefinitely on unresponsive webhooks or slow backend endpoints.
    • send_hook_conversation_created checks resp.status_code != 200 to flag errors. Standard Zapier REST hooks frequently respond with HTTP 201 Created or 204 No Content, which Omi erroneously logs and treats as failure.
    • Dead except requests.exceptions.HTTPError: blocks attempt to access resp.status_code before assignment, risking UnboundLocalError.
    • OmiClient.get_latest_conversation assumes resp.json() returns a list and directly accesses index 0 (resp_json[0]). If upstream returns an error dictionary (e.g. {"detail": "..."} or {"conversations": [...]}), it crashes with KeyError: 0. It also lacks unhandled JSONDecodeError protection on non-JSON proxy responses.
    • ZapierDatabasePropertyModel, ZapierDatabaseModel, and ZapierOAuthModel crash on missing keys or non-dict inputs; multi_from_dict iterates over dictionary keys if given a dict.

  2. plugins/zapier/conversation_created.py:
    • In both get_trigger_conversation_sample and create_zapier_conversation, conversation.structured.emoji.encode('latin1').decode('utf-8') crashes with AttributeError: 'NoneType' object has no attribute 'emoji' if structured is None or AttributeError if emoji is None. Furthermore, unhandled UnicodeDecodeError can crash execution if utf-8 decoding fails.
    • conversation.transcript_segments crashes with TypeError if None, and unshielded lambdas crash if segment items lack the speaker attribute.
    • Subtraction (conversation.finished_at - conversation.started_at) crashes with TypeError if either timestamp is None, and produces negative duration on clock skew.
    • In create_zapier_conversation, sub.decode() crashes with AttributeError: 'str' object has no attribute 'decode' if subscriber URLs in storage or mocks are strings.
    • In subscribe_zapier_trigger and unsubscribe_zapier_trigger, empty or invalid non-HTTP URL schemes are accepted without validation.
    • Error responses ungracefully attempt status code lookups without safe integer coercion.

  3. Zero Unit Test Coverage:
    • plugins/zapier currently contains no unit tests.


Proposed Solution

  1. Add DEFAULT_TIMEOUT = 10.0 across all HTTP client calls in plugins/zapier/client.py.
  2. Treat 200 <= resp.status_code < 300 as successful webhook execution.
  3. Defensively parse resp.json() in get_latest_conversation supporting bare lists, wrapped dicts, and malformed payloads.
  4. Add _build_zapier_conversation_payload helper in plugins/zapier/conversation_created.py with defensive null guards for structured, emoji, transcript_segments, and timestamps.
  5. Support both bytes and str types for subscriber URLs.
  6. Author a 100% hermetic unit test suite (plugins/zapier/test_zapier_hardening.py) with 17 tests running under standard library Python (python3 -S) in <0.01s with zero third-party dependencies.

Proposed bounty: $50.00 USD.
PayPal: [email protected]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions