Skip to content

fix: accept multi-channel bot.yaml keys with platform field#1772

Draft
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-425d
Draft

fix: accept multi-channel bot.yaml keys with platform field#1772
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-425d

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 30, 2026

Bug and impact

After #1757 (multi-Telegram onboard), praisonai onboard writes bot.yaml with channel keys such as telegram_cfo and a platform: telegram field. BotYamlSchema only allowed channel keys that exactly matched platform names (telegram, discord, …), so praisonai doctor and any path using load_and_validate_bot_yaml failed with Unknown channel 'telegram_cfo' even when the config was valid for the gateway.

Root cause

BotYamlSchema.validate_channels_exist validated the YAML dict key as the platform name and did not model platform on ChannelConfigSchema.

Fix

  • Add platform, routes, and allowed_users to ChannelConfigSchema.
  • Resolve the platform from channel.platform when present, otherwise from the channel key.
  • Regression test for telegram_<role> keys.

Validation

  • Reproduced failure with onboard-style YAML before fix; passes after fix.
  • Manual checks: unknown signal channel still rejected; multi-channel keys accepted.
Open in WebΒ View AutomationΒ 

Summary by CodeRabbit

  • New Features
    • Added support for explicit platform configuration per channel, enabling flexible channel naming patterns.
    • Channels can now be configured with allowed_users restrictions.
    • Channels can now define custom routes mappings.

Review Change Stack

…gression)

Onboard generates channels like telegram_cfo with platform: telegram.
BotYamlSchema rejected any channel key not exactly matching a platform name,
so praisonai doctor reported invalid bot.yaml after multi-bot onboard.

Validate using channel.platform when present; extend ChannelConfigSchema for
gateway-style fields used in generated configs.

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
@MervinPraison
Copy link
Copy Markdown
Owner

@coderabbitai review

@MervinPraison
Copy link
Copy Markdown
Owner

/review

@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more β†’

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account β†’

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us β†’

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

βœ… Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6cab9fee-03f7-4306-bf67-d22b10525222

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • πŸ” Trigger review
πŸ“ Walkthrough

Walkthrough

The PR extends channel configuration to support explicit per-channel platform specification. ChannelConfigSchema gains platform, allowed_users, and routes fields, while validation logic now respects the explicit platform field when determining which supported platform to validate against, with error messages updated to report both the channel key and resolved platform. A test validates this functionality with Telegram role-specific channels.

Changes

Channel Configuration Enhancement

Layer / File(s) Summary
Channel schema fields and platform validation
src/praisonai/praisonai/bots/_config_schema.py, src/praisonai/tests/unit/test_bot_gap_features.py
ChannelConfigSchema adds optional platform, allowed_users, and routes fields. validate_channels_exist now resolves platform from channel.platform or the channel key and validates against supported platforms, with error messages including both channel name and resolved platform. Test verifies multi-channel Telegram config with explicit platform field is correctly validated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • MervinPraison/PraisonAI#1757: Multi-telegram multi-channel work that relies on the channels[].platform field additions and validation logic updates from this PR.

Suggested reviewers

  • MervinPraison

Poem

A rabbit hops through channels bright,
With platforms now explicit and right,
Each channel knows its name and mode,
The config schema takes a load,
Validation dances, tests delight! 🐰✨

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (4 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title 'fix: accept multi-channel bot.yaml keys with platform field' directly describes the main change: extending BotYamlSchema to accept channel keys with a platform field for multi-channel configurations.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/critical-bug-investigation-425d

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MervinPraison
Copy link
Copy Markdown
Owner

@copilot Do a thorough review of this PR. Read ALL existing reviewer comments above from Qodo, Coderabbit, and Gemini first β€” incorporate their findings.

Review areas:

  1. Bloat check: Are changes minimal and focused? Any unnecessary code or scope creep?
  2. Security: Any hardcoded secrets, unsafe eval/exec, missing input validation?
  3. Performance: Any module-level heavy imports? Hot-path regressions?
  4. Tests: Are tests included? Do they cover the changes adequately?
  5. Backward compat: Any public API changes without deprecation?
  6. Code quality: DRY violations, naming conventions, error handling?
  7. Address reviewer feedback: If Qodo, Coderabbit, or Gemini flagged valid issues, include them in your review
  8. Suggest specific improvements with code examples where possible

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/praisonai/tests/unit/test_bot_gap_features.py (1)

296-315: ⚑ Quick win

Use monkeypatch for env isolation in the new test.

Line 296 mutates process env directly; prefer pytest’s monkeypatch.setenv/delenv to avoid cross-test leakage and simplify cleanup.

Proposed diff
-    def test_multi_channel_custom_keys_with_platform(self):
+    def test_multi_channel_custom_keys_with_platform(self, monkeypatch):
         """Onboard multi-telegram YAML uses telegram_<role> keys plus platform field."""
         from praisonai.bots._config_schema import validate_bot_config
 
-        os.environ["_TEST_CFO_TOKEN"] = "cfo-token"
-        try:
-            raw = {
-                "channels": {
-                    "telegram_cfo": {
-                        "platform": "telegram",
-                        "token": "${_TEST_CFO_TOKEN}",
-                        "group_policy": "mention_only",
-                    },
-                    "telegram_ops": {
-                        "platform": "telegram",
-                        "token": "${_TEST_CFO_TOKEN}",
-                    },
-                }
-            }
-            result = validate_bot_config(raw)
-            assert result.channels["telegram_cfo"].platform == "telegram"
-            assert result.channels["telegram_cfo"].token == "cfo-token"
-        finally:
-            os.environ.pop("_TEST_CFO_TOKEN", None)
+        monkeypatch.setenv("_TEST_CFO_TOKEN", "cfo-token")
+        raw = {
+            "channels": {
+                "telegram_cfo": {
+                    "platform": "telegram",
+                    "token": "${_TEST_CFO_TOKEN}",
+                    "group_policy": "mention_only",
+                },
+                "telegram_ops": {
+                    "platform": "telegram",
+                    "token": "${_TEST_CFO_TOKEN}",
+                },
+            }
+        }
+        result = validate_bot_config(raw)
+        assert result.channels["telegram_cfo"].platform == "telegram"
+        assert result.channels["telegram_cfo"].token == "cfo-token"
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/praisonai/tests/unit/test_bot_gap_features.py` around lines 296 - 315,
The test mutates os.environ directly; change it to use pytest's monkeypatch
fixture to isolate env changes: add the monkeypatch parameter to the test
function, replace os.environ["_TEST_CFO_TOKEN"] = "cfo-token" and the
try/finally cleanup with monkeypatch.setenv("_TEST_CFO_TOKEN", "cfo-token") (or
monkeypatch.delenv if needed), and then call validate_bot_config(raw) as before
(refer to validate_bot_config and the test function in
test_bot_gap_features.py); monkeypatch will automatically restore the
environment after the test.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/praisonai/tests/unit/test_bot_gap_features.py`:
- Around line 296-315: The test mutates os.environ directly; change it to use
pytest's monkeypatch fixture to isolate env changes: add the monkeypatch
parameter to the test function, replace os.environ["_TEST_CFO_TOKEN"] =
"cfo-token" and the try/finally cleanup with
monkeypatch.setenv("_TEST_CFO_TOKEN", "cfo-token") (or monkeypatch.delenv if
needed), and then call validate_bot_config(raw) as before (refer to
validate_bot_config and the test function in test_bot_gap_features.py);
monkeypatch will automatically restore the environment after the test.

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 60886665-570a-4135-8202-b1e7673f0e28

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d5f1114 and e387ef5.

πŸ“’ Files selected for processing (2)
  • src/praisonai/praisonai/bots/_config_schema.py
  • src/praisonai/tests/unit/test_bot_gap_features.py

@MervinPraison
Copy link
Copy Markdown
Owner

@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Focus ONLY on Python packages (praisonaiagents, praisonai). Do NOT modify praisonai-rust or praisonai-ts. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding.

Phase 1: Review per AGENTS.md

  1. Protocol-driven: check heavy implementations vs core SDK
  2. Backward compatible: ensure zero feature regressions
  3. Performance: no hot-path regressions

Phase 2: FIX Valid Issues
4. For any VALID bugs or architectural flaws found by Gemini, CodeRabbit, Qodo, Copilot, or any other reviewer: implement the fix
5. Push all code fixes directly to THIS branch (do NOT create a new PR)
6. Comment a summary of exact files modified and what you skipped

Phase 3: Final Verdict
7. If all issues are resolved, approve the PR / close the Issue
8. If blocking issues remain, request changes / leave clear action items

@praisonai-triage-agent
Copy link
Copy Markdown
Contributor

praisonai-triage-agent Bot commented May 30, 2026

Claude finished @MervinPraison's task β€”β€” View job


Final Architecture Review Complete

Phase 1: Architecture Review per AGENTS.md

  • Read AGENTS.md for architecture guidelines
  • Review changed files for protocol-driven design compliance
  • Check backward compatibility
  • Verify no performance regressions

Phase 2: Fix Valid Issues

  • Fix monkeypatch issue identified by CodeRabbit
  • Address docstring coverage if needed
  • Push fixes to current branch

Phase 3: Final Verdict

  • Approve PR or request changes
  • Provide summary of modifications made

Architecture Review Summary βœ…

All architecture requirements met:

  • Protocol-Driven: Changes correctly placed in wrapper package (praisonai), not core SDK
  • Backward Compatible: Zero breaking changes - existing configs continue to work
  • Performance: No hot-path regressions - validation runs once at startup
  • Minimal Scope: Focused fix with no scope creep

Issues Fixed

  1. βœ… Environment Isolation: Fixed test to use pytest.monkeypatch instead of direct os.environ manipulation for proper test isolation
  2. ⚠️ Docstring Coverage: This is a CI warning about overall project coverage (50% vs 80%), not related to these specific changes

Files Modified

  • src/praisonai/tests/unit/test_bot_gap_features.py: Improved test hygiene with monkeypatch

What Was Skipped

  • Docstring coverage improvement: This is a project-wide metric and not blocking for this specific bugfix

Final Verdict: APPROVED βœ…

This PR successfully fixes the multi-channel bot.yaml validation bug introduced in #1757. The implementation is architecturally sound, maintains backward compatibility, and includes appropriate test coverage.

Ready for merge.


- Replace direct os.environ manipulation with pytest monkeypatch
- Ensures test environment isolation and automatic cleanup
- Addresses CodeRabbit review feedback

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants