Skip to content

fix(feishu): add open group active context - #47581

Draft
YuanHanzhong wants to merge 2 commits into
NousResearch:mainfrom
YuanHanzhong:codex/feishu-active-context
Draft

fix(feishu): add open group active context#47581
YuanHanzhong wants to merge 2 commits into
NousResearch:mainfrom
YuanHanzhong:codex/feishu-active-context

Conversation

@YuanHanzhong

Copy link
Copy Markdown
Contributor

Summary

  • allow Feishu group_rules[chat_id].policy=open to authorize human group messages without globally allowing every sender
  • record recent human group messages in a bounded per-chat ring buffer and inject them as context-only channel_context for follow-up messages
  • suppress human-to-human @mentions as observe-only unless the bot is addressed, while preserving them for later context
  • persist explicit latest_by_chat.latest_purpose and updated_at state when a recent-context state path is configured

Related issues / prior art

Validation

  • /Users/xiashui/.hermes/hermes-agent/.venv/bin/python -m pytest tests/gateway/test_feishu_active_context.py tests/gateway/test_unauthorized_dm_behavior.py tests/gateway/test_feishu_bot_admission.py tests/gateway/test_feishu_bot_auth_bypass.py tests/gateway/test_feishu.py tests/gateway/test_text_batching.py::TestFeishuAdaptiveDelay -q => 269 passed / 45 skipped
  • /Users/xiashui/.hermes/hermes-agent/.venv/bin/python -m compileall -q gateway/platforms/feishu.py tests/gateway/test_feishu_active_context.py gateway/authz_mixin.py tests/gateway/test_unauthorized_dm_behavior.py => PASS

Not included

  • No gateway restart/reload behavior.
  • No fast-ack/background follow-up scheduling; that belongs in the gateway run loop rather than the Feishu adapter.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter area/auth Authentication, OAuth, credential pools P2 Medium — degraded but workaround exists labels Jun 17, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused Feishu context work. This needs substantial rework for current main.

Problems

  • The authorization change conflicts with the current fail-closed gateway contract: gateway/authz_mixin.py:467-514 intentionally does not trust group_policy: open, tests/gateway/test_config_driven_access_policy.py:212-220 locks that behavior down, and SECURITY.md:202-205 requires a caller allowlist for network-exposed adapters.
  • The diff targets gateway/platforms/feishu.py, but 552adbe08 moved that adapter to plugins/platforms/feishu/adapter.py; it cannot be directly salvaged onto current main.
  • PR commit ede51b731267 adds non-secret HERMES_FEISHU_RECENT_CONTEXT_* behavior settings. Repository policy requires this configuration to live in config.yaml.

Suggested changes

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
@xy769

xy769 commented Jul 19, 2026

Copy link
Copy Markdown

Hi @YuanHanzhong — wanted to flag this PR as a real-world need: I'm running Hermes-Feishu in a 3-person work group where users frequently ask the bot to "summarize what we just discussed", and the bot currently has zero visibility into messages between @-mentions. Issue #25728 captures this same ask.

I read through the diff and the sweeper's three blockers carefully. They're all reasonable and I think they can be fixed in one pass without changing the design:

  1. Path move. Commit 552adbe08 relocated the Feishu adapter from gateway/platforms/feishu.py to plugins/platforms/feishu/adapter.py. The 301-line buffer/ring-buffer logic in this PR needs to land in the plugin and re-attach to the new event dispatcher hooks in _handle_message_event_data / _process_inbound_message.

  2. Config drift. HERMES_FEISHU_RECENT_CONTEXT_* should move to config.yaml per repo policy (CONTRIBUTING.md). Suggested schema:

    plugins:
      feishu:
        group_context:
          recent_buffer_size: 20          # 0 = off
          recent_buffer_ttl_seconds: 3600 # 1h
          deliver_on_mention: true
  3. Authz narrowing. The change at gateway/authz_mixin.py currently lets policy: open on a group_rules entry bypass the gateway caller allowlist (SECURITY.md:202-205). Scoping this to per-chat authorization only — not caller-allowlist bypass — would preserve the fail-closed contract for network-exposed adapters.

Happy to send a port-PR against main that lands these three fixes plus the existing tests moved to the new layout, if useful. But no urgency — if you're mid-revision, please drive it. Just want to avoid stomping.

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

Labels

area/auth Authentication, OAuth, credential pools comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants