Registry Mirror
Skip to content

Conversation

@BLVCK-MAMBA-6

@BLVCK-MAMBA-6 BLVCK-MAMBA-6 commented Dec 1, 2026 •

Copy link
Copy Markdown

Addressed Issues:

Fixes #74

Screenshots/Recordings:

Not applicable — this is a backend logic and test coverage update.

Additional Notes:

_build_conversation_context() previously called thread.history(limit=THREAD_HISTORY_LIMIT, oldest_first=True) without a before cursor, which caused discord.py to fetch the oldest messages in a thread (after=0) rather than the messages immediately preceding the current query.

This PR fixes conversation context retrieval:

  • Fetches thread history newest-first with before=current_msg so only messages immediately preceding the current message are selected (excluding the current message and any newer messages).
  • Reverses the bounded result so messages remain in chronological order for prompt formatting.
  • Preserves the existing THREAD_HISTORY_LIMIT, message formatting, and independent reply-reference handling.
  • Adds offline regression tests verifying history cursor arguments, chronological ordering, and exclusion of current/newer messages.

Validation

Verified offline with unittest using discord.py's history iterator against a mocked HTTP boundary (all regression tests pass with zero warnings).

AI Usage Disclosure

Used an AI coding assistant during local auditing to double-check edge cases in discord.py's history pagination and help scaffold the offline regression tests. I reviewed, tested, and verified all changes manually before submitting.

Checklist

  • My PR addresses a single issue
  • My code follows the project's code style and conventions
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contributing Guidelines

Summary by CodeRabbit

  • Bug Fixes

    • Conversation context now includes the messages immediately before the current message in chronological order, excluding the current and newer messages. Referenced messages remain available even when they fall outside the recent history window.
    • Improved handling of short or unavailable history and failed reference lookups, preserving the conversation context that is available.
  • Tests

    • Added offline regression coverage for conversation history and context behavior.
  • Documentation

    • Documented how to run the offline conversation-history regression tests.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "instructions" at "reviews"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • 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

No actionable comments were generated in the recent review.

Walkthrough

The conversation context builder now fetches up to four thread messages before the current message and processes them in chronological order. Offline regression tests cover message selection, reply references, formatting limits, and fetch failures. The repository guide documents how to run these tests.

Changes

Conversation context

Layer / File(s) Summary
Bounded thread history
bot.py
_build_conversation_context fetches history before the current message, then reverses the newest-first results for chronological processing.
Offline regression coverage
tests/test_conversation_context.py, AGENTS.md
Offline tests cover history selection, reply references, short and empty history, formatting limits, and fetch failures. AGENTS.md documents the test command and fixture requirements.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • AOSSIE-Org/SkillBot#74 — The issue describes the same oldest-messages selection behavior addressed by this change.

Suggested labels: Python Lang, Documentation

Suggested reviewers: kpj2006

Merge Risk: Minimal · up to 7fa83

Conversation context now uses the messages immediately before the current one, in chronological order. Offline regression tests cover this behavior and its failure cases, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix: use recent messages for conversation context" matches the main change. The raw summary and objectives show that _build_conversation_context now fetches up to THREAD_HISTORY_LIMIT messa…
Linked Issues check Passed Issue #74 requires that _build_conversation_context() select the four messages immediately before the current message, in chronological order, excluding the current and newer messages. It also require…
Out of Scope Changes check Passed The changes fall into three groups. The bot.py change is the fix requested by #74. tests/test_conversation_context.py holds the regression tests and fixture that support the #74 behavior. AGENTS.md ad…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "fix: use recent messages for conversation context" matches the main change. The raw summary and objectives show that _build_conversation_context now fetches up to THREAD_HISTORY_LIMIT messages before the current message (newest-first with before=current message), then reverses them into chronological order. The title is short, specific, and states the primary behavior change. The conventional "fix:" prefix fits the bug-correction intent described in issue #74. The title does not mention the added offline regression tests, but that detail is secondary.

Full details: Linked Issues check

Explanation

Issue #74 requires that _build_conversation_context() select the four messages immediately before the current message, in chronological order, excluding the current and newer messages. It also requires keeping the four-message limit, formatting, and independent reply-reference handling. At the reviewed head, bot.py calls thread.history(limit=THREAD_HISTORY_LIMIT, before=current_msg, oldest_first=False), skips the current message by ID, reverses the result for chronological order, and keeps the reply-reference block separate. The reply-reference fetch and the history fetch each have their own try/except, so a failure in one does not discard the other. tests/test_conversation_context.py adds offline regressions that use discord.py's real history iterator with a fixture HTTP boundary. They assert the cursor arguments (before=11, limit=4), the messages 7-10 order, the exclusion of messages 11-15, the no-current-message fallback, reference preservation, and error handling. The whole-PR diff against the merge base was unavailable, so the pre-fix state is taken from the issue and PR summary rather than read from the base blob. The head source and test file were read directly.

Full details: Out of Scope Changes check

Explanation

The changes fall into three groups. The bot.py change is the fix requested by #74. tests/test_conversation_context.py holds the regression tests and fixture that support the #74 behavior. AGENTS.md adds four lines documenting how to run those offline tests. Both the tests and the documentation directly support the #74 change, so no unrelated change was found. The whole-PR diff was unavailable, so the AGENTS.md content is taken from the AI-generated summary and was not read directly. That summary does not show unrelated changes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the thread’s fresh trail,
Four messages before the query prevail.
In order, each reply comes through,
Tests keep the history honest too.
Then off to nibble clover anew!

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a03e0db and 7fa8346.

Files selected for processing: 3

  • AGENTS.md
  • bot.py
  • tests/test_conversation_context.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions github-actions Bot added bug Something isn't working enhancement New feature or request backend Changes to backend code documentation Changes to documentation files python Python code changes size/M Medium PR (51-200 lines changed) first-time-contributor First PR of an external contributor needs-review labels Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Changes to backend code bug Something isn't working documentation Changes to documentation files enhancement New feature or request first-time-contributor First PR of an external contributor needs-review python Python code changes size/M Medium PR (51-200 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: conversation context selects the oldest thread messages instead of recent replies

1 participant