[BUG] Iterating a returned list of Protobuf messages throws outside the evaluation context
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đá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
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, nodejs, typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Start with the repro: run node repro.mjs and confirm the error is thrown at [...result], not during evaluation. The payload names ArrayList.values(), toCel(), getMsgDesc(), getEvalContext() and withEvalContext() as the path where the context is read after it has been cleared, so trace those. Done means the list from repositories iterates and prints 1 without the map(x, x) workaround, with the existing tests still passing.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Iterating an evaluation result containing Protobuf messages throws cannot use getEvalContext outside of an evaluation, even when the message schema is registered in the CEL environment.
This reproduces with @bufbuild/cel 0.6.2 using only public APIs and a standard Protobuf message, without application-specific code. The evaluation itself returns a list; the exception is thrown when the caller subsequently iterates it.
Steps to Reproduce
In an empty directory, install:
npm init -y
npm install --save-exact @bufbuild/[email protected] @bufbuild/[email protected]
Failing case
Save the following as repro.mjs, then run node repro.mjs. The exception is thrown at [...result], after evaluation has returned.
import { celEnv, plan, parse, isCelError } from '@bufbuild/cel';
import { create, createRegistry } from '@bufbuild/protobuf';
import { FileDescriptorProtoSchema } from '@bufbuild/protobuf/wkt';
const env = celEnv({ registry: createRegistry(FileDescriptorProtoSchema) });
const messages = [create(FileDescriptorProtoSchema, { name: 'example.proto' })];
const result = plan(env, parse('repositories'))({ repositories: messages });
if (isCelError(result)) throw result;
const values = [...result];
console.log(values.length);
Expected Behavior
The returned list can be iterated after evaluation, and the program prints 1.
Actual Behavior
Evaluation returns a list, but iterating it throws:
Error: cannot use `getEvalContext` outside of an evaluation
Passing case: identity-map workaround
Save this independent example as workaround.mjs and run node workaround.mjs. The only difference is the CEL expression: repositories.map(x, x) instead of repositories.
import { celEnv, plan, parse, isCelError } from '@bufbuild/cel';
import { create, createRegistry } from '@bufbuild/protobuf';
import { FileDescriptorProtoSchema } from '@bufbuild/protobuf/wkt';
const env = celEnv({ registry: createRegistry(FileDescriptorProtoSchema) });
const messages = [create(FileDescriptorProtoSchema, { name: 'example.proto' })];
const result = plan(env, parse('repositories.map(x, x)'))({ repositories: messages });
if (isCelError(result)) throw result;
const values = [...result];
console.log(values.length);
Output:
1
An identity map(x, x) should not be necessary to make the evaluation result iterable.
Environment
- @bufbuild/cel version: 0.6.2
- @bufbuild/protobuf version: 2.15.0
- @bufbuild/cel-spec version: not used
- Node.js version: v26.13.1
Possible Solution
From inspecting the implementation, the failure appears to involve deferred conversion and the evaluation context lifetime:
ArrayList.values()callstoCel(element)when an element is read.- For a Protobuf message,
toCel()callsreflect(getMsgDesc(v.$typeName), v). getMsgDesc()obtains the registry throughgetEvalContext().- By the time the caller reads the returned list,
withEvalContext()has already removed the context in itsfinallyblock.
It may be necessary to preserve the information needed for deferred conversion in returned values, or complete that conversion before leaving the evaluation context. I have not implemented or validated a library-level fix.
Workarounds
Both approaches below have been verified with the versions listed in Environment. They are caller-side workarounds, not a library-level fix.
1. Force conversion during evaluation with an identity map
The passing example above uses repositories.map(x, x). Reading each element during evaluation lets the library resolve its message descriptor while the evaluation context is active. This requires changing the CEL expression. For large lists, the separate performance issue in #343 is a concern.
2. Supply ReflectMessage values using the public reflect() API
Keep the original CEL expression and wrap each input message with its schema before evaluating. Save this independent example as reflect-workaround.mjs and run node reflect-workaround.mjs:
import { celEnv, plan, parse, isCelError } from '@bufbuild/cel';
import { create, createRegistry } from '@bufbuild/protobuf';
import { reflect } from '@bufbuild/protobuf/reflect';
import { FileDescriptorProtoSchema } from '@bufbuild/protobuf/wkt';
const env = celEnv({ registry: createRegistry(FileDescriptorProtoSchema) });
const message = create(FileDescriptorProtoSchema, { name: 'example.proto' });
const result = plan(env, parse('repositories'))({
repositories: [reflect(FileDescriptorProtoSchema, message)],
});
if (isCelError(result)) throw result;
const values = [...result];
console.log(JSON.stringify({ count: values.length, sameMessage: values[0].message === message }));
Output:
{"count":1,"sameMessage":true}
The values already carry their message descriptors, so reading this result after evaluation does not need to look them up through the evaluation context. The original Message is preserved, as the identity check demonstrates.
This avoids the added CEL identity map, but callers must have the appropriate schemas and prepare all relevant input messages, including those in nested input containers or intermediate bindings. Preparing those inputs also has a traversal/allocation cost. This example does not establish that every CEL input shape is covered, and I have not benchmarked the two approaches end to end.
- Ngôn ngữ chính
- TypeScript
- Star
- 43
- Fork
- 9
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bufbuild/cel-es
-
[BUG] uint / uint fails with "int overflow" when the quotient is >= 2^63Có thể đã có người làm @bardrop đã nhận 21 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] timestamp(int) treats its argument as milliseconds instead of secondsCó thể đã có người làm @bardrop đã nhận 21 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 56/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bufbuild/cel-es
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
makecindy/cindy#15342 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
kwitsch/claude-code-plugin-tooling#219 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
no-repo-link tool-submission
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100