Skip to content

feat(session): publish subagent runtime messages - #98

Merged
delete-cloud merged 2 commits into
mainfrom
subagent-message-routing
May 4, 2026
Merged

delete-cloud merged 2 commits into
mainfrom
subagent-message-routing

Conversation

@delete-cloud

@delete-cloud delete-cloud commented May 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add a product-side SessionManager.publish_subagent_message(...) contract that publishes subagent_message runtime messages on the session bus
  • keep the payload narrow (text plus optional metadata), support caller-provided message ids, and make duplicate ids idempotent success
  • cover prompt injection, duplicate-id behavior, invalid text rejection, and approval-cursor isolation with focused public API tests

Verification

  • uv run pytest tests/ui/test_session_manager_public_api.py -k "publish_subagent_message or submit_approval_rejects_stale_pending_projection_without_store_request" -q
  • uv run pytest tests/ui/test_session_manager_public_api.py -q
  • uv run pytest tests/agentkit/runtime/test_pipeline.py -k "runtime_context_grounding or runtime_message_consumed_after_build_context_reaches_prompt or prompt_runtime_message_after_run_model_is_kept_for_next_turn or runtime_approval_decision_is_left_for_product_consumer" -q
  • uv run pytest tests/agentkit/runtime/test_pipeline.py -q
  • uv run pytest tests/coding_agent/test_approval_runtime_messages.py -q
  • uv run basedpyright src/coding_agent/ui/session_manager.py tests/ui/test_session_manager_public_api.py --level error
  • python3 -m py_compile src/coding_agent/ui/session_manager.py
  • manual driver script that publishes a subagent message and verifies the next pipeline prompt contains it while the approval cursor remains unchanged
  • uv run python -m coding_agent --help

Summary by CodeRabbit

Release Notes

  • New Features
    • Added capability to publish subagent messages to active sessions with optional metadata support.
    • Published messages are automatically integrated into ongoing conversation pipelines for seamless dialogue continuity.
    • Duplicate message identifiers are handled idempotently—only the first unique message is processed and propagated.
    • Session activity tracking and state automatically update upon successful message publication.

Product-side session management needs a narrow subagent_message publishing contract so the existing pipeline prompt wiring can consume messages without expanding agentkit or HTTP scope.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@coderabbitai

coderabbitai Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@delete-cloud has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 34 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1429f050-c46c-4b64-a39b-f3977e995d09

📥 Commits

Reviewing files that changed from the base of the PR and between cdcab6c and 709deb1.

📒 Files selected for processing (2)
  • coding-agent/src/coding_agent/ui/session_manager.py
  • coding-agent/tests/ui/test_session_manager_public_api.py
📝 Walkthrough

Walkthrough

This PR adds SessionManager.publish_subagent_message(...) to publish subagent-generated text messages to a session's runtime message bus with optional metadata. The method validates input, publishes a SUBAGENT_MESSAGE runtime message with automatic ID generation or caller-provided ID, suppresses duplicate IDs, and persists session state. Tests verify message propagation to pipeline prompts, idempotent duplicate handling, approval-cursor independence, and input validation.

Changes

Subagent Message Publishing

Layer / File(s) Summary
Core Implementation
src/coding_agent/ui/session_manager.py
Added _subagent_message_id() helper for unique message ID generation and SessionManager.publish_subagent_message() method with text/metadata validation, runtime message publishing, and idempotent duplicate handling via DuplicateRuntimeMessageError.
Test Infrastructure
tests/ui/test_session_manager_public_api.py
Added _PromptCapturePlugin/_PromptCaptureProvider and helper functions to capture LLM prompts during pipeline execution, enabling assertions on prompt content composition.
Test Coverage
tests/ui/test_session_manager_public_api.py
Four test cases verify subagent message propagation to pipeline prompts, idempotent duplicate-ID handling, approval-cursor independence, and rejection of invalid text inputs; updated imports for typing.Any and agentkit dependencies.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant SessionManager
    participant RuntimeMessageBus
    participant Pipeline
    participant LLM

    Caller->>SessionManager: publish_subagent_message(session_id, text)
    SessionManager->>SessionManager: validate text, generate/validate message_id
    SessionManager->>RuntimeMessageBus: publish(SUBAGENT_MESSAGE, {text, metadata})
    RuntimeMessageBus-->>SessionManager: confirmation
    SessionManager->>SessionManager: update session.last_activity, persist
    SessionManager-->>Caller: return True
    
    Pipeline->>RuntimeMessageBus: consume pending runtime messages
    RuntimeMessageBus-->>Pipeline: [SUBAGENT_MESSAGE payload]
    Pipeline->>Pipeline: compose system prompt with subagent message
    Pipeline->>LLM: execute with updated prompt
    LLM-->>Pipeline: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • [codex] Add runtime message bus #93: Introduces RuntimeMessage, RuntimeMessageBus, and DuplicateRuntimeMessageError types and idempotency semantics that this PR directly depends on for publishing and handling subagent messages.

Poem

🐰 A whisper from subcalls finds its way,
Through buses swift and pipelines gray,
Idempotent and true, each message flows,
To prompts above where wisdom grows!

🚥 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 pull request title clearly and concisely summarizes the primary change: adding a publish_subagent_message method to SessionManager for publishing subagent runtime messages.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch subagent-message-routing

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
Review rate limit: 0/1 reviews remaining, refill in 4 minutes and 34 seconds.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@coding-agent/src/coding_agent/ui/session_manager.py`:
- Around line 1629-1667: publish_subagent_message currently reads the live
Session, publishes to the runtime bus, and persists the session without holding
self._lock, allowing a concurrent remove_session_async()/close_session() to
delete the session and be overwritten; fix by serializing the entire
read-publish-persist path with the session lock: acquire the per-session lock
(self._lock) before calling get_session_async(), keep it held while calling
session.runtime_message_bus.publish(...), updating session.last_activity, and
calling _persist_session_async(session), and only release the lock after persist
(ensure the lock is held across the try/except that handles
DuplicateRuntimeMessageError so you don't resurrect a removed session).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8bd86900-608d-4976-a39e-be5af1682cf0

📥 Commits

Reviewing files that changed from the base of the PR and between 2798d7a and cdcab6c.

📒 Files selected for processing (2)
  • coding-agent/src/coding_agent/ui/session_manager.py
  • coding-agent/tests/ui/test_session_manager_public_api.py

Hold the session lock across subagent message publish and persistence so a concurrent remove cannot restore deleted state. Add a regression test that proves removal waits until publish finishes and leaves the session deleted.
@delete-cloud
delete-cloud merged commit 77872af into main May 4, 2026
1 check passed
@delete-cloud
delete-cloud deleted the subagent-message-routing branch May 4, 2026 07:43
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