Files
tutabridge/crates/bridge
Anthony 62503d439b Retry attachment load on fresh-mail session-key races
When a brand-new mail lands through the realtime event bus, its
attached `File` entities are queryable on the server but the
encryption metadata (`_ownerEncSessionKey` / `_ownerGroup`) may not
have propagated yet — `CryptoEntityClient::load` then returns
'instance missing owner key/group data' a few seconds before the same
load would succeed.

The previous code surfaced that as a permanent attachment-load failure
inside `prefetch_details` (best-effort fallback to a body-only
multipart), so a PDF sent via SMTP appeared body-only in Thunderbird
and only recovered after a manual sync.

Add `load_file_with_retry` in `TutaSession`: when
`is_session_key_transient(e)` (matching on the SDK error message),
back off 1s / 3s / 6s before retrying, then bubble up so the existing
ship-body-only fallback still applies. \~10s of tolerance is enough
in practice while staying well under the SMTP/IMAP latency budget.

Four unit tests cover the helper: matches the exact 'missing owner
key/group data' wording, the generic 'Session key resolution failure'
prefix, rejects unrelated SDK errors, accepts a bare 'missing owner
key/group data' message (paranoid catch).
2026-05-28 19:37:49 +02:00
..