Skip to content

fix: plain input schemas for ui_snapshot and ui_action (closes #145) - #146

Merged
chaodu-agent merged 27 commits into
mainfrom
fix/tool-schema-no-anyof
Nov 19, 2026
Merged

chaodu-agent merged 27 commits into
mainfrom
fix/tool-schema-no-anyof

Conversation

@chaodu-agent

@chaodu-agent chaodu-agent commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #145

ui_snapshot and ui_action were the only tools whose inputSchema used anyOf inside a property, and they were the only two tools missing from Grok's tool list. Both properties are now a single plain string type. The runtime parsers are untouched.

Schema before / after

ui_snapshot.window

before: {"anyOf":[{"type":"string"},{"type":"integer","minimum":0}],"description":"Window title (exact, else case-insensitive substring) or index into the app's window list. Default: focused window."}
after:  {"type":"string","description":"Window title as a string (exact, else case-insensitive substring); a string is always read as a title, even when it looks like a number. Existing callers that send a native JSON integer ≥ 0 still select that index in the app's window list. Default: focused window."}

ui_action.value

before: {"anyOf":[{"type":"string","maxLength":N},{"type":"number"},{"type":"boolean"}],"description":"The new value; set_value only. Never logged or echoed."}
after:  {"type":"string","maxLength":N,"description":"The new value, passed as a string (for example '3' or 'true'); set_value only. Never logged or echoed. A string is set as is. Existing callers that send a native JSON number or boolean are still accepted and set as that number or boolean."}

Note: the runtime reads a string window as a title, never an index, so the description says that instead of "decimal index". A client that can only send strings cannot select a window by index. I did not change that behavior.

Rust daemon (poc/reverse-attach-linux)

No anyOf, oneOf, allOf, not or type arrays in its tool definitions. Nothing changed.

Tests

  • New ToolSchemaShapeTests: walks every ToolCatalog.local inputSchema and fails on anyOf/oneOf/allOf/not or a type array, and requires a single string type on every top-level property. Browser tools come from the upstream Playwright server and are not in the catalog.
  • Parser tests: window as string title and as integer index; value as string, number and bool.
  • Run: swift build and swift test on macOS 27.2.1 and macOS 26.4.1 (clones under /private/tmp): 733 tests, 0 failures on both.
  • With anyOf put back in a remote copy, the walker failed on ui_snapshot.properties.window.anyOf.
  • scripts/check-no-private-identifiers.sh: ok. markdownlint-cli2 with the repo config on docs/ui-tools.md: 0 errors.
  • docs/tool-profiles.md does not describe the schema; only docs/ui-tools.md was updated.

Review fixes (final report issues 1 to 10; gate findings)

  • Window (issue 2). The contract is title-only. I did not add a window_index field: documenting title-only is the smaller change, and it adds no parameter, parse path or error. Native JSON integers in window still select an index for existing callers. Strict clients cannot pick an untitled or duplicate-title window by index. docs/ui-tools.md says so.
  • Value type (issue 1). A string refused with AX error -25201 is retried once as the native number or boolean it spells. The no-native-form message names the type mismatch and says to take a new ui_snapshot. It no longer advises a JSON number.
  • Upstream schemas (issue 3). The pinned @playwright/mcp 0.0.82 tools/list (32 tools) was recorded from a fresh stdio process with the app's flags. The running service was not queried. The recording is Tests/Fixtures/playwright-mcp-0.0.82-tools-list.json. One tool failed: browser_emulate_media used anyOf: [enum string, null] in five properties. Those five are now plain enum strings in UpstreamTool. Clients can no longer send null to clear colorScheme, reducedMotion, forcedColors, contrast or media. Omitting a field still leaves it unchanged. The other 31 tools are forwarded unchanged.
  • Rust (issue 4). Guard tests cover the owner and observe tool lists and the job tools. The arm64 Linux test host ran cargo test twice: 383 and 384 passed, with one or two failures. The consistent failure is proc::tests::a_pid_that_does_not_exist_signals_nothing_and_does_not_panic, which also fails at a95874b. install::tests::from_dir_update_also_uses_no_network failed once and passed on rerun. Both are outside this PR's change.
  • Swift. swift test on the macOS test host: 754 executed, 5 skipped, 0 failures.

ui_snapshot.window and ui_action.value used anyOf, which some MCP clients
(Grok connector) reject, dropping both tools from their list. Both are
now a single {"type":"string"}; the descriptions tell clients to send
strings. The runtime parsers are unchanged and still accept a native
integer window index and a native number/bool value for existing callers.

Adds ToolSchemaShapeTests: walks every ToolCatalog.local inputSchema and
fails on anyOf/oneOf/allOf/not or a type array; plus parser tests for the
old argument shapes.

Verified: swift test on macOS 26 and macOS 27 hosts, clones under
/private/tmp, 733 tests, 0 failures on both. The walker fails when anyOf
is put back (remote copy only). check-no-private-identifiers.sh ok;
markdownlint-cli2 on docs/ui-tools.md: 0 errors.
@chaodu-agent
chaodu-agent force-pushed the fix/tool-schema-no-anyof branch from 59689e0 to a95874b Compare November 17, 2026 17:32
@chaodu-agent

This comment has been minimized.

Review fixes for PR #146, final report issues 1, 2, 5, 6 and 10.

Issue 1: a string set_value that a numeric or boolean control refuses with
kAXErrorIllegalArgument (-25201) is written again as the native value the
string spells ("3" becomes 3, "true" becomes true). A refused write changes
nothing, so the second write is safe. If the retry also fails, or the string
has no native form, the error names the type mismatch and the retry that
works. -25201 on set_value no longer reaches the "does not support set_value"
message. Focus keeps its previous path.

Issue 2 (choice): ui_snapshot gets a flat `window_index` integer, minimum 0.
Reason: a string encoding of an index needs a parsing rule a strict client
cannot check, while an integer property is valid under the plain-type schema.
Native JSON integers in `window` still select an index for existing callers.
Sending both `window` and `window_index` is invalid params. The window index
error now points at window_index.

Issues 5 and 6: the ui_snapshot tool description and the window and value
property descriptions state only what a model can send. The compatibility
sentences moved out of the descriptions.

Issue 10: the parse sites for window and value carry comments naming #145 and
the intentional asymmetry with the schema. docs/ui-tools.md documents
window_index.

Commands (one run at the series head, macOS test host, copy of the worktree
without .agents, .git, .build): swift test
Suites touched: UIActionToolTests 44 passed; UISnapshotToolTests 11 passed.
Failures: 0. Full run: 751 executed, 0 failures, 5 skipped (default-port
launch test skipped while the installed agent holds 8795; real Playwright
install gated by OAB_REAL_INSTALL; two snapshot renders gated by
OAB_SNAPSHOT_DIR; one release-binary check).
…yword, and nested types

Review fixes for PR #146, final report issues 3, 7, 8 and 9.

Issue 7: $ref, $defs and definitions join anyOf, oneOf, allOf and not as
banned keywords. Array-valued type stays banned.

Issue 8: one test per banned keyword (seven tests), plus a test that the
banned set is exactly those seven. Deleting any entry fails its own test.

Issue 9: the plain-type check is recursive. Every schema position (root,
properties values, items in object or tuple form, additionalProperties
schema) must carry one plain string type. The walk enters only schema
positions. Data keywords (default, enum, const, examples) are not inspected,
and a property named like a keyword is a name, not a keyword. A boolean
additionalProperties is not a schema.

Issue 3: UpstreamTool forwards each Playwright inputSchema unchanged, so the
guard runs over eight browser_* descriptors written as fixtures in the shape
the Playwright MCP server publishes. A fixture with anyOf is shown to be
caught. The live upstream tools/list was not queried: no local Playwright
server was contacted for this change.

The first run failed one fixture that also lacked `type`, which the walker
correctly reported. The fixture now carries `type: string`, and the rerun is
clean.

Commands (one run at the series head, macOS test host, copy of the worktree
without .agents, .git, .build): swift test
Suite touched: ToolSchemaShapeTests 19 passed, 0 failures. Full run: 751
executed, 0 failures, 5 skipped (same skips as the previous commit).
Review fix for PR #146, final report issue 4. Adds
tool_schema_shape_tests.rs, which applies the same rules as the Swift
ToolSchemaShapeTests to every tool list the daemon builds:

- tool_list_with for the owner and observe profiles (local tools and job
  tools, no upstreams), and jobs::tools::tool_specs on its own.
- The banned keywords (one test per keyword), array-valued type, a plain
  string type at every schema position, boolean additionalProperties, data
  payloads, and property names that look like keywords.

Upstream schemas are not in these lists; the Swift test covers them. The live
upstream tools/list was not queried.

Commands (one run at the series head, arm64 Linux test host, copy of the
whole worktree without .agents, .git, .build, target, because the crate
include_str!s conformance/ and release/ from the repo root): cargo test
(from poc/reverse-attach-linux, toolchain 1.96.0).
Result: 384 passed, 1 failed, 10 ignored. The 16 new tests in
tool_schema_shape_tests all pass. Failure: proc::tests::
a_pid_that_does_not_exist_signals_nothing_and_does_not_panic, which hits a
rustix debug assertion on kill_pid_checked(u32::MAX). It fails identically at
a95874b (the base of this PR), and this change does not touch proc.rs.
Review fix for PR #146, final report issue 2 (gate finding: window index choice).

Choice: document a title-only contract instead of adding a window_index
integer. Reason: it is the smaller change under the brief. It adds no
parameter, no mutual-exclusion rule and no error path, and the schema stays a
single string. Native JSON integers in `window` still select an index for
existing callers, so nothing that worked before is removed.

Cost, stated in docs/ui-tools.md: strict clients cannot pick an untitled or
duplicate-title window by index. They must use the title.

The ui_snapshot tool description, the window property and the window error
text name only the title. The parse-site comment (#145) is unchanged.

Commands (one run at the series head, macOS test host, scratch copy of the
worktree without .agents, .git, .build): swift test
Result: 751 executed, 5 skipped, 0 failures (full run; the default output
prints no per-suite counts). ToolSchemaShapeTests includes
testSnapshotWindowSchemaIsTitleOnly, which replaces the window_index test.
Review fix for PR #146, final report issues 1 and 6 (gate finding: the
value-type error asks for a native number).

UIActionTool.Errors.valueTypeRejected, for a string with no number or boolean
form, no longer tells the model to send a JSON number or boolean. Strict
clients cannot send one, so that advice named a form the schema forbids. The
message now names the type mismatch (AX error -25201) and the next step: take
a new ui_snapshot to check the control's value type, then send a value of that
type. The retry path message is unchanged.

UIActionTests asserts the exact no-native-form text and that it does not
mention JSON.

The compatibility comment at the value parse site (#145) is unchanged.

Commands (one run at the series head, macOS test host, scratch copy of the
worktree without .agents, .git, .build): swift test
Result: 751 executed, 5 skipped, 0 failures (full run; the default output
prints no per-suite counts).
…ream tools

Review fix for PR #146, final report issue 3 (gate finding: upstream Playwright
schemas are hand-written). Owner chose option B.

Recorded evidence: the pinned @playwright/mcp 0.0.82 tools/list, taken from a
fresh stdio process with the app's flags (--browser chromium
--shared-browser-context --caps vision,pdf --headless). It lists 32 tools. The
running service on the browser port was not queried. The recording is
Tests/Fixtures/playwright-mcp-0.0.82-tools-list.json.

Finding: browser_emulate_media uses anyOf [enum string, {type: null}] in five
properties (colorScheme, reducedMotion, forcedColors, contrast, media). The
other 31 tools were clean.

Change: UpstreamTool.forwardedSchema keeps only the string branch for those
five properties and drops the null branch. Clients can no longer send null to
clear those overrides; omitting a field still leaves it unchanged. Every other
upstream schema is forwarded unchanged.

Tests: testRecordedPlaywrightToolsAreAllPlainAfterForwarding (32 tools pass the
guard), testEmulateMediaOverridesAreForwardedAsPlainEnums (pins the five enums
and descriptions), testOtherRecordedPlaywrightToolsAreForwardedUnchanged.

Commands (one run at the series head, macOS test host, scratch copy of the
worktree without .agents, .git, .build): swift test
Result: 754 executed, 5 skipped, 0 failures (full run; previously 751, plus the
three new tests). Rust is not touched by this commit; the Rust results are in
the PR notes.
@chaodu-agent

This comment has been minimized.

…list path

tools/list served the raw upstream descriptor on three Swift paths (UpstreamTool.descriptor, the browser router's tools(), and the Playwright backend list it wraps) and on the Linux daemon (upstream_tools_for_with). The inputSchema getter was rewritten, but the wire was not, so browser_emulate_media still carried anyOf with a null branch on five properties.

Fix: UpstreamTool.forwardedDescriptor applies forwardedSchema to the descriptor; UpstreamTool.descriptor and BrowserRouter.tools use it. On Linux, forwarded_descriptor applies the same rule in upstream_tools_for_with, so every tool list built from upstreams is covered. tool_schema_shape_tests.rs is rustfmt-clean (the file was failing cargo fmt --check).

New tests (each calls the real tools/list handler on its platform and fails on the unfixed code):
- Swift ToolSchemaShapeTests.testServedToolsListCarriesOptionBForUpstreamEmulateMedia: MCPServer.handle with an UpstreamMCP to a fake upstream serving the recorded 32-tool fixture.
- Swift ToolSchemaShapeTests.testServedToolsListCarriesOptionBForBrowserRouterEmulateMedia: MCPServer.handle with a BrowserRouter over a Playwright backend serving the recorded list.
- Rust tool_schema_shape_tests::served_owner_list_carries_option_b_for_upstream_emulate_media: tool_list_with(owner) over the recorded list.

Before the fix: both Swift tests failed (24 assertion failures, browser_emulate_media anyOf on all five properties); the Rust test failed with the served anyOf in the output.
After the fix, on the Apple build host, swift test: 756 executed, 5 skipped, 0 failures (ToolSchemaShapeTests: 24 executed, 0 failures). Command: swift test in a copy of the worktree (Package.swift at the root).
After the fix, on the Linux build host, cargo test served_owner_list: 1 passed. cargo test tool_schema_shape: 17 passed. cargo test (full): 385 passed, 1 failed, 10 ignored; the failure is proc::tests::a_pid_that_does_not_exist_signals_nothing_and_does_not_panic, which the branch history already records as failing at a95874b and which this change does not touch. rustfmt --check: tool_schema_shape_tests.rs and mcp.rs clean. main.rs still has pre-existing fmt diffs, not changed here.
The Linux shape guard checked the owner list only for browser_emulate_media. The other
forwarded upstream tools were never run through assert_tool_passes, so an anyOf, oneOf,
allOf, $ref, $defs, definitions or array-valued type on any of them would pass.

New test every_served_owner_tool_obeys_the_schema_rules_with_recorded_upstream walks every
tool that tool_list_with("owner") returns over the recorded 32-tool upstream fixture, and
asserts each recorded upstream name is served. The existing option B test is unchanged.

Verification, Linux build host, cargo test tool_schema_shape_tests:
- base 07647ad with this file: 16 passed, 2 failed.
  every_served_owner_tool...: browser_emulate_media, anyOf on colorScheme, contrast,
  forcedColors, media, reducedMotion (plus "no single string type" on those nodes).
  served_owner_list_carries_option_b...: same tool, anyOf in the served schema.
- HEAD dc7786e with this file: 18 passed, 0 failed.
- rustfmt --check on this file: clean.
The window-not-found error listed window indexes as [n], which strict
clients cannot send. The error now tells the caller to match the window
by its title and lists the titles without indexes. docs/ui-tools.md
states that windows are matched by title only, and the long paragraph
is rewrapped.

Checks (remote Swift verification copy in /private/tmp/schema-anyof-verify):
- swift build: Build complete, exit 0
- swift test: Executed 757 tests, 5 skipped, 0 failures (0 unexpected)
- New test testWindowNotFoundErrorIsTitleOnly passes; testWindowSelection
  pins the new exact error text.
…ror to schema

valueTypeRejected now names the `value` property, the key the request
used. The value parse error lists only the type the ui_action schema
declares for `value` (string), not number or boolean. The parser still
accepts a native number or boolean for existing callers, so that error
only fires for arrays, objects and non-finite numbers.

Tests: new testValueTypeRejectedNamesTheValueField and
testValueParseErrorNamesOnlyTheSchemaType; testValueTypeRefusedInBothFormsSaysSo
and testInvalidParams updated to the new wording.

Verification: swift build exit 0; swift test (full suite) exit 0,
Executed 759 tests, 5 skipped, 0 failures, run over ssh on the verification
host in a copy of the worktree.
Apply cargo fmt to poc/reverse-attach-linux/src/main.rs. The only change moves
the `#[cfg(test)] mod tool_schema_shape_tests;` declaration above `mod tools;`
into rustfmt's sorted module order. No code changes.

Toolchain: stable, rustc 1.98.1 / rustfmt 1.9.0-stable (CI uses dtolnay/rust-toolchain@stable, no pin in repo).
cargo fmt --check before: exit 1 (main.rs:49 and main.rs:55 diffs).
cargo fmt --check after: exit 0.
… description

Tests only. No production code changes in this commit.

Schema behavior chosen for finding 1: refuse. A forwarded schema that still
carries a banned construct after option B is hidden from tools/list, and a
call to it is not routed upstream. The fix commit logs the tool name.

New or changed tests (expected to fail on faa323b; read from the code, not run):
- Tests/InstanceMCPCoreTests/ToolSchemaShapeTests.swift
  testServedToolsListHidesUpstreamToolsWithBannedSchemas (finding 1)
  testUpstreamToolWithBannedSchemaIsNotCalled (finding 1)
  testBrowserRouterHidesToolWithBannedSchema (finding 1)
  testBrowserRouterRefusesCallToToolWithBannedSchema (finding 1)
  testForwardedEmulateMediaDescriptionDoesNotMentionNull (finding 2)
  assertServedOptionB also checks the served description has no null (finding 2)
- Tests/InstanceMCPCoreTests/UIActionTests.swift
  testValueTypeRefusedForNativeNumberSaysTheControlRefusesNumbers (finding 3)
  testValueTypeRefusedForNativeBoolSaysTheControlRefusesBooleans (finding 3)
  testValueTypeRefusedForNativeNumber... string-case expectation rewritten (finding 3, wording)
  testValueParseErrorNamesTheAcceptedTypes (renamed from testValueParseErrorNamesOnlyTheSchemaType; wording)
- poc/reverse-attach-linux/src/tool_schema_shape_tests.rs
  served_owner_list_hides_upstream_tools_with_banned_schemas (finding 1)
  forwarded_upstream_list_refuses_banned_tools_and_keeps_recorded_tools (finding 3)
  upstream_does_not_own_a_call_to_a_banned_schema_tool (finding 1)
  served_owner_list_carries_option_b_for_upstream_emulate_media now checks the description (finding 2)

Not verified: nothing was compiled or run on the laptop. Swift and Rust suites
have not been run against this commit.
…es; fix value-type and emulate wording

Schema behavior chosen for finding 1: refuse, not normalize. A forwarded upstream
tool whose inputSchema still has a banned keyword (anyOf, oneOf, allOf, not, $ref,
$defs, definitions) or a non-plain type after option B is hidden from tools/list
and its call is not routed upstream. The refusal is logged with the tool name and
the first offending path. Option B stays limited to browser_emulate_media. The
other pinned upstream tools already pass, so their served output is unchanged.
Refusal applies on the Swift UpstreamMCP and browser router paths and in the
Linux upstream_tools_for_with and upstream_owning_with paths.

Shape rules now live in one place per platform: ToolSchemaShape.swift and
src/schema_shape.rs. The test helpers forward to them.

Finding 2: browser_emulate_media's served description drops the sentence about
null (option B removed the null branch), on both platforms.

Finding 3 (wording): valueTypeRejected takes the sent value. A string with no
native form keeps the "no number or boolean form" text, without advice to send a
number or boolean. A native number or boolean gets a message that the control
does not accept that type. The retried text is unchanged.

Finding 4 (wording): "value must be a string, number or boolean" replaces
"value must be a string", matching what the parser accepts. docs/ui-tools.md
splits the window contract (title-only for strict clients, native integer still
an index) and documents the one string-to-native retry in set_value.

Tests for these changes were added in the preceding commit (HEAD~1). Not run:
nothing was compiled or tested on the laptop, and cargo fmt --check was not run
here. The Swift and Rust suites, and rustfmt, must run remotely before merge.
Not fixed: the prefixed-name keying of option B (Sol LOW 6, latent, production
uses an empty prefix), extending the banned keyword list (Sol NIT 8), and the
window -1 message (Sol NIT 7, Opus NIT 4; reviewers accepted it).
# Conflicts:
#	poc/reverse-attach-linux/src/main.rs
Ran: cargo fmt --check in poc/reverse-attach-linux, passes after this commit.
@chaodu-agent

This comment has been minimized.

…s at call

F1 (review of PR #146): browser_emulate_media was matched on the prefixed
name, so an upstream with a non-empty prefix kept its anyOf schema. The
upstream tools() now forwards each descriptor on the upstream's own name
and adds the prefix afterwards.

F2: the served schema dropped null but tools/call still forwarded it. An
explicit null for colorScheme, reducedMotion, forcedColors, contrast or
media is now refused at the call on three paths: UpstreamMCP.call (Swift),
BrowserRouter.call (Swift), and handle_tool_call_with (Linux). The reason
names the key, never the value. No existing test sent null, so the
refusal is kept rather than documented as advertised-only.

Tests added or changed:
- ToolSchemaShapeTests: testServedToolsListCarriesOptionBUnderAPrefix (F1),
  testNullEmulateMediaOverrideIsRefusedOnTheBrowserRouter (F2)
- UpstreamMCPTests: testNullEmulateMediaOverrideIsRefusedBeforeTheUpstreamSeesIt (F2, prefixed name)
- tool_schema_shape_tests.rs: emulate_media_null_override_is_refused_before_the_upstream_call,
  emulate_media_enum_value_still_reaches_the_upstream (F2)

No test was run on this laptop; Swift and Rust verification runs on the other hosts.
…t and Rust

Both walkers recursed only through properties, items and
additionalProperties. They now also enter patternProperties,
dependentSchemas, prefixItems, propertyNames, contains, if, then and else,
so a banned keyword or a missing single string type under any of them is
reported. The non-object root rule was already "is not an object schema"
on both sides; a Swift test now pins it too. The Playwright fixture
still passes: its only propertyNames entry has a plain type.

Tests added:
- ToolSchemaShapeTests: testWalksPropertyNames, testWalksPatternProperties,
  testWalksDependentSchemas, testWalksPrefixItems, testWalksContains,
  testWalksIfThenElse, testNonObjectRootIsRefused
- tool_schema_shape_tests.rs: walks_property_names_and_pattern_properties,
  walks_dependent_schemas_prefix_items_and_contains, walks_if_then_and_else

No test was run on this laptop; Swift and Rust verification runs on the other hosts.
…retry match

The -25201 message stated a cause as fact. kAXErrorIllegalArgument is a
generic error, so the text now names the likely cause ("The likely cause
is a value type this control does not take"). A native JSON number or
boolean gets the generic wording, because the input category alone does
not say what the control accepts. Text keeps its "no number or boolean
form" line, which is true for the strings it is checked against.

nativeValue trims surrounding whitespace before matching, so " 3 " and
"true\n" retry as native values. Exact-match documentation is not used.
docs/ui-tools.md says so.

Tests changed or added:
- UIActionTests: testValueTypeRejectedForText exact text (hello case),
  testValueTypeRefusedForNativeNumberGivesTheGenericMessage (renamed),
  testValueTypeRefusedForNativeBoolGivesTheGenericMessage (renamed),
  testPaddedNumberStringIsRetriedAsNumber, testNativeFormIgnoresSurroundingWhitespaceOnly

No test was run on this laptop; Swift verification runs on the other hosts.
…s/list fixture

Documents the exact capture: the pinned package from
release/playwright-pins, npm ci with the same flags as the pins smoke
check, the stdio launch flags named in the fixture's source field, the
three JSON-RPC messages, the output path and shape, and the 32-tool count
the suites expect. A Node capture script is included.

No test was run on this laptop, and the capture procedure was not run
here either.
Review B2 on the F5 README: step 2 claimed to be the install that
scripts/playwright-pins.py uses, but the command omitted --userconfig,
--globalconfig, --cache and HOME. A developer's ~/.npmrc could change the
resolved tree, so a re-recorded fixture would not reproduce from the steps.
The command now sets empty user and global npmrc files, a scratch cache, and
HOME to the scratch directory, matching the smoke check.

Tests: none added or changed (documentation only). No test was run on this
laptop; Swift and Rust suites run on the test hosts for the pushed head.
CI run 44520868459 on 47ff103 failed both "Linux hands node" format jobs
(amd64 and arm64) at `cargo fmt --check`. Two hunks in
tool_schema_shape_tests.rs were not wrapped as rustfmt wants: the
"has no single string type" format! call (around line 187) and the
upstream.calls assert_eq! in the emulate_media null refusal test (around
line 481). The change is line wrapping only; no assertion changed.

Tests: no test added or changed. No cargo or rustfmt run on this laptop;
the formatting was applied by hand from the CI diff. The Rust suite and
cargo fmt --check run on the test host for the new head.
On the F1/F2 branch, refused_upstream_tool() calls Managed::tools() on the
call path (mcp.rs upstream_owning_with). With no cached list, tools() starts
the child, so a call to a down browser backend makes that start attempt and
then the real call hits the backoff window. Behavior change: a call to a down
browser backend now returns class "backoff" on the first call, not
"start_failed". Each routed call while the backend is down makes one start
attempt for the listing. Chosen by the parent (option A): keep the banned-
schema refusal on the call path and change this assertion.

Tests: changed backend::tests::a_down_backend_answers_with_its_class_not_unknown_tool
(expects backoff). main passes this test with start_failed, which is the
behavior this commit changes. No cargo or test run on this laptop; the Linux
suite runs on the test host for the pushed head.
@chaodu-agent

This comment has been minimized.

- Linux: decide call-path schema refusal from Upstream::cached_tools,
  never a new tools/list; a down backend answers with start_failed again
- refuse an explicit null for any browser_emulate_media argument
- collapse an anyOf only when every non-string branch is {type: null}
- walk dependencies, additionalItems, unevaluated*, contentSchema, and
  fail closed on any keyword outside the known vocabulary (Swift + Rust)
@chaodu-agent

This comment has been minimized.

Round-5 F1. Both guards say they reject reference keywords but listed
$dynamicRef and $recursiveRef as known (allowed). Move them to the banned
set on the Swift and Rust sides and add one test per side. The anchor
keywords stay allowed.
The exact-set tests on both sides still listed seven keywords, which
failed Linux hands node on 23a9db1. List nine, add per-keyword ban tests
in the existing style, and keep a separate test that the anchors pass.
@chaodu-agent

Copy link
Copy Markdown
Contributor Author

Note

LGTM ✅ - The round-5 item is fixed: both schema guards now ban $dynamicRef and $recursiveRef, with tests on both sides. All findings from rounds 1-5 are resolved, and full CI is green on 22ee32b.

What This PR Does

ui_snapshot and ui_action were left out of Grok's tool list because their input schemas used anyOf inside a property (#145). This PR flattens those properties to plain strings. It also flattens the anyOf: [enum string, null] overrides in the upstream browser_emulate_media tool. Guards on both the Swift app and the Linux daemon refuse any served schema that uses unions, negation, references or type arrays.

How It Works

  • ui_snapshot.window and ui_action.value are advertised as plain strings. The runtime still accepts the native integer, number or boolean forms from existing callers. A string refused with AX error -25201 is retried once as the native number or boolean it spells.
  • browser_emulate_media: only an anyOf made of exactly one string branch plus {type: null} branches is collapsed. Any other union is left alone, so the guard hides the tool and logs why. An explicit null for any argument is refused at call time.
  • ToolSchemaShape (Swift) and schema_shape.rs (Rust) walk every schema position, ban anyOf, oneOf, allOf, not, $ref, $dynamicRef, $recursiveRef, $defs and definitions, and fail closed on keywords they do not recognize.
  • On the Linux daemon, the call-path refusal check reads Upstream::cached_tools and does not issue its own tools/list.

Findings

# Severity Finding Location
1 🟢 Round-5 F1 fixed: $dynamicRef and $recursiveRef moved from the known set to the banned set on both sides. The exact-set tests list nine keywords, each has its own ban test, and a separate test checks that $dynamicAnchor and $recursiveAnchor still pass ToolSchemaShape.swift:10-11, schema_shape.rs:10-20, ToolSchemaShapeTests.swift, tool_schema_shape_tests.rs
2 🟢 Round-4 F1-F4 remain fixed: cached call-path check, narrow [string, null...] collapse, null refusal for every argument, and fail-closed walkers mcp.rs, UpstreamMCP.swift, ToolSchemaShape.swift, schema_shape.rs
3 🟢 Full CI is green on 22ee32b: Swift build and test, Linux hands node (amd64 and arm64), installer units, markdown lint, private-identifier check, and Playwright pin and loopback checks CI
Finding Details

🟢 F1: Reference keywords are banned consistently

Round 5 found that both guards said they reject reference keywords but accepted $dynamicRef and $recursiveRef. Commit 23a9db1 moves them to the banned set. On that commit, banned_set_is_exactly_the_seven_keywords failed on Linux hands node because it still listed seven keywords. Commit 22ee32b updates the exact-set tests on both sides to nine keywords and adds per-keyword ban tests in the existing style (bans! in Rust, testBans* in Swift).

The amd64 run on 23a9db1 also failed install::tests::leftover_marked_staging_is_swept_and_a_lookalike_is_not. That test is outside this change and passed on the rerun at 22ee32b, so it looks flaky. It is noted here and not counted as a finding.

🟢 F2: Context on routing, not a finding

External uses the default Upstream::owns, which calls tools(). Routing a call to an external backend can therefore refresh the tool list once its TTL expires. main already behaves this way (backend.rs:55-59, mcp.rs:204), so it is out of scope for this PR. Only the extra listing this PR had added was in scope, and round 5 confirmed it was removed. If the routing refresh matters, track it in a separate issue.

Review History
Round Head Outcome
1 a95874b Value-type and window-index gaps under the flat schema
2 07647ad browser_emulate_media rewrite did not reach tools/list; cargo fmt --check red
3 faa323b Both blockers fixed; five smaller items
4 d25cdfb Five items fixed; live tools() fetch on call path, null-refusal drift, branch dropping, walker gaps
5 1b90b8b Round-4 items fixed; $dynamicRef / $recursiveRef not banned
6 22ee32b Round-5 item fixed; no open findings

No inline review comments or external review threads exist on this PR, so there is nothing to resolve.

Baseline Check
  • PR opened: 2026-11-17
  • Head: 22ee32b1f6ec86dd9855cba46e8530bb87449305; base main; merge-base 4a2f4ce2b5de7bd6ee002c9b9d2a43e7d20e4a87
  • Since round 5 (1b90b8b..22ee32b): 2 commits, 4 files (the two guards and their tests)
  • Main already has: the Rust daemon, External::tools() with a TTL cache, and the default Upstream::owns that calls tools()
  • Net-new value: plain schemas for ui_snapshot and ui_action, the browser_emulate_media rewrite and call-time null refusal, and the schema guards plus tests on Swift and Rust
What's Good (🟢)
  • Every finding from rounds 1-5 is covered by a test on both platforms.
  • The Swift and Rust guards use the same keyword sets, and their doc comments match the code.
  • The recorded @playwright/mcp 0.0.82 tools/list fixture keeps the upstream check offline and reproducible.

5. Three Reasons We Might Not Need This PR

  1. Scope grew far past the bug - ui_snapshot and ui_action input schemas use anyOf and are dropped by some MCP clients (Grok) #145 needed two property schemas flattened. The PR is now about +3000 lines, mostly guards, fixtures and tests that must be kept in sync across Swift and Rust.
  2. Client-side problem - the root cause is strict clients dropping valid JSON Schema. A fix in the client, or a documented compatibility profile, could avoid narrowing our schemas.
  3. Behavior given up - clients can no longer send null to clear browser_emulate_media overrides, and strict clients cannot pick a window by index. Both are documented trade-offs, but they are losses.

@chaodu-agent
chaodu-agent merged commit 3f6afbe into main Nov 19, 2026
15 checks passed
chaodu-agent added a commit that referenced this pull request Nov 20, 2026
Follow-up to the merge of #146 at 3f6afbe. Both council reviewers approved 1594e56; CI green on that head.

- run_smoke pins check parses the npm ci call with ast and requires --userconfig, --globalconfig, --ignore-scripts and --cache on that call, with tests that fail when any one is removed.
- README pins step documents the isolated npm settings.
- Test-record and CI gaps from #146 addressed.

Open LOW carry-overs are tracked for follow-up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui_snapshot and ui_action input schemas use anyOf and are dropped by some MCP clients (Grok)

1 participant