Skip to content

Commit 9d9fca0

Browse files
rustyconoverclaude
andcommitted
Scalar BindParameters see the transaction plaintext, as table functions do
Over signed HTTP the worker opens transaction_opaque_data for the catalog's commit/rollback callbacks and, since cf1a06e, for table-function params; a scalar's BindParameters.transaction_opaque_data was still the sealed envelope, so a scalar could not tie its work to the transaction the catalog later commits. Worker.bind now passes the opened plaintext to ScalarFunctionGenerator.bind too; the raw bind_call keeps its sealed wire value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 54ec312 commit 9d9fca0

3 files changed

Lines changed: 88 additions & 3 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2025, 2026 Query Farm LLC - https://query.farm
2+
3+
"""Scalar functions see the provider's transaction plaintext over signed HTTP.
4+
5+
The worker opens transaction_opaque_data for the catalog's commit/rollback
6+
callbacks and (since cf1a06e) for table-function params. Scalar
7+
BindParameters still carried the sealed envelope, so a scalar could not tie
8+
its work to the transaction the catalog later commits. Like table functions,
9+
the raw ``bind_call`` keeps the sealed wire value.
10+
"""
11+
12+
from __future__ import annotations
13+
14+
from typing import Any
15+
16+
import pyarrow as pa
17+
import pytest
18+
from vgi_rpc.http._testing import _SyncTestClient
19+
20+
from vgi._test_fixtures.scalar.arithmetic import DoubleFunction
21+
from vgi._test_fixtures.worker import ExampleCatalog, ExampleWorker
22+
from vgi.catalog.catalog_interface import AttachOpaqueData
23+
from vgi.client import Client
24+
from vgi.serve import create_app
25+
26+
_KEY = b"scalar-transaction-plaintext-test-key"
27+
28+
29+
def _client(app: Any, attach: bytes | None = None) -> Client:
30+
return Client.from_http(
31+
"http://vgi.test", httpx_client=_SyncTestClient(app), attach_opaque_data=attach, worker_limit=1
32+
)
33+
34+
35+
def test_scalar_bind_sees_transaction_plaintext(monkeypatch: pytest.MonkeyPatch) -> None:
36+
"""A scalar bound inside a signed-HTTP transaction sees the plaintext the catalog minted."""
37+
minted: list[bytes] = []
38+
seen: list[bytes | None] = []
39+
original_begin = ExampleCatalog.catalog_transaction_begin
40+
original_bind = DoubleFunction.on_bind.__func__ # type: ignore[attr-defined]
41+
42+
def begin(self: Any, *, attach_opaque_data: AttachOpaqueData) -> Any:
43+
tx = original_begin(self, attach_opaque_data=attach_opaque_data)
44+
assert tx is not None
45+
minted.append(bytes(tx))
46+
return tx
47+
48+
def on_bind(cls: Any, params: Any) -> Any:
49+
seen.append(params.transaction_opaque_data)
50+
return original_bind(cls, params)
51+
52+
monkeypatch.setattr(ExampleCatalog, "catalog_transaction_begin", begin)
53+
monkeypatch.setattr(DoubleFunction, "on_bind", classmethod(on_bind))
54+
app = create_app(ExampleWorker, describe=False, signing_key=_KEY)
55+
with _client(app) as catalog:
56+
attach = catalog.catalog_attach(name="example", data_version_spec=None, implementation_version=None)
57+
sealed = catalog.catalog_transaction_begin(attach_opaque_data=AttachOpaqueData(attach.attach_opaque_data))
58+
assert sealed is not None and minted and sealed != minted[0]
59+
with _client(app, attach.attach_opaque_data) as worker:
60+
batches = list(
61+
worker.scalar_function(
62+
function_name="double",
63+
schema_path=["main"],
64+
input=iter([pa.RecordBatch.from_pydict({"x": pa.array([1, 2], pa.int64())})]),
65+
transaction_opaque_data=sealed,
66+
)
67+
)
68+
catalog.catalog_transaction_rollback(
69+
attach_opaque_data=AttachOpaqueData(attach.attach_opaque_data), transaction_opaque_data=sealed
70+
)
71+
assert [b.column(0).to_pylist() for b in batches] == [[2, 4]]
72+
assert seen == [minted[0]]

‎vgi/scalar_function.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ def bind(
685685
*,
686686
ctx: CallContext | None = None,
687687
attach_plaintext: bytes | None = None,
688+
transaction_plaintext: bytes | None = None,
688689
) -> BindResponse:
689690
"""Bind protocol entry point. Do not override; use `on_bind()` instead.
690691
@@ -723,10 +724,13 @@ def bind(
723724
secrets_accessor,
724725
auth,
725726
# ``attach_plaintext`` is the full framework plaintext (uuid||catalog
726-
# bytes); the body sees only the catalog bytes. transaction_opaque_data
727-
# is already sealed.
727+
# bytes); the body sees only the catalog bytes. The transaction is
728+
# the worker-opened provider plaintext -- the same bytes the catalog's
729+
# commit/rollback receive -- while ``input`` keeps its sealed wire
730+
# value, as table functions do. Direct callers that pass no plaintext
731+
# (no signing key: the value was never sealed) get the request's.
728732
attach_catalog_bytes(attach_plaintext),
729-
input.transaction_opaque_data,
733+
transaction_plaintext if transaction_plaintext is not None else input.transaction_opaque_data,
730734
input.argument_names,
731735
)
732736
result = cls.on_bind(bind_params)

‎vgi/worker.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,6 +3298,15 @@ def bind(self, request: BindRequest, ctx: CallContext) -> BindResponse:
32983298
attach_plaintext=attach_plaintext,
32993299
transaction_plaintext=self._unwrap_transaction_for(request),
33003300
)
3301+
elif isinstance(instance, ScalarFunctionGenerator):
3302+
# Scalars, like table functions, see the provider's transaction
3303+
# plaintext in BindParameters.transaction_opaque_data.
3304+
result = instance.bind(
3305+
request,
3306+
ctx=ctx,
3307+
attach_plaintext=attach_plaintext,
3308+
transaction_plaintext=self._unwrap_transaction_for(request),
3309+
)
33013310
else:
33023311
result = instance.bind(request, ctx=ctx, attach_plaintext=attach_plaintext) # type: ignore[attr-defined]
33033312
if not isinstance(result, BindResponse):

0 commit comments

Comments
 (0)