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
This commit is contained in:
jif
2026-11-18 14:11:08 +00:00
committed by copyberry
parent a05444bbeb
commit df975851bf
3 changed files with 48 additions and 6 deletions
@@ -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?;
}
+2 -1
View File
@@ -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.
+38 -1
View File
@@ -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<dyn AgentMessageBoard>, Arc<dyn MessageBoardHost>);
type Boards = Arc<RwLock<HashMap<(SessionId, Option<ThreadId>), BoardBinding>>>;
struct BackendClockHost(Arc<dyn MessageBoardHost>);
impl MessageBoardHost for BackendClockHost {
fn agent_path(&self, caller: ThreadId) -> BoxFuture<'_, Result<AgentPath>> {
self.0.agent_path(caller)
}
fn resolve_agent(&self, path: AgentPath) -> BoxFuture<'_, Result<ThreadId>> {
self.0.resolve_agent(path)
}
fn current_time(&self, caller: ThreadId) -> BoxFuture<'_, Result<DateTime<Utc>>> {
Box::pin(async move {
self.0.agent_path(caller).await?;
Ok(Utc::now())
})
}
fn notify(
&self,
recipient: ThreadId,
post: PostPreview,
) -> BoxFuture<'_, Result<NotificationDelivery>> {
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<dyn MessageBoardHost> = Arc::new(BackendClockHost(host));
boards.insert(
(identity, None),
(
@@ -76,6 +112,7 @@ impl LocalServer {
caller: ThreadId,
host: Arc<dyn MessageBoardHost>,
) -> anyhow::Result<()> {
let host: Arc<dyn MessageBoardHost> = Arc::new(BackendClockHost(host));
let board = self.states.open(identity, host.clone()).await;
let mut boards = self
.boards