Skip to content

fix(files): fail fast with a clear message when Microsoft throttles the certificate pre-flight check - #209

Merged
NityamPareek merged 1 commit into
mainfrom
fix/files-preflight-throttling
Nov 3, 2026
Merged

NityamPareek merged 1 commit into
mainfrom
fix/files-preflight-throttling

Conversation

@NityamPareek

Copy link
Copy Markdown
Collaborator

Problem

Some tenants appeared stuck at "Verifying certificate authentication" in the Files planner even though their certificates and secrets were valid.

Root cause: Microsoft was throttling SharePoint for the app (Graph GET /sites/root → 429, Retry-After: 300, activityLimitReached > throttledRequest > forbiddenQuota). The pre-flight session's urllib3 Retry policy honoured the uncapped Retry-After header, so the check silently retried for up to ~50 minutes (10 × 300 s).

The log line App xxxxx... authenticated and verified. was also misleading: it was printed before any SharePoint access had been checked.

Changes

  • util/constants.py: add THROTTLING_STATUS_CODES = (429, 503) as the single list of throttling codes.
  • ui/files_shallow/shallow_ui_helpers.py
    • Override the pre-flight session retry policy: 2 retries on 500/502/504, respect_retry_after_header=False. 429/503 are no longer retried silently.
    • Add ThrottledError, which carries the status, Retry-After, stage, diagnostics (Graph/SP inner error codes, AADSTS codes, request IDs) and the local retry time.
    • Detect throttling on Graph/SharePoint responses and inside wrapped token-acquisition errors (follows the __cause__/__context__ chain).
    • Show a dedicated Retry/Cancel dialog: "Microsoft is throttling this app (HTTP 429). Retry after N s." plus the local time to wait until. HTTP 503 is worded as "throttling this app or the service is busy".
    • Log a warning in the run log with the stage and diagnostics.
  • util/files_shallow/cert_token_manager.py: a throttled certificate token request gets a throttling-specific message instead of the misleading "ensure certificate.pem is uploaded" advice.
  • util/auth_manager.py: replace "authenticated and verified" with wording that matches what was actually checked:
    • signed in; required API permissions confirmed. when required scopes were checked
    • signed in (access token issued). otherwise

Not in scope

  • Scan-time throttling (SpRestConnector already caps waits at 30 s).
  • Retry policies for the Exchange/Chat scans. Only the Files pre-flight session is overridden.
  • Retry is not disabled until the Retry-After time. The dialog advises waiting, and the button stays clickable.

Testing

  • python3 -m unittest tests.files.shallow_estimator_test: 68/68 pass (7 new tests for 429, 503, throttling found inside a token error, missing Retry-After, non-throttling errors, HTTP-date Retry-After, and the retry policy).
  • Exchange group/shared/IPA and Chat estimator/scanner tests pass.
  • Live run: the two throttled tenants now fail in about 3 s with the throttling dialog instead of hanging. The unthrottled tenant still passes (about 4 s).
…he certificate pre-flight check

The certificate authentication pre-flight used a session Retry policy that honoured uncapped Retry-After headers on 429, so throttled tenants appeared to hang for ~50 minutes at 'Verifying certificate authentication'.

- Override the pre-flight session retry policy (2 retries on 500/502/504, Retry-After ignored).
- Detect HTTP 429/503 on Graph/SharePoint responses and in wrapped token errors and raise ThrottledError.
- Show a dedicated Retry/Cancel dialog with the Retry-After time; log status, stage, error codes and request IDs.
- Word 503 as 'throttling or service busy'.
- Replace the misleading 'authenticated and verified' log with scope-aware sign-in wording.
- Add 7 unit tests.
@NityamPareek
NityamPareek merged commit 5dd49ea into main Nov 3, 2026
10 checks passed
@NityamPareek
NityamPareek deleted the fix/files-preflight-throttling branch November 3, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant