Skip to content

fix: add thread_metadata check to WarnAndStop path#634

Open
ChunHao-dev wants to merge 1 commit intoopenabdev:mainfrom
ChunHao-dev:fix/warn-and-stop-thread-metadata-check
Open

fix: add thread_metadata check to WarnAndStop path#634
ChunHao-dev wants to merge 1 commit intoopenabdev:mainfrom
ChunHao-dev:fix/warn-and-stop-thread-metadata-check

Conversation

@ChunHao-dev
Copy link
Copy Markdown
Contributor

@ChunHao-dev ChunHao-dev commented Apr 29, 2026

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 WarnAndStop path in discord.rs (~L305) checks parent_id to determine if the bot is allowed to post, but doesn't first verify thread_metadata to distinguish threads from category children. In Discord's API, both threads and category child channels have parent_id set — threads point to their parent channel, category children point to their category. Without the thread_metadata check, a category child's parent_id (the category ID) gets matched against allowed_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 the parent_id lookup, so parent_id is only used for the allowlist check when the channel is actually a thread:

// Before
if gc.parent_id.is_some_and(|pid| {

// After
if gc.thread_metadata.is_some() && gc.parent_id.is_some_and(|pid| {

Testing

  • cargo check
  • cargo test — 175 passed, 0 failed ✅

Discord Discussion URL: https://discord.com/channels/1491295327620169908/1498994945384648766

Closes #633

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.
@ChunHao-dev ChunHao-dev requested a review from thepagent as a code owner April 29, 2026 10:32
@github-actions github-actions Bot added the pending-screening PR awaiting automated screening label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-screening PR awaiting automated screening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Bot posts turn-limit warning in channels it is not allowed in

1 participant