Skip to content

Add explicit agent communication logging#30516

Closed
npancha-openai wants to merge 2 commits into
mainfrom
codex/agent-communication-v2
Closed

Add explicit agent communication logging#30516
npancha-openai wants to merge 2 commits into
mainfrom
codex/agent-communication-v2

Conversation

@npancha-openai

@npancha-openai npancha-openai commented Jun 29, 2026

Copy link
Copy Markdown

Currently there is no unified way to observe agent communication lifecycle events. This adds structured logging for communication creation and successful mailbox enqueue.

The records are emitted at TRACE under the codex_core::agent_communication module target. You can opt in with:

RUST_LOG=warn,codex_core::agent_communication=trace

Created event:

{
  "timestamp": "2026-06-29T03:27:51.433693Z",
  "level": "TRACE",
  "fields": {
    "message": "agent communication updated",
    "event.name": "codex.agent_communication",
    "communication_id": "44e6762e-e19e-478d-ab94-c5e0be15209b",
    "kind": "result",
    "state": "created",
    "sender_thread_id": "019f116b-4219-7210-b88e-7615ba34bcef",
    "receiver_thread_id": "019f116b-2ddb-7c41-a9f4-e234bb5e5fc7",
    "content": "Message Type: FINAL_ANSWER\nTask name: /root\nSender: /root/toy_worker\nPayload:\nCHILD_OK"
  },
  "target": "codex_core::agent_communication"
}

Enqueued event:

{
  "timestamp": "2026-06-29T03:27:51.434038Z",
  "level": "TRACE",
  "fields": {
    "message": "agent communication updated",
    "event.name": "codex.agent_communication",
    "communication_id": "44e6762e-e19e-478d-ab94-c5e0be15209b",
    "state": "enqueued"
  },
  "target": "codex_core::agent_communication"
}

@npancha-openai npancha-openai requested a review from a team as a code owner June 29, 2026 03:29
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@npancha-openai npancha-openai marked this pull request as draft June 29, 2026 03:30
))
}

fn new_agent_communication_metadata_unchecked(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

naming is bad will fix

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbfc682ded

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/Cargo.toml
test-log = { workspace = true }
tracing-opentelemetry = { workspace = true }
tracing-subscriber = { workspace = true }
tracing-subscriber = { workspace = true, features = ["json"] }

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.

P2 Badge Refresh Bazel lockfile after enabling json feature

When this crate is built or tested through Bazel, the new tracing-subscriber json feature changes the Cargo dependency metadata, but MODULE.bazel.lock is not part of this commit. Regenerate and include the Bazel lockfile update so Bazel/CI does not reject the dependency drift.

AGENTS.md reference: AGENTS.md:L37-L39

Useful? React with 👍 / 👎.

Comment thread codex-rs/core/src/agent/control.rs Outdated
result
}

fn create_and_emit_agent_communication(

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.

P3 Badge Inline the single-use communication helper

This private helper is only called once and just wraps metadata construction plus the emit call, so it adds one-off method surface instead of keeping the communication logging flow at its only call site; please inline it here or reuse it from the other emitters if it is meant to be shared.

AGENTS.md reference: AGENTS.md:L44-L44

Useful? React with 👍 / 👎.

Comment thread codex-rs/protocol/src/protocol.rs Outdated
Comment on lines +740 to +744
/// Runtime-only metadata used to emit communication lifecycle records.
#[serde(skip)]
#[schemars(skip)]
#[ts(skip)]
pub agent_communication_metadata: Option<AgentCommunicationMetadata>,

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.

P2 Badge Keep runtime metadata out of protocol struct

When any Rust client constructs or destructures InterAgentCommunication with a struct literal or exhaustive pattern, this new public runtime-only field is a source-breaking API change even though it is skipped on the wire; keep the logging metadata in a core-side wrapper/sidecar instead of expanding the public protocol type for an internal logging concern.

AGENTS.md reference: AGENTS.md:L87-L89

Useful? React with 👍 / 👎.

@npancha-openai npancha-openai force-pushed the codex/agent-communication-v2 branch from a4c1cb2 to 0e35d88 Compare June 29, 2026 22:13
@npancha-openai npancha-openai marked this pull request as ready for review June 29, 2026 22:23
@npancha-openai

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e35d88be1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +42 to +44
tracing::trace!(
{
event.name = "codex.agent_communication",

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.

P2 Badge Route communication events to an exported target

In normal TUI/app-server runs this trace! event is emitted under the module target codex_core::agent_communication, but I checked the installed layers and the OTEL log bridge only exports targets accepted by is_log_export_target (codex_otel*), while this PR also disables this same target in the feedback and SQLite log filters. As a result, the new lifecycle records are dropped in production unless a developer opts into a separate file logger; add a dedicated exported target/filter path while keeping the sensitive local sinks suppressed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't think otel matters here

Comment on lines +109 to +112
crate::agent_communication::emit_agent_communication_created(
&communication,
receiver_thread_id,
);

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.

P2 Badge Add integration coverage for communication logging

For this new agent-logic path, the code now generates and emits lifecycle metadata from the real send_message/followup_task flow, but the added coverage is helper/session harness tests; I searched under codex-rs/core/tests/suite and found no integration test driving a v2 tool call through test_codex, so created/enqueued ID and kind correlation can regress in the actual tool path while unit tests still pass. Add an integration test for at least one tool path.

AGENTS.md reference: AGENTS.md:L114-L118

Useful? React with 👍 / 👎.

Comment thread codex-rs/core/src/lib.rs
pub use codex_thread::TryStartTurnIfIdleRejectionReason;
pub use session::turn_context::TurnContext;
mod agent;
mod agent_communication;

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.

P3 Badge Split the logging rollout into smaller stages

This non-mechanical logging rollout changes protocol metadata, core delivery paths, feedback/state filtering, and tests in one roughly 550-line diff; because complex logic changes are expected to stay under 500 lines, split the smallest coherent stages, such as metadata/helper plus focused tests, then tool/result wiring, then filter changes, so each stage can be validated independently.

AGENTS.md reference: AGENTS.md:L125-L131

Useful? React with 👍 / 👎.

github-actions Bot added a commit that referenced this pull request Jun 30, 2026
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
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