Skip to content

feat(exchange): Recoverable Items estimator — $count mode - #221

Merged
NityamPareek merged 3 commits into
exchange-litigation-holdfrom
eo-recoverable-items-count-mode
Nov 17, 2026
Merged

NityamPareek merged 3 commits into
exchange-litigation-holdfrom
eo-recoverable-items-count-mode

Conversation

@NityamPareek

@NityamPareek NityamPareek commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Part 2 of 7 of the Exchange Recoverable Items (litigation hold) work. Targets the exchange-litigation-hold integration branch.

Summary

Adds EORecoverableItemsEstimator, the backend engine that counts IPM.Note emails in the four Recoverable Items folders of primary (user / shared) mailboxes. Backend only: nothing in the UI calls it yet (that comes in PR 4).

Folder label Well-known name
Deletions recoverableitemsdeletions
Purges recoverableitemspurges
DiscoveryHolds recoverableitemsdiscoveryholds
Versions recoverableitemsversions

Request per folder (v1.0, mailbox addressed by UPN):

GET /admin/exchange/mailboxes/{upn}/folders/{wellKnownName}/items
    ?$filter=type eq 'IPM.Note'&$count=true&$top=1&$select=id
ConsistencyLevel: eventual

Requires the MailboxItem.Read.All application permission. The permission check is added when the scan is wired up in PR 4.

API

  • get_folder_counts(upns, failures) → {upn: {Deletions, Purges, DiscoveryHolds, Versions}}, used later for the 4 CSV columns.
  • calculate_resource_count({"user_ids": upns}, failures) → {upn: total}.
  • get_folder_totals() → aggregate per-folder counts, used later for the logs.

Per-mailbox concurrency (Exchange limit: 4 concurrent requests per mailbox)

  • How many mailboxes a call handles is decided by the caller. The scan pipeline (PR 4) will use min(concurrency // 10, 20), the same chunking as primary and shared mailbox scans.
  • Input UPNs are de-duplicated case-insensitively, so a mailbox is requested once.
  • The folders are queried in sequential rounds (Deletions + Purges, then DiscoveryHolds + Versions).
  • Each round is sent as sequential $batch calls of at most graph_batch_size (10) requests, i.e. up to 5 mailboxes × 2 folders. A mailbox's 2 requests for a round are always in the same $batch, enforced by an explicit check.
  • A call has only one $batch in flight at a time, and has no internal thread pool. The pipeline will run calls in parallel over disjoint mailboxes.
  • Normal peak is 2 concurrent requests per mailbox. Even if a timed-out $batch is still running server-side while it is retried, the peak is 2 + 2 = 4.

The estimator calls UrlInvoker.execute_batch_request directly (as fetch_user_batch_data already does) instead of invoke, because invoke drops 4xx responses. This keeps real status codes and messages in failure reports.

Failure handling (no fallbacks)

Outcome Result
200 with @odata.count Count used
200 without @odata.count 0, partial failure (INVALID_DATA)
404 0, partial failure (NOT_FOUND)
Other 4xx/5xx 0, partial failure with Graph's error message
No response after retries 0, partial failure (NOT_FOUND)
All 4 folders failed Single full failure for the mailbox

Partial failures carry the folder label as folderId (shown as "Failed Resource" by the existing failure logging).

Other changes

  • util/constants.py: folder allow-list, report column names, max requests per mailbox per batch (2).
  • ScanConfig.scan_recoverable_items (default False).
  • EstimatorFactory.get_recoverable_items_estimator() (main token manager).
  • Folder hierarchy mode (when the Recursive setting is on) raises NotImplementedError until PR 3.

Testing

  • New tests/eo_recoverable_items/eo_recoverable_items_tests.py (13 offline tests): every failure outcome, request shape and encoding, batch composition limits (≤ graph_batch_size per $batch, ≤ 2 per mailbox, each folder requested once), de-duplication, 200 mailboxes chunked as the pipeline will at concurrency 10 / 30 / 100 never exceeding 2 in-flight requests per mailbox, stop handling, invalid input.
  • All existing offline suites pass (201 tests total).
Add EORecoverableItemsEstimator, which counts IPM.Note emails in the
Deletions, Purges, DiscoveryHolds and Versions Recoverable Items folders
of primary mailboxes via the v1.0 admin mailbox API ($count per folder,
mailbox addressed by UPN). Backend only; not wired to the UI yet.

- Per-mailbox concurrency: mailboxes are de-duplicated, processed 10 at a
  time in sequential rounds of one $batch, with at most 2 requests per
  mailbox per $batch, so Exchange's limit of 4 concurrent requests per
  mailbox is never exceeded.
- Every folder error counts 0 and is reported as a partial failure; a
  mailbox whose four folders all fail is reported as a full failure.
- Folder hierarchy mode (Recursive setting) raises NotImplementedError
  until it is added in a follow-up PR.
- New constants, ScanConfig.scan_recoverable_items, factory accessor and
  unit tests.
…ther mailbox scans

Drop RECOVERABLE_ITEMS_MAILBOXES_PER_TASK. The caller decides how many
mailboxes a call handles (the scan pipeline will use min(concurrency // 10, 20),
as for primary and shared mailboxes). Within a call, each round of two folders
is sent as sequential $batch calls of at most graph_batch_size requests, keeping
each mailbox's requests for the round in the same $batch.
@NityamPareek
NityamPareek merged commit 5da6ba3 into exchange-litigation-hold Nov 17, 2026
1 check passed
@NityamPareek
NityamPareek deleted the eo-recoverable-items-count-mode branch November 17, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant