codex icon indicating copy to clipboard operation
codex copied to clipboard

app-server: subagent spawns and follow-ups carry no message text

Open SeanLF opened this issue 2 weeks ago • 3 comments

What variant of Codex are you using?

app-server, Codex CLI 0.169.0 (same on 0.167.2), macOS arm64, multi_agent_v2 = true, fresh CODEX_HOME

What feature would you like to see?

When a parent agent spawns a subagent or sends it a follow-up, an app-server client can't see what it said. Both show up only as subAgentActivity items, and those have no text.

Could the text be in the stream? A field on subAgentActivity for started and interacted would work, or a userMessage item on the child thread. If leaving it out is on purpose (the message parameter of spawn_agent, send_message and followup_task is marked encrypted), it would help to know, so clients stop looking for it.

To reproduce, with multi_agent_v2 = true: have the parent call spawn_agent with task_name: "kestrel", then followup_task with target: "kestrel". The child's model receives both messages. The client stream has:

  • subAgentActivity items started, interacted, completed, none with text
  • no userMessage item on the child thread
  • neither message anywhere in the stream

I scripted the model's replies to rule out model behaviour. A real model gives the same stream.

The follow-up, timestamps removed:

{"type":"subAgentActivity","id":"c2","kind":"interacted","agentThreadId":"01a1e2be-839c-79d0-970c-eeda5ba46acd","agentPath":"/root/kestrel","model":null,"reasoningEffort":null}

Additional information

  • #27007 replaced the v2 spawn_agent, send_message and followup_task events with subAgentActivity. The old events carried the prompt.
  • #28561 puts the text on raw items, but those need experimentalRawEvents, which is marked internal only.
  • codex-acp already shows a child's userMessage to its clients (agentclientprotocol/codex-acp#760), so that option would work there as is.
  • Related: #34919 and #50581 (exec --json), #32125 (desktop).

SeanLF avatar Nov 16 '26 05:11 SeanLF

I think the harder contract behind this report is not merely "make the spawn/follow-up string visible". It is: what evidence can a client use to reconstruct the currently effective assignment of a particular child, as distinct from the history of messages sent to it?

The distinction matters even if the missing text is exposed. On current main, the V2 message handler sends a message and then emits SubAgentActivity { kind: Interacted, id: call_id, agent_thread_id, agent_path, ... }. The app-server projection carries that activity, but not an assignment relation; the public item type likewise holds activity, not effective mandate. A new message display field would help the reporter's immediate case, but would still leave clients guessing whether a follow-up adds to, corrects, replaces, or cancels a previous assignment. A follow-up should not be assumed to revoke previous instructions automatically.

Proposed design premise to evaluate: treat agent-to-agent task instructions as versioned delegation relations, with their visibility, delivery/consumption, and current validity assessed separately. A narrow public-facing contract could preserve (or resolve) the originating parent thread/turn and call ID, immutable child thread ID, assignment/update relation (add / explicit amendment / explicit withdrawal if supported), sequence/causal predecessor, and a payload-visibility state (readable / deliberately opaque). The client's effective task view would be a reconstruction from those relations, not a list of activity labels and not simply the most recent string. This does not infer tool authorization or human approval from an agent-authored message.

A discriminating acceptance matrix:

  • Correction case: the same child receives task A, then an explicitly superseding instruction B. A history view may show both; an effective assignment view must not still present A as live.
  • Additive case: the same child receives two independent tasks. The second must not silently erase the first. This is why "latest message wins" is wrong.
  • Opaque case: the sender/child relationship and observed receipt can be inspected without pretending the encrypted task contents are readable or that receipt proves consumption.
  • Nonfit: for a trusted, single-shot local debug view with no follow-ups, merely displaying already-authorized plaintext may be sufficient; no elaborate delegation model is needed.

This is distinct from the already documented readable-audit gap #28058 and the consumed-input barrier #55738. Neither a readable history nor a consumption watermark by itself determines which obligation is still operative after an explicit amendment. If Codex deliberately does not model amendment/withdrawal, exposing that limitation to consumers is more honest than silently implying that interacted or a displayed prompt describes the child's current task.

The conceptual separation comes from Nakagawa Master's original Vol. 12 (instance/lineage/governance subject are distinct) and Vol. 16 (asynchronous state and reconnection must not silently overwrite history/currentness). Here it is an engineering design hypothesis for the app-server delegation contract, not a claim that these principles are already implemented.

Implementation bridge — versioned child assignment projection

The public V2 message handler and app-server event mapping are the practical producer/projection seams. A new first-class assignment event stream should carry host-issued child ID, stable assignment ID, causally ordered revision and explicit operation. Here is an executable JavaScript reducer for that new public projection contract (not an API currently present in Codex):

function effectiveAssignments(events) {
  const active = new Map();
  for (const e of events) { // already verified + sorted by host sequence
    if (e.op === 'add') {
      if (active.has(e.assignmentId)) throw Error('duplicate add');
      active.set(e.assignmentId, { rev: e.rev, task: e.task });
    } else if (e.op === 'amend' || e.op === 'withdraw') {
      const old = active.get(e.assignmentId);
      if (!old || old.rev !== e.previousRev) throw Error('causal gap');
      if (e.op === 'withdraw') active.delete(e.assignmentId);
      else active.set(e.assignmentId, { rev: e.rev, task: e.task });
    }
  }
  return active;
}

Test: add(A,r1), add(B,r1), amend(A,r2,previousRev:r1) keeps B and shows only A@r2; withdraw(B,previousRev:r1) removes B; an out-of-order amendment fails closed instead of guessing from the newest text; Interacted or a visible old prompt alone does not manufacture any assignment event. Events must be host-authenticated, persisted/replayed and scoped to the correct child; a message delivery receipt is separate from a consumption/acceptance receipt and from human permission. This is a testable projection core, not an implemented Rust/app-server schema or production permission gate.

Nakagawa-master avatar Nov 16 '26 05:11 Nakagawa-master

I investigated this issue and implemented a proposed fix on my fork:

Repository: https://github.com/alobroke/codex
Branch: fix/61750-subagent-message-visibility
Commit: 9691da88d0
Branch link: https://github.com/alobroke/codex/tree/fix/61750-subagent-message-visibility

Problem

Sub-agent spawn and follow-up operations correctly deliver messages to the child agent, but the corresponding SubAgentActivity events do not include the message text. As a result, clients consuming app-server activity events cannot see what task was assigned to a sub-agent or what follow-up instruction was sent.

Implementation

I updated the multi-agent v2 message flow and protocol representation to carry the original plaintext message through sub-agent activity events.

1. Core protocol changes

  • Added an optional message: Option<String> field to SubAgentActivityItem in protocol/src/items.rs.
  • Added the corresponding optional field to the app-server v2 ThreadItemPayload::SubAgentActivity representation.
  • Updated the From<CoreTurnItem> conversion to propagate the message into the v2 protocol payload.

2. Spawn activity

  • Updated multi_agents_v2/spawn.rs to derive an activity-safe message from the original AgentMessage.
  • Included the plaintext task message in the Started activity event.
  • Preserved the original AgentMessage when constructing the ThreadSpawnRequest.

3. Follow-up activity

  • Updated multi_agents_v2/message_tool.rs to capture the message before dispatching it to the target agent.
  • Included the plaintext follow-up instruction in the Interacted activity event.
  • Preserved the original message representation when passing it through AgentInput::Message.

4. Encrypted message handling

  • Added a shared message_for_activity helper in multi_agents_v2.rs.
  • Plaintext messages are included in activity events.
  • Encrypted messages are represented as None, ensuring encrypted payloads are never exposed through activity notifications.

5. Backward compatibility

  • Added #[serde(default, skip_serializing_if = "Option::is_none")] to the new optional protocol fields.
  • Updated existing activity constructors, event mappings, history reconstruction, rollout migration code, and test fixtures.
  • Older serialized activity records that do not contain the message field continue to deserialize with None.

6. Tests

  • Added unit tests verifying that plaintext messages are included in activity data.
  • Added unit tests verifying that encrypted messages are excluded.
  • Updated the core-to-v2 protocol conversion test to verify message propagation.
  • Added backward-compatibility coverage for older core and app-server v2 activity JSON without the new field.

Validation

  • cargo fmt --all -- --check — passed.
  • git diff --check — passed.
  • Rust compilation and tests could not be completed in my local Windows environment because the required MSVC linker (link.exe) is unavailable.

Review request

The repository currently restricts pull request creation to collaborators, so I have pushed the complete implementation to my fork instead.

Could a maintainer please review the proposed changes and let me know if this approach aligns with the expected protocol and event-handling design? I would be happy to make any requested adjustments.

Thank you!

alobroke avatar Nov 16 '26 08:11 alobroke

Disclosure: I maintain TeamSwarm, a local multi-agent workspace. This is a source-reading observation, not an independently reproduced result or a claim that our project fixes this issue.

@alobroke One useful test boundary in 9691da88d0 is the tool-call source before message_for_activity, not just the helper's two AgentMessage variants. In agent_message_from_tool, only DirectPlaintextMessage and CodeMode produce Plaintext; all other sources produce Encrypted. The new helper therefore intentionally still omits text for those other sources. A test that constructs AgentMessage::Plaintext directly cannot establish whether the reporter's scripted/real-model invocation takes the now-visible path.

I'd keep the fix narrow and add a source-to-wire fixture: exercise spawn plus follow-up through each supported source, inspect the actual app-server notifications, then read the persisted thread history after reconnect. For eligible plaintext, check that both views retain the same text and item/child identity; for encrypted input, check that neither view exposes its payload. This would separate an intentional visibility boundary from a projection/persistence loss without requiring a broader assignment model.

Also, with the current optional-field design, an absent message can mean either an older record or intentionally withheld content. Clients should label that as unavailable, not specifically encrypted or empty. I haven't compiled or run this fork, so these are suggested acceptance checks rather than a validation report.

DrPei12 avatar Nov 16 '26 18:11 DrPei12

Thanks @DrPei12 for the detailed source-level observation, and thanks to the reviewer for taking the time to examine the implementation and test coverage.

I agree that the important boundary is the ToolCallSource classification before message_for_activity, rather than testing only the resulting AgentMessage variants. I've extended the changes on my fork to address that distinction and strengthen the activity and persistence coverage.

Updates made:

  1. Source classification: Added unit tests covering all three relevant sources:

    • Direct → AgentMessage::Encrypted
    • DirectPlaintextMessage → AgentMessage::Plaintext
    • CodeMode → AgentMessage::Plaintext
  2. Spawn activity: Extended the integration test to verify that the live Started activity and persisted rollout contain the original message for plaintext input, while encrypted input is not exposed.

  3. Follow-up activity: Updated the followup_task fixture to explicitly exercise the plaintext collaboration-tool path. Added assertions verifying that the live Interacted activity and persisted rollout retain the follow-up message.

  4. Thread history: Updated the history test fixture for the optional message field.

Commits pushed:

  • 9691da88d0 — fix: include plaintext messages in subagent activity
  • 14adaef092 — test: cover subagent plaintext activity messages

Branch: https://github.com/alobroke/codex/tree/fix/61750-subagent-message-visibility

The changes are pushed and ready for review. GitHub currently restricts PR creation to repository collaborators, so I would appreciate a maintainer's help opening a PR from this branch or advising on the appropriate contribution path.

Thanks again for the feedback.

alobroke avatar Nov 17 '26 14:11 alobroke