Skip to content

Commit 1060597

Browse files
rustyconoverclaude
andcommitted
Use vgi. prefix for log metadata keys for consistency
All logging metadata keys now use the vgi. prefix to match the existing vgi.status key pattern. This ensures protocol consistency. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b55894b commit 1060597

3 files changed

Lines changed: 27 additions & 21 deletions

File tree

docs/protocol.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ Input and output data are standard Arrow RecordBatches matching the declared sch
194194
- `vgi.status`: One of `NEED_MORE_INPUT`, `HAVE_MORE_OUTPUT`, `FINISHED`
195195
- `vgi.log_level`: Log level if log message present (optional)
196196
- `vgi.log_message`: Log message text (optional)
197+
- `vgi.log_extra`: JSON-encoded additional context (optional)
197198

198199
---
199200

vgi/client/client.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,18 @@ def _handle_log_message(
180180
) -> bool:
181181
"""Handle a log message from the worker if present.
182182
183-
Detects log messages by checking for zero-row batches with log_level and
184-
log_message metadata keys. When detected, logs the message using structlog
185-
at the appropriate level. If the log level is "exception", raises a
186-
ClientError with the message and traceback.
183+
Detects log messages by checking for zero-row batches with vgi.log_level
184+
and vgi.log_message metadata keys. When detected, logs the message using
185+
structlog at the appropriate level. If the log level is "exception",
186+
raises a ClientError with the message and traceback.
187187
188188
Args:
189189
output_batch: The output batch from the worker. A log message is
190190
detected when this has zero rows.
191191
output_metadata: Custom metadata dictionary from the batch. Must
192-
contain b"log_level" and b"log_message" keys for the batch
193-
to be treated as a log message. May optionally contain
194-
b"log_extra" with JSON-encoded additional context.
192+
contain b"vgi.log_level" and b"vgi.log_message" keys for the
193+
batch to be treated as a log message. May optionally contain
194+
b"vgi.log_extra" with JSON-encoded additional context.
195195
196196
Returns:
197197
True if this was a log message and the caller should continue to
@@ -207,31 +207,31 @@ def _handle_log_message(
207207

208208
if not (
209209
output_batch.num_rows == 0
210-
and output_metadata.get(b"log_level") is not None
211-
and output_metadata.get(b"log_message") is not None
210+
and output_metadata.get(b"vgi.log_level") is not None
211+
and output_metadata.get(b"vgi.log_message") is not None
212212
):
213213
return False
214214

215215
extra: dict[str, Any] = {}
216-
if output_metadata.get(b"log_extra") is not None:
216+
if output_metadata.get(b"vgi.log_extra") is not None:
217217
try:
218-
extra = json.loads(output_metadata[b"log_extra"].decode())
218+
extra = json.loads(output_metadata[b"vgi.log_extra"].decode())
219219
except json.JSONDecodeError as e:
220220
log.error(
221221
"failed_to_decode_log_extra",
222222
error=str(e),
223-
raw=output_metadata[b"log_extra"],
223+
raw=output_metadata[b"vgi.log_extra"],
224224
)
225225

226-
level_name = output_metadata[b"log_level"].decode().lower()
226+
level_name = output_metadata[b"vgi.log_level"].decode().lower()
227227
worker_log._proxy_to_logger(
228228
level_name,
229-
output_metadata[b"log_message"].decode(),
229+
output_metadata[b"vgi.log_message"].decode(),
230230
**extra,
231231
)
232232

233233
if level_name == "exception":
234-
message = output_metadata[b"log_message"].decode()
234+
message = output_metadata[b"vgi.log_message"].decode()
235235
traceback = extra.get("traceback", "")
236236
full_message = f"Worker Exception: {message}\n{traceback}"
237237
raise ClientError(full_message)
@@ -261,6 +261,11 @@ def _parse_bind_result(self, batch: pa.RecordBatch) -> _BindResult:
261261
- raw_batch: The original RecordBatch for reference
262262
263263
"""
264+
if batch.num_rows != 1:
265+
raise ClientError(
266+
"Expected single-row RecordBatch for bind result,"
267+
f" got {batch.num_rows} rows"
268+
)
264269
max_processes_array = batch.column(
265270
batch.schema.get_field_index("max_processes")
266271
)

vgi/log.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ def add_to_metadata(
203203
204204
Returns:
205205
New dict containing original entries plus:
206-
- log_level: The Level value (e.g., "INFO", "EXCEPTION")
207-
- log_message: The human-readable message text
208-
- log_extra: JSON string with {correlation_id, invocation_id,
206+
- vgi.log_level: The Level value (e.g., "INFO", "EXCEPTION")
207+
- vgi.log_message: The human-readable message text
208+
- vgi.log_extra: JSON string with {correlation_id, invocation_id,
209209
pid, ...extra kwargs}
210210
211211
"""
212212
result = dict(metadata) if metadata else {}
213-
result["log_level"] = self.level.value
213+
result["vgi.log_level"] = self.level.value
214214
log_data: dict[str, Any] = {
215215
"correlation_id": invocation.correlation_id,
216216
"invocation_id": invocation.invocation_id.hex()
@@ -220,8 +220,8 @@ def add_to_metadata(
220220
}
221221
if self.extra:
222222
log_data.update(self.extra)
223-
result["log_message"] = self.message
224-
result["log_extra"] = json.dumps(log_data)
223+
result["vgi.log_message"] = self.message
224+
result["vgi.log_extra"] = json.dumps(log_data)
225225
return result
226226

227227
@classmethod

0 commit comments

Comments
 (0)