Skip to content

fix(backend): red-proof deletion-fence read errors and revert dormant plane splits - #12674

Merged
Git-on-my-level merged 2 commits into
mainfrom
agent/deletion-fence-plane
Sep 3, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
agent/deletion-fence-plane

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

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 share account_deletion_firestore_client() → get_data_plane_firestore_client(). A resolved-client Firestore read error (timeout, ServiceUnavailable) already propagated to HTTP 503, but swallowing only snapshot.get() into None left every fence test green. This PR drives enforce_account_deletion_http_access through the real get_user_deletion_wipe_status with a resolved data-plane client whose .collection().document().get() raises, and asserts 503.

grants_cloud_screen_vectors already called get_user_valid_subscription(..., firestore_client=get_customer_firestore_client(), provision=False). Flipping provision back to True JIT-writes plan: basic onto 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 call user_ref.set and must resolve to basic. Lookup exceptions still fail open.

#12667 also pinned first_open_obligations.py, goals.py, and the three get_data_plane_firestore_client() injections in knowledge_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 their origin/main (pre-#12667) behaviour exactly, including the test-stub exports that existed only for those pins, so those three do not land as dormant FC-plane-seam-adopted-by-reader-not-writer splits. 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_raises drives enforce_account_deletion_http_access → the real get_user_deletion_wipe_status in account_deletion_marker.py with a resolved data-plane client whose .get() raises, and asserts HTTP 503. Baseline with the new test: 16 passed.
  • Red-proof (review §6 mutation a2: wrap only snapshot.get() in except Exception: return None):
FAILED tests/unit/test_account_deletion_auth_fence.py::test_auth_fence_fails_closed_when_the_resolved_data_plane_read_raises
Failed: DID NOT RAISE <class 'fastapi.exceptions.HTTPException'>
1 failed, 15 passed in 0.29s

The other 15 fence tests stay green on that swallow. Restoring the uncaught .get() returns 16 passed.

  • test_screen_vector_entitlement_does_not_write_when_customer_subscription_doc_is_missing drives grants_cloud_screen_vectors with a customer client whose users/{uid} doc is missing; user_ref.set is not called and the in-memory plan is PlanType.basic (not entitled). test_screen_vector_entitlement_reads_customer_firestore_without_provisioning source-pins get_customer_firestore_client() and provision=False. Flipping provision=False back to True:
FAILED test_screen_vector_entitlement_reads_customer_firestore_without_provisioning
assert 'provision=False' in source
FAILED test_screen_vector_entitlement_does_not_write_when_customer_subscription_doc_is_missing
AssertionError: Expected 'set' to not have been called. Called 1 times.
2 failed in 1.94s

Lookup exceptions still fail open (test_the_entitlement_gate_fails_open).

  • CI-shaped backend unit run: cd backend && BACKEND_PYTEST_FILE_ISOLATION=1 bash scripts/run-unit-ci.sh --changed-files <changed-files>. first_open_obligations.py selects the full backend unit suite. test_mentor_notifications.py::test_process_mentor_proactive_notification_sends hangs past 90s on this branch and on current origin/main 77575a8f7f (unmocked current_date_for_uid → live db.collection('users') with ADC); it is not this change.
  • Pyright on the changed backend production files: 0 errors.
  • Line-count ratchet: OK: no unapproved line-count increase across 3 changed product source file(s). No Line-Count-Exception (the fix(backend): account-deletion fence reads the data plane the marker is written on #12667 subscription.py 1680→1682 growth is already on main).

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_raises
  • test_screen_vector_entitlement_reads_customer_firestore_without_provisioning
  • test_screen_vector_entitlement_does_not_write_when_customer_subscription_doc_is_missing

Existing 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_client because those modules no longer import it.

Failure class (fixes)

Failure-Class: FC-plane-seam-adopted-by-reader-not-writer

Rollback hazards

  • Reverting the three unreachable pins restores pre-fix(backend): account-deletion fence reads the data plane the marker is written on #12667 compute defaults for first-open, goals, and knowledge-ledger read tools. On GKE with SERVICE_ACCOUNT_JSON those accessors still coincide with the data plane. On a split plane they again match their compute-default siblings (conversations.py CRUD, action_items.py / task_intelligence_control.py, MemoryService / canonical adapter).
  • Mixed desktop-backend fleet (from fix(backend): account-deletion fence reads the data plane the marker is written on #12667, still true): during a mixed desktop-backend rollout, old revisions read BYOK and assistant settings on the compute plane and will miss values the new revision wrote. That is mixed-fleet degradation (BYOK looks unenrolled; web-search opt-out looks absent/allowed), not a deleting account reopening. Old Cloud Run backend sees the same data plane because its accessors coincide.
  • Screen-vector entitlement stays at provision=False plus 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.
  • Rolling this follow-up back re-introduces the three dormant reader/writer splits on first-open, goals, and knowledge-ledger tools. It does not reopen the Beta deletion-fence miss.

Named sibling seams

Seam Verdict
BYOK key lookup (utils/byok.py → users.get_byok_state) Fixed in #12667. get_byok_state / set_byok_active / clear_byok_active use get_data_plane_firestore_client() (users.py:285, :331, :337).
Screen-vector entitlement with provision=True Fixed in #12667; ratcheted here. grants_cloud_screen_vectors calls get_user_valid_subscription(..., firestore_client=get_customer_firestore_client(), provision=False) (subscription.py:144-146). A missing customer subscription doc does not call user_ref.set. Lookup exceptions still fail open.
Web-search opt-out Fixed in #12667. get_assistant_settings / _get_raw_assistant_settings / update_assistant_settings read and write users/{uid} through get_data_plane_firestore_client() (users.py:2204, :2217, :2249).
Pinecone / Typesense wipe fence Fixed in #12667. vector_db.py defaults to data_plane_db; atom_keyword_index.py imports data_plane_db as default_db_client.
Deletion marker, legal holds, cutover, memory ledger, MCP OAuth Fixed in #12667; kept. Reachable from desktop-backend, or no compute-default sibling on the same collection.

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 — sibling backend/database/conversations.py:561 (CRUD defaults at :795, :835, :919, :1624 also get_firestore_client()). Same users/{uid}/conversations/{id} family (jit_first_open lives on the conversation). Not reachable from desktop-backend.
  • backend/database/goals.py — siblings backend/database/action_items.py:53 (firestore_client or db) and backend/database/task_intelligence_control.py:20 (from database._client import db). Same users/{uid}/goals and task_intelligence_control collections. /v1/goals is a 410 on desktop-backend.
  • backend/utils/retrieval/tools/knowledge_ledger_tools.py — siblings backend/utils/memory/memory_service.py:19 and backend/utils/memory/canonical_memory_adapter.py:18 (both default db). Same users/{uid}/memory_items / apply-control collections. Desktop-backend JIT snapshots already inject the data plane; the read tools are not invoked from desktop_chat.py.
  • backend/routers/mcp_sse.py authorize path (:1788-1801) does not call enforce_account_deletion_http_access. It relies on create_grant_and_authorization_code_if_allowed reading account_deletions through data_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.
  • Field-disjoint users/{uid} telemetry writers still on compute: record_client_device / record_user_platform (users.py:135, :178) merge-write the compute copy while BYOK and assistant_settings now live on the data plane. Field-disjoint, so it does not reopen deletion or clobber byok. 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. The provision=False behavioral 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.

Review in cubic

Git-on-my-level and others added 2 commits September 3, 2026 04:43
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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 9 files

Confidence score: 5/5

  • In backend/tests/unit/test_agent_vm_firebase_project_split.py, the stored = users_db.get_user_valid_subscription(...) block repeats a call already made by grants_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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@Git-on-my-level
Git-on-my-level merged commit ad82b23 into main Sep 3, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/deletion-fence-plane branch September 3, 2026 10:31
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