Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agent-reviews): keep PresentReview's schema root free of unions (#9516)

Wolf Mermelsteinbb2962ed2706
diff --git a/crates/agent_code_mode/src/inbound/reviews.rs b/crates/agent_code_mode/src/inbound/reviews.rs
index 15385bc7d6..f803fd261b 100644
--- a/crates/agent_code_mode/src/inbound/reviews.rs
+++ b/crates/agent_code_mode/src/inbound/reviews.rs
@@ -1,5 +1,9 @@
//! A saved review presentation is a completed tool call, never a suspended approval.
-use crate::domain::reviews::{CreateReview, ReviewDecision, ReviewId, ReviewService};
+use crate::domain::ExecutionId;
+use crate::domain::reviews::{
+ CalendarDraft, CreateReview, EmailDraft, ImportDraft, ReviewDecision, ReviewId, ReviewKind,
+ ReviewService, ReviewTitle,
+};
use agent_session::domain::model::AgentSession;
use ai_toolset::{
AsyncTool, AsyncToolCollection, RequestContext, ServiceContext, ToolAnnotated, ToolAnnotations,
@@ -10,6 +14,9 @@ use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::{Value, json};
+#[cfg(test)]
+mod test;
+
/// Authenticated session facts and the shared persisted review service.
#[derive(Clone)]
pub struct ReviewToolContext {
@@ -34,7 +41,37 @@ pub fn toolset() -> AsyncToolCollection<ReviewToolContext> {
title = "PresentReview",
description = "Present an editable email stack, calendar event stack, or import plan to the user without pausing the conversation. Returns immediately after the saved review is displayed; it does not send email, create an event, import anything, or wait for approval. User decisions later deliver their recorded outcomes as typed system events. Use the existing ACP question tool for questions. Supply kind (email, calendar, import), title, and 1–100 drafts. Email drafts use SendEmail arguments (Markdown body); calendar drafts use CreateCalendarEvent arguments; an import review has exactly one draft {\"source\":\"notion\" | \"linear\" | \"jira\"} and presents the plan ImportFromNotion, ImportFromLinear or ImportFromJira staged. executionId is optional and should be omitted outside ExecuteCode. Do not automatically submit these drafts or duplicate completed actions. After presenting, end your message by asking \"Should I kick it off?\"; if the person whose account the review uses says yes, submit it with DecideReview."
)]
-pub struct PresentReview(CreateReview);
+pub struct PresentReview(#[schemars(with = "PresentReviewSchema")] CreateReview);
+
+/// The model-facing shape of [`CreateReview`]. Its flattened kind-tagged drafts
+/// would put a union at the schema root, which Anthropic rejects for every
+/// request carrying the tool; here the union sits under `drafts.items` and
+/// deserialization still pairs each kind with its drafts.
+#[derive(JsonSchema)]
+#[serde(rename_all = "camelCase")]
+#[expect(dead_code, reason = "schema only")]
+struct PresentReviewSchema {
+ /// Optional code execution that prepared these drafts.
+ #[serde(default)]
+ execution_id: Option<ExecutionId>,
+ /// Stack label.
+ title: ReviewTitle,
+ /// The review's kind; every draft must match it.
+ kind: ReviewKind,
+ /// 1–100 SendEmail arguments for email, 1–100 CreateCalendarEvent
+ /// arguments for calendar, or exactly one import plan selection.
+ drafts: Vec<AnyReviewDraft>,
+}
+
+/// A draft of any kind, for [`PresentReviewSchema`].
+#[derive(JsonSchema)]
+#[serde(untagged)]
+#[expect(dead_code, reason = "schema only")]
+enum AnyReviewDraft {
+ Email(EmailDraft),
+ Calendar(CalendarDraft),
+ Import(ImportDraft),
+}
impl ToolAnnotated for PresentReview {
const ANNOTATIONS: ToolAnnotations =
diff --git a/crates/agent_code_mode/src/inbound/reviews/test.rs b/crates/agent_code_mode/src/inbound/reviews/test.rs
new file mode 100644
index 0000000000..79f7a36f09
--- /dev/null
+++ b/crates/agent_code_mode/src/inbound/reviews/test.rs
@@ -0,0 +1,41 @@
+use super::PresentReview;
+use ai_toolset::schema::generate_validated_input_schema;
+use serde_json::json;
+
+/// Anthropic rejects every request whose tools include a root `oneOf`,
+/// `allOf` or `anyOf`, and PresentReview ships to every harness.
+#[test]
+fn present_review_schema_has_no_root_union() {
+ let schema = serde_json::to_value(
+ generate_validated_input_schema::<PresentReview>()
+ .unwrap()
+ .schema,
+ )
+ .unwrap();
+
+ for keyword in ["oneOf", "allOf", "anyOf"] {
+ assert!(schema.get(keyword).is_none(), "root {keyword}: {schema}");
+ }
+ assert_eq!(schema["type"], "object");
+ assert!(schema["properties"]["kind"].is_object());
+ assert!(schema["properties"]["title"].is_object());
+ assert_eq!(schema["properties"]["drafts"]["type"], "array");
+}
+
+#[test]
+fn present_review_still_decodes_kind_tagged_drafts() {
+ let import: PresentReview = serde_json::from_value(json!({
+ "title": "Notion import",
+ "kind": "import",
+ "drafts": [{"source": "notion"}],
+ }))
+ .unwrap();
+ assert_eq!(import.0.title.as_ref(), "Notion import");
+
+ let mismatched = serde_json::from_value::<PresentReview>(json!({
+ "title": "Notion import",
+ "kind": "email",
+ "drafts": [{"source": "notion"}],
+ }));
+ assert!(mismatched.is_err());
+}