Skip to content

Log multi-agent communication lifecycle#30872

Merged
bolinfest merged 1 commit into
mainfrom
pr30872
Jul 2, 2026
Merged

Log multi-agent communication lifecycle#30872
bolinfest merged 1 commit into
mainfrom
pr30872

Conversation

@bolinfest

@bolinfest bolinfest commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Why

#30867 makes submit_inter_agent_communication the common outbound sink for multi-agent v2 communications. This follow-up uses that single point to log every communication lifecycle without requiring new hooks as spawn, messaging, follow-up, or result paths evolve.

For each communication, the logs need to identify its type, sender and receiver threads, and content, while correlating the successful send with receipt by the destination mailbox. The logging path must not query externally supplied time providers because those calls can be expensive for app-server clients.

What changed

  • Added structured INFO events on the OpenTelemetry-exported codex_otel.agent_communication target for spawn, message, followup, and result communications.
  • Logged successful sends from submit_inter_agent_communication with the communication kind, sender and receiver thread IDs, content, and submission ID.
  • Logged receives after the communication has been enqueued in the receiver mailbox, using the same submission ID.
  • Avoided time-provider calls and other asynchronous work in the logging path.
  • Narrowed ordinary spawn and send-input APIs to Vec<UserInput> so Op::InterAgentCommunication cannot bypass the context-bearing centralized path.

The refactor does not change submission IDs, capacity checks, last-task bookkeeping, mailbox ordering, protocol types, rollout data, or model-visible context.

Event shape

Illustrative JSON representation of the two independently emitted records:

[
  {
    "event.name": "codex.agent_communication",
    "communication_id": "019f20e1-40d1-7890-a123-456789abcdef",
    "kind": "spawn",
    "state": "send",
    "sender_thread_id": "019f20df-fbe1-7890-a123-456789abcdef",
    "receiver_thread_id": "019f20e1-3f79-7890-a123-456789abcdef",
    "content": "inspect the repository"
  },
  {
    "event.name": "codex.agent_communication",
    "communication_id": "019f20e1-40d1-7890-a123-456789abcdef",
    "state": "receive"
  }
]

Consumers join the receive record to the send record by communication_id for the immutable communication metadata.

Testing

  • Extended the existing end-to-end multi-agent v2 spawn test to verify content, both thread IDs, and a correlated send/receive submission ID.
  • Re-ran focused control and handler coverage for direct messages, follow-up tasks, and completion results.

@bolinfest bolinfest requested a review from a team as a code owner July 1, 2026 22:09
@bolinfest bolinfest changed the base branch from main to pr30867 July 1, 2026 22:09
@bolinfest bolinfest force-pushed the pr30872 branch 7 times, most recently from 7f74f9a to 82ed1d2 Compare July 1, 2026 23:36
@bolinfest bolinfest requested a review from rka-oai July 1, 2026 23:41
let output: &'static Mutex<Vec<u8>> = Box::leak(Box::new(Mutex::new(Vec::new())));
let subscriber = tracing_subscriber::fmt()
.with_ansi(false)
.with_max_level(Level::TRACE)

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.

The events are emitted as INFO right? Maybe we should set INFO instead of TRACE here?

#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct AgentCommunicationContext {
kind: AgentCommunicationKind,
pub(crate) sender_thread_id: ThreadId,

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.

OOC, do we need sender_thread_id to be set to pub(crate)? should other modules be able to access/view it (looks like it’s only accessed within this module, so could it remain private)

bolinfest added a commit that referenced this pull request Jul 2, 2026
## Why

Multi-agent v2 communications currently use separate outbound paths:
direct messages, follow-up tasks, and completion results go through
`send_inter_agent_communication`, while a spawn's initial message goes
through the generic input submission path. That split makes it difficult
to add complete communication lifecycle logging in one place.

This refactor makes `submit_inter_agent_communication` the common sink
for those paths, preparing the follow-up observability work discussed in
[#30516](#30516).

## What changed

- Routed all current outbound `InterAgentCommunication` paths in
`AgentControl`—direct messages, follow-up tasks, completion results, and
multi-agent v2 spawn initial messages—through
`submit_inter_agent_communication`.
- Centralized the actual submission and last-task-message bookkeeping
there, providing one place for the follow-up PR to instrument
communication creation and successful enqueue.
- Left non-communication input handling and the multi-agent v1 spawn
flow unchanged.

## Testing

- `just test -p codex-core 'agent::control::tests::'` (51 passed)
- `just test -p codex-core
'suite::subagent_notifications::encrypted_multi_agent_v2_spawn_sends_agent_message_to_child'`
(passed)








---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/30867).
* #30872
* __->__ #30867
Base automatically changed from pr30867 to main July 2, 2026 00:08
@bolinfest bolinfest force-pushed the pr30872 branch 4 times, most recently from 4123e51 to be18a5e Compare July 2, 2026 00:38
@bolinfest bolinfest merged commit 129ea2a into main Jul 2, 2026
78 of 100 checks passed
@bolinfest bolinfest deleted the pr30872 branch July 2, 2026 01:11
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants