Schema encoding can return an internal symbol across module copies

Đã đóng
#10,381 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #10382 của @schickling-assistant — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start with packages/effect/test/schema/HMR.test.ts and reproduce the two failing cases using separate imports after vi.resetModules(). Then read internal/schema/parser.ts and trace how missing, missingExit, and sameExit are compared by the parser and its consumers. Done means the regression tests return the original empty string and false across module copies; an open linked pull request is already addressing the issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Schema encoding can return an internal symbol across module copies

Reproduction

Reproduced on main at c0981a29044194e7e1ad35cb7aad02c5849d5aab. Two independently loaded Effect module graphs in the same realm can disagree about parser sentinels:

import { expect, it, vi } from "vitest"

it.each(["", false])("encodes %j across module copies", async (input) => {
  const A = await import("effect/Schema")
  vi.resetModules()
  const B = await import("effect/Schema")
  const schema = typeof input === "string" ? A.String : A.Boolean
  expect(B.encodeSync(schema)(input)).toBe(input)
})

Expected: "" and false, respectively. Actual: Symbol() in both cases. The equivalent regression added to packages/effect/test/schema/HMR.test.ts fails twice before the fix (the five existing tests pass).

This surfaced in LiveStore DevTools, where the application creates schemas and a separately bundled DevTools copy of Effect encodes them.

Root cause

internal/schema/parser.ts allocates module-local missing, missingExit, and sameExit. AST parser methods retain their creating module's sentinels, while SchemaParser and the interpreter/codegen consumers compare against their own sentinels by identity. An unrecognized foreign sameExit is treated as an ordinary success containing a foreign missing symbol, which escapes as the encoded value.

Sharing only missing is insufficient: sameExit is also identity-sensitive and means “return the original input,” not “return missing.” A namespaced same-realm global registry can share the exit objects as well as the missing symbol. This addresses copies implementing the shared protocol; it does not retrofit an already loaded unpatched copy or transfer identities across realms.

Related precedent: #1561 (CJS–ESM hazard).

Posted on behalf of @schickling
field value
agent_identity agent/livestore/owner
session 01a1f40c
agent_persona generalist
agent_supervisor unavailable
agent_tool OMP
agent_tool_version 18.12.5
agent_runtime OMP 18.12.5
agent_model anthropic/claude-opus-5-5
worktree unknown
Ngôn ngữ chính
TypeScript
Star
16.7k
Fork
808
Merge trung bình
12 giờ 17 phút
Pull request đã merge (30 ngày)
805

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Effect-TS/effect

Tất cả issue của Effect-TS/effect

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.