Skip to content

fix(gateway): complete lazy-install rebind for slack/feishu/matrix + ensure_and_bind helper#25038

Merged
alt-glitch merged 1 commit into
mainfrom
fix/gateway-lazy-deps-rebind
May 14, 2026
Merged

fix(gateway): complete lazy-install rebind for slack/feishu/matrix + ensure_and_bind helper#25038
alt-glitch merged 1 commit into
mainfrom
fix/gateway-lazy-deps-rebind

Conversation

@alt-glitch

Copy link
Copy Markdown
Collaborator

Problem

Fixes #25028.

The lazy-install hooks added in #25014 installed packages correctly but failed to rebind module-level globals after install. In a long-lived gateway process (non-Docker), this causes:

  • Slack: NameError: name 'aiohttp' is not defined on first file upload
  • Feishu: TypeError: 'NoneType' object is not callable on adapter instantiation (all ~25 lark_oapi symbols stay None)
  • Matrix: mautrix.types enums stay as stub classes with wrong values

DingTalk was already correct and served as the reference.

Fix

1. New helper: tools.lazy_deps.ensure_and_bind()

DRY helper that combines ensure() + an importer callable + globals().update():

def check_slack_requirements() -> bool:
    if SLACK_AVAILABLE:
        return True

    def _import():
        from slack_bolt.async_app import AsyncApp
        import aiohttp
        return {"AsyncApp": AsyncApp, "aiohttp": aiohttp, "SLACK_AVAILABLE": True, ...}

    from tools.lazy_deps import ensure_and_bind
    return ensure_and_bind("platform.slack", _import, globals(), prompt=False)

This eliminates the error-prone pattern of manually listing every global + rebind assignment. The _import() function is the single source of truth — if it imports a name, it gets bound.

2. Platform fixes using the new helper:

Platform Names rebound
Slack AsyncApp, AsyncSocketModeHandler, AsyncWebClient, aiohttp
Feishu All 25 lark_oapi symbols (lark, CreateMessageRequest, FeishuWSClient, etc.)
Matrix All 10 mautrix.types symbols (EventType, RoomCreatePreset, TrustState, etc.)

3. pyproject.toml [slack] extra — added missing aiohttp==3.13.3 (needed by slack-bolt's async path).

Related

@alt-glitch alt-glitch requested a review from a team May 13, 2026 14:14
@github-actions

github-actions Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/gateway-lazy-deps-rebind vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8261 on HEAD, 8252 on base (🆕 +9)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4333 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/slack Slack app adapter platform/feishu Feishu / Lark adapter platform/matrix Matrix adapter (E2EE) labels May 13, 2026
…add ensure_and_bind helper

Fixes #25028.

The lazy-install hooks added in #25014 installed packages correctly but
failed to rebind module-level globals after install:

- Slack: missing aiohttp rebind → NameError on file uploads
- Feishu: none of the ~25 lark_oapi symbols rebound → TypeError on
  adapter instantiation
- Matrix: mautrix.types enums stayed as stubs → mismatched values at
  runtime

Introduces tools.lazy_deps.ensure_and_bind() — a DRY helper that
combines ensure() + importer-callable + globals().update(). This
eliminates the error-prone pattern of manually listing every global
that needs updating after lazy-install. Each platform adapter now
defines a single _import() function returning all bindings.

Also fixes: pyproject.toml [slack] extra was missing aiohttp (needed
by slack-bolt's async path).
@alt-glitch alt-glitch force-pushed the fix/gateway-lazy-deps-rebind branch from 968c3a6 to dd00003 Compare May 13, 2026 14:38
@alt-glitch alt-glitch merged commit d898e0e into main May 14, 2026
20 of 21 checks passed
@alt-glitch alt-glitch deleted the fix/gateway-lazy-deps-rebind branch May 14, 2026 05:11
sunJose pushed a commit to sunJose/hermes-agent that referenced this pull request May 14, 2026
…add ensure_and_bind helper (NousResearch#25038)

Fixes NousResearch#25028.

The lazy-install hooks added in NousResearch#25014 installed packages correctly but
failed to rebind module-level globals after install:

- Slack: missing aiohttp rebind → NameError on file uploads
- Feishu: none of the ~25 lark_oapi symbols rebound → TypeError on
  adapter instantiation
- Matrix: mautrix.types enums stayed as stubs → mismatched values at
  runtime

Introduces tools.lazy_deps.ensure_and_bind() — a DRY helper that
combines ensure() + importer-callable + globals().update(). This
eliminates the error-prone pattern of manually listing every global
that needs updating after lazy-install. Each platform adapter now
defines a single _import() function returning all bindings.

Also fixes: pyproject.toml [slack] extra was missing aiohttp (needed
by slack-bolt's async path).
jsboige pushed a commit to jsboige/hermes-agent that referenced this pull request May 14, 2026
…add ensure_and_bind helper (NousResearch#25038)

Fixes NousResearch#25028.

The lazy-install hooks added in NousResearch#25014 installed packages correctly but
failed to rebind module-level globals after install:

- Slack: missing aiohttp rebind → NameError on file uploads
- Feishu: none of the ~25 lark_oapi symbols rebound → TypeError on
  adapter instantiation
- Matrix: mautrix.types enums stayed as stubs → mismatched values at
  runtime

Introduces tools.lazy_deps.ensure_and_bind() — a DRY helper that
combines ensure() + importer-callable + globals().update(). This
eliminates the error-prone pattern of manually listing every global
that needs updating after lazy-install. Each platform adapter now
defines a single _import() function returning all bindings.

Also fixes: pyproject.toml [slack] extra was missing aiohttp (needed
by slack-bolt's async path).
AlexFoxD pushed a commit to AlexFoxD/hermes-agent that referenced this pull request May 21, 2026
…add ensure_and_bind helper (NousResearch#25038)

Fixes NousResearch#25028.

The lazy-install hooks added in NousResearch#25014 installed packages correctly but
failed to rebind module-level globals after install:

- Slack: missing aiohttp rebind → NameError on file uploads
- Feishu: none of the ~25 lark_oapi symbols rebound → TypeError on
  adapter instantiation
- Matrix: mautrix.types enums stayed as stubs → mismatched values at
  runtime

Introduces tools.lazy_deps.ensure_and_bind() — a DRY helper that
combines ensure() + importer-callable + globals().update(). This
eliminates the error-prone pattern of manually listing every global
that needs updating after lazy-install. Each platform adapter now
defines a single _import() function returning all bindings.

Also fixes: pyproject.toml [slack] extra was missing aiohttp (needed
by slack-bolt's async path).
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…add ensure_and_bind helper (NousResearch#25038)

Fixes NousResearch#25028.

The lazy-install hooks added in NousResearch#25014 installed packages correctly but
failed to rebind module-level globals after install:

- Slack: missing aiohttp rebind → NameError on file uploads
- Feishu: none of the ~25 lark_oapi symbols rebound → TypeError on
  adapter instantiation
- Matrix: mautrix.types enums stayed as stubs → mismatched values at
  runtime

Introduces tools.lazy_deps.ensure_and_bind() — a DRY helper that
combines ensure() + importer-callable + globals().update(). This
eliminates the error-prone pattern of manually listing every global
that needs updating after lazy-install. Each platform adapter now
defines a single _import() function returning all bindings.

Also fixes: pyproject.toml [slack] extra was missing aiohttp (needed
by slack-bolt's async path).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter platform/matrix Matrix adapter (E2EE) platform/slack Slack app adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(gateway): lazy-install rebind incomplete in slack/feishu/matrix adapters (follow-up to #25014)

2 participants