Skip to content

Fix Metric.isMetric runtime brand - #6822

Merged
fubhy merged 4 commits into
mainfrom
fix/metric-is-metric
Aug 1, 2026
Merged

Fix Metric.isMetric runtime brand#6822
fubhy merged 4 commits into
mainfrom
fix/metric-is-metric

Conversation

@fubhy

@fubhy fubhy commented Jul 31, 2026

Copy link
Copy Markdown
Member

Fixes Metric.isMetric to check the current internal Metric brand so constructed and transformed metrics are recognized.

Adds focused tests, a corrected JSDoc example, and a patch changeset.

Validation:

  • focused Metric tests
  • targeted Metric doctest
  • package-local docgen and check
  • pnpm lint-fix
  • git diff --check

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 31, 2026
@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eca831d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Jul 31, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • isMetric now checks the actual TypeId constant ("~effect/observability/Metric") instead of the stale string "~effect/Metric"
  • JSDoc example updated to show correct true/false results
  • Test suite added covering constructed metrics, transformed metrics (mapInput, withAttributes), and false-negatives including the old brand string
  • Patch changeset included

The fix is correct: Metric$ (line 1728) sets readonly [TypeId] = TypeId with TypeId = "~effect/observability/Metric" (line 1725), and all metric subclasses inherit this. The old "~effect/Metric" value was a leftover from a previous brand rename.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.31 KB 6.31 KB 0.00 KB (0.00%)
cache.ts 10.16 KB 10.16 KB 0.00 KB (0.00%)
config.ts 20.32 KB 20.32 KB 0.00 KB (0.00%)
differ.ts 19.93 KB 19.93 KB 0.00 KB (0.00%)
http-client.ts 21.02 KB 21.02 KB 0.00 KB (0.00%)
logger.ts 10.32 KB 10.32 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.33 KB 7.33 KB 0.00 KB (0.00%)
pubsub.ts 14.46 KB 14.46 KB 0.00 KB (0.00%)
queue.ts 11.13 KB 11.13 KB 0.00 KB (0.00%)
schedule.ts 10.31 KB 10.31 KB 0.00 KB (0.00%)
schema-class.ts 18.86 KB 18.86 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.67 KB 28.67 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 24.99 KB 24.99 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.99 KB 12.99 KB 0.00 KB (0.00%)
schema-string.ts 10.65 KB 10.65 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.85 KB 14.85 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.66 KB 21.66 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.08 KB 24.08 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.91 KB 18.91 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.59 KB 18.59 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.33 KB 22.33 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.25 KB 19.25 KB 0.00 KB (0.00%)
schema.ts 18.12 KB 18.12 KB 0.00 KB (0.00%)
stm.ts 12.11 KB 12.11 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Metric.isMetric to validate against the current internal Metric runtime brand so both newly constructed and transformed metrics are recognized correctly at runtime.

Changes:

  • Update Metric.isMetric implementation to check the current Metric brand (TypeId) instead of the legacy string key.
  • Add focused unit tests covering constructed metrics, transformed metrics, and non-metric values.
  • Add a patch changeset and simplify/correct the isMetric JSDoc example.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/effect/test/Metric.test.ts Adds coverage for Metric.isMetric across constructed/transformed/non-metric inputs.
packages/effect/src/Metric.ts Updates Metric.isMetric runtime brand check and adjusts the JSDoc example accordingly.
.changeset/fix-metric-is-metric.md Adds a patch changeset entry describing the runtime brand fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/effect/src/Metric.ts Outdated

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Fixed isMetric type predicate variance — changed from Metric<unknown, never> to Metric<never, unknown>, matching the Metric<in Input, out State> variance (Input contravariant → never; State covariant → unknown)

  • Added type-level regression test — verifies Metric.value(input) returns Effect<unknown> after narrowing through the guard

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes since the prior Pullfrog review at 04f645d:

  • Removed dedicated isMetric runtime tests — the it("isMetric") block in packages/effect/test/Metric.test.ts was dropped. The JSDoc doctest covering true for a real counter and false for a plain object remains as the test surface.
  • Removed type-level test filepackages/effect/typetest/Metric.tst.ts was deleted. The variance (Metric<never, unknown>) was already verified in the prior review and the fixed isMetric source code is unchanged.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@fubhy
fubhy merged commit 5441c8e into main Aug 1, 2026
19 checks passed
@fubhy
fubhy deleted the fix/metric-is-metric branch August 1, 2026 08:40
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Done in PR Backlog Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants