Repository navigation
Conversation
drive +download fetched each file in one response. open.feishu.cn resets
that stream about five minutes in ("stream error: stream ID 5;
INTERNAL_ERROR; received from peer"), so any file that takes longer than
that to transfer can never be downloaded, and every retry restarts from
byte 0.
Route +download through extension/download in 128 MiB Range requests with
per-part retries. Drive download responses carry no ETag and a file token
can be overwritten in place, so parts are combined only when the file's
latest_modify_time was read before the first part; it is re-read before
the output is committed and a change fails with representation_changed.
Without a revision the download keeps using one full response.
Refs larksuite#2324
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Adapt the single-invocation revision checks from larksuite#2839 and share them with +pull. Keep persistent resume separate for the next change. Co-authored-by: xu4wang <311397+xu4wang@users.noreply.github.com>
|
I've updated #2663 to use the same 128 MiB ranges and This PR can stay focused on transfers within one invocation. The resume follow-up binds the checkpoint to the source and revision, keeps it when metadata lookup fails, and rechecks before publishing. It retains the documented same-second overwrite limitation. If this lands first, I'll rebase #2663 and drop the overlapping transfer changes. The unit/race, dry-run, and lint checks pass. My live rerun and three existing live fixture workflows in |
PR Quality SummaryCI did not complete successfully. Use the failed check links below to decide whether this PR needs a code change or a rerun. CI status
|
Summary
drive +downloadfetches a file in one streaming response. open.feishu.cn resets that stream about five minutes after it starts, so any Drive file that takes longer than that to transfer cannot be downloaded at all, and each retry restarts from byte 0 (#2324). This PR moves+downloadonto the existingextension/downloadengine (already used byim +messages-resources-download) with 128 MiB Range requests, and pins the file revision so parts are never combined from two versions of the same token.Changes
drive +downloadstreams throughextension/download.OpenwithPartSize = 128 MiB, so every response stays far below the reset window; failed parts are retried by the engine.ETag, and a file token can be replaced in place (+upload --file-token) with same-size, different bytes. So:latest_modify_time(frommetas/batch_query) is read before the first part. Only when it is present are parts combined (ImmutableSource); otherwiseMutableSourcekeeps today's single full response.latest_modify_timeis re-read when the body reaches EOF, before the atomic save commits. A change fails withnetwork/representation_changed(retryable) and no output file is written.latest_modify_timehas one-second resolution, so a replacement within the same second as the first read is not detected. A server validator (ETag or a readable version) would close it.--output, the metadata read is best-effort (no new required scope). If it fails, the download falls back to one request and, for files larger than one part, prints a stderr warning.common.DriveMetagainsLatestModifyTime(read withGetStringLoose).--outputnow also issues one metadata call (the dry-run test that pinned "explicit output skips metadata" is updated).api/rate_limit(retryable, with backoff hint), the same contract as im resource downloads, instead ofnetworkwith code 429.Test Plan
go test ./shortcuts/drive/ ./shortcuts/common/ ./extension/download/ ./internal/downloadtransport/shortcuts/drive/drive_download_ranged_test.go: multi-part assembly with exact Range headers; replacement between parts fails withrepresentation_changedand commits nothing; metadata error falls back to one full response; missinglatest_modify_timefalls back; numericlatest_modify_timestill pins; single-part files skip the re-check.+download, always-ImmutableSource, no re-check, re-check on single-part files, ignoring a revision mismatch, swallowing the re-check error, not passing the revision, andGetStringinstead ofGetStringLooseeach make at least one of these tests fail.go test ./tests/cli_e2e/drive/ -run TestDriveDownloadDryRun(aftermake build)go vet ./...,gofmt -l,golangci-lint run --new-from-rev(v2.1.6, Go 1.23): 0 issues;go run -C lint .passescannot create file: stream error: stream ID 5; INTERNAL_ERROR; received from peer(with and without an HTTP proxy)An unmodified run that happened to finish in 305 s succeeded, which is consistent with a reset at roughly 5 minutes of stream time rather than a size limit.
Part size: each Range request waits ~0.5–1.2 s for its first byte. Measured sequential throughput was 10.2 MB/s with 32 MiB parts versus 15–16 MB/s with 128 MiB parts, which matches a single full stream (~15.8 MB/s).
Related Issues
--continue) is out of scope here.extension/download, but withMutableSource, which requires a strong ETag before combining parts. The Drive download endpoint does not send one (206 responses includeContent-RangeandAccept-Ranges: bytes, but noETag/Last-Modified). In anhttp2debug=2trace of feat(drive): resumable chunked downloads for +download and +pull #2663 at1e66abc1, a 300 MB download sends oneRange: bytes=0-67108863probe and then a second request withoutRange, so the transfer is still a single stream. This PR pins the revision withlatest_modify_timeinstead and does not add resume (--continue), so the two approaches could be combined.Summary by CodeRabbit
New Features
Bug Fixes
Documentation