fix: add thread_metadata check to WarnAndStop path#634
Open
ChunHao-dev wants to merge 1 commit intoopenabdev:mainfrom
Open
fix: add thread_metadata check to WarnAndStop path#634ChunHao-dev wants to merge 1 commit intoopenabdev:mainfrom
ChunHao-dev wants to merge 1 commit intoopenabdev:mainfrom
Conversation
The WarnAndStop path checks parent_id to determine if a bot is allowed to post a turn-limit warning, but doesn't check thread_metadata to distinguish threads from category children. This is the same class of bug fixed by detect_thread() in PRs openabdev#506/openabdev#518/openabdev#519, but was never applied to the WarnAndStop code path. Add gc.thread_metadata.is_some() guard before the parent_id lookup, consistent with detect_thread() logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
When running multiple agents (e.g. Kiro in channel A, Gemini in channel B), if channel A sits under a Discord category whose ID happens to match one of Gemini's
allowed_channels, Gemini incorrectly believes it has permission to post in channel A.This is especially easy to trigger with cronjobs — cronjob messages are bot messages that don't reset the turn counter. Once the counter hits
soft_limit, Gemini's WarnAndStop fires and posts a "turn limit reached" warning in channel A, where it should never appear.Root Cause
The
WarnAndStoppath indiscord.rs(~L305) checksparent_idto determine if the bot is allowed to post, but doesn't first verifythread_metadatato distinguish threads from category children. In Discord's API, both threads and category child channels haveparent_idset — threads point to their parent channel, category children point to their category. Without thethread_metadatacheck, a category child'sparent_id(the category ID) gets matched againstallowed_channels, causing a false positive.This is the same class of bug that
detect_thread()fixed in PRs #506/#518/#519, but the fix was never applied to the WarnAndStop code path.Fix
Add
gc.thread_metadata.is_some()guard before theparent_idlookup, soparent_idis only used for the allowlist check when the channel is actually a thread:Testing
cargo check✅cargo test— 175 passed, 0 failed ✅Discord Discussion URL: https://discord.com/channels/1491295327620169908/1498994945384648766
Closes #633