Repository navigation
Conversation
…llowance lookup failure resolve_transcription_allowance() fails closed on any lookup error so a live listen socket never opens on an unknown entitlement. routers/sync.py reused that same boolean to set the durable `is_locked` flag on a synced conversation, so a single transient allowance_unavailable/usage_invalid resolution permanently 402s that conversation for its paying owner — nothing routine clears is_locked outside a subscription transition. Add should_lock_synced_conversation_for_missing_credits(), which only locks for a resolved, durable no-credits reason (subscription_inactive, trial_paywalled, plan_allowance_exhausted), mirroring how resolve_conversation_processing_allowance() already treats the same two transient reasons. Wire both sync.py call sites to it. fixes #15232
This was referenced Sep 25, 2026
This branch has not been deployed
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
resolve_transcription_allowance()deliberately fails closed on any lookuperror (
allowance_unavailable) or untrusted usage record (usage_invalid) —correct for its original caller, the listen WebSocket, where the alternative
is opening a billed STT socket on an unknown entitlement.
routers/sync.pyreused that same boolean (viahas_transcription_credits)to decide
should_lock, which is written onto the conversation as thedurable
is_lockedflag. Nothing routine clearsis_locked— only the threesubscription-transition handlers in
routers/payment.pycallunlock_all_conversations. So a single transient Firestore blip during sync(one allowance lookup times out) permanently 402s that conversation for its
paying owner, on every later read: app, folders, search, MCP, and the
developer API.
The repo already drew this exact distinction for the other paid gate —
resolve_conversation_processing_allowance()treatsallowance_unavailableand
usage_invalidas allowed, citing #12663 — but the sync-time lockcollapsed both into one fail-closed boolean.
Fix
Add
should_lock_synced_conversation_for_missing_credits()inutils/subscription.py: it locks only for a resolved, durable no-creditsreason (
subscription_inactive,trial_paywalled,plan_allowance_exhausted), not for a lookup the resolver itself flags asuntrustworthy. Both
should_lockcall sites inrouters/sync.py(
sync_local_files,sync_local_files_v2) now use it instead ofhas_transcription_credits;has_transcription_creditsitself is untouchedand still fails closed for the listen socket.
Testing
tests/unit/test_transcription_allowance.pythat runs the new function over the full allowance-resolution matrix and
asserts it locks only for the three durable reasons — and explicitly
asserts
allowance_unavailable/usage_invaliddo not lock even thoughhas_transcription_creditsstill (correctly) says no for those rows.(
test_sync_local_files_async.py's AST offload check,test_sync_cloud_tasks.py,test_sync_v2.py,test_sync_silent_failure.py,test_sync_fair_use_gate.py,test_sync_pcm_decode.py,test_sync_opus_decode.py)..venv/bin/python -m pytestgreen acrosstest_transcription_allowance.py(81 tests) and every
test_sync_*.pyfile, plus the full changed-fileselector from
scripts/select_backend_unit_tests.py(63 files) — the onlytwo non-green files (
test_subscription_restructure.py,test_sync_bridge_lifecycle.py) fail/hang identically on unmodifiedorigin/main, confirmed by re-running against a clean checkout.bash test-preflight.shandscripts/pr-preflight --suggest/scripts/pr-preflight --pr-body-fileboth clean.Line-Count-Exception: backend/utils/subscription.py | 1950 -> 1970 | adds one durable-lock-vs-live-socket allowance wrapper (
should_lock_synced_conversation_for_missing_credits) next to the resolver it wraps, mirroring the existinghas_transcription_credits/resolve_conversation_processing_allowancepattern in the same file — fixes #15232.Failure-Class: none
Auto-generated from issue feedback by the mini issues-improver — tested and merged.