fix!: preserve job attempt lineage, retries, and lifecycle states

BREAKING CHANGE: JobDescription, JobEventsRequest, FunctionErrorsRequest, and FunctionErrors gain optional Rust metadata/cursor fields. Existing struct literals must initialize them; use None when unavailable.

Preserve typed attempt state, pinned retry lineage, result decoders and freshness fences, and retained diagnostic paging across SDKs. Keep Python job data access method-only.
This commit is contained in:
Jack Ye
2026-11-20 20:35:59 -08:00
committed by GitHub
parent bfb55c72e9
commit b44807e4db
35 changed files with 1822 additions and 55 deletions
+2 -2
View File
@@ -114,7 +114,7 @@ async def test_cleanup_submission_wait_and_reopen(asynchronous, outcome):
db = lancedb.connect(**kwargs)
table = db.create_table("test", [{"id": 1}])
job = table.cleanup_async(min_age_seconds=0)
assert job.id == "cleanup-job" and not polls
assert job.id() == "cleanup-job" and not polls
if outcome in ("missing", "FAILED", "CANCELLED"):
with pytest.raises(
Exception,
@@ -133,7 +133,7 @@ async def test_cleanup_submission_wait_and_reopen(asynchronous, outcome):
assert isinstance(stats, CleanupResult)
assert stats.old_versions == result["old_versions"]
reopened = (
await db.open_job(job.id) if asynchronous else db.open_job(job.id)
await db.open_job(job.id()) if asynchronous else db.open_job(job.id())
)
assert (await reopened.wait() if asynchronous else reopened.wait()) == stats
assert len(server.tickets) == 1
+56 -2
View File
@@ -9,10 +9,11 @@ from types import SimpleNamespace
from unittest.mock import AsyncMock, MagicMock
import pytest
import pyarrow as pa
from lancedb.exceptions import JobCancelledError, JobFailedError
from lancedb.db import DBConnection
from lancedb.job import AsyncJob, Job, _progress_eta
from lancedb.job import AsyncJob, Job, JobState, _progress_eta
from lancedb.remote.errors import HttpError, RetryError
@@ -69,17 +70,30 @@ async def test_job_checkout_latest_refreshes_the_complete_snapshot(
creation_ms=2000, spec=spec, result=result, failure=failure
)
inner = SimpleNamespace(
_state=None, _description=None, job_type=None, status=AsyncMock()
id="operation-1",
_state=None,
_description=None,
job_type=None,
status=AsyncMock(),
)
async def observe():
inner._state = state
inner.job_type = "refresh_column"
inner._description = description
inner.job_id = "attempt-2"
inner.operation_id = "operation-1"
inner.attempt = 2
inner.retry_of = "attempt-1"
inner.lifecycle_state = str(JobState(state))
inner.source_table_version = 7
inner.execution_epoch = 3
inner.refresh = AsyncMock(side_effect=observe)
job, call = job_snapshot(inner)
assert job.state() is None
assert job.job_id() == "operation-1"
assert job.lifecycle_state() is None
assert job.job_type() is None
assert job.creation_ms() is None
assert job.spec() is None
@@ -94,6 +108,14 @@ async def test_job_checkout_latest_refreshes_the_complete_snapshot(
assert job.spec() is spec
assert job.result() is result
assert job.failure() is failure
assert job.id() == "operation-1"
assert job.job_id() == "attempt-2"
assert job.operation_id() == "operation-1"
assert job.attempt() == 2
assert job.retry_of() == "attempt-1"
assert job.lifecycle_state() == JobState(state)
assert job.source_table_version() == 7
assert job.execution_epoch() == 3
inner.refresh.assert_awaited_once_with()
inner.status.assert_not_called()
@@ -151,6 +173,38 @@ async def test_job_checkout_latest_for_completed_local_jobs(job_snapshot):
assert Job(None).checkout_latest() is None
@pytest.mark.parametrize("sync", [False, True])
def test_local_jobs_retain_identity_and_typed_state(sync):
job = AsyncJob(None)
if sync:
job = Job(job)
assert job.job_id() == job.operation_id()
assert job.job_id() == job.job_id()
assert job.attempt() == 1
assert job.retry_of() is None
assert job.lifecycle_state() is JobState.SUCCEEDED
def test_unknown_job_state_is_preserved_without_becoming_success():
state = JobState("future_publication_state")
assert state.value == "future_publication_state"
assert str(state) == "future_publication_state"
assert not state.is_terminal
assert not state.is_success
@pytest.mark.asyncio
async def test_history_follows_page_tokens():
first = pa.table({"event_seq": [2, 1]}).replace_schema_metadata(
{b"lancedb.job_coordinator.page_token": b"next"}
)
last = pa.table({"event_seq": [0]})
inner = SimpleNamespace(events=AsyncMock(side_effect=[first, last]))
pages = [page async for page in AsyncJob(inner).history(limit=2)]
assert [page["event_seq"].to_pylist() for page in pages] == [[2, 1], [0]]
assert inner.events.call_args_list[1].kwargs["page_token"] == "next"
@pytest.mark.parametrize("sync", [False, True])
def test_job_repr_bounds_large_payloads_without_fetching(sync):
spec = {"initialization": list(range(100000)), "source": "x" * 100000}
+44
View File
@@ -9034,3 +9034,47 @@ def test_remote_prewarm_preview_reports_old_server_format_support():
):
table.explain_prewarm_data()
assert len(server.tickets) == 1
@pytest.mark.parametrize("async_table", [False, True])
@pytest.mark.asyncio
async def test_paged_function_errors_retain_history_and_expose_continuation(
async_table,
):
received = []
def handler(request):
length = int(request.headers.get("content-length", 0))
body = json.loads(request.rfile.read(length)) if length else {}
if request.path == "/v1/table/test/describe/":
response = {"version": 8, "schema": {"fields": []}}
else:
assert request.path == "/v1/table/test/errors"
received.append(body)
response = {
"records": [],
"fragments": [],
"truncated": False,
"workflow_version": 1,
"page_token": "next",
}
request.send_response(200)
request.send_header("Content-Type", "application/json")
request.end_headers()
request.wfile.write(json.dumps(response).encode())
if async_table:
async with mock_lancedb_connection_async(handler) as db:
table = await db.open_table("test")
errors = await table.function_errors(job_id="attempt-1", page_token="")
assert errors.page_token == "next"
with pytest.raises(ValueError, match="current failures"):
await errors.rows()
else:
with mock_lancedb_connection(handler) as db:
table = db.open_table("test")
errors = table.function_errors(job_id="attempt-1", page_token="")
assert errors.page_token == "next"
with pytest.raises(ValueError, match="current failures"):
errors.rows()
assert received == [{"job_id": "attempt-1", "page_token": "", "history": True}]