Skip to content

Inject shared chat mode notices - #26

Merged
TraderSamwise merged 1 commit into
masterfrom
feat/multi-user-chat-agent-context
May 24, 2026
Merged

Inject shared chat mode notices#26
TraderSamwise merged 1 commit into
masterfrom
feat/multi-user-chat-agent-context

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented May 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • inject an agent-facing note when a shared chat enters multi-user mode
  • inject a downgrade note when the same shared chat returns to single-user mode
  • keep persisted chat history as the original human messages while only changing agent-bound input

Verification

  • yarn vitest run src/multiplexer/session-runtime-core.test.ts src/collaboration.test.ts
  • yarn typecheck
  • yarn build

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved handling of collaboration context when transitioning between multi-user and single-user modes.
    • Enhanced message formatting and metadata preservation during mode switches.
  • Tests

    • Expanded test coverage for multi-user mode transitions and message storage.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR updates writeAgentInput to inject collaboration-mode notices into agent input before serialization, with per-session deduping to prevent redundant notices. Two new helpers handle notice generation and merging with the input shape. The test is extended to validate notice text and formatting changes across multi→multi→single mode transitions.

Changes

Collaboration-mode notice injection

Layer / File(s) Summary
Collaboration-mode notice infrastructure
src/multiplexer/session-runtime-core.ts
Imports AgentInputPart type and adds consumeCollaborationModeNotice (generates a mode-change notice when collaboration.shareId and collaboration.mode are set, deduping per session and shareId:mode pair) and applyCollaborationContextForAgent (prepends notice to parts if present, otherwise prefixes data).
writeAgentInput integration
src/multiplexer/session-runtime-core.ts
writeAgentInput now calls applyCollaborationContextForAgent to conditionally inject collaboration-mode notices based on the incoming collaboration object and session deduping state, replacing the previous prefix-only approach.
Mode transition test coverage
src/multiplexer/session-runtime-core.test.ts
Test extended to submit two additional writeAgentInput calls (one in multi mode, one switching to single) and validates that collaboration-note prefixes, message formatting, chatMode, and clientMessageId values match the expected sequence across the multi→multi→single transition.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • TraderSamwise/aimux#21: Wires trusted header parsing/stripping that produces the collaboration context object that this PR injects into agent input.
  • TraderSamwise/aimux#18: Establishes the ShareChatMode upgrade/downgrade and message prefixing rules that this PR's collaboration-mode notice injection implements.

Poem

🐰 A notice now whispers when modes align,
Multi speaks to single through the design,
Sessions remember, no repeat refrain,
Input flows richer through the agent's domain! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Inject shared chat mode notices' directly and specifically describes the main change in both modified files—adding collaboration mode context injection to agent input in the runtime core and extending tests to validate this behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/multi-user-chat-agent-context

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/multiplexer/session-runtime-core.test.ts (1)

206-260: ⚡ Quick win

Consider adding test coverage for single→multi transition and shareId switching.

The current test validates multi→multi(dedupe)→single, which covers the core functionality. To ensure robustness, consider adding test cases for:

  1. single→multi transition: Start in single mode then upgrade to multi mode to verify the upgrade notice.
  2. ShareId switching: Write with share_A→share_B→share_A to confirm the deduping behavior when switching conversation contexts.

These additions would validate edge cases but are not critical for the current implementation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/multiplexer/session-runtime-core.test.ts` around lines 206 - 260, Add two
focused test cases in session-runtime-core.test.ts: one for single→multi
transition and one for shareId switching. For the single→multi test, use
writeAgentInput to send an initial message with mode "single" (e.g., client-1),
then send another with mode "multi" and the same shareId (e.g., client-2) and
assert writes contains the "Aimux collaboration note" upgrade message and both
messages are recorded via readSessionMessages with correct chatMode values. For
the shareId switching test, call writeAgentInput with shareId "share_A", then
"share_B", then "share_A" again and assert writes and readSessionMessages
reflect deduping/notice behavior when switching shareId (verify messages keep
correct shareId fields and ordering). Use the existing helpers writeAgentInput,
readSessionMessages and the writes array and expect(...) assertions to mirror
the style of the surrounding tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/multiplexer/session-runtime-core.test.ts`:
- Around line 206-260: Add two focused test cases in
session-runtime-core.test.ts: one for single→multi transition and one for
shareId switching. For the single→multi test, use writeAgentInput to send an
initial message with mode "single" (e.g., client-1), then send another with mode
"multi" and the same shareId (e.g., client-2) and assert writes contains the
"Aimux collaboration note" upgrade message and both messages are recorded via
readSessionMessages with correct chatMode values. For the shareId switching
test, call writeAgentInput with shareId "share_A", then "share_B", then
"share_A" again and assert writes and readSessionMessages reflect
deduping/notice behavior when switching shareId (verify messages keep correct
shareId fields and ordering). Use the existing helpers writeAgentInput,
readSessionMessages and the writes array and expect(...) assertions to mirror
the style of the surrounding tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c7b9e1c1-ba59-44e6-bfb8-7f5c3e250d97

📥 Commits

Reviewing files that changed from the base of the PR and between e420233 and c14d5c0.

📒 Files selected for processing (2)
  • src/multiplexer/session-runtime-core.test.ts
  • src/multiplexer/session-runtime-core.ts

@TraderSamwise
TraderSamwise merged commit 66f88fc into master May 24, 2026
1 check passed
@TraderSamwise
TraderSamwise deleted the feat/multi-user-chat-agent-context branch May 24, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant