From 49dedd4329cb6acac39038a99b20e335837cf602 Mon Sep 17 00:00:00 2001 From: Jack Ye Date: Sat, 21 Nov 2026 00:18:29 -0800 Subject: [PATCH] fix: expose Function metadata in SDK job listings (#5096) Expose affected columns, pinned Function name/version, completion time, duration and failure summaries on `JobInfo` in the Rust, Python and TypeScript SDKs. Values come from the listing response, so callers can inspect recent computed column refreshes without opening every job. Older servers keep optional values absent; measured zero durations stay zero. ```python latest = next((info for info in db.list_jobs(table="events", job_type="function_refresh") if "embedding" in info.columns), None) if latest is not None: print(latest.function_name, latest.function_version, latest.duration_millis) if latest.failure is not None: print(latest.failure.message) ``` Duration is creation-to-completion wall time, including queueing and pauses. Adds listing response coverage across SDKs and documents the metadata contract, including SQL `SHOW JOBS EXTENDED` for the expanded listing. Plain `SHOW JOBS` preserves its original columns. Local builds and tests were skipped as requested. The dependency advisory check also fails on current main because `libsais-rs 0.2.0` is yanked ([main job](https://github.com/lancedb/lancedb/actions/runs/44470513618/job/135378545456)); this PR does not change dependencies. This changes the public shape of Rust and TypeScript `JobInfo`: callers constructing summaries must supply the added fields (including TypeScript `columns`). TypeScript table filtering remains a separate concern; the guide now shows its client-side selection and namespace limitation alongside Python and Rust server-side filters. Refs ENT-3903. --- docs/src/js/interfaces/JobInfo.md | 60 +++++++++++++++++++ docs/web/basics/jobs.mdx | 84 +++++++++++++++++++++++++++ docs/web/sql/ddl/job.mdx | 17 ++++++ nodejs/__test__/remote.test.ts | 32 +++++++++- nodejs/src/job.rs | 18 ++++++ python/python/lancedb/_lancedb.pyi | 12 ++++ python/python/tests/test_remote_db.py | 43 +++++++++++++- python/src/job.rs | 18 ++++++ rust/lancedb/src/database.rs | 14 +++++ rust/lancedb/src/remote/db.rs | 35 ++++++++++- 10 files changed, 327 insertions(+), 6 deletions(-) diff --git a/docs/src/js/interfaces/JobInfo.md b/docs/src/js/interfaces/JobInfo.md index 5de1d5e55..510fd7f28 100644 --- a/docs/src/js/interfaces/JobInfo.md +++ b/docs/src/js/interfaces/JobInfo.md @@ -10,6 +10,26 @@ A row from `Connection.listJobs`: one server-side job. ## Properties +### columns + +```ts +columns: string[]; +``` + +Affected columns; empty when unavailable or not column-scoped. + +*** + +### completedAtMillis? + +```ts +optional completedAtMillis: number; +``` + +Terminal timestamp in milliseconds since the epoch, when known. + +*** + ### createdAtMillis ```ts @@ -20,6 +40,46 @@ When the job was created, in milliseconds since the epoch. *** +### durationMillis? + +```ts +optional durationMillis: number; +``` + +Creation-to-completion wall time, including queueing and pauses. + +*** + +### failure? + +```ts +optional failure: JobFailureInfo; +``` + +Durable failure summary, when available. + +*** + +### functionName? + +```ts +optional functionName: string; +``` + +Pinned Function catalog name, with namespace segments joined by `$`. + +*** + +### functionVersion? + +```ts +optional functionVersion: string; +``` + +Pinned Function version, when known. + +*** + ### jobId ```ts diff --git a/docs/web/basics/jobs.mdx b/docs/web/basics/jobs.mdx index 69801dc10..890c5d504 100644 --- a/docs/web/basics/jobs.mdx +++ b/docs/web/basics/jobs.mdx @@ -243,6 +243,90 @@ listing. It is a lazy iterator: iteration performs requests and can raise request errors. Use `list(db.list_jobs(...))` to collect all remaining results; there is no `.to_list()` method. +{/* Draft for the SDK and Enterprise releases that provide job listing metadata. + +With a server and SDK that provide listing metadata, `JobInfo` also exposes +`columns`, `function_name`, `function_version`, `completed_at_millis`, +`duration_millis`, and `failure`. Function names include their namespace, joined +by `$`, and the version is pinned to the computed column refresh. Duration is +creation-to-completion wall time, including queueing and pauses; running jobs +have no completed duration. Unknown scalar values and failure summaries stay +absent (`None` in Python/Rust, `undefined` in TypeScript), and unavailable or +non-column-scoped `columns` are empty. A zero duration is a measured value. +Failure summaries include phase, message, and retryability; open the job for +full diagnostics. + + +```python Python icon="python" +latest = next( + ( + info + for info in db.list_jobs(table="events", job_type="function_refresh") + if "embedding" in info.columns + ), + None, +) +if latest is not None: + print(latest.function_name, latest.function_version, latest.duration_millis) + if latest.failure is not None: + print(latest.failure.message) +``` + +```rust Rust icon="rust" +use futures::TryStreamExt; +use lancedb::{database::JobListFilter, listing::ListingOptions, Connection, Result}; + +async fn print_latest_refresh(db: &Connection) -> Result<()> { + let mut filter = JobListFilter::default(); + filter.table = Some("events".into()); + filter.job_types = vec!["function_refresh".into()]; + let mut jobs = db.list_jobs_filtered(filter, ListingOptions::default()); + while let Some(info) = jobs.try_next().await? { + if info.columns.iter().any(|column| column == "embedding") { + println!( + "{:?} {:?} {:?}", + info.function_name, info.function_version, info.duration_millis + ); + if let Some(failure) = info.failure { + println!("{:?}", failure.message); + } + break; + } + } + Ok(()) +} +``` + +```typescript TypeScript icon="js" +for await (const info of db.listJobs({ pageLimit: 50 })) { + if ( + info.jobType === "function_refresh" && + info.table === "events" && + info.columns.includes("embedding") + ) { + console.log(info.functionName, info.functionVersion, info.durationMillis); + if (info.failure !== undefined) { + console.log(info.failure.message); + } + break; + } +} +``` + + +Python and Rust support server-side table filtering. TypeScript `listJobs` +currently accepts only pagination options, so its example filters rows on the +client and may read more pages. The displayed table name has no namespace; +use a table name unique within the listed database for this TypeScript example. +Use Python, Rust, or SQL for an exact namespaced table listing. + +SQL `SHOW JOBS EXTENDED` and `SHOW JOBS EXTENDED FOR TABLE events` expose the +same metadata. Plain `SHOW JOBS` keeps its existing result columns. +The extended result returns `columns` as a list and `failure` as nullable JSON +text. + +*/} + Job filters and synchronous `Listing` indexing, slicing, and `len()` require a Python SDK release that includes these APIs. Older SDKs expose only diff --git a/docs/web/sql/ddl/job.mdx b/docs/web/sql/ddl/job.mdx index 8b507e6bc..914d2944b 100644 --- a/docs/web/sql/ddl/job.mdx +++ b/docs/web/sql/ddl/job.mdx @@ -34,6 +34,23 @@ values remain NULL. Children are read-only diagnostic identities. following backend continuation pages up to that limit. Child history can be `available`, `not_yet_recorded`, or `unavailable` after archival. +{/* Draft for the Enterprise release that provides extended job listing metadata. + +```sql +SHOW JOBS EXTENDED; +SHOW JOBS EXTENDED FOR TABLE documents; +``` + +`EXTENDED` adds `completed_at_millis`, `duration_millis`, `columns`, +`function_name`, `function_version`, and `failure` to database and table +listings. Plain `SHOW JOBS` keeps its existing result columns. `columns` is a +list, Function identity is pinned to the computed column refresh, and +`failure` is nullable JSON text with phase, message, and retryability. Duration +is creation-to-completion wall time, including queueing and pauses; it is +NULL when unfinished or unavailable. `EXTENDED` does not apply to `FOR JOB`. + +*/} + A job you completed weeks ago eventually stops appearing here -- it was archived, not deleted. Two deployment-scheduled jobs sweep the registry on a diff --git a/nodejs/__test__/remote.test.ts b/nodejs/__test__/remote.test.ts index 602239544..14b581a2c 100644 --- a/nodejs/__test__/remote.test.ts +++ b/nodejs/__test__/remote.test.ts @@ -2287,7 +2287,13 @@ describe("remote connection jobs surface", () => { .end( '{"jobs": [{"job_id": "job-2", "table": "t2", ' + '"job_type": "create_index", "state": "succeeded", ' + - '"created_at_millis": 2000}]}', + '"created_at_millis": 2000, "completed_at_millis": 2000, ' + + '"duration_millis": 0, "columns": ["embedding"], ' + + '"function_name": "features$embed", "function_version": "7"}, ' + + '{"job_id": "job-3", "table": "t2", "job_type": "function_refresh", ' + + '"state": "failed", "created_at_millis": 3000, "duration_millis": 200, ' + + '"completed_at_millis": 3200, "failure": {"phase": "execute", ' + + '"message": "worker failed", "retryable": false}}]}', ); } } else if (req.url === "/v1/jobs/describe") { @@ -2356,9 +2362,31 @@ describe("remote connection jobs surface", () => { }, async (db) => { const jobs = await collect(db.listJobs()); - expect(jobs.map((job) => job.jobId)).toEqual(["job-1", "job-2"]); + expect(jobs.map((job) => job.jobId)).toEqual([ + "job-1", + "job-2", + "job-3", + ]); expect(jobs[0].state).toEqual("running"); expect(jobs[1].state).toEqual("finished"); + expect(jobs[0].completedAtMillis).toBeUndefined(); + expect(jobs[0].durationMillis).toBeUndefined(); + expect(jobs[0].columns).toEqual([]); + expect(jobs[0].functionName).toBeUndefined(); + expect(jobs[0].functionVersion).toBeUndefined(); + expect(jobs[0].failure).toBeUndefined(); + expect(jobs[1].completedAtMillis).toBe(2000); + expect(jobs[1].durationMillis).toBe(0); + expect(jobs[1].columns).toEqual(["embedding"]); + expect(jobs[1].functionName).toBe("features$embed"); + expect(jobs[1].functionVersion).toBe("7"); + expect(jobs[1].failure).toBeUndefined(); + expect(jobs[2].state).toBe("failed"); + expect(jobs[2].durationMillis).toBe(200); + expect(jobs[2].failure?.phase).toBe("execute"); + expect(jobs[2].failure?.message).toBe("worker failed"); + expect(jobs[2].failure?.retryable).toBe(false); + expect(jobs[2].failure?.traceback).toBeUndefined(); expect(jobs[0].progress).toEqual({ // biome-ignore lint/style/useNamingConvention: server wire format job_type: "create_index", diff --git a/nodejs/src/job.rs b/nodejs/src/job.rs index cd7c6a469..211420ce9 100644 --- a/nodejs/src/job.rs +++ b/nodejs/src/job.rs @@ -288,6 +288,18 @@ pub struct JobInfo { pub state: String, /// When the job was created, in milliseconds since the epoch. pub created_at_millis: i64, + /// Terminal timestamp in milliseconds since the epoch, when known. + pub completed_at_millis: Option, + /// Creation-to-completion wall time, including queueing and pauses. + pub duration_millis: Option, + /// Affected columns; empty when unavailable or not column-scoped. + pub columns: Vec, + /// Pinned Function catalog name, with namespace segments joined by `$`. + pub function_name: Option, + /// Pinned Function version, when known. + pub function_version: Option, + /// Durable failure summary, when available. + pub failure: Option, /// Structured lifecycle, queue, pause, and job-type-specific progress. #[napi(ts_type = "Record")] pub progress: serde_json::Value, @@ -304,6 +316,12 @@ impl From for JobInfo { job_type: info.job_type, state: info.state, created_at_millis: info.created_at_millis, + completed_at_millis: info.completed_at_millis, + duration_millis: info.duration_millis, + columns: info.columns, + function_name: info.function_name, + function_version: info.function_version, + failure: info.failure.map(Into::into), progress, paused: info.paused, } diff --git a/python/python/lancedb/_lancedb.pyi b/python/python/lancedb/_lancedb.pyi index a930728d7..5fdeb56b2 100644 --- a/python/python/lancedb/_lancedb.pyi +++ b/python/python/lancedb/_lancedb.pyi @@ -492,6 +492,18 @@ class JobInfo: @property def created_at_millis(self) -> int: ... @property + def completed_at_millis(self) -> Optional[int]: ... + @property + def duration_millis(self) -> Optional[int]: ... + @property + def columns(self) -> list[str]: ... + @property + def function_name(self) -> Optional[str]: ... + @property + def function_version(self) -> Optional[str]: ... + @property + def failure(self) -> Optional[JobFailureInfo]: ... + @property def progress(self) -> Optional[dict[str, Any]]: ... @property def paused(self) -> bool: ... diff --git a/python/python/tests/test_remote_db.py b/python/python/tests/test_remote_db.py index 4e531262d..162522a83 100644 --- a/python/python/tests/test_remote_db.py +++ b/python/python/tests/test_remote_db.py @@ -6984,10 +6984,29 @@ def test_remote_connection_jobs_surface(): dict( job_id="job-2", table="t2", - job_type="create_index", + job_type="function_refresh", state="succeeded", created_at_millis=2000, - ) + completed_at_millis=2000, + duration_millis=0, + columns=["embedding"], + function_name="features$embed", + function_version="7", + ), + dict( + job_id="job-3", + table="t2", + job_type="function_refresh", + state="failed", + created_at_millis=3000, + completed_at_millis=3200, + duration_millis=200, + failure=dict( + phase="execute", + message="worker failed", + retryable=False, + ), + ), ] ) request.send_response(200) @@ -7085,7 +7104,7 @@ def test_remote_connection_jobs_surface(): with mock_lancedb_connection(handler) as db: jobs = list(db.list_jobs()) - assert [job.job_id for job in jobs] == ["job-1", "job-2"] + assert [job.job_id for job in jobs] == ["job-1", "job-2", "job-3"] assert jobs[0].state == "running" assert jobs[0].table == "t1" assert jobs[0].progress == { @@ -7099,6 +7118,24 @@ def test_remote_connection_jobs_surface(): } assert jobs[0].paused is True assert jobs[1].state == "finished" + assert jobs[0].completed_at_millis is None + assert jobs[0].duration_millis is None + assert jobs[0].columns == [] + assert jobs[0].function_name is None + assert jobs[0].function_version is None + assert jobs[0].failure is None + assert jobs[1].completed_at_millis == 2000 + assert jobs[1].duration_millis == 0 + assert jobs[1].columns == ["embedding"] + assert jobs[1].function_name == "features$embed" + assert jobs[1].function_version == "7" + assert jobs[1].failure is None + assert jobs[2].state == "failed" + assert jobs[2].duration_millis == 200 + assert jobs[2].failure.phase == "execute" + assert jobs[2].failure.message == "worker failed" + assert jobs[2].failure.retryable is False + assert jobs[2].failure.traceback is None assert db.cancel_job("job-1") is True assert db.cancel_job("missing") is False diff --git a/python/src/job.rs b/python/src/job.rs index fdaa67ba6..54c22a8e1 100644 --- a/python/src/job.rs +++ b/python/src/job.rs @@ -254,6 +254,18 @@ pub struct JobInfo { job_type: String, state: String, created_at_millis: i64, + /// Terminal timestamp in milliseconds since the epoch, when known. + completed_at_millis: Option, + /// Creation-to-completion wall time, including queueing and pauses. + duration_millis: Option, + /// Affected columns; empty when unavailable or not column-scoped. + columns: Vec, + /// Pinned Function catalog name, with namespace segments joined by `$`. + function_name: Option, + /// Pinned Function version, when known. + function_version: Option, + /// Durable failure summary, when available. + failure: Option, _progress_json: Option, paused: bool, } @@ -290,6 +302,12 @@ impl From for JobInfo { job_type: info.job_type, state: info.state, created_at_millis: info.created_at_millis, + completed_at_millis: info.completed_at_millis, + duration_millis: info.duration_millis, + columns: info.columns, + function_name: info.function_name, + function_version: info.function_version, + failure: info.failure.map(Into::into), _progress_json: Some(progress), paused: info.paused, } diff --git a/rust/lancedb/src/database.rs b/rust/lancedb/src/database.rs index d53383ce5..b89c9f95e 100644 --- a/rust/lancedb/src/database.rs +++ b/rust/lancedb/src/database.rs @@ -291,6 +291,20 @@ pub struct JobInfo { pub state: String, /// When the job was created, in milliseconds since the epoch. pub created_at_millis: i64, + /// Terminal timestamp, in milliseconds since the epoch; unknown on older servers. + pub completed_at_millis: Option, + /// Creation-to-completion wall time, including queueing and pauses. + /// Absent for unfinished jobs or when the server cannot establish the duration. + pub duration_millis: Option, + /// Columns affected by this job. Empty when unavailable or not column-scoped. + pub columns: Vec, + /// Pinned Function catalog name, with namespace segments joined by `$`. + /// Present for computed column refreshes when supplied by the server. + pub function_name: Option, + /// Pinned Function version, when supplied by the server. + pub function_version: Option, + /// Durable failure summary; absent when unavailable or the job did not fail. + pub failure: Option, /// Latest progress sample for a job type that reports structured progress. pub progress: Option, /// Coarse server-derived phase, including phases introduced by newer diff --git a/rust/lancedb/src/remote/db.rs b/rust/lancedb/src/remote/db.rs index def3c85fd..2e91fc15d 100644 --- a/rust/lancedb/src/remote/db.rs +++ b/rust/lancedb/src/remote/db.rs @@ -742,6 +742,18 @@ struct RemoteListJobRow { #[serde(default)] created_at_millis: i64, #[serde(default)] + completed_at_millis: Option, + #[serde(default)] + duration_millis: Option, + #[serde(default)] + columns: Vec, + #[serde(default)] + function_name: Option, + #[serde(default)] + function_version: Option, + #[serde(default)] + failure: Option, + #[serde(default)] progress: Option, #[serde(default)] phase: Option, @@ -1371,6 +1383,12 @@ impl Database for RemoteDatabase { job_type: row.job_type, state: job_state_to_client(&row.state), created_at_millis: row.created_at_millis, + completed_at_millis: row.completed_at_millis, + duration_millis: row.duration_millis, + columns: row.columns, + function_name: row.function_name, + function_version: row.function_version, + failure: row.failure, progress: row.progress, phase: row.phase, paused: row.paused, @@ -4628,7 +4646,7 @@ mod tests { http::Response::builder() .status(200) .body( - r#"{"jobs": [{"job_id": "job-2", "table": "t2", "job_type": "create_index", "state": "succeeded", "created_at_millis": 2000}, {"job_id": "job-3", "table": "t3", "job_type": "create_index", "state": "timed_out", "created_at_millis": 3000}]}"#, + r#"{"jobs": [{"job_id": "job-2", "table": "t2", "job_type": "create_index", "state": "succeeded", "created_at_millis": 2000}, {"job_id": "job-3", "table": "t3", "job_type": "create_index", "state": "timed_out", "created_at_millis": 3000, "completed_at_millis": 3000, "duration_millis": 0, "columns": ["embedding"], "function_name": "features$embed", "function_version": "7", "failure": {"phase": "execute", "message": "worker failed", "retryable": false}}]}"#, ) .unwrap() } @@ -4646,11 +4664,26 @@ mod tests { assert_eq!(jobs[0].progress.as_ref().unwrap()["rows_computed"], 4); assert_eq!(jobs[0].phase.as_deref(), Some("running")); assert!(jobs[0].paused); + assert_eq!(jobs[0].completed_at_millis, None); + assert_eq!(jobs[0].duration_millis, None); + assert!(jobs[0].columns.is_empty()); + assert_eq!(jobs[0].function_name, None); + assert_eq!(jobs[0].function_version, None); + assert_eq!(jobs[0].failure, None); assert_eq!(jobs[1].job_id, "job-2"); assert_eq!(jobs[1].state, "finished"); assert_eq!(jobs[1].created_at_millis, 2000); assert_eq!(jobs[2].job_id, "job-3"); assert_eq!(jobs[2].state, "failed"); + assert_eq!(jobs[2].completed_at_millis, Some(3000)); + assert_eq!(jobs[2].duration_millis, Some(0)); + assert_eq!(jobs[2].columns, ["embedding"]); + assert_eq!(jobs[2].function_name.as_deref(), Some("features$embed")); + assert_eq!(jobs[2].function_version.as_deref(), Some("7")); + let failure = jobs[2].failure.as_ref().unwrap(); + assert_eq!(failure.message.as_deref(), Some("worker failed")); + assert_eq!(failure.retryable, Some(false)); + assert_eq!(failure.traceback, None); } #[tokio::test]