Skip to content

fix: update channel.go fix #1641 - #1647

Merged
Calcium-Ion merged 4 commits into
QuantumNous:alphafrom
aotsukiqx:main
Aug 25, 2025
Merged

fix: update channel.go fix #1641#1647
Calcium-Ion merged 4 commits into
QuantumNous:alphafrom
aotsukiqx:main

Conversation

@aotsukiqx

@aotsukiqx aotsukiqx commented Aug 24, 2025

Copy link
Copy Markdown
Contributor

DisableChannel禁用渠道时会先判断渠道AutoBan设置,如果未允许自动禁用则不进行任何操作。

Summary by CodeRabbit

  • Bug Fixes
    • Channel auto-disable now correctly respects the AutoBan preference. If AutoBan is disabled, the system skips disabling the channel and avoids sending notifications. If enabled, the existing behavior remains: the channel is auto-disabled and an admin notification is sent. This prevents unintended service interruptions and reduces unnecessary alerts, improving reliability for operators.

@coderabbitai

coderabbitai Bot commented Aug 24, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds an early guard in service/channel.go: DisableChannel now checks channelError.AutoBan. If false, it optionally logs a debug message and returns without changing status or notifying. If true, it proceeds to set the channel to AutoDisabled and notifies the root user on success.

Changes

Cohort / File(s) Summary
Channel auto-ban guard
service/channel.go
Inserted AutoBan check with early return and optional debug log; preserved existing flow to UpdateChannelStatus(AutoDisabled) and root notification when AutoBan is true.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Service as ChannelService
  participant Store as ChannelStore
  participant Notifier as RootNotifier
  Note over Service: DisableChannel()

  Caller->>Service: DisableChannel(channelID, channelError)
  alt AutoBan = false
    Note over Service: Debug log (if enabled)
    Service-->>Caller: return (no status change, no notify)
  else AutoBan = true
    Service->>Store: UpdateChannelStatus(channelID, AutoDisabled)
    alt Update OK
      Service->>Notifier: Notify root with formatted message
      Notifier-->>Service: ack
      Service-->>Caller: return success
    else Update Failed
      Service-->>Caller: return error
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at flags that ban,
If AutoBan is false—I ran!
No status flipped, no bells to ring,
Just quiet logs, a subtle thing.
But when it’s true, hop—disable fast,
A note to root, and that’s that, alas! 🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
service/channel.go (1)

23-25: Include the disable reason in the debug log for better forensics.

Adding reason helps correlate the skipped action with the triggering condition during incident review.

Apply this diff:

-        if common.DebugEnabled {
-            common.SysLog(fmt.Sprintf("通道「%s」(#%d)未启用自动禁用功能,跳过禁用操作", channelError.ChannelName, channelError.ChannelId))
-        }
+        if common.DebugEnabled {
+            common.SysLog(fmt.Sprintf("通道「%s」(#%d)未启用自动禁用功能,跳过禁用操作。原因:%s", channelError.ChannelName, channelError.ChannelId, reason))
+        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c826d06 and cb6fa7d.

📒 Files selected for processing (1)
  • service/channel.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
service/channel.go (2)
common/constants.go (1)
  • DebugEnabled (70-70)
common/logger.go (1)
  • SysLog (50-53)
🔇 Additional comments (2)
service/channel.go (2)

22-27: AutoBan guard aligns behavior with PR intent.

Early-return when channelError.AutoBan is false cleanly prevents unintended auto-disables on channels that opted out. Side-effects (status change + notifications) are correctly avoided. LGTM.


22-27: Review ChannelError.AutoBan Initialization

Summary:

  • The ChannelError struct in types/channel_error.go defines an AutoBan bool field.
  • There is a NewChannelError(..., autoBan bool) constructor that takes an autoBan parameter and builds a ChannelError.
  • In controller/channel-billing.go, calls to DisableChannel use *types.NewChannelError(..., channel.GetAutoBan()), so AutoBan is explicitly populated.
  • In controller/relay.go, DisableChannel is invoked with a channelError variable—ensure that this channelError was originally constructed via NewChannelError (or otherwise set) so that AutoBan reflects the intended value.

Action items:

  • Confirm that NewChannelError actually assigns the AutoBan: autoBan field in its returned struct.
  • Trace the origin of the channelError passed into controller/relay.go (likely earlier in that handler) and verify it’s constructed with the correct autoBan value.

@Calcium-Ion Calcium-Ion changed the title Update channel.go fix #1641 fix: update channel.go fix #1641 Aug 25, 2025
@Calcium-Ion
Calcium-Ion changed the base branch from main to alpha August 25, 2025 02:23
@Calcium-Ion
Calcium-Ion merged commit f96a733 into QuantumNous:alpha Aug 25, 2025
2 of 5 checks passed
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
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.

3 participants