Skip to content

fix(drive): add rate limit recovery hints - #2253

Open
zzzchao123 wants to merge 1 commit into
mainfrom
feat/fix-drive-hints
Open

fix(drive): add rate limit recovery hints#2253
zzzchao123 wants to merge 1 commit into
mainfrom
feat/fix-drive-hints

Conversation

@zzzchao123

@zzzchao123 zzzchao123 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

When a Drive/Doc request is rate limited, append exponential-backoff-with-jitter guidance to the typed error's hint so AI agents stop retrying immediately and back off. Mirrors PR #2218's call-site style rather than an implicit blanket decorator.

Changes

  • Detect rate-limited responses via SubtypeRateLimit, business code 99991400, or HTTP 429 — excluding the 1063006 daily-quota code (recovery is next-day reset, not short backoff) — and append recovery guidance to the typed error hint (withDriveRateLimitRecoveryHint).
  • Apply the hint explicitly inside each drive shortcut's Execute via a one-line defer, replacing the implicit blanket decorateDriveShortcutRateLimit loop over the shortcut registry. Covers all drive shortcuts on every return path while keeping the behavior visible in each shortcut's own code.
  • Cover the docs +resource-download (cover) path, which streams from the same Drive media-download endpoint as +media-download, reusing withDocMediaDownloadRecoveryHint.
  • Remove the now-unused decorator and its test; hint judgment is idempotent (skips when a backoff hint already exists) and preserves the typed error category/subtype.

Test Plan

  • Unit tests pass (go test ./shortcuts/drive/... ./shortcuts/doc/...)
  • go build ./..., gofmt -l, go vet clean
  • Added contract test for the docs cover download rate-limit path
  • Manual local verification confirms the lark-cli drive/docs flows work as expected

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Rate-limit errors now include actionable recovery guidance, including exponential backoff and jitter recommendations.
    • Media preview and document cover download errors provide clearer retry and preview-access guidance.
    • Existing error details and quota-specific guidance are preserved.
  • Bug Fixes

    • Improved handling and classification of throttled requests, including HTTP 429 responses.
  • Tests

    • Added coverage for rate-limit recovery messages, duplicate prevention, metadata preservation, and media preview dry runs.
  • Documentation

    • Updated media preview coverage documentation.

@github-actions github-actions Bot added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8247c30e-1e65-4144-941e-0e38cee24a02

📥 Commits

Reviewing files that changed from the base of the PR and between ee1296a and aa5de22.

📒 Files selected for processing (1)
  • shortcuts/drive/drive_errors.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/drive/drive_errors.go

📝 Walkthrough

Walkthrough

The PR adds rate-limit recovery hints for document media and Drive errors. It centralizes Drive throttling detection, propagates hints through shortcut execution handlers, updates batch classification, and adds document media and CLI dry-run coverage.

Changes

Rate-limit recovery guidance

Layer / File(s) Summary
Document media recovery handling
shortcuts/doc/*, tests/cli_e2e/docs/*
Document preview and cover downloads add exponential-backoff and jitter guidance for throttled errors. Tests verify typed error preservation, HTTP 429 handling, output-file behavior, and dry-run endpoint planning.
Drive rate-limit classification and batch handling
shortcuts/drive/drive_errors.go, shortcuts/drive/drive_errors_test.go, shortcuts/drive/drive_push.go
Drive throttling detection covers typed errors, error codes, and HTTP 429 responses while excluding daily permission quota code 1063006. Batch failures use the shared classification and preserve structured hints.
Drive shortcut error propagation
shortcuts/drive/*.go
Drive shortcut Execute handlers use named return errors and deferred withRateLimitRecoveryHint processing. Existing request, output, polling, and persistence flows remain unchanged.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested labels: bugfix

Suggested reviewers: fangshuyu-768

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: adding rate-limit recovery hints for Drive operations.
Description check ✅ Passed The description includes all required sections, explains the changes, and documents completed and pending verification steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fix-drive-hints

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shortcuts/drive/drive_upload.go (1)

178-181: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Decorate rate-limited metadata lookup errors before logging.

If common.FetchDriveMetaURL returns a typed rate-limit error, Execute still returns nil. The deferred wrapper does not run on metaErr. The warning then omits the recovery guidance.

Apply withDriveRateLimitRecoveryHint(metaErr) before writing the warning. Add a regression test for this successful-upload and rate-limited-URL-lookup path.

🤖 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_upload.go` around lines 178 - 181, Update the metaErr
warning branch in Execute to pass FetchDriveMetaURL errors through
withDriveRateLimitRecoveryHint before logging, while preserving the successful
upload result. Add a regression test covering a successful upload followed by a
typed rate-limit URL lookup failure and verify the warning includes the recovery
guidance.
🤖 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 `@shortcuts/doc/doc_media_test.go`:
- Around line 828-831: The HTTP 429 contract tests must also validate the
returned error subtype through errs.ProblemOf. In
shortcuts/doc/doc_media_test.go:828-831, assert the expected subtype for the
wrapped preview error; in shortcuts/doc/doc_resource_cover_test.go:135-138,
assert the expected subtype for the wrapped cover-download error, while
preserving the existing category and status-code assertions.

In `@tests/cli_e2e/docs/docs_media_download_dryrun_test.go`:
- Around line 77-104: Extend TestDocsMediaPreviewDryRun_PlansPreviewDownload
with a live E2E workflow that creates or provisions the required media, invokes
docs +media-preview using bot credentials, and validates the actual streamed
preview and rate-limit recovery behavior through runtime.DoAPIStream. Make the
workflow self-contained by cleaning up all created resources, while preserving
the existing dry-run request-plan assertions.

---

Outside diff comments:
In `@shortcuts/drive/drive_upload.go`:
- Around line 178-181: Update the metaErr warning branch in Execute to pass
FetchDriveMetaURL errors through withDriveRateLimitRecoveryHint before logging,
while preserving the successful upload result. Add a regression test covering a
successful upload followed by a typed rate-limit URL lookup failure and verify
the warning includes the recovery guidance.
🪄 Autofix

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 Plus

Run ID: 1f8b5f4e-14b5-4a9e-940b-f84e25de7aee

📥 Commits

Reviewing files that changed from the base of the PR and between 2016120 and 1b34ef7.

📒 Files selected for processing (44)
  • shortcuts/doc/doc_errors.go
  • shortcuts/doc/doc_media_preview.go
  • shortcuts/doc/doc_media_test.go
  • shortcuts/doc/doc_resource_cover.go
  • shortcuts/doc/doc_resource_cover_test.go
  • shortcuts/drive/drive_add_comment.go
  • shortcuts/drive/drive_add_reply.go
  • shortcuts/drive/drive_apply_permission.go
  • shortcuts/drive/drive_batch_query_comments.go
  • shortcuts/drive/drive_copy.go
  • shortcuts/drive/drive_cover.go
  • shortcuts/drive/drive_create_folder.go
  • shortcuts/drive/drive_create_shortcut.go
  • shortcuts/drive/drive_delete.go
  • shortcuts/drive/drive_delete_reply.go
  • shortcuts/drive/drive_download.go
  • shortcuts/drive/drive_errors.go
  • shortcuts/drive/drive_errors_test.go
  • shortcuts/drive/drive_export.go
  • shortcuts/drive/drive_export_download.go
  • shortcuts/drive/drive_import.go
  • shortcuts/drive/drive_inspect.go
  • shortcuts/drive/drive_list_comments.go
  • shortcuts/drive/drive_list_replies.go
  • shortcuts/drive/drive_member_add.go
  • shortcuts/drive/drive_member_list.go
  • shortcuts/drive/drive_move.go
  • shortcuts/drive/drive_permission_get_setting.go
  • shortcuts/drive/drive_preview.go
  • shortcuts/drive/drive_pull.go
  • shortcuts/drive/drive_push.go
  • shortcuts/drive/drive_react_reply.go
  • shortcuts/drive/drive_resolve_comment.go
  • shortcuts/drive/drive_search.go
  • shortcuts/drive/drive_secure_label.go
  • shortcuts/drive/drive_status.go
  • shortcuts/drive/drive_sync.go
  • shortcuts/drive/drive_task_result.go
  • shortcuts/drive/drive_update_reply.go
  • shortcuts/drive/drive_update_title.go
  • shortcuts/drive/drive_upload.go
  • shortcuts/drive/drive_version.go
  • tests/cli_e2e/docs/coverage.md
  • tests/cli_e2e/docs/docs_media_download_dryrun_test.go

Comment thread shortcuts/doc/doc_media_test.go
Comment thread tests/cli_e2e/docs/docs_media_download_dryrun_test.go
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@aa5de22cab035d0a0753f4cf0b860e5feb4e9e04

🧩 Skill update

npx skills add larksuite/cli#feat/fix-drive-hints -y -g

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.59459% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.37%. Comparing base (199762b) to head (aa5de22).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/drive/drive_errors.go 78.94% 1 Missing and 3 partials ⚠️
shortcuts/doc/doc_errors.go 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2253      +/-   ##
==========================================
+ Coverage   76.36%   76.37%   +0.01%     
==========================================
  Files        1011     1011              
  Lines      111269   111330      +61     
==========================================
+ Hits        84970    85032      +62     
+ Misses      19815    19813       -2     
- Partials     6484     6485       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zzzchao123
zzzchao123 force-pushed the feat/fix-drive-hints branch 2 times, most recently from 28148be to ee1296a Compare August 10, 2026 06:52
Detect rate-limited Drive/Doc responses (SubtypeRateLimit, business code
99991400, or HTTP 429; excluding the 1063006 daily quota) and append
exponential-backoff-with-jitter guidance to the typed error hint, so AI
agents stop hammering and retry sensibly.

Apply the recovery hint explicitly inside each drive shortcut's Execute
via a defer, mirroring PR #2218's call-site style, instead of an implicit
blanket decorator over the shortcut registry. Also cover the docs
+resource-download cover path, which streams from the same Drive media
download endpoint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant