fix(discord): move bot turn tracker before gating (#483)#484
Conversation
e44d74c to
181c530
Compare
|
All PRs must reference a prior Discord discussion to ensure community alignment before implementation. Please edit the PR description to include a link like: This PR will be automatically closed in 3 days if the link is not added. |
12bd9f3 to
e393e13
Compare
OpenAB PR Screening
Screening report## IntentThis PR is trying to make Discord bot-to-bot turn limiting actually work in multi-bot conversations. The user-visible problem is that two OpenAB bots can get into an unbounded ping-pong loop because the turn tracker only runs after early-return gates, so bot-authored messages are never counted toward the soft or hard limit. FeatThis is a bug fix in the Discord runtime. In plain terms, it moves bot-turn accounting earlier in the inbound message pipeline so bot messages, including the bot's own replies and other bots' replies, increment the tracker before self-message and bot-message gating can short-circuit processing. Who It ServesThe primary beneficiaries are Discord end users and agent runtime operators. It also helps maintainers and reviewers because it restores a safety mechanism that is supposed to prevent runaway automated conversations. Rewritten PromptAdjust the Discord message handling flow in Merge PitchThis is worth moving forward because it fixes a broken safety boundary rather than adding optional behavior. Right now the configured soft and hard turn caps appear present but fail in exactly the multi-bot loop case they are meant to contain. The risk profile is moderate but acceptable: the change touches message-order semantics in a hot path, so reviewer concern will be whether counting before gating creates false positives or changes single-bot behavior. The right review focus is on preserving normal human-triggered flows while making multi-bot loops observable to the limiter. Best-Practice ComparisonThe most relevant comparison points are safety and execution-boundary discipline, not durable scheduling. Against OpenClaw:
Against Hermes Agent:
Net: this PR aligns with a good systems principle shared by both references: apply safety accounting at the earliest reliable observation point, before downstream filters can erase evidence of activity. Implementation OptionsOption 1: Minimal reorder fixMove the existing bot-turn tracker invocation to run immediately after multibot detection and before self-check and bot gating. Reuse the current tracker structure and warning behavior with the smallest possible code movement. Option 2: Balanced pipeline normalizationRefactor inbound Discord handling into an explicit sequence: classify sender, update turn tracker, evaluate turn-limit outcome, then apply self-gating and mention gating for response generation. Keep behavior the same, but make the ordering and intent obvious in code and tests. Option 3: Broader conversation-safety layerIntroduce a more formal conversation guard abstraction for Discord bot interactions that tracks actor type, consecutive automated turns, reset conditions, and enforcement outcomes. Use it as a reusable pre-processing stage for current Discord handling and potentially other chat gateways later. Comparison Table
RecommendationThe balanced pipeline normalization is the right path for merge discussion. It keeps the scope anchored to the current bug, but avoids shipping a fragile "just move this block upward" patch whose correctness still depends on implicit control-flow knowledge in If the author wants to reduce merge risk, this can be sequenced in two steps:
|
Suggested fix: warn-once semantics in
|
e393e13 to
e1c32d7
Compare
Bot turn limits never triggered in multi-bot ping-pong because the tracker ran after both the self-check and bot message gating. Changes: - Move tracker before self-check so ALL bot messages count (including own) - soft_limit=20 means 20 total bot messages (~10 per bot in two-bot scenario) - Warn-once via type system: SoftLimit/HardLimit fire at == threshold, Throttled/Stopped fire at > threshold (silent return, no warning) - 5-variant TurnResult: Ok, SoftLimit, Throttled, HardLimit, Stopped - Updated docs/discord.md with counting and warn-once behavior - Added tests: warn-once for soft/hard, two-bot ping-pong, human reset
e1c32d7 to
10bcb54
Compare
Closes #483
The Bug
Bot turn limits (soft=20, hard=100) never trigger in multi-bot ping-pong because the tracker runs after both the self-check and bot message gating.
The Fix
Move tracker before self-check and gating. Count ALL bot messages including own.
Warn-Once Semantics
Warning messages are sent only on the exact threshold hit to prevent warnings from ping-ponging between bots:
Changes
soft_limit=20= 20 total bot messages (~10 per bot in two-bot scenario)HardLimitnow carries count for warn-once checkn == max(exact hit), silently return whenn > maxdocs/discord.mdwith counting and warn-once behaviorsoft_limit_warn_once_semantics,hard_limit_warn_once_semantics,two_bot_pingpong_hits_soft_limit,two_bot_pingpong_human_resets