Skip to content

Rust SDK uploads and ingests local files - #2195

Open
yorkhellen wants to merge 1 commit into
ClickHouse:mainfrom
yorkhellen:feat/rust-file-ingestion
Open

yorkhellen wants to merge 1 commit into
ClickHouse:mainfrom
yorkhellen:feat/rust-file-ingestion

Conversation

@yorkhellen

@yorkhellen yorkhellen commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Part of issue #52. This implements file ingestion helpers and does not close the issue.

Related: #52

Changelog category

  • New Feature

Changelog entry

The Rust SDK uploads and downloads files, starts local file ingestion, and waits for ingestion status through async and blocking clients. File ingestion errors retain the upload, prepared submission, job ID and last status when those values are known.

Why

Uploading a local file requires binary HTTP, a content digest, an ingestion request and status polling. Typed helpers let callers perform that sequence through the configured client and save a returned job ID before waiting.

let job = client.knowledge_start_file_ingest("notes.pdf").await?;
let status = client.knowledge_wait_for_ingest(&job.ingestion_id).await?;
let bytes = client.knowledge_download(&job.source_uri).await?;

The helpers reuse the existing transport for authentication, retry decisions and final request metadata. Binary requests own a shared Bytes payload so cloning a request for an HTTP attempt does not copy the whole file. sha2 moves from test dependencies to runtime dependencies to hash the bytes sent; bytes becomes a direct dependency and is already used by the HTTP transport.

Scope and risk

  • Five helper groups, each with a default and options method, on both clients: upload, download, ingest file, start file ingest, and wait for ingest. Existing client entry points stay flat.
  • Typed upload output and business options, plus Error::ingest_context() for known recovery information. The original error source, category and retryability remain available. Metadata describes the final attempt of the last logical request.
  • Files and downloads are fully buffered. File reads, path resolution and hashing run in the blocking pool. This is not a streaming API.
  • Default source URIs follow CPython 3.14 non-strict path resolution and retain raw path characters. Native differential CI covers Linux and Windows with the minimum and stable Rust toolchains. Native Windows execution and real UNC fixtures remain unverified locally.
  • Waiting returns complete terminal statuses, including failed, partial, cancelled and not-found results. Callers must check the status and retrieval fields before treating ingestion as successful. The wait timeout starts after submission and does not interrupt an HTTP request or shorten the polling sleep.
  • An unknown submission result is not automatically resubmitted. Retaining a prepared request does not prove that the server rejected it. Durable recovery after a lost submission response requires a separate server contract and is outside this PR.
  • Dropping an ingestion future does not guarantee a returned job ID. Callers that need to resume waiting should use start, save the returned ID, then wait. The example refuses to overwrite an existing ID file.

Compatibility, rollout and rollback

  • Wire: no operations, fields or server defaults change. The helpers call the existing upload, download, ingestion and ingestion-status routes. No generated SDK files change.
  • Operator steps: none. No migration, setting or deployment order is required.
  • Existing public binary requests still accept Vec<u8>; only their private storage changes to Bytes. The minimum Rust version remains 1.85.
  • Rollback removes the SDK helpers and native path workflow. Uploaded files and ingestion jobs follow the existing server lifecycle; no new storage is introduced.
  • Public documentation will be updated after merge and the next SDK release so examples refer to a published version.

Tests

Against the latest upstream baseline:

  • LOOM_ENV_FILE= make format, make lint and make typecheck: passed, including all generator checks.
  • cargo test --locked --all-targets: 677 passed, 0 failed, 7 ignored.
  • cargo test --locked --all-targets --features blocking: 722 passed, 0 failed, 8 ignored.
  • cargo test --locked --doc, with and without --features blocking: each passed 10 tests, with no failures or ignored tests.
  • cargo clippy --locked --all-targets -- -D warnings, with and without --features blocking: passed.
  • cargo +1.85.1 check --locked --all-targets, with and without --features blocking, and cargo fmt --check: passed.
  • python sdk/rust/tests/native_paths/check.py --toolchain 1.85.1 and --toolchain stable, with CPython 3.14.7 on macOS: each passed 14 resolver tests and 37 differential cases.
  • Native harness Ruff checks and probe rustfmt: passed.
  • LOOM_ENV_FILE= .venv/bin/python -m pytest tests/unit/test_public_copy.py -q: 6 passed.
  • cargo package --list --allow-dirty --manifest-path sdk/rust/Cargo.toml: includes both new modules, the example and all new test files. This checks package contents, not installation of a published crate.
  • Independent source review found no verified defects in the complete feature diff and separately passed 14 resolver tests and 37 differential cases on macOS. Hosted platform evidence remains pending.
  • Draft and new public source prose checks, plus git diff --check: passed.

Earlier integration validation exercised all 20 helpers against a disposable server and database, with deterministic extraction and a fake embedder. The three Python ingestion/download contract files passed 179 tests in an isolated Linux environment. These runs precede the latest upstream sync and do not verify real document parsers.

The existing authenticated Rust live tests remain ignored and require disposable tenant tokens. Native hosted CI, including Windows filesystem behavior, remains a PR check.

AI assistance in the code

  • AI-generated: GPT agent in TRAE wrote most of the diff. Validation includes regression tests, full Rust target and documentation tests, compatibility checks, disposable service calls and independent source reviews. No maintainer self-review or CLA signature is claimed here.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI.
  • Generated file checks pass; this PR changes no generated contracts.
  • No migrations or plugin files change.
  • No frontend files change.
  • Operator steps and wire changes are stated above; public documentation follows the next SDK release.
  • New public source text passes the prose checker.
  • Commits are signed off (git commit -s).
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

Note

Medium Risk
Large new client surface and platform-specific path resolution affect how local files are read and identified; behavior is confined to the SDK with no wire contract changes, but Windows/native edge cases and buffered full-file I/O increase integration risk.

Overview
Adds whole-file knowledge helpers to the Rust SDK on async and blocking clients: upload/download via /v1/knowledge.upload and /v1/knowledge.download, plus local-path flows that read a file, hash bytes, upload, submit ingestion, and optionally poll until a terminal status. Callers get typed options (FileIngestOptions, IngestWaitOptions, etc.), an ingest_file example, and Error::Ingest / IngestContext so failures can retain upload metadata, a prepared ingest request, job ID, and last status for recovery (without auto-resubmit on ambiguous transport loss).

Supporting changes include file_scope() validation for explicit org/namespace, new file I/O error variants, route bodies stored as shared Bytes (so retries clone requests without copying large payloads), sha2 promoted to a runtime dependency, and blocking submit applying retry policy consistently for file jobs.

A new knowledge_path::resolve implementation targets CPython 3.14 non-strict Path.resolve semantics (Unix symlinks; Windows reparse points, junctions, long paths, etc.), with unit tests plus CI workflow rust-file-paths.yml that differentially compares the resolver against CPython 3.14 on Ubuntu and Windows across Rust 1.85.1 and stable.

Reviewed by Cursor Bugbot for commit 833d95e. Bugbot is set up for automated code reviews on this repo. Configure here.

Typed async and blocking helpers compose binary upload, ingestion submission, status polling and download through the existing transport. Errors retain known submission context, and shared binary payloads avoid whole-file copies between HTTP attempts.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
@vercel

vercel Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 5, 2026 1:42am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 1:42am UTC

Request Review

@zlareb1 zlareb1 self-assigned this Dec 5, 2026

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Three Rust SDK failures reproduced on this head with loopback fixtures. Both Windows jobs also stopped at the resolver unit tests before reaching the CPython comparison.

options,
)
.await?;
Ok(CallResult {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — A 307 response from knowledge.download returns its response body as successful document bytes. The transport disables redirects and the raw route returns this status with its body. Reject non-success statuses in the typed download helper and retain the status and request metadata.

let source_uri = options.source_uri.clone();
let title = options.title.clone();
let (source_uri, title) =
tokio::task::spawn_blocking(move || prepare(path, source_uri, title))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — The helper reads the original path before resolving the default source URI. A probe read from a FIFO through a symlink, retargeted the link before EOF, and uploaded the first target's bytes under the second target's URI. Resolve the path once and read that target, while keeping the caller's filename and title defaults.

)
.await?
.data;
save_id(Path::new("ingestion-id.txt"), &job.ingestion_id).map_err(|error| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — With an existing ingestion-id.txt, the example uploads the file and queues another job before failing to save the new ID. The first ID remains on disk. Reserve the destination before sending either request, or resume the saved job.

#[cfg(unix)]
let path = fs::canonicalize(path).unwrap();
#[cfg(windows)]
let path = std::path::absolute(path).unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — Both Windows toolchains fail because the fixture expects an 8.3 temporary path and the resolver returns its long spelling. Use the canonical root in the expected results and retain coverage of non-verbatim inputs. Windows job

.custom_flags(0x00200000 | 0x02000000)
.open(&link)
.unwrap();
assert_eq!(resolve(&link).unwrap(), link);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — Both Windows jobs return the removed target's path here, so the unit test stops the run before the CPython comparison. Compare the result with CPython under the same held handle and cover that behavior in the regression. Windows job

This branch has not been deployed

No deployments
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.

2 participants