From 33093b02d5dff25e75ea1c91e34d0f47b612c805 Mon Sep 17 00:00:00 2001 From: sofyan48 Date: Tue, 24 Nov 2026 23:10:03 +0000 Subject: [PATCH] Adapt omitted Claude tool input handling from upstream --- docs/maintenance-2026-11-25.md | 64 ++++++++++++++++++++++++++++++++++ src/protocol/messages.rs | 7 ++-- src/protocol/tests.rs | 24 +++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 docs/maintenance-2026-11-25.md diff --git a/docs/maintenance-2026-11-25.md b/docs/maintenance-2026-11-25.md new file mode 100644 index 0000000..4e168f0 --- /dev/null +++ b/docs/maintenance-2026-11-25.md @@ -0,0 +1,64 @@ +# Upstream maintenance review — 2026-11-25 + +## Scope and ancestry + +Fork baseline: `1bb9115b` on `sofyan48/AI48Proxy:main`. +Upstream inspected: `router-for-me/CLIProxyAPI` default `main`, tip +`85225381d89915595598ed13766cd79890c03a84`. + +The Rust fork and Go upstream have independent root commits. Git ancestry and +patch IDs therefore cannot establish semantic coverage: `git cherry` reports +4,242 unmatched non-merge commits, not 4,242 proven missing features. Do not merge +unrelated histories or copy the Go tree into this Home-managed Rust worker. + +This is a **partial** adaptation of upstream `d2b7dbbdbc9ceeee0312b08c48867ec2789fde30` +(missing Claude tool input). It does not claim coverage of the upstream tip. +The shared Claude call adapter now emits the JSON object string `"{}"` for omitted +`input`. Explicit null, string, array and boolean values remain invalid. Existing +object arguments and tool-result ownership checks remain intact. This applies +only to existing supported translation paths; it does not expand Codex source +format support or relax unsupported-feature gates. + +## Features preserved and conflict handling + +No textual merge was attempted because the histories and languages differ. +Adapted the upstream improvement to the existing strict Rust translation boundary +without replacing the fork architecture. Preserved AI48 branding, Home-selected +credentials, mTLS/RESP lifecycle, database-backed control-plane ownership, +accounting, plugin startup guards, payload-rule ordering, existing API routes and +fail-closed validation. No Home or UI API shape changes are introduced. + +## Database + +No worker schema migration is involved. Home `origin/main` schema version is 29; +upstream Home schema version is 20. Home stays **29 -> 29**. No migration was +renumbered, removed, added or executed. Production databases were not accessed. + +## Pending upstream review + +- `85225381`: credential-scoped signature cache; fork docs explicitly exclude full + signed reasoning replay. Do not infer that enabled config implies cache parity. +- `bffe6e7e`: credential-replacement transport pool isolation needs a Rust-specific + pool identity audit, not a copied Go implementation. +- `e049c336`: Imagen predict normalization; specialized Vertex Imagen operations + are explicitly outside the worker's current supported matrix. +- Recent Gemini/Antigravity terminal, filter-error, tool and thinking fixes require + path-specific regression review. This PR does not mark those fixes as covered. + +## Verification + +Added a regression for omitted input producing string-valued `{}`, retained object +arguments, rejection of explicit invalid input and rejection of unmatched tool +results. + +- `cargo test --locked --all-targets`: 525 passed, 0 failed, 1 ignored. +- `cargo fmt --all --check`: passed after installing rustfmt. +- `git diff --check`: passed. +- `cargo clippy --locked --all-targets -- -D warnings`: failed under Rust 1.100.0 + in unchanged `codex_catalog.rs`, `ws_recovery.rs`, `websocket.rs`, + `codex_multiagent_tests.rs` and `gateway_client_tests.rs` (six lint errors). + These unrelated baseline issues were not silenced or refactored. PR must remain + draft until required verification succeeds. + +Fixtures are synthetic; no live provider, deployment, service restart or production +migration is authorized. diff --git a/src/protocol/messages.rs b/src/protocol/messages.rs index fe23487..ab3f7c6 100644 --- a/src/protocol/messages.rs +++ b/src/protocol/messages.rs @@ -46,9 +46,12 @@ pub(super) fn openai_call(call: &Value) -> Result { } pub(super) fn claude_call(block: &Value) -> Result { fields(block, &["type", "id", "name", "input"])?; - object(&block["input"])?; + // Parameterless Claude calls may omit input; explicit invalid values still fail closed. + let empty_input = json!({}); + let input = block.get("input").unwrap_or(&empty_input); + object(input)?; Ok( - json!({"id":nonempty(&block["id"])?,"type":"function","function":{"name":nonempty(&block["name"])?,"arguments":serde_json::to_string(&block["input"]).map_err(|_| invalid("tool input serialization"))?}}), + json!({"id":nonempty(&block["id"])?,"type":"function","function":{"name":nonempty(&block["name"])?,"arguments":serde_json::to_string(input).map_err(|_| invalid("tool input serialization"))?}}), ) } pub(super) fn openai_messages(v: &Value) -> Result<(Vec, String)> { diff --git a/src/protocol/tests.rs b/src/protocol/tests.rs index 91c8e32..1ab6c68 100644 --- a/src/protocol/tests.rs +++ b/src/protocol/tests.rs @@ -84,6 +84,30 @@ fn basic_tool_conversation_both_directions() { )); } #[test] +fn parameterless_claude_calls_default_only_missing_input() { + let mut request = json!({"model":"m","max_tokens":100,"messages":[ + {"role":"user","content":"time"}, + {"role":"assistant","content":[{"type":"tool_use","id":"t","name":"time"}]}, + {"role":"user","content":[{"type":"tool_result","tool_use_id":"t","content":"noon"}]} + ]}); + let translated = req(C, &request).unwrap(); + let arguments = &translated["messages"][1]["tool_calls"][0]["function"]["arguments"]; + assert!(arguments.is_string()); + assert_eq!(arguments, "{}"); + assert_eq!(translated["messages"][2]["tool_call_id"], "t"); + for invalid in [Value::Null, json!(""), json!([]), json!(false)] { + request["messages"][1]["content"][0]["input"] = invalid; + assert!(req(C, &request).is_err()); + } + request["messages"][1]["content"][0]["input"] = json!({"city":"Paris"}); + assert_eq!( + req(C, &request).unwrap()["messages"][1]["tool_calls"][0]["function"]["arguments"], + "{\"city\":\"Paris\"}" + ); + request["messages"][2]["content"][0]["tool_use_id"] = json!("wrong"); + assert!(req(C, &request).is_err()); +} +#[test] fn nonstream_responses_and_tools() { let o = json!({"id":"r","object":"chat.completion","created":123,"model":"target","choices":[{"index":0,"message":{"role":"assistant","content":"hi"},"finish_reason":"stop"}],"usage":{"prompt_tokens":7,"completion_tokens":3,"total_tokens":10}}); let c = resp(O, &o).unwrap();