Repository navigation
fix(sync): don't durably lock a conversation on a transient allowance lookup failure - #15952
Merged
Merged
Conversation
… lookup failure routers/sync.py wrote is_locked=True onto a conversation whenever has_transcription_credits() returned False, and that helper fails closed for any lookup it can't trust (a Firestore blip, an untrusted usage record) as well as for genuine exhaustion. Unlike gating a live listen socket, nothing routinely clears is_locked afterward, so a transient failure paywalled the conversation on every future read (app, folders, search, MCP, developer API) until the user's subscription happened to change. resolve_conversation_processing_allowance already treats these same two reasons (allowance_unavailable, usage_invalid) as fail-open for the other paid gate, citing #12663. This applies the same distinction to the durable sync lock: only lock when the resolver's reason indicates the plan is actually out of minutes. fixes #15232
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
routers/sync.pywroteis_locked=Trueonto a synced conversation wheneverhas_transcription_credits()returnedFalse. That helper fails closed notonly when a plan's minutes are genuinely exhausted, but also when the
allowance lookup itself couldn't be trusted (a Firestore read that timed out,
an unparseable usage record) —
resolve_transcription_allowance()returnsallowance_unavailable/usage_invalidfor exactly those cases.Fail-closed is correct for gating a live listen socket (never open a billed
socket on an unknown entitlement). It's wrong for the sync lock:
is_lockedis written durably, and nothing routinely re-checks it — only three
subscription-transition handlers in
routers/payment.pyever callunlock_all_conversations. So a paying subscriber whose plan never changes,who hits one transient Firestore blip during sync, gets that conversation
paywalled with a 402 on every future read (app, folders, search, MCP,
developer API) forever.
The repo already draws this exact distinction for the sibling paid gate:
resolve_conversation_processing_allowancetreatsallowance_unavailableand
usage_invalidas allowed, citing #12663. This applies the samedistinction to the durable sync lock in both
sync_local_filesandsync_local_files_v2— only lock when the resolver's reason means the planis actually out of minutes.
Why (evidence from the issue)
#15232 traced this precisely to
backend/routers/sync.py'sshould_lockcomputation and
resolve_transcription_allowance'sexceptclause inbackend/utils/subscription.py, both confirmed unchanged on currentmain.What I tested
tests/unit/test_transcription_allowance.pypinning
TRANSCRIPTION_ALLOWANCE_TRANSIENT_REASONSto exactly{allowance_unavailable, usage_invalid}, asserting real-exhaustion reasonsstay out of it.
tests/unit/test_transcription_allowance.py,test_sync_local_files_async.py(the AST check that the credit gate staysoffloaded via
run_blocking(critical_executor, ...)in both handlers),test_subscription_plans.py,test_byok_security_quota.py— all pass.scripts/select_backend_unit_tests.pyselection forthis diff (65 files) individually per-file: all pass except two failures
that reproduce identically on unmodified
main(a protobuf descriptor-poolcollision in
test_subscription_restructure.pyand cross-fileMagicMockpollution in
test_sync_fair_use_gate.py'sTestCreateConversationLockPropagationwhen run in the same combinedbatch as certain other reload-heavy sync tests) — pre-existing test-order
pollution, not caused by this change.
Line-Count-Exception: backend/routers/sync.py | 2104 -> 2120 | is_locked is a durable paywall decision; the fix needs the resolver's specific failure reason at both call sites, which has to live inline (not extracted to a helper) to keep the existing
test_sync_local_files_async.pyAST check honest about the credit gate staying offloaded viarun_blocking.Line-Count-Exception: backend/utils/subscription.py | 1950 -> 1958 | adds the
TRANSCRIPTION_ALLOWANCE_TRANSIENT_REASONSconstant thatrouters/sync.pyneeds to draw the same transient-vs-exhausted distinctionresolve_conversation_processing_allowancealready applies (#12663).Failure-Class: new
Auto-generated from issue feedback by the mini issues-improver — tested and merged.