From d9b49e8889ada1f5eed6d6019cf57f0301a5ac60 Mon Sep 17 00:00:00 2001 From: Yang Cen Date: Sun, 22 Nov 2026 16:00:50 +0800 Subject: [PATCH] feat: report capacity waits in function refresh job status (#5154) An Enterprise Function refresh can spend time waiting for execution workers. Applications polling `job.status()` currently see `running` during that wait. Return `waiting_for_capacity` when the server reports that phase for an active Function refresh. The next status request reports `running` when execution resumes. Applications can use `job.wait()` to wait through both states until completion. Rust, Python and Node read the phase from the existing job description response. ## Validation Two HTTP regression tests exercise the public job handle. They cover the wait, work resuming, completion after another wait, a stale phase at completion, queued and paused refreshes, other job types, and servers that omit the phase. The Rust CI remote job runs these tests. --- docs/src/js/classes/Job.md | 4 +- docs/web/basics/jobs.mdx | 13 ++++--- nodejs/lancedb/job.ts | 4 +- nodejs/src/job.rs | 4 +- python/python/lancedb/job.py | 13 ++++--- rust/lancedb/src/job.rs | 21 ++++++++--- rust/lancedb/src/remote/db.rs | 69 +++++++++++++++++++++++++++++++++++ 7 files changed, 104 insertions(+), 24 deletions(-) diff --git a/docs/src/js/classes/Job.md b/docs/src/js/classes/Job.md index 6d30996d2..86c5abc1f 100644 --- a/docs/src/js/classes/Job.md +++ b/docs/src/js/classes/Job.md @@ -449,8 +449,8 @@ Select this exact attempt's pinned successor. Requires backend support. status(): Promise ``` -The operation's current lifecycle state: "running", "finished", "failed", -or "cancelled". +The current status, usually "running", "finished", "failed", or "cancelled". +A Function refresh waiting for execution workers reports "waiting_for_capacity". A point snapshot; unlike [Job.wait](Job.md#wait) it does not block or reject on a terminal failure state. Also refreshes the getters above. diff --git a/docs/web/basics/jobs.mdx b/docs/web/basics/jobs.mdx index cdff84339..80726a5f1 100644 --- a/docs/web/basics/jobs.mdx +++ b/docs/web/basics/jobs.mdx @@ -106,10 +106,10 @@ print(result, job.spec()) ``` -The four lifecycle strings below are the usual SDK contract; newer server -states may pass through an older client. Do not infer execution progress from -`state` alone. Structured progress methods and queue fields require matching -SDK/server support; see [refresh admission](/feature-engineering/refresh-column#admission). +`job.state()` reports the last observed lifecycle state, usually `running`, +`finished`, `failed`, or `cancelled`. Newer server states may pass through an +older client. For execution progress and queue details, use `job.progress()` +with a supporting SDK and server. See [refresh admission](/feature-engineering/refresh-column#admission). ## Submit and wait for a job {#waiting} @@ -120,11 +120,12 @@ SDK/server support; see [refresh admission](/feature-engineering/refresh-column# result. If it failed or was cancelled, inspect the failure details and any results it committed before stopping. -In Python, `job.status()` returns the current state: +In Python, `job.status()` reports the current status. -| State | Meaning | +| Status | Meaning | | --- | --- | | `running` | The operation is in progress. | +| `waiting_for_capacity` | An Enterprise Function refresh is waiting for execution workers. This status is nonterminal. It returns to `running` when execution resumes. | | `finished` | The operation completed successfully. | | `failed` | The operation failed. | | `cancelled` | The operation was cancelled. | diff --git a/nodejs/lancedb/job.ts b/nodejs/lancedb/job.ts index 49b83477c..a8298c8b9 100644 --- a/nodejs/lancedb/job.ts +++ b/nodejs/lancedb/job.ts @@ -251,8 +251,8 @@ export class Job { } /** - * The operation's current lifecycle state: "running", "finished", "failed", - * or "cancelled". + * The current status, usually "running", "finished", "failed", or "cancelled". + * A Function refresh waiting for execution workers reports "waiting_for_capacity". * * A point snapshot; unlike {@link Job.wait} it does not block or reject on a * terminal failure state. Also refreshes the getters above. diff --git a/nodejs/src/job.rs b/nodejs/src/job.rs index 0ff4b916b..b76793717 100644 --- a/nodejs/src/job.rs +++ b/nodejs/src/job.rs @@ -106,8 +106,8 @@ impl Job { self.inner.execution_epoch() } - /// The operation's current lifecycle state: "running", "finished", - /// "failed", or "cancelled". + /// The current status, usually "running", "finished", "failed", or "cancelled". + /// A Function refresh waiting for execution workers reports "waiting_for_capacity". /// /// A point snapshot; unlike {@link Job.wait} it does not block or reject /// on a terminal failure state. States a newer server reports that this diff --git a/python/python/lancedb/job.py b/python/python/lancedb/job.py index 6bdb026f7..778d44e2b 100644 --- a/python/python/lancedb/job.py +++ b/python/python/lancedb/job.py @@ -316,8 +316,9 @@ class AsyncJob(Generic[T]): return self._inner.id if self._inner is not None else None async def status(self) -> str: - """The operation's current lifecycle state: "running", "finished", - "failed", or "cancelled". + """Return the current status, usually "running", "finished", "failed", + or "cancelled". A Function refresh waiting for execution workers reports + "waiting_for_capacity". A point snapshot; unlike `wait` it does not block or raise on a terminal failure state. States a newer server reports that this @@ -384,8 +385,7 @@ class AsyncJob(Generic[T]): Queue metadata and counters are included when supplied by the server. Older servers may omit counters, and in-process operations return ``None``. A missing - counter is unknown rather than zero. This is additive to :meth:`status`, - whose string contract is unchanged. + counter is unknown rather than zero. """ if self._inner is None: return None @@ -1070,8 +1070,9 @@ class Job(Generic[T]): return self._inner._id if self._inner is not None else None def status(self) -> str: - """The operation's current lifecycle state: "running", "finished", - "failed", or "cancelled". + """Return the current status, usually "running", "finished", "failed", + or "cancelled". A Function refresh waiting for execution workers reports + "waiting_for_capacity". See :meth:`AsyncJob.status`. """ diff --git a/rust/lancedb/src/job.rs b/rust/lancedb/src/job.rs index 44928eca7..5485c8905 100644 --- a/rust/lancedb/src/job.rs +++ b/rust/lancedb/src/job.rs @@ -516,17 +516,25 @@ where }; match handle.describe().await { Ok(description) => { - let state = description.state.clone(); let mut cache = self.cache_write(); - cache.state = Some(state.clone()); + cache.state = Some(description.state.clone()); cache.lifecycle_state = Some( description .lifecycle_state .clone() - .unwrap_or_else(|| JobState::from(state.as_str())), + .unwrap_or_else(|| JobState::from(description.state.as_str())), ); + let status = if cache.lifecycle_state == Some(JobState::InProgress) + && description.job_type == "function_refresh" + && description.paused_at_millis.is_none() + && description.phase.as_deref() == Some("waiting_for_capacity") + { + "waiting_for_capacity".to_owned() + } else { + description.state.clone() + }; cache.description = Some(description); - Ok(state) + Ok(status) } // An in-process job knows its own state and nothing more. Err(Error::NotSupported { .. }) => { @@ -540,8 +548,9 @@ where } } - /// The operation's current lifecycle state: "running", "finished", - /// "failed", or "cancelled". + /// The current status, usually "running", "finished", "failed", or "cancelled". + /// A running Function refresh reports "waiting_for_capacity" while it + /// waits for execution workers. [`Job::wait`] continues polling during this wait. /// /// A point snapshot; unlike [`Job::wait`] it does not block, raise on a /// terminal failure state, or retry. States a newer server reports that diff --git a/rust/lancedb/src/remote/db.rs b/rust/lancedb/src/remote/db.rs index b44d6e26f..9b26c9f3b 100644 --- a/rust/lancedb/src/remote/db.rs +++ b/rust/lancedb/src/remote/db.rs @@ -5126,6 +5126,75 @@ mod tests { )); } + #[tokio::test] + async fn function_refresh_status_tracks_capacity_without_ending_wait() { + let polls = Arc::new(AtomicUsize::new(0)); + let count = polls.clone(); + let conn = Connection::new_with_handler(move |request| { + assert_eq!(request.url().path(), "/v1/jobs/describe"); + // Open, status while waiting, status after admission, another wait + // observed inside wait(), and finally a successful completion. + let (state, phase) = match count.fetch_add(1, Ordering::SeqCst) { + 0 | 1 | 3 => ("IN_PROGRESS", "waiting_for_capacity"), + 2 => ("IN_PROGRESS", "running"), + _ => ("SUCCEEDED", "waiting_for_capacity"), + }; + http::Response::builder() + .status(200) + .body( + serde_json::json!({ + "job_id": "job-1", "job_type": "function_refresh", + "job_state": state, "phase": phase, "creation_ms": 1 + }) + .to_string(), + ) + .unwrap() + }); + let job = conn.open_job("job-1").await.unwrap(); + assert_eq!(job.status().await.unwrap(), "waiting_for_capacity"); + assert_eq!(job.state().as_deref(), Some("running")); + assert_eq!(job.status().await.unwrap(), "running"); + job.wait().await.unwrap(); + assert_eq!(job.status().await.unwrap(), "finished"); + assert!(polls.load(Ordering::SeqCst) >= 6); + } + + #[tokio::test] + async fn capacity_status_requires_an_active_function_refresh() { + for (job_type, lifecycle, phase, paused_at) in [ + ( + "create_index", + "in_progress", + Some("waiting_for_capacity"), + None, + ), + ( + "function_refresh", + "in_progress", + Some("waiting_for_capacity"), + Some(42), + ), + ( + "function_refresh", + "queued", + Some("waiting_for_capacity"), + None, + ), + ("function_refresh", "in_progress", None, None), + ] { + let conn = Connection::new_with_handler(move |_| { + http::Response::builder().status(200).body( + serde_json::json!({ + "job_id": "job-1", "job_type": job_type, "job_state": "IN_PROGRESS", + "lifecycle_state": lifecycle, "phase": phase, "paused_at_millis": paused_at + }).to_string() + ).unwrap() + }); + let job = conn.open_job("job-1").await.unwrap(); + assert_eq!(job.status().await.unwrap(), "running"); + } + } + #[tokio::test] async fn test_conn_job_waits_to_done() { let polls = Arc::new(AtomicUsize::new(0));