Skip to content

fix(telemetry): resolve enum values through nested schema wrappers - #2315

Merged
nattallius merged 1 commit into
ChromeDevTools:mainfrom
Liohtml:fix/metrics-enum-unwrap
Jul 9, 2026
Merged

fix(telemetry): resolve enum values through nested schema wrappers#2315
nattallius merged 1 commit into
ChromeDevTools:mainfrom
Liohtml:fix/metrics-enum-unwrap

Conversation

@Liohtml

@Liohtml Liohtml commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What

generateToolMetrics reads an enum parameter's values by unwrapping at most
one
optional wrapper:

if (schema._def.values?.length > 0) {
  values = schema._def.values;
} else {
  values = schema._def.innerType._def.values; // only one level
}

An enum parameter wrapped in .default().optional() (or any nested
optional/default/nullable combination) therefore falls through to
schema._def.innerType._def.values === undefined, and npm run update-metrics
(run as part of npm run gen) crashes:

TypeError: Cannot read properties of undefined (reading '0')
    at validateEnumHomogeneity (build/src/telemetry/metricsRegistry.js:12)
    at generateToolMetrics (build/src/telemetry/metricsRegistry.js:59)

Why it matters

npm run gen is required whenever a tool is added or changed (per
CONTRIBUTING.md). Declaring an enum parameter with a default — a natural,
documented zod pattern — silently breaks docs/metrics generation.

Fix

Add getEnumValues() in transformation.ts that recursively unwraps
optional / default / nullable / effects wrappers, mirroring the existing
getZodType(), and use it in generateToolMetrics. Behavior is unchanged for
the existing bare-enum and single-optional cases.

Tests

  • getEnumValues unit tests: bare enum, optional, default, both orders of
    default+optional, and throws for a non-enum type.
  • generateToolMetrics regression test with zod.enum(...).default(...).optional().
  • npm run typecheck, the telemetry tests, and npm run check-format pass.

First-time contributor here — happy to sign the CLA.

@google-cla

google-cla Bot commented Jul 7, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Liohtml
Liohtml force-pushed the fix/metrics-enum-unwrap branch from d565672 to 27082d6 Compare July 7, 2026 13:52
generateToolMetrics only unwrapped a single optional wrapper when reading an
enum parameter's values, so an enum wrapped in .default().optional() (or any
nested optional/default/nullable combination) fell through to
schema._def.innerType._def.values === undefined and crashed
`npm run update-metrics` (part of `npm run gen`) with
"Cannot read properties of undefined (reading '0')".

Add getEnumValues(), which recursively unwraps optional/default/nullable/effects
wrappers (mirroring getZodType), and use it in generateToolMetrics. Behavior is
unchanged for the existing bare-enum and single-optional cases.
@Liohtml
Liohtml force-pushed the fix/metrics-enum-unwrap branch from 27082d6 to 4289526 Compare July 8, 2026 05:52
@nattallius

Copy link
Copy Markdown
Contributor

LGTM, but @yulunz can you please check it as well?

@Liohtml

Liohtml commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look, @nattallius! Happy to address anything @yulunz flags — the change is small and isolated (a recursive enum-value unwrap in the telemetry helper) with unit + regression tests.

@yulunz
yulunz self-requested a review July 8, 2026 17:46

@yulunz yulunz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Liohtml looks great, thanks!

please wait for approval from @nattallius too

@yulunz
yulunz requested a review from nattallius July 8, 2026 17:47
@nattallius
nattallius added this pull request to the merge queue Jul 9, 2026
Merged via the queue into ChromeDevTools:main with commit c065fd9 Jul 9, 2026
27 of 29 checks passed
kku1993 pushed a commit to kku1993/chrome-devtools-mcp that referenced this pull request Jul 14, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.6.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.5.0...chrome-devtools-mcp-v1.6.0)
(2026-07-14)


### 🎉 Features

* add experimentalGcfFormat flag for GCF-encoded tool responses
([ChromeDevTools#2235](ChromeDevTools#2235))
([3d21389](ChromeDevTools@3d21389))
* Print object count and total sizes in get_heapsnapshot_details
([ChromeDevTools#2325](ChromeDevTools#2325))
([15a6b78](ChromeDevTools@15a6b78))
* support --allow-unrestricted-paths configuration
([ChromeDevTools#2296](ChromeDevTools#2296))
([6e56c02](ChromeDevTools@6e56c02))
* Support filter with heap snapshots aggregates
([ChromeDevTools#2323](ChromeDevTools#2323))
([2812902](ChromeDevTools@2812902))
* update Lighthouse to 13.4.0
([ChromeDevTools#2317](ChromeDevTools#2317))
([ffc6060](ChromeDevTools@ffc6060))


### 🛠️ Fixes

* enforce .gz instead of json.gz in performance tools
([ChromeDevTools#2305](ChromeDevTools#2305))
([b06e39b](ChromeDevTools@b06e39b))
* keep a still-open selected page instead of falling back to the first
page
([ChromeDevTools#2328](ChromeDevTools#2328))
([c645eee](ChromeDevTools@c645eee)),
closes
[ChromeDevTools#2304](ChromeDevTools#2304)
* keep page ids unique across browser reconnects
([ChromeDevTools#2345](ChromeDevTools#2345))
([3e8d922](ChromeDevTools@3e8d922))
* paginate page 0 in list_network_requests and list_console_messages
([ChromeDevTools#2359](ChromeDevTools#2359))
([d0025b3](ChromeDevTools@d0025b3))
* release held modifiers when press_key key event fails
([ChromeDevTools#2347](ChromeDevTools#2347))
([78ccb19](ChromeDevTools@78ccb19))
* report when the selected page was auto-replaced by the fallback
([ChromeDevTools#2308](ChromeDevTools#2308))
([2c16ac3](ChromeDevTools@2c16ac3)),
closes
[ChromeDevTools#2304](ChromeDevTools#2304)
* resolve page ids only among listed pages
([ChromeDevTools#2332](ChromeDevTools#2332))
([eb04951](ChromeDevTools@eb04951)),
closes
[ChromeDevTools#2304](ChromeDevTools#2304)
* **snapshot:** resolve element ids on the correct snapshot
([ChromeDevTools#2295](ChromeDevTools#2295))
([b703f2c](ChromeDevTools@b703f2c))
* **telemetry:** resolve enum values through nested schema wrappers
([ChromeDevTools#2315](ChromeDevTools#2315))
([c065fd9](ChromeDevTools@c065fd9))
* Wait until daemon is started
([ChromeDevTools#2327](ChromeDevTools#2327))
([ed7e95d](ChromeDevTools@ed7e95d))


### 📄 Documentation

* add Grok Build CLI configuration section
([ChromeDevTools#2294](ChromeDevTools#2294))
([aa4be07](ChromeDevTools@aa4be07))
* update memory leak debugging skill
([ChromeDevTools#2330](ChromeDevTools#2330))
([c1736a0](ChromeDevTools@c1736a0))


### ⚡ Performance

* concurrent I/O in Root Path Resolution
([ChromeDevTools#2279](ChromeDevTools#2279))
([b2c63e6](ChromeDevTools@b2c63e6))


### 🏗️ Refactor

* clean up McpContext getters
([ChromeDevTools#2340](ChromeDevTools#2340))
([5b33deb](ChromeDevTools@5b33deb))
* clean up more of the context interface
([ChromeDevTools#2335](ChromeDevTools#2335))
([9cd734b](ChromeDevTools@9cd734b))
* clean up page management
([ChromeDevTools#2333](ChromeDevTools#2333))
([16db01f](ChromeDevTools@16db01f))
* clean up page snapshot generation
([ChromeDevTools#2348](ChromeDevTools#2348))
([68cfce2](ChromeDevTools@68cfce2))
* make collectors work per page
([ChromeDevTools#2324](ChromeDevTools#2324))
([9bc61b4](ChromeDevTools@9bc61b4))
* move and rename files
([ChromeDevTools#2355](ChromeDevTools#2355))
([9c3542b](ChromeDevTools@9c3542b))
* move DevTools universe to McpPage
([ChromeDevTools#2341](ChromeDevTools#2341))
([c006c9b](ChromeDevTools@c006c9b))
* move remaining McpContext getters
([ChromeDevTools#2342](ChromeDevTools#2342))
([58ba174](ChromeDevTools@58ba174))
* remove isolated context getter
([ChromeDevTools#2336](ChromeDevTools#2336))
([8a4ddb3](ChromeDevTools@8a4ddb3))
* Use array instead of Map for idToClassKey
([ChromeDevTools#2321](ChromeDevTools#2321))
([ff53b7b](ChromeDevTools@ff53b7b))
* use helper for Dialog handle
([ChromeDevTools#2334](ChromeDevTools#2334))
([64005f9](ChromeDevTools@64005f9))
* use response page in formatting
([ChromeDevTools#2349](ChromeDevTools#2349))
([c53c1ec](ChromeDevTools@c53c1ec))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants