Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cli/docs/local-agent-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ delivery, and restart recovery then use that child identity.

Approvals appear as Inline action buttons in the conversation where the turn
is running, including its reply thread. Only the owner can resolve them.
When Codex asks to run an MCP tool, the card names the tool (`server · tool`),
shows its arguments (bounded, control characters removed) and offers Codex's
own choices: Allow, the remember options Codex allows, and Cancel, which skips
that one call while the turn goes on. An unanswered card closes as no longer
needed when its turn ends or is interrupted. Every question card also ends
with Cancel, which tells the agent the question went unanswered, and `/stop`
with no turn running cancels whatever the open cards still wait on.
Mid-turn owner directions steer when the provider supports steering; `/queue`
always queues explicitly and provides Undo until work starts. An uncertain
steering response is never automatically retried as another prompt: Inline
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{
"label": "open",
"text": "Codex wants to use linear · create_issue\n{\n \"labels\": [\n \"bug\"\n ],\n \"team\": \"ENG\",\n \"title\": \"Parser drops trailing commas\"\n}",
"markdown": false,
"blocks": [
{
"approval": {
"subject": "SUBJECT_TOOL",
"title": "Codex wants to use linear · create_issue",
"children": [
{
"code": {
"text": "{\n \"labels\": [\n \"bug\"\n ],\n \"team\": \"ENG\",\n \"title\": \"Parser drops trailing commas\"\n}",
"language": "json"
}
}
],
"state": "BLOCK_DECISION_STATE_PENDING",
"action_ids": [
"v2-0",
"v2-1",
"v2-2",
"v2-3"
]
}
}
],
"buttons": [
{
"id": "v2-0",
"label": "Allow",
"style": "primary"
},
{
"id": "v2-1",
"label": "Allow for this session",
"style": "default"
},
{
"id": "v2-2",
"label": "Always allow",
"style": "default"
},
{
"id": "v2-3",
"label": "Cancel",
"style": "default"
}
]
},
{
"label": "decided",
"text": "Codex wants to use linear · create_issue\n{\n \"labels\": [\n \"bug\"\n ],\n \"team\": \"ENG\",\n \"title\": \"Parser drops trailing commas\"\n}\nAllow (answered by Dena)",
"markdown": false,
"blocks": [
{
"approval": {
"subject": "SUBJECT_TOOL",
"title": "Codex wants to use linear · create_issue",
"children": [
{
"code": {
"text": "{\n \"labels\": [\n \"bug\"\n ],\n \"team\": \"ENG\",\n \"title\": \"Parser drops trailing commas\"\n}",
"language": "json"
}
}
],
"state": "BLOCK_DECISION_STATE_ACCEPTED",
"decided_by_user_id": 7
}
},
{
"footer": "Allow (answered by Dena)"
}
]
}
]
77 changes: 77 additions & 0 deletions cli/src/bridge/v2/blocks/fixtures/approval/codex-mcp-tool.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"source": "Codex app-server v2 mcpServer/elicitation/request for an MCP tool call: a message-only form with codex_approval_kind mcp_tool_call (see crates/agent-bridge/tests/fixtures/harness/codex/mcp-tool-approval.json).",
"native": {
"method": "mcpServer/elicitation/request",
"id": 51,
"params": {
"_meta": {
"codex_approval_kind": "mcp_tool_call",
"persist": [
"session",
"always"
],
"tool_name": "create_issue",
"tool_params": {
"labels": [
"bug"
],
"team": "ENG",
"title": "Parser drops trailing commas"
}
},
"message": "Allow the linear MCP server to run tool \"create_issue\"?",
"mode": "form",
"requestedSchema": {
"properties": {},
"type": "object"
},
"serverName": "linear",
"threadId": "thr-1",
"turnId": "turn-1"
}
},
"input": {
"agent": "Codex",
"folder": "/work/inline",
"interaction": {
"id": "51",
"turn": "turn-1",
"kind": {
"decisions": [
{
"id": "accept",
"kind": "accept",
"label": "Allow"
},
{
"id": "acceptForSession",
"kind": "accept_for_session",
"label": "Allow for this session"
},
{
"id": "acceptAlways",
"kind": "accept_and_remember",
"label": "Always allow"
},
{
"id": "cancel",
"kind": "decline",
"label": "Cancel"
}
],
"kind": "approval",
"subject": {
"input": {
"labels": [
"bug"
],
"team": "ENG",
"title": "Parser drops trailing commas"
},
"kind": "tool",
"name": "linear · create_issue"
}
}
}
}
}
61 changes: 61 additions & 0 deletions cli/src/bridge/v2/faults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ struct FakeSession {
live: Mutex<Option<TurnId>>,
/// Interactions the session waits on, as `live_work` reports them.
open: Mutex<Vec<inline_agent_bridge::harness::InteractionId>>,
/// Answers that reached the session (interaction, decision), each
/// claimed once as a harness does.
answers: Mutex<Vec<(String, String)>>,
}

impl FakeSession {
Expand Down Expand Up @@ -174,6 +177,25 @@ impl Session for FakeSession {
if let Op::Mode { mode } = &op {
self.modes.lock().unwrap().push(mode.as_str().to_owned());
}
if let Op::Answer {
interaction,
response,
..
} = &op
{
let mut answers = self.answers.lock().unwrap();
if answers.iter().any(|(id, _)| id == interaction.as_str()) {
return Box::pin(async { Err(OpError::InteractionNotPending) });
}
let decision = match response {
inline_agent_bridge::harness::InteractionResponse::Decision {
decision, ..
} => decision.as_str().to_owned(),
inline_agent_bridge::harness::InteractionResponse::Cancel => "(cancel)".to_owned(),
_ => "(answers)".to_owned(),
};
answers.push((interaction.as_str().to_owned(), decision));
}
Box::pin(async { Ok(OpOutcome::accepted()) })
}

Expand Down Expand Up @@ -327,6 +349,7 @@ fn session_fixture(
steers,
live: Mutex::new(None),
open: Mutex::new(Vec::new()),
answers: Mutex::new(Vec::new()),
});
let harness = Arc::new(FakeHarness {
session,
Expand Down Expand Up @@ -2326,6 +2349,44 @@ async fn a_dismissed_task_suggestion_never_starts_and_a_next_step_answers_once()
assert!(state(&runtime, &input_id(2, 9, 42, "widget-81")).is_none());
}

#[tokio::test]
async fn codex_mcp_tool_cards_answer_once_and_a_withdrawn_one_reaches_nothing() {
let (runtime, harness, _cleanup) = fixture(false);
runtime.agent.names.remember(1, "Owner".into()).await;
work::recovery_tests::codex_mcp_tool_card_taps(
runtime.agent.clone(),
harness.session.clone() as Arc<dyn Session>,
)
.await;
// Allow and Cancel each reached Codex once; the second Allow and the
// tap on the withdrawn card reached nothing.
assert_eq!(
*harness.session.answers.lock().unwrap(),
[
("51".to_owned(), "accept".to_owned()),
("52".to_owned(), "cancel".to_owned())
]
);
}

#[tokio::test]
async fn a_question_card_can_be_cancelled_and_stop_ends_a_request_with_no_turn() {
let (runtime, harness, _cleanup) = fixture(false);
runtime.agent.names.remember(1, "Owner".into()).await;
work::recovery_tests::question_cancel_and_turnless_stop(
runtime.agent.clone(),
harness.session.clone() as Arc<dyn Session>,
)
.await;
assert_eq!(
*harness.session.answers.lock().unwrap(),
[
("61".to_owned(), "(cancel)".to_owned()),
("62".to_owned(), "(cancel)".to_owned())
]
);
}

#[tokio::test]
async fn plan_cards_are_superseded_unless_someone_decided_them() {
let (runtime, _, _cleanup) = fixture(false);
Expand Down
10 changes: 10 additions & 0 deletions cli/src/bridge/v2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ impl Renderer {
self.card_answers.insert(interaction.clone(), kept);
}

/// Whether an open interaction blocks on nothing a stop could end: no
/// turn, not a sub-agent's, and not a question left open on purpose.
pub(crate) fn waits_on_no_turn(&self, id: &InteractionId) -> bool {
self.interactions.get(id).is_some_and(|interaction| {
interaction.turn.is_none()
&& interaction.parent.is_none()
&& !matches!(&interaction.kind, InteractionKind::Question { form } if form.asynchronous)
})
}

pub(crate) fn apply(&mut self, envelope: &Envelope) -> Vec<RenderOp> {
let mut ops = Vec::new();
let now = envelope.at_ms;
Expand Down
Loading
Loading