Repository navigation
fix(drive): report files over the 100 MiB limit as FILE_TOO_LARGE without uploading - #136
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
使用者遇到的問題
Library 裡有一個 291 MB 的
heart-rate.jsonl,WSPC Drive 一直顯示DRIVE_PATH_ERROR: HTTP 413,看起來像路徑出錯,其實是檔案超過 Drive 的單檔上限。更糟的是,這個檔案每天 append,每次變動 CLI 都會把整個 291 MB 讀進記憶體、上傳、再被拒收一次。背景
tod_01M2SXD7M2DSKKRQT8HYCY8JEN(來源tod_01M2S85BY0A38RM37TMNC4KTDY)。docs/superpowers/specs/2026-09-18-drive-oversized-file-design.md(docs(drive): specify oversized file handling for sync [skip deploy] #135)。CONTEXT.md的 Oversized File 詞彙已在 spec PR 加入。sadcoderlabs/wspcpackages/drive/worker/src/limits.ts,判定為>),沒有透過 API 公開,也沒有 multipart/resumable upload。實作前已讀回spec/openapi.json:drive_file_uploadresponses 仍無 413、DriveLibrary無上限欄位。問題出在哪裡
Edge 在 worker 之前擋下超大 body,回的是沒有 JSON
code的 413。driveHttpError()只從 body 取 code:沒有 code 時
drivePathErrorSummary()退回DRIVE_PATH_ERROR。worker 自己拒收時會帶FILE_TOO_LARGE,所以在小於 edge 上限、大於 100 MiB 的區間看不出問題,只有真正很大的檔案才會掉到DRIVE_PATH_ERROR。runDriveSyncOnce()在上傳前完全不看檔案大小,決策為 upload 就走readStableUploadBody()整檔讀進記憶體再送出。修法
retry.ts:413 且 body 沒有 code 時補上FILE_TOO_LARGE;有 code 則沿用 server 的。sync.ts:在 Permanent Upload Rejection 迴圈之前、pendingPaths計算之前,對不在movedPaths的 path 檢查本輪 scan 的size_bytes:為什麼這樣寫:
rejectedPaths:沿用拒收略過集合(spec 允許實作者決定),該 path 自動排除於pendingPaths與 progresstotal,也就不會進executeDrivePathAction()讀檔。upload_create/upload_update時判定:conflict照一般流程(spec 明訂不預檢)。DRIVE_PATH_ERROR拒收紀錄仍由既有 CLI version 規則刪除,之後改報FILE_TOO_LARGE。兩者同時命中時,recordDrivePathError()本身依 path 去重,所以拒收迴圈不需要額外略過(有測試守護errors === 1)。state.json:每輪重新判定,縮小、刪除、改名、ignore 後自然恢復。這個 PR 不修什麼
sadcoderlabs/wspc立 spec。FILE_TOO_LARGE。已知副作用
FILE_TOO_LARGEpath error、sync onceexit 1,直到使用者處理該檔(spec 預期行為)。code: "FILE_TOO_LARGE",符合 spec。測試
依 spec 四個切片,每片先寫失敗測試(
test/handwritten/drive/retry.test.ts、test/handwritten/drive/sync.test.ts,大檔用truncate建 sparse file):maps a 413 without a code to FILE_TOO_LARGE/keeps the server code on a 413AssertionError: expected undefined to be 'FILE_TOO_LARGE'reports a bare upload 413 as FILE_TOO_LARGE and remembers that codecode為DRIVE_PATH_ERRORnever reads or uploads an oversized file and reports it every roundexpected [] to deeply equal [ { path: 'big.bin', …(3) } ](檔案被上傳)leaves an oversized file out of progress and syncs other filesexpected Set{ 2 } to deeply equal Set{ 1 }uploads a file of exactly 100 MiB(自訂uploadFile只記byteLength)>=的 mutation 會紅stops uploading a synced file once it grows over the limitupload_create的 mutation 會紅replaces a rejection recorded by an older CLI with FILE_TOO_LARGE、reports an oversized file once when a current rejection also matches本機
npm run typecheck、npm test(66 files/799 tests)、npm run build通過。決定後回報(spec 要求):sparse file 測試單筆最長約 0.64 秒,不需替代做法;
debug.logevent 欄位維持path、op、code、message。Review 結果
src/generated//path-executor.ts/state.ts/watch.ts、只留說明 why 的英文註解、無null。path_errorsshape、state.jsonschema、retryable語意不變。設計判斷(非違規):常數未 export(spec 為「建議」且無 importer);拒收迴圈的重複回報交給recordDrivePathError()的既有去重(spec 已知陷阱列出的兩種處理之一)。未完成驗收
typecheck/test/build(本機已通過,待 PR CI)。mkfile -n 101m手動驗證並回報在 Todo comment。🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.