mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
feat: expose Function worker stack inspection (#5043)
Adds `Job::stack(worker_id)` in Rust and `Job.stack(worker_id)` /
`AsyncJob.stack(worker_id)` in Python for server-side Function jobs. The
response preserves capture availability, timestamps, truncation, and
session details; unsupported local or query handles retain their
existing unsupported-operation behavior. Refresh wrappers forward the
request to their tracked server job.
```python
evidence = job.stack("worker-id")
for session in evidence["stacks"]:
print(session["status"], session["stack"])
```
Requires a server implementing `/v1/jobs/stack` and system operate
privilege. The API propagates authorization and transport errors without
waiting for job completion. Existing progress snapshots already preserve
server warning fields.
Includes mocked request/response and synchronous/asynchronous Python
coverage. Local builds and tests were intentionally skipped as
requested.
This commit is contained in:
@@ -1027,3 +1027,48 @@ async def test_export_timeline_reports_filesystem_errors(tmp_path):
|
||||
)
|
||||
with pytest.raises(FileNotFoundError):
|
||||
await job.export_timeline(tmp_path / "missing" / "trace.json")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("sync", [False, True])
|
||||
async def test_stack_preserves_evidence_and_does_not_wait(sync):
|
||||
evidence = {
|
||||
"worker_id": "worker",
|
||||
"status": "unavailable",
|
||||
"execution_epoch": 1,
|
||||
"stacks": [],
|
||||
"omitted_sessions": 0,
|
||||
}
|
||||
inner = SimpleNamespace(
|
||||
stack=AsyncMock(return_value=json.dumps(evidence)),
|
||||
wait=AsyncMock(),
|
||||
cancel=AsyncMock(),
|
||||
)
|
||||
job = AsyncJob(inner)
|
||||
actual = (
|
||||
await asyncio.to_thread(Job(job).stack, "worker")
|
||||
if sync
|
||||
else await job.stack("worker")
|
||||
)
|
||||
assert actual == evidence
|
||||
inner.stack.assert_awaited_once_with("worker")
|
||||
inner.wait.assert_not_awaited()
|
||||
inner.cancel.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("sync", [False, True])
|
||||
async def test_stack_propagates_errors_and_rejects_local_handles(sync):
|
||||
error = RuntimeError("system operate privilege required")
|
||||
job = AsyncJob(SimpleNamespace(stack=AsyncMock(side_effect=error)))
|
||||
with pytest.raises(RuntimeError) as failure:
|
||||
if sync:
|
||||
await asyncio.to_thread(Job(job).stack, "worker")
|
||||
else:
|
||||
await job.stack("worker")
|
||||
assert failure.value is error
|
||||
with pytest.raises(NotImplementedError):
|
||||
if sync:
|
||||
Job(None).stack("worker")
|
||||
else:
|
||||
await AsyncJob(None).stack("worker")
|
||||
|
||||
Reference in New Issue
Block a user