fix: guide drive import concurrency conflicts - #1751
Conversation
📝 WalkthroughWalkthroughAdds concurrent-operation error code detection to the drive import failure path, marking matching errors retryable with a fixed hint. Unit tests cover the new error shaping, and drive import docs now require serial execution for same-target batch imports. ChangesConcurrency Error Detection in Drive Import
Serial Import Documentation Updates
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1751 +/- ##
=======================================
Coverage 74.42% 74.42%
=======================================
Files 854 854
Lines 88457 88477 +20
=======================================
+ Hits 65832 65852 +20
+ Misses 17556 17555 -1
- Partials 5069 5070 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@0d9916a1050157bf6b391452594e607c0aae3805🧩 Skill updatenpx skills add larksuite/cli#fix/drive-import-concurrency-guidance -y -g |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/drive/drive_import_common.go (1)
458-480: 📐 Maintainability & Code Quality | 🔵 TrivialCorrect, but consider a regexp-based simplification for readability.
The manual substring scan with
isASCIIDigitboundary checks is correct and covered by tests (verified against the "longer numeric code containing known code" test case), but it's more code than needed. Aregexpwith word-boundary anchors would express the same intent (find a code not embedded in a longer digit run) more concisely.
[optional_and_nitpick]♻️ Optional simplification using regexp
-func driveImportConcurrentOperationCode(msg string) (int, bool) { - for _, code := range driveImportConcurrentOperationCodes { - codeText := strconv.Itoa(code) - for idx := strings.Index(msg, codeText); idx >= 0; { - end := idx + len(codeText) - if (idx == 0 || !isASCIIDigit(msg[idx-1])) && (end == len(msg) || !isASCIIDigit(msg[end])) { - return code, true - } - - nextStart := idx + 1 - next := strings.Index(msg[nextStart:], codeText) - if next < 0 { - break - } - idx = nextStart + next - } - } - return 0, false -} - -func isASCIIDigit(ch byte) bool { - return ch >= '0' && ch <= '9' -} +var driveImportConcurrentOperationCodePattern = regexp.MustCompile( + `(?:^|\D)(` + strings.Join(driveImportConcurrentOperationCodeStrings(), "|") + `)(?:\D|$)`, +) + +func driveImportConcurrentOperationCode(msg string) (int, bool) { + m := driveImportConcurrentOperationCodePattern.FindStringSubmatch(msg) + if m == nil { + return 0, false + } + code, _ := strconv.Atoi(m[1]) + return code, true +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/drive/drive_import_common.go` around lines 458 - 480, The current driveImportConcurrentOperationCode helper correctly finds standalone error codes, but it uses a manual substring scan with isASCIIDigit boundary checks that can be simplified. Replace the nested strings.Index logic in driveImportConcurrentOperationCode with a regexp-based match that looks for each code only when it is not part of a longer digit sequence, while keeping the same return behavior and preserving the existing test coverage for longer numeric strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@shortcuts/drive/drive_import_common.go`:
- Around line 458-480: The current driveImportConcurrentOperationCode helper
correctly finds standalone error codes, but it uses a manual substring scan with
isASCIIDigit boundary checks that can be simplified. Replace the nested
strings.Index logic in driveImportConcurrentOperationCode with a regexp-based
match that looks for each code only when it is not part of a longer digit
sequence, while keeping the same return behavior and preserving the existing
test coverage for longer numeric strings.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d212c17b-8ded-4455-8e2a-f78568596987
📒 Files selected for processing (5)
shortcuts/drive/drive_import_common.goshortcuts/drive/drive_import_common_test.goskill-template/domains/drive.mdskills/lark-drive/SKILL.mdskills/lark-drive/references/lark-drive-import.md
12737b5 to
0d9916a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@skills/lark-drive/SKILL.md`:
- Line 106: Update the retry guidance in the drive import conflict row so the
cap is clearly per failed item, not batch-wide. In the `SKILL.md` entry
describing `232140101` / `232140100` / `233523001`, rewrite the retry wording to
state that each failed item may be retried up to 3 times independently, with a
few seconds wait before each retry, while keeping the existing serial execution
guidance for concurrent imports to the same target.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 079cf034-086a-4108-87b8-f9ee89281e64
📒 Files selected for processing (5)
shortcuts/drive/drive_import_common.goshortcuts/drive/drive_import_common_test.goskill-template/domains/drive.mdskills/lark-drive/SKILL.mdskills/lark-drive/references/lark-drive-import.md
✅ Files skipped from review due to trivial changes (2)
- skill-template/domains/drive.md
- skills/lark-drive/references/lark-drive-import.md
🚧 Files skipped from review as they are similar to previous changes (2)
- shortcuts/drive/drive_import_common_test.go
- shortcuts/drive/drive_import_common.go
Summary
Improve
drive +importguidance when import task failures include known same-location concurrency error codes, so agents can retry safely without looping indefinitely.Changes
232140101,232140100, and233523001in import task failure messages and expose the matched code on the typed API error.Test Plan
go test ./shortcuts/drivelark-cli drive +importflow works as expected: ran 20 concurrent real imports against the temporary Drive test folder; observed upload rate limits but no target concurrency codes, then cleaned up all created sheets.Related Issues
Summary by CodeRabbit
drive +importfailure handling: concurrency-related backend errors are now recognized in the error message, labeled retryable, and include a clearer user hint for resolving conflicts.--target-token).232140101/232140100/233523001) with a serial retry approach for failed items (up to 3 attempts with delays) before stopping and reporting.