You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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"
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 tests cover history selection, reply references, short and empty history, formatting limits, and fetch failures. AGENTS.md documents the test command and fixture requirements.
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: 4
Check name
Status
Explanation
Title check
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
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
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
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.
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!
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.
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
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.
Addressed Issues:
Fixes #74
Screenshots/Recordings:
Not applicable — this is a backend logic and test coverage update.
Additional Notes:
_build_conversation_context()previously calledthread.history(limit=THREAD_HISTORY_LIMIT, oldest_first=True)without abeforecursor, which causeddiscord.pyto fetch the oldest messages in a thread (after=0) rather than the messages immediately preceding the current query.This PR fixes conversation context retrieval:
before=current_msgso only messages immediately preceding the current message are selected (excluding the current message and any newer messages).THREAD_HISTORY_LIMIT, message formatting, and independent reply-reference handling.Validation
Verified offline with
unittestusingdiscord.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
Summary by CodeRabbit
Bug Fixes
Tests
Documentation