Repository navigation
fix(backend): red-proof deletion-fence read errors and revert dormant plane splits - #12674
Merged
Merged
Conversation
A Firestore .get() error after the data-plane client has already resolved must be HTTP 503, not a clean miss. Pin grants_cloud_screen_vectors at provision=False so a missing customer subscription doc cannot JIT-write. Co-Authored-By: cursor grok-4.6 <[email protected]> Co-authored-by: Cursor <[email protected]>
…eams first_open_obligations, goals, and knowledge_ledger_tools are not reachable from desktop-backend; their sibling readers/writers still default to compute. Restoring origin/main avoids landing those dormant plane splits. Co-Authored-By: cursor grok-4.6 <[email protected]> Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
1 issue found across 9 files
Confidence score: 5/5
- In
backend/tests/unit/test_agent_vm_firebase_project_split.py, thestored = users_db.get_user_valid_subscription(...)block repeats a call already made bygrants_cloud_screen_vectors, adding little guard-level coverage and mostly re-testing existing behavior; remove the duplicate assertion or replace it with a distinct validation.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/tests/unit/test_agent_vm_firebase_project_split.py">
<violation number="1" location="backend/tests/unit/test_agent_vm_firebase_project_split.py:191">
P3: The `stored = users_db.get_user_valid_subscription(...)` block re-executes the identical call that `grants_cloud_screen_vectors` already performs internally, so it adds no guard-level coverage and instead re-tests a helper already covered elsewhere. The meaningful no-write/resolve-to-basic behavior is already captured by `entitled is False` and `user_ref.set.assert_not_called()`. Drop the redundant direct call (and the now-unused `users_db`/`stored` assertions) to keep the test focused on the entitlement guard.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| monkeypatch.setattr(subscription, "get_customer_firestore_client", lambda: customer_client) | ||
|
|
||
| entitled = grants_cloud_screen_vectors(uid) | ||
| stored = users_db.get_user_valid_subscription(uid, firestore_client=customer_client, provision=False) |
There was a problem hiding this comment.
P3: The stored = users_db.get_user_valid_subscription(...) block re-executes the identical call that grants_cloud_screen_vectors already performs internally, so it adds no guard-level coverage and instead re-tests a helper already covered elsewhere. The meaningful no-write/resolve-to-basic behavior is already captured by entitled is False and user_ref.set.assert_not_called(). Drop the redundant direct call (and the now-unused users_db/stored assertions) to keep the test focused on the entitlement guard.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/tests/unit/test_agent_vm_firebase_project_split.py, line 191:
<comment>The `stored = users_db.get_user_valid_subscription(...)` block re-executes the identical call that `grants_cloud_screen_vectors` already performs internally, so it adds no guard-level coverage and instead re-tests a helper already covered elsewhere. The meaningful no-write/resolve-to-basic behavior is already captured by `entitled is False` and `user_ref.set.assert_not_called()`. Drop the redundant direct call (and the now-unused `users_db`/`stored` assertions) to keep the test focused on the entitlement guard.</comment>
<file context>
@@ -157,3 +157,40 @@ def test_desktop_chat_quota_reads_customer_firestore_without_provisioning() -> N
+ monkeypatch.setattr(subscription, "get_customer_firestore_client", lambda: customer_client)
+
+ entitled = grants_cloud_screen_vectors(uid)
+ stored = users_db.get_user_valid_subscription(uid, firestore_client=customer_client, provision=False)
+
+ assert entitled is False
</file context>
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 changed and why
Follow-up to merged #12667. The deletion fence itself is on
main. The adversarial review of that PR found no blocking defect; this change lands the two remaining should-fix guards and stops creating dormant plane splits.Writers and readers of
account_deletions/{uid}already shareaccount_deletion_firestore_client()→get_data_plane_firestore_client(). A resolved-client Firestore read error (timeout,ServiceUnavailable) already propagated to HTTP 503, but swallowing onlysnapshot.get()intoNoneleft every fence test green. This PR drivesenforce_account_deletion_http_accessthrough the realget_user_deletion_wipe_statuswith a resolved data-plane client whose.collection().document().get()raises, and asserts 503.grants_cloud_screen_vectorsalready calledget_user_valid_subscription(..., firestore_client=get_customer_firestore_client(), provision=False). Flippingprovisionback toTrueJIT-writesplan: basiconto a missing customer subscription doc, and no test failed on that flip. This PR adds a source pin and a behavioral test: a missing subscription doc with the customer client must not calluser_ref.setand must resolve to basic. Lookup exceptions still fail open.#12667 also pinned
first_open_obligations.py,goals.py, and the threeget_data_plane_firestore_client()injections inknowledge_ledger_tools.py. Those modules are unreachable from desktop-backend, and their sibling readers/writers of the same collections still default to the compute client. This PR restores theirorigin/main(pre-#12667) behaviour exactly, including the test-stub exports that existed only for those pins, so those three do not land as dormantFC-plane-seam-adopted-by-reader-not-writersplits. Every other pin from #12667 stays.Product invariants affected
none
How it was verified
test_auth_fence_fails_closed_when_the_resolved_data_plane_read_raisesdrivesenforce_account_deletion_http_access→ the realget_user_deletion_wipe_statusinaccount_deletion_marker.pywith a resolved data-plane client whose.get()raises, and asserts HTTP 503. Baseline with the new test:16 passed.snapshot.get()inexcept Exception: return None):The other 15 fence tests stay green on that swallow. Restoring the uncaught
.get()returns16 passed.test_screen_vector_entitlement_does_not_write_when_customer_subscription_doc_is_missingdrivesgrants_cloud_screen_vectorswith a customer client whoseusers/{uid}doc is missing;user_ref.setis not called and the in-memory plan isPlanType.basic(not entitled).test_screen_vector_entitlement_reads_customer_firestore_without_provisioningsource-pinsget_customer_firestore_client()andprovision=False. Flippingprovision=Falseback toTrue:Lookup exceptions still fail open (
test_the_entitlement_gate_fails_open).cd backend && BACKEND_PYTEST_FILE_ISOLATION=1 bash scripts/run-unit-ci.sh --changed-files <changed-files>.first_open_obligations.pyselects the full backend unit suite.test_mentor_notifications.py::test_process_mentor_proactive_notification_sendshangs past 90s on this branch and on currentorigin/main77575a8f7f(unmockedcurrent_date_for_uid→ livedb.collection('users')with ADC); it is not this change.OK: no unapproved line-count increase across 3 changed product source file(s).NoLine-Count-Exception(the fix(backend): account-deletion fence reads the data plane the marker is written on #12667subscription.py1680→1682 growth is already onmain).Could not exercise a live Beta request against production Firestore (no production access). The two-plane unit test remains the behavioral stand-in for that path.
Tests
test_auth_fence_fails_closed_when_the_resolved_data_plane_read_raisestest_screen_vector_entitlement_reads_customer_firestore_without_provisioningtest_screen_vector_entitlement_does_not_write_when_customer_subscription_doc_is_missingExisting fence, cutover, BYOK, goals, first-open, and knowledge-ledger tests keep their importer-binding patches. The goals / first-open / knowledge-ledger isolation stubs no longer export
get_data_plane_firestore_clientbecause those modules no longer import it.Failure class (fixes)
Failure-Class: FC-plane-seam-adopted-by-reader-not-writer
Rollback hazards
SERVICE_ACCOUNT_JSONthose accessors still coincide with the data plane. On a split plane they again match their compute-default siblings (conversations.pyCRUD,action_items.py/task_intelligence_control.py,MemoryService/ canonical adapter).backendsees the same data plane because its accessors coincide.provision=Falseplus the customer Firestore client. A miss defaults to basic (no cloud screen vectors) instead of JIT-creating a subscription doc. Lookup exceptions still fail open and write vectors.Named sibling seams
utils/byok.py→users.get_byok_state)get_byok_state/set_byok_active/clear_byok_activeuseget_data_plane_firestore_client()(users.py:285,:331,:337).provision=Truegrants_cloud_screen_vectorscallsget_user_valid_subscription(..., firestore_client=get_customer_firestore_client(), provision=False)(subscription.py:144-146). A missing customer subscription doc does not calluser_ref.set. Lookup exceptions still fail open.get_assistant_settings/_get_raw_assistant_settings/update_assistant_settingsread and writeusers/{uid}throughget_data_plane_firestore_client()(users.py:2204,:2217,:2249).vector_db.pydefaults todata_plane_db;atom_keyword_index.pyimportsdata_plane_db as default_db_client.Follow-ups
Next instances of
FC-plane-seam-adopted-by-reader-not-writer. Move each module together with its sibling(s) in one change; do not pin the reader (or writer) alone.backend/database/first_open_obligations.py— siblingbackend/database/conversations.py:561(CRUD defaults at:795,:835,:919,:1624alsoget_firestore_client()). Sameusers/{uid}/conversations/{id}family (jit_first_openlives on the conversation). Not reachable from desktop-backend.backend/database/goals.py— siblingsbackend/database/action_items.py:53(firestore_client or db) andbackend/database/task_intelligence_control.py:20(from database._client import db). Sameusers/{uid}/goalsandtask_intelligence_controlcollections./v1/goalsis a 410 on desktop-backend.backend/utils/retrieval/tools/knowledge_ledger_tools.py— siblingsbackend/utils/memory/memory_service.py:19andbackend/utils/memory/canonical_memory_adapter.py:18(both defaultdb). Sameusers/{uid}/memory_items/ apply-control collections. Desktop-backend JIT snapshots already inject the data plane; the read tools are not invoked fromdesktop_chat.py.backend/routers/mcp_sse.pyauthorize path (:1788-1801) does not callenforce_account_deletion_http_access. It relies oncreate_grant_and_authorization_code_if_allowedreadingaccount_deletionsthroughdata_plane_db(mcp_oauth.py:575-590). An unresolvable data-plane client raises out of the grant write as HTTP 500, not mapped to 503. Fail-closed, different status. MCP is not mounted on desktop-backend. Subsequent MCP data calls do use the HTTP fence.users/{uid}telemetry writers still on compute:record_client_device/record_user_platform(users.py:135,:178) merge-write the compute copy while BYOK andassistant_settingsnow live on the data plane. Field-disjoint, so it does not reopen deletion or clobberbyok. Pre-existing telemetry-to-empty-dev-Firestore.The
.get()-swallow guard named in the #12667 review is fixed in this PR.New guards
The resolved-client
.get()raise test is the recurrence guard for swallowing a deletion-marker read error into a clean miss. Theprovision=Falsebehavioral test is the recurrence guard for JIT-writing Free onto a missing customer subscription doc from screen-vector entitlement. They are not a repo-wide plane-seam checker because the plane is a runtime client identity, not a static import graph.