Skip to content

fix(backend): stop durably paywalling a conversation on a transient allowance lookup failure - #15513

Open
kodjima33 wants to merge 1 commit into
mainfrom
issues-improver/15232-sync-lock-fail-closed
Open

kodjima33 wants to merge 1 commit into
mainfrom
issues-improver/15232-sync-lock-fail-closed

Conversation

@kodjima33

@kodjima33 kodjima33 commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

What

resolve_transcription_allowance() deliberately fails closed on any lookup
error (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.py reused that same boolean (via has_transcription_credits)
to decide should_lock, which is written onto the conversation as the
durable is_locked flag. Nothing routine clears is_locked — only the three
subscription-transition handlers in routers/payment.py call
unlock_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() treats allowance_unavailable
and usage_invalid as allowed, citing #12663 — but the sync-time lock
collapsed both into one fail-closed boolean.

Fix

Add should_lock_synced_conversation_for_missing_credits() in
utils/subscription.py: it locks only for a resolved, durable no-credits
reason (subscription_inactive, trial_paywalled,
plan_allowance_exhausted), not for a lookup the resolver itself flags as
untrustworthy. Both should_lock call sites in routers/sync.py
(sync_local_files, sync_local_files_v2) now use it instead of
has_transcription_credits; has_transcription_credits itself is untouched
and still fails closed for the listen socket.

Testing

  • Added a parametrized regression test to tests/unit/test_transcription_allowance.py
    that 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_invalid do not lock even though
    has_transcription_credits still (correctly) says no for those rows.
  • Updated the sync-side tests that referenced the old function name/behavior
    (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 pytest green across test_transcription_allowance.py
    (81 tests) and every test_sync_*.py file, plus the full changed-file
    selector from scripts/select_backend_unit_tests.py (63 files) — the only
    two non-green files (test_subscription_restructure.py,
    test_sync_bridge_lifecycle.py) fail/hang identically on unmodified
    origin/main, confirmed by re-running against a clean checkout.
  • bash test-preflight.sh and scripts/pr-preflight --suggest /
    scripts/pr-preflight --pr-body-file both 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 existing has_transcription_credits/resolve_conversation_processing_allowance pattern in the same file — fixes #15232.

Failure-Class: none

Auto-generated from issue feedback by the mini issues-improver — tested and merged.

Review in cubic

…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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A failed allowance lookup during sync paywalls a paying user's conversation permanently

1 participant