Skip to content

fix(multiplex): per-profile cron scope, credential isolation, and per-chat-id rate limiting - #65319

Closed
soddy022 wants to merge 5 commits into
NousResearch:mainfrom
soddy022:fix/multiplex-cron-credential-scope
Closed

soddy022 wants to merge 5 commits into
NousResearch:mainfrom
soddy022:fix/multiplex-cron-credential-scope

Conversation

@soddy022

Copy link
Copy Markdown

Summary

Fixes the get_secret('OPENAI_API_KEY') called with no profile secret scope active while multiplexing is on crash that kills cron jobs in multiplexed deployments (#Workstream A).

Root Cause

When multiplex_profiles is enabled, get_secret() requires an active profile_runtime_scope. The cron scheduler was missing this, so agent-mode cron jobs from non-default profiles crashed before generating any content (#8446d44c7a67, #c6dc075ef4b4).

Changes

1. agent/profile_scope.py (new)

Shared context manager used by both the gateway inbound path and the cron scheduler — breaks the natural gateway → cron import cycle.

2. cron/scheduler.py

Wraps run_one_job in profile_runtime_scope when multiplexing is active. Adds helpers:

  • _is_multiplex_active() — gate on whether to enter the scope
  • _parse_delivery_chat_id() — extract chat_id from deliver string
  • _resolve_target_profile_home() — 4-tier resolution (explicit path → profile name → chat_id scan → root)

3. gateway/config.py

Replaces os.getenv("WEIXIN_TOKEN") / os.getenv("WEIXIN_ACCOUNT_ID") with get_secret() — ensures each multiplexed profile reads its own token, not the process-global env.

4. gateway/platforms/weixin.py

Per-chat-id rate limit isolation:

  • _rate_limit_circuit_until and _rate_limit_events changed from scalar to defaultdict[str, ...]
  • New _expire_rate_limit_circuit(chat_id) self-heal method — clears expired breakers without needing a successful send
  • All rate-limit methods now take chat_id parameter

5. tests/cron/test_cron_multiplex_profile_scope.py (new)

Regression tests covering profile scope resolution, credential isolation, and per-chat-id rate limiting.

Design Doc

See docs/design/multiplexing-gateway.md (Workstream A) for architectural rationale.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery platform/wecom WeCom / WeChat Work adapter area/auth Authentication, OAuth, credential pools P2 Medium — degraded but workaround exists needs-decision Awaiting maintainer decision before any implementation 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 labels Jul 16, 2026
@soddy022 soddy022 closed this Jul 16, 2026
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/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists platform/wecom WeCom / WeChat Work adapter 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.

2 participants