Skip to content

refactor(discord): extract build_sender_context + ChannelRef.parent_id + doc comments#587

Merged
thepagent merged 1 commit intoopenabdev:mainfrom
chaodu-agent:follow-up/583-sender-context-improvements
Apr 26, 2026
Merged

refactor(discord): extract build_sender_context + ChannelRef.parent_id + doc comments#587
thepagent merged 1 commit intoopenabdev:mainfrom
chaodu-agent:follow-up/583-sender-context-improvements

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

Summary

Follow-up from PR #583 review. Implements three improvements identified by the monk review team:

1. Extract build_sender_context() pure function (#584)

The SenderContext assembly logic was embedded inside EventHandler::message(), making it impossible to unit test without mocking serenity. Extracted as a pure function (same pattern as detect_thread()) with 3 table-driven tests:

  • in-thread → channel_id = parent, thread_id = Some(thread)
  • non-thread → channel_id = channel, thread_id = None
  • bot sender → is_bot flag propagated correctly

2. Populate ChannelRef.parent_id for Discord threads (#585)

When a message is inside a Discord thread, the thread_channel ChannelRef now carries parent_id. channel_id remains the thread's own channel ID (required for routing).

3. Doc comments clarifying SenderContext vs ChannelRef semantics (#586)

Added doc comments to both structs in adapter.rs explaining:

  • ChannelRef = routing (channel_id is where to send messages)
  • SenderContext = metadata for agent (channel_id is the parent channel)

Testing

  • 3 new unit tests for build_sender_context()
  • All existing tests unaffected (no behavioral change)
  • rustfmt passes with no syntax errors

References

Closes #584, closes #585, closes #586
Follow-up from #583 (merged)

….parent_id + doc comments

- Extract build_sender_context() pure function from EventHandler::message
  for testability, with 3 unit tests covering in-thread, non-thread, and
  bot sender scenarios (openabdev#584)

- Populate ChannelRef.parent_id when in a Discord thread, so downstream
  consumers have complete context. channel_id remains the thread's own
  channel ID for routing (openabdev#585)

- Add doc comments to ChannelRef and SenderContext in adapter.rs clarifying
  the semantic difference: ChannelRef.channel_id is for routing (send to),
  SenderContext.channel_id is metadata for agent (came from) (openabdev#586)

Closes openabdev#584, closes openabdev#585, closes openabdev#586
@chaodu-agent chaodu-agent requested a review from thepagent as a code owner April 26, 2026 20:45
@github-actions github-actions Bot added pending-screening PR awaiting automated screening closing-soon PR missing Discord Discussion URL — will auto-close in 3 days labels Apr 26, 2026
@github-actions
Copy link
Copy Markdown

⚠️ This PR is missing a Discord Discussion URL in the body.

All PRs must reference a prior Discord discussion to ensure community alignment before implementation.

Please edit the PR description to include a link like:

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

This PR will be automatically closed in 3 days if the link is not added.

@thepagent thepagent merged commit d23bb50 into openabdev:main Apr 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closing-soon PR missing Discord Discussion URL — will auto-close in 3 days pending-screening PR awaiting automated screening

Projects

None yet

2 participants