Skip to content

Commit 663b940

Browse files
rustyconoverclaude
andcommitted
protocol 3.4: argument references and init: StateRef; VGI leaves the call-state slot
Argument references (vgi docs/large-values-3.4.md §2, §5, §5a): - vgi/arguments_ref.py: resolve_bind_call / resolve_request_arguments / resolved_arguments. Every worker method that receives a bind call (bind, projection, cardinality, plan, statistics, dynamic-to-string, init, and the table-buffering init read back from storage) resolves arguments_location at its entry through ctx.resolve_argument_ref (vgi-rpc opens the sealed ref, checks size/sha256, goes through the object cache single-flight, verifies the bytes). User code gets a bind call whose arguments holds the resolved value (fleet workers reading bind_call.arguments keep working) and which still serializes as the bytes the client sent (with_resolved_arguments), so the reference, never the value, goes back on the wire, into stream state and into table-buffering storage. The require_arguments() stopgaps are gone; framework readers use resolved_arguments(). - Refusals: invalid_arguments_ref and arguments_ref_integrity pass through from vgi-rpc; arguments_ref_missing (NOT_FOUND) carries the exact message "this prepared statement's large argument has expired; prepare it again"; invalid_bind_request is BindRequest's own (2c). - VGI-Arguments-Ref-Bytes (default 4194304, VGI_ARGUMENTS_REF_BYTES) is sent on every response by vgi serve and the fixture HTTP server whenever they vend upload URLs and their storage is an ObjectStore. - Split-token fingerprint: a location (also after resolution) contributes 0x01 || u64le(size) || sha256, never the sealed ref; inline arguments 0x00 || u64le(len) || IPC bytes (was repr()). init: StateRef (§6): - VgiCallState, _VgiCallStateHolder, CALL_STATE_TYPE and bind_call_state are gone, and init() no longer passes Stream(call_state=...). Scalar, producer and table-in-out states carry one serialized field, init: a vgi-rpc StateRef to VgiStreamInit(init_call, init_response), created with ctx.state_ref() in the init handler only; later turns copy it. - rehydrate() has no call context, so it only records the worker; the turn's entry (process / produce / exchange / on_cancel) resolves the ref with ctx.resolve, resolves the arguments, then rebuilds the transient fields. Pipe streams are built already resolved and never resolve per turn. - The output schema is carried once: when the stream's output schema (in vgi-rpc's call token) equals the init output schema, the init's copy is left out and restored from the turn's output collector. - The attach plaintext is still re-derived per turn from the sealed envelope; the stale VgiCallState access-log note went with the class (vgi-rpc's access log records state sizes only). serve: token_ttl=21600 and cursor_rule="error" (the cursor rule is now a hard cursor_too_large error, as the spec asks once the port is done). Tests: tests/test_arguments_ref.py drives vgi serve against the fake vendor the way the extension does: header and switch, a 12-turn producer and three split streams on one referenced argument (one vendor GET each, init stays inline), tampered / mis-sized refs, a deleted object with a cold cache (the prepared-statement message), raw-preserving re-encode and the fingerprint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 779dc67 commit 663b940

20 files changed

Lines changed: 983 additions & 219 deletions

‎CLAUDE.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ vgi-client --input data.parquet --function sum_all_columns --worker vgi-fixture-
331331
| `VGI_RPC_MAX_REQUEST_BYTES` | `vgi-serve --http` (and `vgi-fixture-http` with the vendor): advertised and enforced request cap; clients upload larger requests via the vendor's upload URLs |
332332
| `VGI_RPC_EXTERNALIZE_THRESHOLD_BYTES` / `VGI_RPC_EXTERNAL_COMPRESSION` / `VGI_RPC_MAX_UPLOAD_BYTES` | With the vendor: result externalization threshold (default 1 MiB), its compression, and the advertised upload size (unset: the inbound fetch cap) |
333333
| `VGI_RPC_MAX_FETCH_BYTES` | With the vendor: largest request fetched from an inbound upload pointer. Default 256 MiB, raised to `VGI_RPC_MAX_UPLOAD_BYTES` when that is larger; an upload cap above an explicit fetch cap fails startup. vgi-rpc never advertises an upload size above it |
334+
| `VGI_ARGUMENTS_REF_BYTES` | Protocol 3.4 argument references: the `VGI-Arguments-Ref-Bytes` value advertised with the upload-URL capability (default 4194304). Arguments IPC over `min(this, VGI-Max-Request-Bytes / 4)` is uploaded once and bound by reference (`vgi/arguments_ref.py`). Sent only when the server vends upload URLs and its storage can fetch objects by id |
335+
| `VGI_TEST_DISABLE_ARGUMENTS_REF` | Test switch: `1` stops sending `VGI-Arguments-Ref-Bytes` (the extension's `arguments_ref_fallback.test`) |
334336

335337
### Worker Debug Mode
336338

‎tests/catalog/column_native_reference.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from vgi_rpc import ArrowSerializableDataclass
2020
from vgi_rpc.rpc import OutputCollector
2121

22+
from vgi.arguments_ref import resolved_arguments
2223
from vgi.catalog import Catalog, ReadOnlyCatalogInterface, ScanFunctionResult, Schema, SchemaObjectType
2324
from vgi.catalog.sql import ColumnExpressions, with_column_expressions
2425
from vgi.invocation import BindResponse, GlobalInitResponse
@@ -34,7 +35,7 @@
3435

3536
def _args(params: Any) -> dict[str, Any]:
3637
call = params.bind_call if isinstance(params, BindParams) else params.init_call.bind_call
37-
target = json.loads(present(call.require_arguments().positional[0]).as_py())
38+
target = json.loads(present(resolved_arguments(call).positional[0]).as_py())
3839
return dict(
3940
attach_opaque_data=params.attach_opaque_data,
4041
transaction_opaque_data=params.transaction_opaque_data,

‎tests/catalog/generated_columns_reference.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from vgi_rpc import ArrowSerializableDataclass
2222
from vgi_rpc.rpc import OutputCollector
2323

24+
from vgi.arguments_ref import resolved_arguments
2425
from vgi.catalog import (
2526
Catalog,
2627
CatalogObjectRef,
@@ -54,7 +55,7 @@ def _args(params: Any) -> dict[str, Any]:
5455
return dict(
5556
attach_opaque_data=params.attach_opaque_data,
5657
transaction_opaque_data=params.transaction_opaque_data,
57-
**json.loads(present(call.require_arguments().positional[0]).as_py()),
58+
**json.loads(present(resolved_arguments(call).positional[0]).as_py()),
5859
)
5960

6061

‎tests/catalog/test_writable_signed_transactions.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from vgi.client.errors import ClientError
3636
from vgi.invocation import GlobalInitResponse
3737
from vgi.meta_worker import MetaWorker
38-
from vgi.protocol import VgiCallState
38+
from vgi.protocol import VgiStreamInit
3939
from vgi.rpc_server import build_rpc_server
4040
from vgi.serve import create_app
4141

@@ -225,7 +225,7 @@ def test_signed_http_wrong_attachment_rejected_before_service(service: SQLiteTra
225225
def test_signed_http_callback_token_survives_init_continuation_and_finalize(
226226
service: SQLiteTransactorService, monkeypatch: pytest.MonkeyPatch, use_meta_worker: bool
227227
) -> None:
228-
"""All callbacks see provider bytes, while serialized call state keeps the seal."""
228+
"""All callbacks see provider bytes, while the serialized stream init keeps the seal."""
229229
seen: list[tuple[str, bytes | None]] = []
230230
original_bind = GenericTableInsert.on_bind
231231
original_process = GenericTableInsert.process
@@ -238,7 +238,7 @@ def check(phase: str, params: Any) -> None:
238238
assert bind.transaction_opaque_data == sealed
239239
assert params.transaction_opaque_data == plaintext
240240
if phase in {"process", "finalize"}:
241-
state = VgiCallState(init_call=params.init_call, init_response=params.init_response)
241+
state = VgiStreamInit(init_call=params.init_call, init_response=params.init_response)
242242
raw = state.serialize_to_bytes()
243243
assert plaintext is not None and sealed is not None
244244
assert plaintext not in raw

‎tests/catalog/transactional_write_reference.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
from vgi._sqlite_wal import enable_wal, immediate_transaction
4444
from vgi._test_fixtures.simple_writable import _parse_write_options
45+
from vgi.arguments_ref import resolved_arguments
4546
from vgi.catalog import (
4647
AttachOpaqueData,
4748
Catalog,
@@ -97,7 +98,7 @@ def _identifier(name: str) -> str:
9798

9899
def _table_argument(params: BindParams[None] | InitParams[None] | ProcessParams[None]) -> str:
99100
bind = present(params).bind_call if isinstance(params, BindParams) else present(params.init_call).bind_call
100-
arguments = bind.require_arguments().positional
101+
arguments = resolved_arguments(bind).positional
101102
if len(arguments) != 1 or arguments[0] is None:
102103
raise _error("one table-name argument is required")
103104
name = arguments[0].as_py()

‎tests/test_argument_metadata.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from vgi_rpc.rpc import CallContext
1414

1515
from vgi.arguments import Arguments
16+
from vgi.arguments_ref import resolved_arguments
1617
from vgi.client import Client
1718
from vgi.invocation import BindResponse, FunctionType
1819
from vgi.protocol import BindRequest, InitRequest
@@ -86,10 +87,10 @@ def test_bind_and_init_preserve_argument_metadata() -> None:
8687
original = _arguments()
8788
bind = BindRequest(function_name="f", arguments=Arguments.from_batch(original), function_type=FunctionType.TABLE)
8889
restored = BindRequest.deserialize_from_bytes(bind.serialize_to_bytes())
89-
assert restored.require_arguments().to_batch().equals(original, check_metadata=True)
90+
assert resolved_arguments(restored).to_batch().equals(original, check_metadata=True)
9091
init = InitRequest(bind_call=restored, output_schema=pa.schema([]))
9192
restored_init = InitRequest.deserialize_from_bytes(init.serialize_to_bytes())
92-
assert restored_init.bind_call.require_arguments().to_batch().equals(original, check_metadata=True)
93+
assert resolved_arguments(restored_init.bind_call).to_batch().equals(original, check_metadata=True)
9394

9495

9596
@pytest.mark.parametrize(
@@ -145,7 +146,7 @@ class _MetadataWorker(Worker):
145146
"""Return the decoded argument schema through the real bind RPC."""
146147

147148
def bind(self, request: BindRequest, ctx: CallContext) -> BindResponse:
148-
return BindResponse(output_schema=request.require_arguments().schema())
149+
return BindResponse(output_schema=resolved_arguments(request).schema())
149150

150151

151152
def test_public_http_bind_preserves_argument_metadata() -> None:

0 commit comments

Comments
 (0)