Skip to content

feat: create_index returns a Job handle - #3742

Merged
wkalt merged 12 commits into
lancedb:mainfrom
wkalt:wyatt/create-index-job-handle
Jul 31, 2026
Merged

wkalt merged 12 commits into
lancedb:mainfrom
wkalt:wyatt/create-index-job-handle

Conversation

@wkalt

@wkalt wkalt commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

IndexBuilder::execute now returns a Job with wait and cancel methods. Local tables build the index synchronously and return an already-done job. Remote tables read the job id the server returns from create_index and track it through the /v1/jobs API: wait polls describe until the job reaches a terminal state and cancel posts a cancellation. Servers that return no job id yield a done job, so behavior against older servers is unchanged. The job id is not exposed on the handle.

The Python and TypeScript bindings keep their current signatures and discard the handle; exposing Job there is left to follow-ups.

@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 Rust Rust related issues labels Jul 28, 2026
@wjones127
wjones127 self-requested a review July 28, 2026 23:28

@wjones127 wjones127 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.

I'd like to understand a little more expected usage, and have various non-blocking suggestions.

Comment thread rust/lancedb/src/remote/job.rs Resolved
Comment thread rust/lancedb/src/remote/job.rs Resolved
Comment thread rust/lancedb/src/error.rs Outdated
Comment on lines +45 to +46
#[snafu(display("Job was cancelled"))]
JobCancelled,

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.

suggestion: is there at least a job id that could be exposed here? That way if it's unknown why the job was cancelled we might be able to find the answer in logs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated, thanks

Comment thread rust/lancedb/examples/simple.rs Outdated
Comment on lines +121 to +124
table
.create_index(&["vector"], Index::Auto)
.execute()
.await?;

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.

question(blocking): what does this .await wait for? The job to start? or the completion of the job?

My initial idea was that Job itself implemented IntoFuture, but that might make an awkward API like:

    table
        .create_index(&["vector"], Index::Auto)
        .execute()
        .await?
        .await?;

(double await)

Alternatively the API now is:

    table
        .create_index(&["vector"], Index::Auto)
        .execute()
        .await?
        .wait()
        .await?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

.await here is awaiting submission of the job in the remote SDK. That is not the same as start or completion necessarily. In general I have been thinking of the usual calling style as less pipelined, like

let job = table.create_index(...).execute().await?

job.wait().await?;
// ... or
job.cancel().await?;

Chaining cancel() doesn't make much sense and having styles for the two seems a bit odd to me. What do you think, do you prefer the first?

Comment thread rust/lancedb/src/job.rs Resolved
Comment thread rust/lancedb/src/job.rs
Comment on lines +22 to +24
pub struct Job {
handle: Option<Box<dyn JobHandle>>,
}

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.

thought: part of me wonders whether we need both layers. Maybe we should just return Box<dyn JobHandle>, and local operations just have a job handle where wait() returns immediately and cancel() errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Returning Box<dyn JobHandle> seems like a less clean and less extensible public API than returning a concrete Job to me. What do you see as the advantage?

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 was seeing them as roughly equivalent to the user, and Box<dyn JobHandle> just seemed like strictly less code.

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.

suggestion: should we have a test that has two tasks one calling wait() and then another starting a bit later concurrently calling cancel(). What happens to the wait() future? Does that error? (This might be defined more by server behavior, I suppose.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, defined by the server I think. We should add this test in enterprise though.

@wkalt
wkalt force-pushed the wyatt/create-index-job-handle branch from 6ff4454 to 2a58d82 Compare July 29, 2026 00:01
@wkalt

wkalt commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@wjones127 thanks for the review, updated/responded to your comments

@cmccabe

cmccabe commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

In the past we talked about having the remote API block in a similar fashion to the local API. In other words, making non-blocking an option, while blocking was the default. This PR seems to go in a different direction by continuing the existing behavior of treating enterprise as a special case with different rules from local.

I also don't understand the thinking behind not exposing the job ID, can you clarify? It seems like something users would certainly want. Or did I misunderstand and the ID will be accessible through a future API?

@github-actions github-actions Bot added the Python Python SDK label Jul 29, 2026
@wkalt
wkalt force-pushed the wyatt/create-index-job-handle branch from 957ae8c to 74a737e Compare July 29, 2026 15:22
wkalt and others added 2 commits July 29, 2026 14:51
IndexBuilder::execute_async returns a Job exposing wait and cancel,
leaving execute unchanged. Local tables build the index synchronously
and return an already-done job. Remote tables read the job id the
server returns from create_index and track it through the /v1/jobs API:
wait polls describe until the job reaches a terminal state and cancel
posts a cancellation. Servers that return no job id yield a done job.
The job id is not exposed on the handle.

Keeping execute as it is means a future release can give OSS tables a
live job without silently changing what an existing call waits for.

Co-Authored-By: Claude Fable 5 <[email protected]>
Parse the describe response into a typed struct with a JobState enum;
states this client does not know count as still running. The job error
variants carry the job id so a failure or cancellation can be traced in
server logs. Rename Job::done to new_done.

Co-Authored-By: Claude Fable 5 <[email protected]>
@wkalt
wkalt force-pushed the wyatt/create-index-job-handle branch from 74a737e to e12a8f8 Compare July 29, 2026 21:53
wkalt and others added 2 commits July 29, 2026 15:06
create_index is unchanged. create_index_async returns an AsyncJob on
async tables and a Job on sync ones, each with wait and cancel. Job
failures raise JobFailedError and cancellations JobCancelledError.

Co-Authored-By: Claude Fable 5 <[email protected]>
createIndex is unchanged. createIndexAsync returns a Job exposing wait
and cancel.

Co-Authored-By: Claude Fable 5 <[email protected]>
@wkalt
wkalt force-pushed the wyatt/create-index-job-handle branch from e12a8f8 to 29dc516 Compare July 29, 2026 22:07
execute_async on a local table now spawns the index build instead of
building it inline, so wait and cancel do the same thing they do against
a server: wait resolves when the build finishes, and cancel aborts it.
Input is validated before spawning so bad arguments still surface from
execute_async itself. Job ids are server-side, so the error variants
carry an optional one.

Co-Authored-By: Claude Fable 5 <[email protected]>
@wkalt
wkalt force-pushed the wyatt/create-index-job-handle branch from 02447e1 to 192c11a Compare July 29, 2026 23:47
@wkalt
wkalt requested a review from wjones127 July 30, 2026 15:38
Job::id returns the id the server assigned, for correlating with server
logs or the jobs API. Jobs that run in this process have none and return
None. The value is opaque; resuming a job from an id is not supported.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread rust/lancedb/src/job.rs Outdated
#[async_trait]
impl JobHandle for SpawnedJob {
async fn wait(&self) -> Result<()> {
let Some(task) = self.task.lock().await.take() else {

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.

issue (blocking): self.task.lock().await.take() means only the first caller of wait() on a given Job ever observes the real outcome — every subsequent (or concurrently racing) caller gets a spurious Ok(()) even if the build actually failed or was cancelled; acceptance criterion: add a test with two tasks both awaiting the same Job::wait() (or one wait() racing a cancel()) and make every caller see the correct terminal result, e.g. by storing the result behind a tokio::sync::watch/OnceCell instead of consuming the JoinHandle.

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'm open to multiple ways to solve this, but I think the current behavior seems wrong. We could either make it impossible for multiple calls to wait() to happen or else support multiple callers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added in 070c096. Multiple callers are now supported and the same result is returned to all via a tokio::sync::watch.

)
)

def create_index_async(

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.

question (non-blocking): Local Table.create_index_async exposes replace, but this remote counterpart doesn't — is that intentional (matching submit_create_index in Rust, which never reads index.replace for remote tables), or a gap that should be closed for parity?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated in 62ce3d5

async def test_create_index_async_returns_done_job(some_table: AsyncTable):
job = await some_table.create_index_async("id", config=BTree())
await job.wait()
await job.cancel()

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.

nitpick: Add an assertion that the index actually exists after wait() so this test can't pass if index creation silently no-ops.

Suggested change
await job.cancel()
job = await some_table.create_index_async("id", config=BTree())
await job.wait()
assert len(await some_table.list_indices()) == 1
await job.cancel()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated in e743bc0

Comment thread rust/lancedb/src/job.rs
Comment on lines +22 to +24
pub struct Job {
handle: Option<Box<dyn JobHandle>>,
}

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 was seeing them as roughly equivalent to the user, and Box<dyn JobHandle> just seemed like strictly less code.

const job = await tbl.createIndexAsync("vec");
expect(job.id).toBeNull();
await job.wait();
await job.cancel();

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.

question(blocking): is the behavior of cancel after completion to silently pass? Maybe worth a comment here that's what's going on. It does seem consistent with some other systems that cancelling something that finished silently succeeds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, that's intended. I'll make sure it's documented, thanks.

Comment thread rust/lancedb/src/remote/job.rs Outdated
Comment on lines +32 to +33
#[serde(other)]
Other,

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.

suggestion: I wonder if this could somehow be:

Suggested change
#[serde(other)]
Other,
#[serde(other)]
Other(String),

so we an print it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated

wkalt and others added 5 commits July 30, 2026 11:58
wait took the JoinHandle, so only the first caller saw the real outcome
and later ones were told the job succeeded even when it had failed or
been cancelled. A second task now watches the first and publishes the
outcome, which every waiter reads. Watching also gives an aborted job an
outcome, which it previously only had for the caller that consumed it.

Co-Authored-By: Claude Fable 5 <[email protected]>
An unknown state was collapsed into a unit variant, so a client polling
a state it does not know had nothing to report. It now carries the name
and is logged while polling continues.

Co-Authored-By: Claude Fable 5 <[email protected]>
The local counterpart takes it, and the remote create_index already
accepts it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Also note in the nodejs test that cancelling a finished job is a no-op.

Co-Authored-By: Claude Fable 5 <[email protected]>
The method was only on the concrete tables, so it was missing from the
abstract base the docs point at, and the job types were not importable
from the package.

Co-Authored-By: Claude Fable 5 <[email protected]>
@wkalt
wkalt requested a review from wjones127 July 30, 2026 21:24

@wjones127 wjones127 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.

On piece of non-blocking feedback. Nice work on this!

Comment thread rust/lancedb/src/job.rs Outdated
tokio::spawn(async move {
let outcome = match task.await {
Ok(Ok(())) => Outcome::Succeeded,
Ok(Err(err)) => Outcome::Failed(err.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.

issue (non-blocking): Local job failures now always collapse to a generic Error::JobFailed{message}, losing the original error's variant (previously Ok(result) => result preserved it) — necessitated by Outcome needing Clone. Consider Outcome::Failed(Arc<Error>) instead of stringifying, so callers can still match on the underlying error kind.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm a little bit stumped on this because the remote SDK won't be able to do that with the same fidelity as local. I wonder if we may need some kind of error protocol in the public API to address this correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

actually, I guess this same problem must exist in a lot of places in the SDK so it shouldn't be a design blocker here. We can afford some divergence and standardize it all later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added more info to the failure message and attached the source error for the local case.

A failed job reported "job reached the FAILED state", a string invented to
satisfy a non-optional message field, and locally the real error was
stringified so its type was lost. JobFailed now carries a JobFailure whose
fields are absent when the backend cannot supply them: a local job keeps the
error it failed with, a remote job carries what the server reported, and a
server that reports nothing yields "Job <id> failed" with nothing invented.

The shape is the same on both backends so callers need not branch. Phase and
retryability stay absent locally, since everything reaching wait() is the build
stage and classifying retryability here could disagree with the server.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@wkalt
wkalt merged commit a6418b6 into lancedb:main Jul 31, 2026
25 checks passed
wkalt added a commit that referenced this pull request Jul 31, 2026
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.

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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