Repository navigation
Rust SDK uploads and ingests local files - #2195
yorkhellen wants to merge 1 commit into
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
zlareb1
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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| { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
Part of issue #52. This implements file ingestion helpers and does not close the issue.
Related: #52
Changelog category
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.
The helpers reuse the existing transport for authentication, retry decisions and final request metadata. Binary requests own a shared
Bytespayload so cloning a request for an HTTP attempt does not copy the whole file.sha2moves from test dependencies to runtime dependencies to hash the bytes sent;bytesbecomes a direct dependency and is already used by the HTTP transport.Scope and risk
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.Compatibility, rollout and rollback
Vec<u8>; only their private storage changes toBytes. The minimum Rust version remains 1.85.Tests
Against the latest upstream baseline:
LOOM_ENV_FILE= make format,make lintandmake 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, andcargo fmt --check: passed.python sdk/rust/tests/native_paths/check.py --toolchain 1.85.1and--toolchain stable, with CPython 3.14.7 on macOS: each passed 14 resolver tests and 37 differential cases.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.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
make test-unitand applicable integration results are reported by CI.git commit -s).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.uploadand/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.), aningest_fileexample, andError::Ingest/IngestContextso 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 sharedBytes(so retries clone requests without copying large payloads),sha2promoted to a runtime dependency, and blockingsubmitapplying retry policy consistently for file jobs.A new
knowledge_path::resolveimplementation targets CPython 3.14 non-strictPath.resolvesemantics (Unix symlinks; Windows reparse points, junctions, long paths, etc.), with unit tests plus CI workflowrust-file-paths.ymlthat 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.