mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Route message-board notifications through agent mailboxes (#59139)
## Why Board notifications were skipped when recipients had no active turn accepting mailbox delivery. Queue them through the ordinary agent-message path so idle recipients can receive them in a later turn. ## What changed - Submit board notices as `Op::InterAgentCommunication` with `trigger_turn` disabled, preserving normal mailbox scheduling without reopening finalized answers. - Hold a residency guard through dispatch of submitted agent messages to coordinate delivery with agent eviction. - Update board tool descriptions to describe the host's notification queueing and wake policy. ## Testing Update local and HTTP board scenarios to cover queued idle notices, delivery after a finalized answer, and mailbox delivery before a pending tool call. Extend residency coverage to verify that submission waits for the eviction gate and queued messages survive eviction. GitOrigin-RevId: a77137fc40932f5903852e14742483844e07c9bc
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! Exercises board tools through the runtime, including resume and active-only notices.
|
||||
//! Exercises board tools through the runtime, including resume and native mailbox notifications.
|
||||
|
||||
use anyhow::Context;
|
||||
use codex_core::TurnInputRequest;
|
||||
@@ -7,6 +7,7 @@ use codex_message_board::PostMetadata;
|
||||
use codex_protocol::items::TurnItem;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::ThreadSettingsOverrides;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use core_test_support::context_snapshot;
|
||||
use core_test_support::context_snapshot::ContextSnapshotOptions;
|
||||
@@ -250,7 +251,7 @@ async fn board_post_and_reads_reach_model_context_without_self_notices(
|
||||
#[test_case::test_case(false; "disk")]
|
||||
#[test_case::test_case(true; "in_memory")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn board_is_shared_with_children_and_skips_idle_notices(
|
||||
async fn board_is_shared_with_children_and_queues_idle_notices(
|
||||
in_memory: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let server = responses::start_mock_server().await;
|
||||
@@ -341,11 +342,7 @@ async fn board_is_shared_with_children_and_skips_idle_notices(
|
||||
)
|
||||
.await;
|
||||
root.submit_turn("Read the worker's decision.").await?;
|
||||
assert!(
|
||||
read.requests()
|
||||
.iter()
|
||||
.all(|request| !request.body_contains_text("Message Type: CHANNEL_POST"))
|
||||
);
|
||||
assert!(read.requests()[1].body_contains_text("Message Type: CHANNEL_POST"));
|
||||
let output = read.requests()[1]
|
||||
.function_call_output_text("root-read")
|
||||
.expect("read result");
|
||||
@@ -454,7 +451,8 @@ async fn board_notifications_do_not_reopen_a_final_answer(
|
||||
gate: Some(child_gate),
|
||||
body: done(),
|
||||
}],
|
||||
response(done()),
|
||||
// Native mail is drained after the new task's first model step.
|
||||
response(tool("next-step", "get_channels", json!({}))),
|
||||
response(done()),
|
||||
])
|
||||
.await;
|
||||
@@ -550,18 +548,22 @@ async fn board_notifications_do_not_reopen_a_final_answer(
|
||||
let next_turn = requests.last().context("next root request")?["client_metadata"]["turn_id"]
|
||||
.as_str()
|
||||
.context("next root turn ID")?;
|
||||
for (turn, notified) in [(target_turn.as_str(), false), (next_turn, !after_final)] {
|
||||
for (turn, expected_requests, notified) in
|
||||
[(target_turn.as_str(), 1, false), (next_turn, 2, true)]
|
||||
{
|
||||
let requests = requests
|
||||
.iter()
|
||||
.filter(|request| request["client_metadata"]["turn_id"] == turn)
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
requests.len(),
|
||||
1,
|
||||
"recipient must not sample again after its final"
|
||||
expected_requests,
|
||||
"unexpected sampling count for root turn {turn}"
|
||||
);
|
||||
assert_eq!(
|
||||
requests[0]["input"].to_string().contains(¬ification),
|
||||
requests.last().context("root request")?["input"]
|
||||
.to_string()
|
||||
.contains(¬ification),
|
||||
notified
|
||||
);
|
||||
}
|
||||
@@ -955,6 +957,8 @@ async fn codex_instances_share_board_with_fixed_access() -> anyhow::Result<()> {
|
||||
let server = responses::start_mock_server().await;
|
||||
let response = |body| vec![StreamingSseChunk { gate: None, body }];
|
||||
let (release, gate) = oneshot::channel();
|
||||
let mut started = ev_message_item_added("watching", "");
|
||||
started["item"]["phase"] = json!("commentary");
|
||||
let mut working = ev_assistant_message("watching", "Watching the policy board.");
|
||||
working["item"]["phase"] = json!("commentary");
|
||||
let (streaming, _) = start_streaming_sse_server(vec![
|
||||
@@ -984,11 +988,15 @@ async fn codex_instances_share_board_with_fixed_access() -> anyhow::Result<()> {
|
||||
vec![
|
||||
StreamingSseChunk {
|
||||
gate: None,
|
||||
body: sse(vec![ev_response_created("watching"), working]),
|
||||
body: sse(vec![ev_response_created("watching"), started]),
|
||||
},
|
||||
StreamingSseChunk {
|
||||
gate: Some(gate),
|
||||
body: tool("checkpoint", "get_channels", json!({})),
|
||||
body: sse(vec![
|
||||
working,
|
||||
ev_function_call_with_namespace("checkpoint", "collaboration", "get_channels", "{}"),
|
||||
ev_completed("checkpoint"),
|
||||
]),
|
||||
},
|
||||
],
|
||||
// Separate responses order the writes before snapshotting last_message_id.
|
||||
@@ -1015,6 +1023,8 @@ async fn codex_instances_share_board_with_fixed_access() -> anyhow::Result<()> {
|
||||
}),
|
||||
)),
|
||||
response(done()),
|
||||
// Queued board notices preempt the commentary before its planned checkpoint.
|
||||
response(tool("checkpoint", "get_channels", json!({}))),
|
||||
response(done()),
|
||||
])
|
||||
.await;
|
||||
@@ -1132,8 +1142,13 @@ async fn codex_instances_share_board_with_fixed_access() -> anyhow::Result<()> {
|
||||
text_elements: vec![],
|
||||
}]))
|
||||
.await?;
|
||||
let guardian_turn = wait_for_event_match(guardian, |event| match event {
|
||||
EventMsg::TurnStarted(event) => Some(event.turn_id.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
wait_for_event(guardian, |event| {
|
||||
matches!(event, EventMsg::ItemCompleted(event)
|
||||
matches!(event, EventMsg::ItemStarted(event)
|
||||
if matches!(&event.item, TurnItem::AgentMessage(message) if message.id == "watching"))
|
||||
})
|
||||
.await;
|
||||
@@ -1144,6 +1159,16 @@ async fn codex_instances_share_board_with_fixed_access() -> anyhow::Result<()> {
|
||||
}]))
|
||||
.await?;
|
||||
wait_for_event(writer, |event| matches!(event, EventMsg::TurnComplete(_))).await;
|
||||
// Acknowledgement is ordered after both notices in the recipient's submission queue.
|
||||
guardian
|
||||
.update_thread_settings(ThreadSettingsOverrides::default())
|
||||
.await?;
|
||||
assert_eq!(
|
||||
guardian
|
||||
.wait_for_input_activity(&guardian_turn, std::time::Duration::from_secs(/*secs*/ 10))
|
||||
.await,
|
||||
codex_core::InputWaitOutcome::MailboxActivity,
|
||||
);
|
||||
release
|
||||
.send(())
|
||||
.expect("release Guardian after notification delivery");
|
||||
@@ -1154,6 +1179,20 @@ async fn codex_instances_share_board_with_fixed_access() -> anyhow::Result<()> {
|
||||
.iter()
|
||||
.any(|body| String::from_utf8_lossy(body).contains("Message Type: CHANNEL_POST"))
|
||||
);
|
||||
let resumed: Value = serde_json::from_slice(&requests[16])?;
|
||||
assert!(
|
||||
resumed["input"]
|
||||
.to_string()
|
||||
.contains("Message Type: CHANNEL_POST")
|
||||
);
|
||||
assert!(
|
||||
!resumed["input"]
|
||||
.as_array()
|
||||
.context("resumed input")?
|
||||
.iter()
|
||||
.any(|item| item["call_id"] == "checkpoint"),
|
||||
"queued board mail must be read before the planned checkpoint runs",
|
||||
);
|
||||
let last: Value = serde_json::from_slice(requests.last().unwrap())?;
|
||||
let checkpoint = last["input"]
|
||||
.as_array()
|
||||
@@ -1169,7 +1208,7 @@ async fn codex_instances_share_board_with_fixed_access() -> anyhow::Result<()> {
|
||||
.iter()
|
||||
.map(|body| serde_json::from_slice::<Value>(body))
|
||||
.collect::<serde_json::Result<Vec<_>>>()?;
|
||||
assert_eq!(bodies.len(), 17);
|
||||
assert_eq!(bodies.len(), 18);
|
||||
for body in &mut bodies {
|
||||
for item in body["input"].as_array_mut().context("request input")? {
|
||||
if let Some(Value::String(output)) = item.get_mut("output") {
|
||||
|
||||
@@ -200,15 +200,14 @@ async fn http_board_is_shared_with_children(mode: BoardMode) -> anyhow::Result<(
|
||||
.map_or(output.as_str(), |(_, json)| json);
|
||||
serde_json::from_str(json).with_context(|| format!("board result: {output}"))
|
||||
};
|
||||
let posted = responses::mount_sse_sequence(
|
||||
&server,
|
||||
board_turn(
|
||||
"worker-post",
|
||||
"post",
|
||||
json!({"new_channel_name":"design","text":"Worker's durable decision."}),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
let mut post_arguments =
|
||||
json!({"new_channel_name":"design","text":"Worker's durable decision."});
|
||||
if mode == BoardMode::Feature {
|
||||
post_arguments["agents_to_notify"] = json!(["/root"]);
|
||||
}
|
||||
let posted =
|
||||
responses::mount_sse_sequence(&server, board_turn("worker-post", "post", post_arguments))
|
||||
.await;
|
||||
child
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "Find the board tools and post your decision.".into(),
|
||||
@@ -261,6 +260,9 @@ async fn http_board_is_shared_with_children(mode: BoardMode) -> anyhow::Result<(
|
||||
if let Some(writer) = writer {
|
||||
writer.rollback().await?;
|
||||
}
|
||||
if mode == BoardMode::Feature {
|
||||
assert!(read.requests()[1].body_contains_text("Message Type: CHANNEL_POST"));
|
||||
}
|
||||
let result = board_result(
|
||||
read.requests().last().context("parent follow-up")?,
|
||||
"root-read",
|
||||
|
||||
+5
-4
@@ -116,7 +116,8 @@ Scenario: Independent Codex runtimes share a local board: a writer publishes, an
|
||||
21:function_call_output:{"channel_name":"policy","enabled":true,"last_message_id":"<UUID 1>","target_agent":"/root/00000000000040008000000000000001","thread_id":null}
|
||||
22:message/assistant:
|
||||
Watching the policy board.
|
||||
23:function_call/collaboration.get_channels:{}
|
||||
24:function_call_output:{"board_permissions":{"create_channel":false,"edit_metadata":false,"manage_permissions":false},"has_more...ata":false,"post":false,"read":true,"reply":false}}]} [hash=7cc8dc25fc1c52b2]
|
||||
25:agent_message
|
||||
26:agent_message
|
||||
23:agent_message
|
||||
24:agent_message
|
||||
-- request 18 (request) --
|
||||
25:function_call/collaboration.get_channels:{}
|
||||
26:function_call_output:{"board_permissions":{"create_channel":false,"edit_metadata":false,"manage_permissions":false},"has_more...ata":false,"post":false,"read":true,"reply":false}}]} [hash=7cc8dc25fc1c52b2]
|
||||
|
||||
+4
-3
@@ -45,7 +45,7 @@ Scenario: The config flag starts an in-memory MCP board shared by a parent and c
|
||||
08:tool_search_call
|
||||
09:tool_search_output
|
||||
-- request 3 (request) --
|
||||
10:function_call/mcp__codex_message_board.post:{"new_channel_name":"design","text":"Worker's durable decision."}
|
||||
10:function_call/mcp__codex_message_board.post:{"agents_to_notify":["/root"],"new_channel_name":"design","text":"Worker's durable decision."}
|
||||
11:function_call_output:Wall time: <DURATION> seconds
|
||||
Output:
|
||||
{"author":"/root/worker","channel_name":"design","created_at":"<TIMESTAMP>","message_id":"<UUID 1>","thread_id":"<UUID 1>"}
|
||||
@@ -95,8 +95,9 @@ Scenario: The config flag starts an in-memory MCP board shared by a parent and c
|
||||
11:tool_search_output
|
||||
12:agent_message
|
||||
13:agent_message
|
||||
14:agent_message
|
||||
-- request 6 (request) --
|
||||
14:function_call/mcp__codex_message_board.search_posts:{"channel_name":"design"}
|
||||
15:function_call_output:Wall time: <DURATION> seconds
|
||||
15:function_call/mcp__codex_message_board.search_posts:{"channel_name":"design"}
|
||||
16:function_call_output:Wall time: <DURATION> seconds
|
||||
Output:
|
||||
{"has_more":false,"n_returned":1,"next_cursor":null,"results":[{"author":"/root/worker","channel_name":"...ecision.","thread_id":"<UUID 1>","truncated":false}]} [hash=0322071c1fb9baa5]
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ Scenario: Permission discovery preserves legacy output, exposes reply-only acces
|
||||
|
||||
## Window 1
|
||||
-- request 1 (request) --
|
||||
00:additional_tools/developer (3; hash=e49a28343a9fe4ed):
|
||||
00:additional_tools/developer (3; hash=788c4a5014dcfe4f):
|
||||
- namespace/functions; hash=c8b8fa91706a7620
|
||||
- function/exec_command
|
||||
- function/write_stdin
|
||||
@@ -17,7 +17,7 @@ Scenario: Permission discovery preserves legacy output, exposes reply-only acces
|
||||
- namespace/clock: Tools for reading and waiting on time.; hash=a80435c7a3a3943f
|
||||
- function/curr_time
|
||||
- function/sleep
|
||||
- namespace/collaboration: Tools for spawning and managing sub-agents.; hash=ba5664aaab81db64
|
||||
- namespace/collaboration: Tools for spawning and managing sub-agents.; hash=5c5c29d91fa33d4a
|
||||
- function/create_channel
|
||||
- function/followup_task
|
||||
- function/get_channels
|
||||
|
||||
Reference in New Issue
Block a user