Skip to content

fix(sync): don't durably lock a conversation on a transient allowance lookup failure - #15952

Merged
kodjima33 merged 1 commit into
mainfrom
issues-improver/15232-sync-transient-lock
Sep 22, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
issues-improver/15232-sync-transient-lock

Conversation

@kodjima33

@kodjima33 kodjima33 commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

routers/sync.py wrote is_locked=True onto a synced conversation whenever
has_transcription_credits() returned False. That helper fails closed not
only 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() returns
allowance_unavailable / usage_invalid for 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_locked
is written durably, and nothing routinely re-checks it — only three
subscription-transition handlers in routers/payment.py ever call
unlock_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_allowance treats allowance_unavailable
and usage_invalid as allowed, citing #12663. This applies the same
distinction to the durable sync lock in both sync_local_files and
sync_local_files_v2 — only lock when the resolver's reason means the plan
is actually out of minutes.

Why (evidence from the issue)

#15232 traced this precisely to backend/routers/sync.py's should_lock
computation and resolve_transcription_allowance's except clause in
backend/utils/subscription.py, both confirmed unchanged on current main.

What I tested

  • New regression test in tests/unit/test_transcription_allowance.py
    pinning TRANSCRIPTION_ALLOWANCE_TRANSIENT_REASONS to exactly
    {allowance_unavailable, usage_invalid}, asserting real-exhaustion reasons
    stay out of it.
  • Full targeted run: tests/unit/test_transcription_allowance.py,
    test_sync_local_files_async.py (the AST check that the credit gate stays
    offloaded via run_blocking(critical_executor, ...) in both handlers),
    test_subscription_plans.py, test_byok_security_quota.py — all pass.
  • Ran the repo's own scripts/select_backend_unit_tests.py selection for
    this diff (65 files) individually per-file: all pass except two failures
    that reproduce identically on unmodified main (a protobuf descriptor-pool
    collision in test_subscription_restructure.py and cross-file MagicMock
    pollution in test_sync_fair_use_gate.py's
    TestCreateConversationLockPropagation when run in the same combined
    batch 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.py AST check honest about the credit gate staying offloaded via run_blocking.
Line-Count-Exception: backend/utils/subscription.py | 1950 -> 1958 | adds the TRANSCRIPTION_ALLOWANCE_TRANSIENT_REASONS constant that routers/sync.py needs to draw the same transient-vs-exhausted distinction resolve_conversation_processing_allowance already applies (#12663).

Failure-Class: new

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

Review in cubic

… 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
@kodjima33
kodjima33 merged commit 9657214 into main Sep 22, 2026
63 checks passed
@kodjima33
kodjima33 deleted the issues-improver/15232-sync-transient-lock branch September 22, 2026 15:42
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.

1 participant