Skip to content

feat: connection-level job operations - #3755

Merged
wkalt merged 4 commits into
lancedb:mainfrom
wkalt:ticket/ent-1956/jobs-surface
Jul 31, 2026
Merged

wkalt merged 4 commits into
lancedb:mainfrom
wkalt:ticket/ent-1956/jobs-surface

Conversation

@wkalt

@wkalt wkalt commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Adds job operations to the connection surface, building on the Job
handle from #3742: job(id), list_jobs, get_job, cancel_job, and
job_history, plus a non-blocking Job.status(). Implemented on the
Database trait (defaulting to NotSupported), the remote backend
(/v1/jobs), and the Python and Node bindings; job_history returns Arrow
batches.

errors() and progress() are not included.

Tested with mocked endpoints in all three languages.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added enhancement New feature or request Python Python SDK Rust Rust related issues labels Jul 31, 2026
@wkalt
wkalt force-pushed the ticket/ent-1956/jobs-surface branch from 384ed8c to 39ef1ea Compare July 31, 2026 16:56
@wkalt

wkalt commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@claude review once

Self::InProgress => "running".to_string(),
Self::Done => "finished".to_string(),
Self::Failed => "failed".to_string(),
Self::Cancelled => "cancelled".to_string(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is one more that is TimedOut

@jackye1995 jackye1995 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly looks good to me, 1 comment

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beyond the two nits noted inline, I also checked the finder's concern that #[pyclass(get_all, skip_from_py_object)] on JobInfo/JobFailureInfo/JobDescription (python/src/job.rs) would fail to compile — it's a real, valid pyclass option in pyo3 0.28 (this repo's pinned version), so that candidate issue is not a bug.

Extended reasoning...

Verified against the vendored pyo3-macros-backend 0.28.3 source that skip_from_py_object is a recognized PyClassPyO3Option, confirming the finder-raised compile-failure concern does not hold.

Comment thread python/python/lancedb/db.py Outdated
Comment on lines +653 to +660
def errors(
self, job_id: Optional[str] = None, table: Optional[str] = None
) -> List[dict]:
"""Per-row errors recorded by server-side jobs running with a
skip-errors policy.

This surface is not yet supported.
"""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Python's DBConnection/AsyncConnection gain a public errors() method that always raises NotImplementedError('errors is not yet supported'), while neither nodejs/lancedb/connection.ts nor rust/lancedb/src/connection.rs expose any errors/get_errors symbol at all — the PR description itself notes errors() is intentionally excluded from this change. This is a pre-emptive, Python-only public API surface (visible in docs/IDE, subclassable) with no sibling in Node or Rust; it's low-risk since it always raises, but worth a short parity note or dropping the stub until the feature ships everywhere.

Extended reasoning...

This PR adds job/list_jobs/get_job/cancel_job/job_history in parallel across Python, Node, and Rust — a clean three-way parity story. Alongside those, python/python/lancedb/db.py also adds a new public errors() method to DBConnection (line ~653) and to AsyncConnection (~line 2012), both of which simply raise NotImplementedError("errors is not yet supported"), and python/python/tests/test_remote_db.py asserts that calling it raises. No corresponding errors/getErrors method was added to nodejs/lancedb/connection.ts's Connection class or to the Database trait / Connection impl in rust/lancedb/src/connection.rs. The PR description is explicit about this: "errors() and progress() are not included." So this isn't an oversight in the sense of a forgotten binding update — it's a deliberate placeholder that only exists in the Python surface.

The reason this is worth flagging (rather than being a no-op) is that errors() is a public, documented method: it shows up in IDE autocomplete, in generated docs (it's a plain method on the exported DBConnection/AsyncConnection classes, not behind any private/internal naming convention), and it can be overridden/subclassed. That makes it part of Python's public contract even though it does nothing useful today. If a future PR implements the real errors() behavior only on the Node or Rust side first (e.g. as part of finishing the jobs work), there's now an existing-but-inert Python signature that a reviewer might assume already matches, or that might need a different shape than what's already public. The repo's own REVIEW.md explicitly asks reviewers to check exactly this case: "If the change adds or modifies a public API in one SDK but not the other, open the sibling SDK's corresponding module and state whether an equivalent exists. If not, note it as a possible parity gap and suggest a follow-up issue" — verified against both sibling files, no equivalent exists in nodejs or rust.

I considered the counterargument (raised independently during review) that this isn't a "real" parity gap because there is no errors() in the shared Rust core to begin with, and because raise-only NotImplementedError stubs are already an established pattern in this exact file (serialize, namespace_client, create_namespace, describe_namespace all default to raising NotImplementedError on the base DBConnection). That's a fair point for those other methods, since they're either connection-plumbing that's inherently Python/local-specific, or namespace operations layered over a shared lance_namespace client rather than the rust/lancedb core. errors() is different in kind: it's presented as a forthcoming feature of the jobs surface being built out in this very PR family, explicitly scoped out "for now" in the description, which is exactly the shape of thing that tends to accumulate silent one-sided stubs unless it's tracked. The REVIEW.md rule is about public API surface, not about whether the method currently does anything — a NotImplementedError-raising method is still public API surface once it's an unqualified method on an exported class.

Concretely, to reproduce the asymmetry: in Python, import lancedb; help(lancedb.LanceDBConnection.errors) (or AsyncConnection.errors) resolves to a real, documented method today. Trying the equivalent in TypeScript — db.errors on a Connection instance from nodejs/lancedb/connection.ts — is simply undefined; there is no such property, abstract or concrete. Same for Rust: Connection::errors doesn't exist on rust/lancedb/src/connection.rs's Connection impl, nor is there a default on the Database trait in rust/lancedb/src/database.rs (unlike job/list_jobs/get_job/cancel_job/job_history, which all got trait defaults there). That's the observable, factual asymmetry, even though calling errors() in Python currently produces the same practical outcome (a raised error) as calling nothing at all in Node/Rust.

This is advisory only, per REVIEW.md's own framing ("It is advisory, not a merge blocker"), and there's zero behavioral risk today since it always raises — so it shouldn't hold up the PR. The straightforward options are either to drop the Python-only errors() stub until the feature is ready to land across bindings, or to file a quick follow-up issue tracking that Node/Rust need the same forward-declared stub (or the real implementation) when errors() ships.

Comment on lines +459 to +476
struct RemoteReportedFailure {
phase: String,
message: String,
retryable: bool,
}

#[derive(serde::Deserialize)]
struct RemoteDescribeJobResponse {
job_id: String,
#[serde(default)]
job_type: String,
job_state: String,
#[serde(default)]
creation_ms: i64,
#[serde(default)]
spec: serde_json::Value,
#[serde(default)]
failure: Option<RemoteReportedFailure>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 RemoteReportedFailure (rust/lancedb/src/remote/db.rs) and the near-identical ReportedFailure (rust/lancedb/src/remote/job.rs) declare phase/message/retryable as required fields with no #[serde(default)], so a present-but-partial failure object from the server would fail the entire job describe response instead of degrading gracefully. This is inconsistent with the rest of the response handling (e.g. job_state_to_client/JobState::Other explicitly pass through unknown states, and the outer failure field itself is optional), so it'd be worth making these three sub-fields Option<T> with #[serde(default)] for the same forward-compatibility.

Extended reasoning...

What the bug is. Both RemoteReportedFailure (used by Database::get_job in rust/lancedb/src/remote/db.rs:459-464) and ReportedFailure (used by Job::wait/Job::status via RemoteJob::describe in rust/lancedb/src/remote/job.rs) are defined as:

struct RemoteReportedFailure {
    phase: String,
    message: String,
    retryable: bool,
}

None of these three fields carry #[serde(default)], which makes them required in serde's eyes. The outer failure: Option<RemoteReportedFailure> field is correctly annotated with #[serde(default)], so a response that omits failure entirely deserializes fine (None). But if the server sends a failure object that is present yet missing (or has renamed) even one of phase, message, or retryable, serde_json fails the deserialization of the entire enclosing response (RemoteDescribeJobResponse / DescribeJobResponse), not just the failure detail.

Code path. Connection::get_job calls RemoteDatabase::get_job, which does rsp.json::<RemoteDescribeJobResponse>(). Job::status/Job::wait call RemoteJob::describe, which does serde_json::from_str::<DescribeJobResponse>(&body). In both cases, a partial failure object turns what should be a job_state: "FAILED" result (with maybe a missing failure reason) into a hard deserialization error, taking down the whole describe call.

Why nothing else in the PR catches this. The rest of this same PR is explicitly designed for forward compatibility: JobState::Other and job_state_to_client pass through any state string this client doesn't recognize instead of failing, and nearly every other field in these structs (job_type, creation_ms, spec, table, state, created_at_millis) has #[serde(default)]. The three failure sub-fields are the only required, non-defaulted fields left, which looks like an oversight given the surrounding style rather than an intentional protocol contract.

Impact. With the current server (which always emits all three sub-fields together, per the PR's own tests), nothing breaks today. The risk is purely forward/backward compatibility: if a future or different server version omits retryable for job types where retry doesn't apply, or renames one of these keys, every get_job, Job::status, and Job::wait call for a failed job on that server would start hard-failing with a JSON parse error instead of surfacing a slightly less detailed failure reason.

Step-by-step proof. 1) Server returns {"job_id": "j1", "job_type": "create_index", "job_state": "FAILED", "creation_ms": 1, "failure": {"phase": "execute", "message": "oom"}} (no retryable key — e.g. a job type where the server doesn't compute retryability). 2) RemoteDatabase::get_job calls rsp.json::<RemoteDescribeJobResponse>(). 3) serde_json sees failure is present, tries to deserialize it as RemoteReportedFailure, and fails with missing field retryable`` because there's no #[serde(default)] on it. 4) That error propagates up through `.err_to_http(request_id)`, so `get_job("j1")` returns `Err`, even though the job did fail and the server told us why — the caller can no longer learn any of `state`, `spec`, or `failure` for this job. The same sequence applies to `RemoteJob::describe` for `Job::wait`/`Job::status`.

Fix. Make phase, message, and retryable Option<T> with #[serde(default)] in both RemoteReportedFailure (db.rs) and ReportedFailure (job.rs), matching the tolerant style already used for the outer failure field and every sibling field in these structs. This is a client-only, backward-compatible change — no server or wire-format changes needed.

wkalt and others added 4 commits July 31, 2026 12:18
Add JobInfo/JobDescription and five Database trait methods -- job,
list_jobs, get_job, cancel_job, job_history -- defaulting to
NotSupported, with Connection wrappers.

The remote backend implements them against /v1/jobs: bounded paginated
list, describe with the server-reported failure mapped into JobFailure,
cancel with 404 mapped to false, query_events parsed from an Arrow IPC
stream. conn.job(id) wraps the same RemoteJob handle create_index
returns.

Job/JobHandle gain status(): a non-blocking snapshot in the client
vocabulary (running/finished/failed/cancelled). In-process jobs report
it from their outcome channel.

Co-Authored-By: Claude Fable 5 <[email protected]>
JobInfo, JobDescription, and JobFailureInfo pyclasses plus Connection
bindings for job, list_jobs, get_job, cancel_job, and job_history, and
a status() binding on Job. job_history crosses to pyarrow record
batches; describe specs cross as JSON strings. Typing stubs updated.

Co-Authored-By: Claude Fable 5 <[email protected]>
DBConnection, AsyncConnection, and the remote sync connection gain
job(job_id) plus list_jobs, get_job, cancel_job, and job_history.
Job/AsyncJob gain status(), a non-blocking snapshot that does not raise
on terminal failure states. errors() raises NotImplementedError until
the server-side per-row error store exists.

Tested against a mock server: list pagination, failure mapping, cancel,
Arrow-stream history, and wait() raising JobFailedError.

Co-Authored-By: Claude Fable 5 <[email protected]>
The Connection gains job(jobId) returning the Job handle from the
create-index work, plus listJobs, getJob, cancelJob, and jobHistory
(crossing as an Arrow IPC buffer, surfaced as an Arrow table). Job
gains status(). Generated typedoc updated.

Tested against a mock HTTP server: list pagination, describe failure
mapping, cancel for known and unknown ids, Arrow-stream history,
status(), and wait() rejecting with the server's failure message.

Co-Authored-By: Claude Fable 5 <[email protected]>
@wkalt
wkalt force-pushed the ticket/ent-1956/jobs-surface branch from 39ef1ea to e994f90 Compare July 31, 2026 19:18
@wkalt
wkalt merged commit e3b472c into lancedb:main Jul 31, 2026
25 checks passed
@mintlify

mintlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

Docs PR opened: https://github.com/lancedb/docs/pull/326

Added an Enterprise page documenting connection-level job APIs for listing, describing, cancelling, and inspecting server-side background work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Python Python SDK Rust Rust related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants