Skip to content

Commit 5e4a590

Browse files
rustyconoverclaude
andcommitted
Replace protocol version negotiation with feature flags
Switch from semantic versioning (major.minor) to feature flags for protocol capability negotiation between client and worker. Changes: - Remove PROTOCOL_VERSION, ProtocolVersionError, negotiate_protocol_version() - Add client_features: frozenset[str] to Invocation - Add active_features: frozenset[str] to OutputSpec - Worker returns intersection of client and worker features - Client validates active_features is subset of requested features This enables more granular capability negotiation for features like: - Alternative IPC mechanisms (memfd, shared memory) - DuckDB extensions (catalogs, databases) Also consolidates util.py into ipc_utils.py. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4f354e9 commit 5e4a590

6 files changed

Lines changed: 130 additions & 230 deletions

File tree

‎vgi/client/client.py‎

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@
6666
from pyarrow import ipc
6767

6868
from vgi.function import (
69-
PROTOCOL_VERSION,
7069
Arguments,
7170
GlobalInitResult,
7271
Invocation,
73-
ProtocolVersionError,
7472
)
7573
from vgi.ipc_utils import IPCError, read_ipc_batch
7674
from vgi.table_function import GlobalStateInitInput
@@ -114,7 +112,7 @@ class _BindResult:
114112
max_processes: int
115113
invocation_id: bytes | None
116114
output_schema: pa.Schema
117-
protocol_version: tuple[int, int] | None
115+
active_features: frozenset[str]
118116
raw_batch: pa.RecordBatch
119117

120118

@@ -234,22 +232,22 @@ def _parse_bind_result(self, batch: pa.RecordBatch) -> _BindResult:
234232
"""Parse the bind result batch from a worker into structured data.
235233
236234
Extracts function metadata from the worker's bind response, including
237-
max_processes (cast to int32), invocation_id, protocol version (if
238-
present), and the output schema (deserialized from IPC bytes).
235+
max_processes (cast to int32), invocation_id, active_features,
236+
and the output schema (deserialized from IPC bytes).
239237
240238
Args:
241239
batch: The bind result RecordBatch from the worker. Expected columns:
242240
- max_processes: Maximum parallel workers the function supports
243241
- invocation_id: Unique identifier for this invocation (bytes)
244242
- output_schema: IPC-serialized Arrow schema for output batches
245-
- protocol_version_major/minor: Optional protocol version fields
243+
- active_features: List of feature flags active for this invocation
246244
247245
Returns:
248246
A _BindResult dataclass containing:
249247
- max_processes: int, the function's parallelism limit
250248
- invocation_id: bytes or None, unique invocation identifier
251249
- output_schema: pa.Schema, deserialized output schema
252-
- protocol_version: tuple[int, int] or None, (major, minor) version
250+
- active_features: frozenset[str], features active for this invocation
253251
- raw_batch: The original RecordBatch for reference
254252
255253
"""
@@ -263,16 +261,14 @@ def _parse_bind_result(self, batch: pa.RecordBatch) -> _BindResult:
263261
)
264262
invocation_id = invocation_id_array.to_pylist()[0]
265263

266-
# Extract protocol version if present
267-
protocol_version: tuple[int, int] | None = None
268-
if "protocol_version_major" in batch.schema.names:
269-
worker_major = batch.column(
270-
batch.schema.get_field_index("protocol_version_major")
264+
# Extract active features - default to empty set for backward compatibility
265+
active_features: frozenset[str] = frozenset()
266+
if "active_features" in batch.schema.names:
267+
features_list = batch.column(
268+
batch.schema.get_field_index("active_features")
271269
).to_pylist()[0]
272-
worker_minor = batch.column(
273-
batch.schema.get_field_index("protocol_version_minor")
274-
).to_pylist()[0]
275-
protocol_version = (worker_major, worker_minor)
270+
if features_list is not None:
271+
active_features = frozenset(features_list)
276272

277273
# Extract output schema
278274
output_schema_bytes = batch.column(
@@ -284,45 +280,40 @@ def _parse_bind_result(self, batch: pa.RecordBatch) -> _BindResult:
284280
max_processes=max_processes,
285281
invocation_id=invocation_id,
286282
output_schema=output_schema,
287-
protocol_version=protocol_version,
283+
active_features=active_features,
288284
raw_batch=batch,
289285
)
290286

291-
def _validate_protocol_version(
292-
self, protocol_version: tuple[int, int] | None
287+
def _validate_features(
288+
self,
289+
requested: frozenset[str],
290+
active: frozenset[str],
293291
) -> None:
294-
"""Validate that the worker's protocol version is compatible with the client.
292+
"""Validate that the worker activated only features we support.
295293
296-
Checks that the major version matches between client and worker. Minor
297-
version differences are allowed (backward compatible). If the worker
298-
did not report a protocol version, validation is skipped (assumed
299-
compatible for older workers).
294+
Checks that the active features returned by the worker are a subset
295+
of the features the client requested. This ensures the worker doesn't
296+
activate features the client cannot handle.
300297
301298
Args:
302-
protocol_version: The worker's protocol version as a (major, minor)
303-
tuple, or None if the worker did not report a version.
299+
requested: The client_features sent in the Invocation.
300+
active: The active_features returned in the OutputSpec.
304301
305302
Raises:
306-
ProtocolVersionError: If the major version differs between client
307-
and worker. The error message includes both versions.
303+
ClientError: If the worker activated features not requested by
304+
the client.
308305
309306
"""
310-
if protocol_version is None:
311-
return # No version info, assume compatible
312-
313-
worker_major, worker_minor = protocol_version
314-
315-
if worker_major != PROTOCOL_VERSION[0]:
316-
raise ProtocolVersionError(
317-
f"Protocol version mismatch: client uses major version "
318-
f"{PROTOCOL_VERSION[0]}, worker responded with major version "
319-
f"{worker_major}. Major versions must match."
307+
if not active <= requested:
308+
unexpected = active - requested
309+
raise ClientError(
310+
f"Worker activated unsupported features: {unexpected}"
320311
)
321312

322313
log.debug(
323-
"protocol_version_validated",
324-
client_version=PROTOCOL_VERSION,
325-
worker_version=protocol_version,
314+
"features_validated",
315+
requested_features=requested,
316+
active_features=active,
326317
)
327318

328319
def _determine_max_processes(self, requested: int) -> int:
@@ -407,7 +398,7 @@ def _initialize_stream_common(
407398
ClientError: If the worker process is not started, or if reading
408399
the bind result or init result fails.
409400
OSError: If writing the Invocation or GlobalStateInitInput fails.
410-
ProtocolVersionError: If the worker's protocol version is incompatible.
401+
ClientError: If the worker activated unsupported features.
411402
412403
"""
413404
if self._stdin_sink is None or self._stdout_buffered is None:
@@ -416,12 +407,16 @@ def _initialize_stream_common(
416407
# Send initialization batch
417408
log.debug("sending_init_batch", function=function_name, arguments=arguments)
418409

410+
# Client features - currently empty, will be populated as features are added
411+
client_features: frozenset[str] = frozenset()
412+
419413
initial_request = Invocation(
420414
function_name=function_name,
421415
arguments=arguments,
422416
in_out_function_input_schema=input_schema,
423417
correlation_id=self.correlation_id,
424418
invocation_id=None,
419+
client_features=client_features,
425420
)
426421
call_parameters_batch_bytes = initial_request.serialize()
427422

@@ -444,15 +439,15 @@ def _initialize_stream_common(
444439

445440
bind_result = self._parse_bind_result(bind_result_batch)
446441

447-
# Validate protocol version
448-
self._validate_protocol_version(bind_result.protocol_version)
442+
# Validate features
443+
self._validate_features(client_features, bind_result.active_features)
449444

450445
# Apply limits to max_processes
451446
bind_result = _BindResult(
452447
max_processes=self._determine_max_processes(bind_result.max_processes),
453448
invocation_id=bind_result.invocation_id,
454449
output_schema=bind_result.output_schema,
455-
protocol_version=bind_result.protocol_version,
450+
active_features=bind_result.active_features,
456451
raw_batch=bind_result.raw_batch,
457452
)
458453

0 commit comments

Comments
 (0)