Skip to content

Rework the interface for session task to get result from registered upload#690

Merged
seanses merged 7 commits intomainfrom
di/update-session-task-result-api
Mar 11, 2026
Merged

Rework the interface for session task to get result from registered upload#690
seanses merged 7 commits intomainfrom
di/update-session-task-result-api

Conversation

@seanses
Copy link
Collaborator

@seanses seanses commented Mar 9, 2026

This PR updates the interface for retrieving per-task results after UploadCommit::commit() or DownloadGroup::finish(). The problem with the previous interface is that commit() and finish() return a vector of FileMetadata or DownloadResult, making it difficult for users to associate each result with a specific task.

The new interface uses task_id as a strong binding bridge:

Upload per-task result access patterns

After commit() completes, there are two equivalent ways to retrieve a per-task FileMetadata result:

  1. Lookup in the global result map:
let commit = session.new_upload_commit()?;
let handle = commit.upload_from_path(src)?;
let results = commit.commit()?;
let result = results.get(&handle.task_id)
  1. Direct access from the handle:
let commit = session.new_upload_commit()?;
let handle = commit.upload_from_path(src)?;
commit.commit()?;
// handle.result() is populated by commit() via the shared Arc.
let result = handle.result()

Download per-task result access patterns

The pattern is similar to the above.

Why not put results in a vector in the same order as tasks are registered to the commit instance?

After a commit instance is created, it can be cloned (since it is itself an Arc wrapping an internal struct) and sent to different threads. When multiple threads are registering tasks, there is no static registration order that a program can observe upfront.

Fix XET-890

@seanses seanses changed the title Rework task get result interface Rework session task get result interface Mar 9, 2026
@seanses seanses marked this pull request as ready for review March 9, 2026 23:05
@seanses seanses changed the title Rework session task get result interface Rework the interface for session task to get result Mar 9, 2026
@seanses seanses changed the title Rework the interface for session task to get result Rework the interface for session task to get result from registered upload Mar 11, 2026
// Enqueue all uploads; each starts immediately in the background.
let n_files = files.len();
let handles: Vec<TaskHandle> = files
let handles: Vec<_> = files
Copy link
Contributor

Choose a reason for hiding this comment

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

for the sake of examples, can we avoid omitting types, this makes me have to go to the code to figure out all the return types I need to use, making the example less useful (still useful, but more useful with no explicit type omissions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes for sure! Inserted types

Copy link
Collaborator

@hoytak hoytak left a comment

Choose a reason for hiding this comment

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

LGTM. Some minor thoughts, but I think we should get this in and then iterate.

@seanses seanses merged commit cacd713 into main Mar 11, 2026
7 checks passed
@seanses seanses deleted the di/update-session-task-result-api branch March 11, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants