Skip to content

fix(clickup-app): harden error handling, null guards, session lifecycle, and type coercion (#14267) - #14268

Merged
Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
TheRWX:fix/clickup-app-hardening
Sep 17, 2026
Merged

Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
TheRWX:fix/clickup-app-hardening

Conversation

@TheRWX

@TheRWX TheRWX commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR resolves #14267 by hardening plugins/omi-clickup-app/ against in-memory session leaks, non-dict/HTML gateway outage payloads, non-numeric assignee IDs, due date variations, and unhandled exceptions:

  1. Session Lifecycle Management & Memory Leak Remediation (simple_storage.py):

    • Implemented delete_session(session_id: str) -> bool and cleanup_old_sessions(max_age_seconds: int = 3600) -> int to evict expired or abandoned sessions from the global sessions dictionary.
    • Wired periodic cleanup sweeping into monitor_session_timeouts in main.py.
    • Migrated deprecated datetime.utcnow() to timezone-aware UTC timestamps (datetime.now(timezone.utc)).
  2. Defensive Response Parsing & Null Guards (clickup_client.py):

    • Added _safe_json(response) helper ensuring gateway error pages (HTML 502/504) or malformed payloads do not raise AttributeError or JSONDecodeError.
    • Guarded get_spaces, get_lists, get_folders, get_folder_lists, and get_workspace_members against None collections, non-dict list items, and missing keys.
  3. Resilient Parameter Coercion (clickup_client.py):

    • In create_task: safely coerced assignee IDs to integers via try/except (ValueError, TypeError), dropping non-numeric strings (e.g. "me", "admin") without throwing unhandled exceptions.
    • Supported raw millisecond integer due dates, numeric strings, and ISO 8601 strings (with or without time components).
    • Safely unpacked status whether returned as a nested dictionary ({"status": "..."}), a string, or None.
  4. Decoupled OpenAI Client Initialization (task_detector.py):

    • Decoupled eager top-level initialization into lazy get_openai_client().
    • Implemented safe deterministic fallbacks for ai_extract_task_details and ai_match_list when the client or API key is not configured.
    • Protected list and member traversals against non-dict elements and missing attributes.
  5. Defensive Transcript Processing (main.py):

    • Added _extract_segment_texts helper safely extracting non-empty string texts from transcript segment arrays.
    • Guarded against null task_content and protected selected_list lookups against non-dict items.
  6. Notification Safety (omi_notifications.py):

    • Added get_omi_credentials() for dynamic runtime loading and sanitized exception logging to avoid AST log safety tripwires.
  7. Expanded Hermetic Test Suite (test_clickup_client.py):

    • Expanded in-place test suite from 5 to 37 hermetic unit tests covering _safe_json, client endpoints, create_task coercion, session storage lifecycle and TTL eviction, detector trigger parsing, and segment extraction.
    • Runs in <0.05s under pure Python standard library (python3 -S).

Preflight Verification

  • scripts/pr-preflight --lane ci: 16/16 manifest checks passed.
  • clickup-app-client-tests: 37/37 tests passed (0.033s).
  • clickup-app-settings-page-tests: 2/2 tests passed (0.003s).
  • plugin-oauth-client-log-safety-tests: 5/5 tests passed (1.871s).
  • Single-directory isolation: 100% confined to plugins/omi-clickup-app/.

Fixes #14267
PayPal: [email protected]

Failure class (fixes)

Failure-Class: none

Review in cubic

…le, and type coercion (BasedHardware#14267)

Harden plugins/omi-clickup-app against unbounded session memory leaks,
non-dict/HTML gateway outage payloads, non-numeric assignee IDs, and
eager OpenAI client initialization.

- simple_storage.py: implement bounded session lifecycle methods (delete_session
  and cleanup_old_sessions) and migrate to timezone-aware UTC timestamps.
- clickup_client.py: implement _safe_json defensive parsing; add null and non-dict
  guards across spaces, lists, folders, and workspace members; safely coerce
  assignee IDs to integers and normalize due date and status handling.
- task_detector.py: decouple OpenAI client into lazy get_openai_client() with
  graceful deterministic fallbacks and null-safe list/member parsing.
- main.py: add _extract_segment_texts helper, safe list lookups, and periodic
  session cleanup in monitor_session_timeouts.
- omi_notifications.py: dynamic credentials and safe exception logging.
- test_clickup_client.py: expand from 5 to 37 hermetic unit tests running in
  <0.05s under pure stdlib (python3 -S).

Fixes BasedHardware#14267
PayPal: [email protected]

Failure-Class: none
…ponse for stdlib test runners (BasedHardware#14267)

Avoid evaluating requests.Response at import time in environments where
requests is stubbed or uninstalled, and stub Response/RequestException
on the test requests module stub.

Failure-Class: none
@TheRWX

TheRWX commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Resolved CI import evaluation issue in commit 0d7c2eb3c7:

  1. Import Annotation Safety: Removed the requests.Response parameter type annotation on _safe_json(response) in plugins/omi-clickup-app/clickup_client.py:9 to rely on duck typing across runtime responses and test stubs, preventing eager evaluation failures in minimal/stubbed runtime environments.
  2. Test Stub Completeness: Added Response and RequestException stubs to the _requests mock module in plugins/omi-clickup-app/test_clickup_client.py:17-18.
  3. Verification: Executed all 37 unit tests under python3 -S (0.04s, 37/37 pass) and verified clean execution against the full local preflight harness (scripts/pr-preflight --lane ci, 16/16 checks pass).

PayPal: [email protected]

…asedHardware#14267)

Resolve NameError on Any during class definition under Python runtimes
evaluating annotations at class creation time.

Failure-Class: none
@TheRWX

TheRWX commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

All checks green: added missing Any import from typing in commit 3bfd2a2cbc to ensure type annotation compatibility across all Python runtimes. Full test suite (37/37 hermetic tests) and all 16 CI preflight manifest checks pass with zero warnings or errors.

PayPal: [email protected]

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @TheRWX — reviewed this against issue #14267 and verified it locally: all six modules compile, and the expanded hermetic suite passes 37/37 offline (requests/dotenv/fastapi/openai stubbed, no network, no secrets). This is a cohesive hardening pass, well scoped to the plugin.

Per-file notes:

  • clickup_client.py — _safe_json() cleanly covers dict/list/HTML-error payloads, and every collection getter (get_spaces, get_lists, get_folders, get_folder_lists, get_workspaces, get_workspace_members) now guards its traversal. create_task's assignee coercion (drop non-numeric like "me"/"admin"), due-date handling (int ms / numeric string / ISO with-or-without time), and dict-or-string status unpacking all behave as described and are covered by tests.
  • simple_storage.py — delete_session() + cleanup_old_sessions() bound the in-memory dict, and the utcnow() → timezone-aware migration includes naive-timestamp repair in get_session_idle_time(), so mixed old/new records don't break idle detection.
  • main.py — the 60-tick cleanup sweep inside monitor_session_timeouts is the right integration point, and _extract_segment_texts() properly tolerates dict/bare-string/None/whitespace segments (previously seg.get("text", "") would raise on string segments).
  • task_detector.py — lazy get_openai_client() removes the import-time crash when OPENAI_API_KEY is unset, and the deterministic fallbacks return well-formed tuples instead of raising.
  • omi_notifications.py — lazy get_omi_credentials() fixes the import-time env capture; notification behavior unchanged.
  • test_clickup_client.py — genuinely useful hermetic coverage; the FastAPI-stub import of main.py is a nice touch that keeps CI honest.

Two non-blocking observations for a possible follow-up:

  1. delete_session()/cleanup_old_sessions() mutate only the in-memory dict and never call save_sessions() — an evicted session will resurrect from sessions.json on restart. The in-process leak is still fixed; persisting evictions (or dropping session persistence entirely) would close the loop.
  2. Error prints now log only type(e).__name__. It avoids leaking response bodies into logs, which is good, but it also drops status codes that would help debugging — worth logging response.status_code where it's in scope.

Separately, and pre-existing rather than introduced here: OAuth access tokens are stored in plain JSON at rest. Not this PR's job to solve, but worth a maintainers' conversation.

Overall this is in good shape — leaving the merge decision with 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 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.

Reviewed all 6 files at head 3bfd2a2. Verdict: approve.

  • clickup_client.py: _safe_json guards non-JSON bodies; every list/dict accessor isinstance-checked; get_all_lists preserves the #13808 fail-closed folder contract (folder walk failure → [] rather than a silently short picker); create_task coerces priority/assignees/due_date and returns structured error dicts instead of raising.
  • main.py / task_detector.py / omi_notifications.py: import-time AsyncOpenAI(...) and credential crashes replaced with lazy getters; monitor loop evicts sessions every 60 ticks (SimpleSessionStorage.cleanup_old_sessions); error prints emit exception type only, no payloads.
  • simple_storage.py: naive datetime.utcnow() → tz-aware datetime.now(timezone.utc) with tzinfo backfill for legacy stamps; update_timezone no longer shadows the timezone import; bounded session eviction added.
  • Verified locally at head: python3 plugins/omi-clickup-app/test_clickup_client.py → 37/37 OK; test_settings_page.py → 2/2 OK. Both suites are already CI-wired via checks-manifest.

CI green on this head (no fail/pending), merge-tree clean vs 75e42d3. No open review threads.

@Git-on-my-level
Git-on-my-level merged commit acb1ed0 into BasedHardware:main Sep 17, 2026
31 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, null guards, session lifecycle, and type coercion in omi-clickup-app

2 participants