From df975851bf906d71e5a1ead04f1eaec41d26ca16 Mon Sep 17 00:00:00 2001 From: jif Date: Wed, 18 Nov 2026 13:56:33 +0000 Subject: [PATCH] Use the system clock for in-memory MCP message boards (#62284) ## Why The in-memory MCP backend depended on the runner's clock, so a runner clock failure could prevent posting. The standalone SQLite backend already uses the system clock. ## What changed Read UTC time from the MCP backend's system clock after validating caller membership. Apply this to both tree and agent-specific bindings. ## Testing Update the HTTP integration scenario to make the runner clock fail and verify that a child agent's post timestamp falls within the posting window. GitOrigin-RevId: bad5dec5a9be7246cf627b017897fbfe2c960cd1 --- .../scenarios_agent_message_board_http.rs | 12 ++++-- codex-rs/message-board-mcp/README.md | 3 +- codex-rs/message-board-mcp/src/local.rs | 39 ++++++++++++++++++- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/codex-rs/core/tests/suite/scenarios_agent_message_board_http.rs b/codex-rs/core/tests/suite/scenarios_agent_message_board_http.rs index 0d54d86443..59c5064977 100644 --- a/codex-rs/core/tests/suite/scenarios_agent_message_board_http.rs +++ b/codex-rs/core/tests/suite/scenarios_agent_message_board_http.rs @@ -164,7 +164,8 @@ async fn http_board_is_shared_with_children(mode: BoardMode) -> anyhow::Result<( ] .into(), clock: Default::default(), - fail_clock: Default::default(), + // MCP timestamps must not depend on the runner's clock. + fail_clock: true.into(), agent_path_calls: Default::default(), active: Default::default(), fail_notifications: Default::default(), @@ -208,6 +209,7 @@ async fn http_board_is_shared_with_children(mode: BoardMode) -> anyhow::Result<( let posted = responses::mount_sse_sequence(&server, board_turn("worker-post", "post", post_arguments)) .await; + let before_post = chrono::Utc::now().timestamp_millis(); child .start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text { text: "Find the board tools and post your decision.".into(), @@ -220,9 +222,11 @@ async fn http_board_is_shared_with_children(mode: BoardMode) -> anyhow::Result<( "worker-post", )?; assert_eq!(post["author"], "/root/worker"); - if mode == BoardMode::InMemory { - assert_eq!(post["created_at"], "2026-09-18T12:00:00Z"); - } + let created_at = chrono::DateTime::parse_from_rfc3339( + post["created_at"].as_str().context("post timestamp")?, + )? + .timestamp_millis(); + assert!((before_post..=chrono::Utc::now().timestamp_millis()).contains(&created_at)); if mode != BoardMode::Feature { child.shutdown_and_wait().await?; } diff --git a/codex-rs/message-board-mcp/README.md b/codex-rs/message-board-mcp/README.md index 9cccdb4d6f..f72709bee3 100644 --- a/codex-rs/message-board-mcp/README.md +++ b/codex-rs/message-board-mcp/README.md @@ -102,7 +102,8 @@ existing launcher lifecycle; explicit host-supplied board connections are unchan A runner calls `launch_in_memory()`, then registers each tree with `server.add_board(session_id, host)`. It supplies the existing `MessageBoardHost` -for membership, clocks and notification delivery. Configure the same MCP server +for membership and notification delivery. Timestamps use the MCP backend's system +clock, as in the standalone SQLite server. Configure the same MCP server with `server.url()` and the `Authorization` header from `server.authorization()`; this overrides the plugin endpoint through normal configuration. diff --git a/codex-rs/message-board-mcp/src/local.rs b/codex-rs/message-board-mcp/src/local.rs index c06ad91f69..9a492fd412 100644 --- a/codex-rs/message-board-mcp/src/local.rs +++ b/codex-rs/message-board-mcp/src/local.rs @@ -1,16 +1,24 @@ //! Runner-owned HTTP lifecycle over the existing in-memory board and host interfaces. //! Agent-specific bindings share tree state while retaining each caller's host. +//! Timestamps use the MCP backend's system clock, independently of the agent clock. use crate::MessageBoardMcpServer; use crate::serve_http; use axum::http::HeaderValue; +use chrono::DateTime; +use chrono::Utc; use codex_message_board::AgentMessageBoard; use codex_message_board::InMemoryAgentMessageBoard; use codex_message_board::InMemoryMessageBoards; use codex_message_board::MessageBoardHost; use codex_message_board::MessageBoardTool; +use codex_message_board::NotificationDelivery; +use codex_message_board::PostPreview; +use codex_protocol::AgentPath; use codex_protocol::SessionId; use codex_protocol::ThreadId; +use codex_protocol::error::Result; +use futures::future::BoxFuture; use rmcp::ErrorData; use rmcp::transport::StreamableHttpServerConfig; use std::collections::HashMap; @@ -23,6 +31,33 @@ use tokio_util::sync::CancellationToken; type BoardBinding = (Arc, Arc); type Boards = Arc), BoardBinding>>>; +struct BackendClockHost(Arc); + +impl MessageBoardHost for BackendClockHost { + fn agent_path(&self, caller: ThreadId) -> BoxFuture<'_, Result> { + self.0.agent_path(caller) + } + + fn resolve_agent(&self, path: AgentPath) -> BoxFuture<'_, Result> { + self.0.resolve_agent(path) + } + + fn current_time(&self, caller: ThreadId) -> BoxFuture<'_, Result>> { + Box::pin(async move { + self.0.agent_path(caller).await?; + Ok(Utc::now()) + }) + } + + fn notify( + &self, + recipient: ThreadId, + post: PostPreview, + ) -> BoxFuture<'_, Result> { + self.0.notify(recipient, post) + } +} + /// One runner-owned endpoint. Dropping it initiates HTTP and MCP session cleanup. /// Call [`Self::shutdown`] to wait until that cleanup has finished. /// Credentials are deliberately excluded from Debug and startup output. @@ -45,7 +80,7 @@ impl LocalServer { } /// Registers a tree before its first tool call. The runner supplies authoritative - /// membership and clocks; the service never registers or spawns agents itself. + /// membership; the service never registers or spawns agents itself. pub fn add_board( &self, identity: SessionId, @@ -59,6 +94,7 @@ impl LocalServer { !boards.keys().any(|(tree, _)| *tree == identity), "board session already registered" ); + let host: Arc = Arc::new(BackendClockHost(host)); boards.insert( (identity, None), ( @@ -76,6 +112,7 @@ impl LocalServer { caller: ThreadId, host: Arc, ) -> anyhow::Result<()> { + let host: Arc = Arc::new(BackendClockHost(host)); let board = self.states.open(identity, host.clone()).await; let mut boards = self .boards