Skip to content

fix(backend): account-deletion fence reads the data plane the marker is written on - #12667

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

The account-deletion auth fence read account_deletions/{uid} through get_firestore_client() (compute plane). The deletion executor writes that marker on the customer data plane. On Omi Beta (desktop-backend) the planes differ, so the lookup missed cleanly, returned None, and a user whose deletion was in progress kept reading and writing production data. HTTP 503 only fired on an exception, never on a clean miss.

Writers and readers now share one accessor, account_deletion_firestore_client() in backend/database/account_deletion_marker.py, which pins get_data_plane_firestore_client(). If that client cannot be resolved, the fence fails closed (503). Sibling per-user markers that had the same reader/writer split are pinned the same way.

Product invariants affected

  • INV-MEM-1
  • INV-MEM-3
  • INV-MEM-4
  • INV-CUTOVER-1

How it was verified

  • Guard test: backend/tests/unit/test_account_deletion_auth_fence.py::test_auth_fence_refuses_when_the_deletion_marker_is_only_on_the_data_plane runs the production fence (enforce_account_deletion_http_access → get_user_deletion_wipe_status) with two fake Firestore clients (compute empty, data plane holding wipe_status=running) and asserts HTTP 403.
  • Fail-closed: test_auth_fence_fails_closed_when_the_data_plane_client_cannot_be_resolved asserts HTTP 503 when the data-plane client cannot be resolved.
  • Red-proof: mutating account_deletion_firestore_client to return get_firestore_client():
FAILED test_auth_fence_refuses_when_the_deletion_marker_is_only_on_the_data_plane
FAILED test_auth_fence_fails_closed_when_the_data_plane_client_cannot_be_resolved
Failed: DID NOT RAISE <class 'fastapi.exceptions.HTTPException'>
2 failed in 0.59s

Restoring the data-plane accessor: 15 passed in 0.69s. Reintroducing the same fallback: Failed: DID NOT RAISE HTTPException again (1 failed in 0.65s).

  • Isolation stubs that load_module_fresh database.users / database.conversations now export get_data_plane_firestore_client so the new import does not die at collection time. Typesense upserts default to data_plane_db (matching Pinecone) instead of passing None into the fence.
  • CI-shaped backend unit run: cd backend && BACKEND_PYTEST_FILE_ISOLATION=1 bash scripts/run-unit-ci.sh --changed-files <changed-files>. test_mentor_notifications.py::test_process_mentor_proactive_notification_sends hangs past 90s on this branch and on origin/main e37febd0b3 (unmocked current_date_for_uid → live db.collection('users') with ADC); it is not this fence change.
  • Pyright on the changed backend files: 0 errors.

Could not exercise a live Beta request against production Firestore (no production access). The two-plane unit test is the behavioral stand-in for that path.

Tests

Regression that would have caught the bug: test_auth_fence_refuses_when_the_deletion_marker_is_only_on_the_data_plane. Existing fence, cutover, and BYOK tests keep their importer-binding patches.

Failure class (fixes)

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

Line-Count-Exception: backend/utils/subscription.py | 1680 -> 1682 | screen-vector entitlement pins customer Firestore with provision=False

Rollback hazards

  • Desktop-backend without OMI_FIRESTORE_DATA_PLANE_PROJECT fails closed (HTTP 503) on every authenticated request instead of serving. That env var is already required on desktop-backend; this makes the deletion fence honor it.
  • A data-plane service-account / OMI_FIRESTORE_DATA_PLANE_PROJECT mismatch still raises (existing _build_data_plane_firestore_client behavior) and now maps to 503 on the fence.
  • Screen-vector entitlement uses provision=False plus the customer Firestore client. A miss now defaults to basic (no cloud screen vectors) instead of JIT-creating a subscription doc. Lookup exceptions still fail open and write vectors (existing fail-open).
  • Legal-hold acquire/finish on the wipe executor no longer injects compute database_client.db. On a split plane the gate and the marker stay on the data plane together; rolling back re-splits them.
  • Memory write fences that used to pass a compute-default client now omit it so the shared accessor resolves the data plane. Typesense upserts default to data_plane_db (same as Pinecone) and pass that client into the fence. If the data plane cannot be resolved, those writes fail closed instead of proceeding.
  • Rolling this PR back reopens the Beta deletion-fence miss: a deleting account keeps access.
  • Goals, memory ledger, MCP OAuth, first-open obligations, and knowledge-ledger read tools now default to the data plane. On GKE with SERVICE_ACCOUNT_JSON that coincides with the old client.

Named sibling seams

Seam Verdict
BYOK key lookup (utils/byok.py → users.get_byok_state) Fixed. 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. grants_cloud_screen_vectors now calls get_user_valid_subscription(..., firestore_client=get_customer_firestore_client(), provision=False) (subscription.py:144-146). Entitlements stay on the customer client, not the data-plane user-doc client.
Web-search opt-out Fixed. 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 wipe fence Fixed. vector_db.py defaults to data_plane_db and external_write_fence uses that client (vector_db.py:15, :50). memories.py:46 / :54 omit an injected client so the shared accessor resolves the data plane. atom_keyword_index.py imports data_plane_db as default_db_client and passes that resolved client into the fence (atom_keyword_index.py:16, :297), matching Pinecone.

Also pinned in this sweep (same reader/writer class):

  • Deletion marker R/W: account_deletion_firestore_client() imported by users.py, legal_holds.py.
  • Wipe executor legal-hold acquire/finish: dropped firestore_client=database_client.db so the accessor owns the plane (account_deletion.py background_wipe_user_data).
  • Canonical derived purge and maintenance-registry delete: get_data_plane_firestore_client().
  • Account cutover control docs: get_data_plane_firestore_client() (account_cutover.py:25, :180).
  • First-open obligations: get_data_plane_firestore_client() (first_open_obligations.py:13, :94).
  • Goals: _get_db prefers get_data_plane_firestore_client (goals.py:60).
  • Memory ledger: data_plane_db (memory_ledger.py:22).
  • MCP OAuth: data_plane_db (mcp_oauth.py:15).
  • Knowledge-ledger read tools: get_data_plane_firestore_client() (knowledge_ledger_tools.py:325+). Write tools already threaded a data-plane client.

Remaining get_firestore_client() readers of deletion / JIT / cutover collections

Verified against a backend-wide grep of get_firestore_client() after the sweep.

Site Why it is already correct, or remaining
account_deletion_transitions.py:21 read_agent_vm_migration_journals Verified-safe. users/{uid}/agentVmMigrations is compute-local (GCE / agentVm). Must keep get_firestore_client().
users.py:2110 get_agent_vm Verified-safe. Reads compute-local agentVm on db.
users.py:1751, :1796 location-context consent Verified-safe for this class. Reader and writer share get_firestore_client(); there is no reader/writer split. On GKE, SERVICE_ACCOUNT_JSON makes this the data plane.
users.py:1678 get_user_subscription Verified-safe for the named seam. Defaults to db; screen-vector now injects get_customer_firestore_client(). Quota/paywall callers that need production entitlements already pass the customer client.
users.py:1304 delete_user_data Verified-safe. Wipe runs on GKE, where SERVICE_ACCOUNT_JSON makes db the data plane. Not the Beta serving-plane split.
account_deletion_projection_fence.py:22 Verified-safe. Requires an injected db_client. Callers (memory_system.py:52, canonical_memory_adapter.py:3545, daily_memory_sweep.py:2853, jit_proactivity_store via data_plane_db) pass the data-plane client.
jit_proactivity_store.py:83 Verified-safe. Defaults to data_plane_db; reads account_deletions/{uid} on that client.
knowledge_ledger_writer_transition.py:399 _client_or_default Verified-safe. Default is get_firestore_client(), but production knowledge_ledger_migration.py:344 always threads db_client.
canonical_graph.py:89, routers/knowledge_graph.py:73, :258 Remaining default, GKE-coinciding. Graph routes run on the GKE backend, where SERVICE_ACCOUNT_JSON makes get_firestore_client() the data plane. Not served on desktop-backend.
memories.py:125 _get_db Remaining default for memory writes. The deletion fence no longer uses this client. Memory document CRUD still defaults to get_firestore_client(); GKE coincides.
mcp_api_key.py:41, dev_api_key.py:34 Verified-safe. Credential wipe runs on GKE; SERVICE_ACCOUNT_JSON is the data plane.
conversations.py, action_items.py, recording_sessions.py, and other get_firestore_client() user-subtree modules Remaining GKE-coinciding defaults. The deletion executor wipes users/{uid} through delete_user_data on GKE (db == data plane). These are not the Beta auth-fence path. Migrating every user-doc default is a follow-up, not this fence fix.

New guards

The two-plane auth-fence unit test is the recurrence guard for this class on the deletion marker. It is not a repo-wide plane-seam checker because the plane is a runtime client identity, not a static import graph; a shared primitive that grepped get_firestore_client() would false-positive every compute-local agentVm path. The real merged instance this would have caught is the 2026-08-30 adversarial finding (same class as PR #12402).

Review in cubic

Git-on-my-level and others added 2 commits September 3, 2026 02:00
…is written on

The Beta serving plane's compute Firestore is empty for account_deletions/{uid};
the marker lives on the data plane. A compute-plane fallback was a clean miss
that reopened a deleting account. Pin readers and writers to one accessor.

Co-Authored-By: cursor grok-4.6 <[email protected]>
Co-authored-by: Cursor <[email protected]>
Passing None into the deletion fence made Typesense upserts fail open and
broke isolation stubs that load users/conversations after the plane pin.

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.

5 issues found across 28 files

Confidence score: 2/5

  • backend/services/users/account_deletion.py can purge canonical state on the data plane while deleting users/{uid} through the compute-plane database when projects differ, risking incomplete or inconsistent account deletion; ensure all deletion reads and writes use the data-plane client and strengthen the regression test in backend/tests/services/users/test_account_deletion.py to assert that exact client.
  • backend/database/account_cutover.py raises RuntimeError when the data-plane client cannot be resolved before callers can map the condition to 503, exposing an unexpected server error instead of the intended unavailable response; convert this failure to the typed unavailable state at the boundary.
  • backend/database/legal_holds.py performs data-plane resolution outside its fail-closed try block, so account-deletion admission can reach the generic HTTP 500 handler rather than returning a retryable 503; move resolution into the guarded path or normalize the exception.
  • backend/database/memories.py resolves the write fence against the data plane while the wrapped memory write still uses another client, which can allow the fence and write to observe different stores; align the memory write client with the data-plane fence or explicitly verify the intended client pairing.
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/services/users/test_account_deletion.py">

<violation number="1" location="backend/tests/services/users/test_account_deletion.py:1522">
P3: The regression guard only asserts that a `db_client` kwarg is present, not that it is the data-plane client. Because the PR's fix is specifically about pinning deletion reads/writes to `get_data_plane_firestore_client()`, this assertion would still pass if the call regressed to the compute-plane `get_firestore_client()`. Verify the kwarg value equals `database_client.get_data_plane_firestore_client()` (mocking that accessor in the test) so the test actually guards the seam it is meant to protect.</violation>
</file>

<file name="backend/services/users/account_deletion.py">

<violation number="1" location="backend/services/users/account_deletion.py:216">
P1: When the data-plane and compute-plane projects differ, this worker now purges canonical state on the data plane but still deletes `users/{uid}` through `users_db.delete_user_data`, which uses the compute-plane `db`; the account can therefore retain user documents or have only part of its data wiped. Resolve one pinned client before the worker starts and thread it through the user-data deletion and every Firestore inventory read in this flow.</violation>
</file>

<file name="backend/database/legal_holds.py">

<violation number="1" location="backend/database/legal_holds.py:132">
P2: When the data-plane client cannot be resolved, this new call raises before the fail-closed `try` block, so account-deletion admission reaches the route's generic HTTP 500 handler instead of returning the retryable 503 promised for this fence. Resolve the client inside the authority-error wrapper and map that typed failure to 503 at the deletion endpoint.</violation>
</file>

<file name="backend/database/account_cutover.py">

<violation number="1" location="backend/database/account_cutover.py:25">
P2: When the data-plane client cannot be resolved, this new default raises `RuntimeError` before the cutover callers can map the state to 503. Handle data-plane resolution failures as the same typed unavailable state at the database/HTTP boundary so `/v1/account/cutover/control` and the cutover auth fence return a retryable 503 rather than an unhandled 500.</violation>
</file>

<file name="backend/database/memories.py">

<violation number="1" location="backend/database/memories.py:45">
P2: In _account_write_gated/_destination_account_write_gated, the fence now resolves to the data plane (via account_deletion_firestore_client -> get_data_plane_firestore_client) while the wrapped memory write still resolves its own client via _get_db -> get_firestore_client (compute plane) when no firestore_client is injected. The deletion-marker fence and the write it guards now run on different planes by default, which is the same read/write plane seam the PR is meant to close. Resolve one shared client in the decorator and pass it to both the fence and the wrapped write so they stay on the same plane.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


try:
canonical_result = purge_canonical_derived_user_data(uid)
canonical_result = purge_canonical_derived_user_data(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: When the data-plane and compute-plane projects differ, this worker now purges canonical state on the data plane but still deletes users/{uid} through users_db.delete_user_data, which uses the compute-plane db; the account can therefore retain user documents or have only part of its data wiped. Resolve one pinned client before the worker starts and thread it through the user-data deletion and every Firestore inventory read in this flow.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/services/users/account_deletion.py, line 216:

<comment>When the data-plane and compute-plane projects differ, this worker now purges canonical state on the data plane but still deletes `users/{uid}` through `users_db.delete_user_data`, which uses the compute-plane `db`; the account can therefore retain user documents or have only part of its data wiped. Resolve one pinned client before the worker starts and thread it through the user-data deletion and every Firestore inventory read in this flow.</comment>

<file context>
@@ -213,7 +213,9 @@ def require_vector_index(operation: str):
 
     try:
-        canonical_result = purge_canonical_derived_user_data(uid)
+        canonical_result = purge_canonical_derived_user_data(
+            uid, db_client=database_client.get_data_plane_firestore_client()
+        )
</file context>

if not uid:
raise LegalHoldAuthorityUnavailable("account deletion legal-hold lookup requires a uid")
client = firestore_client or get_firestore_client()
client = account_deletion_firestore_client(firestore_client=firestore_client)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: When the data-plane client cannot be resolved, this new call raises before the fail-closed try block, so account-deletion admission reaches the route's generic HTTP 500 handler instead of returning the retryable 503 promised for this fence. Resolve the client inside the authority-error wrapper and map that typed failure to 503 at the deletion endpoint.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/database/legal_holds.py, line 132:

<comment>When the data-plane client cannot be resolved, this new call raises before the fail-closed `try` block, so account-deletion admission reaches the route's generic HTTP 500 handler instead of returning the retryable 503 promised for this fence. Resolve the client inside the authority-error wrapper and map that typed failure to 503 at the deletion endpoint.</comment>

<file context>
@@ -129,7 +129,7 @@ def assert_account_deletion_permitted(uid: str, *, firestore_client: Any | None
     if not uid:
         raise LegalHoldAuthorityUnavailable("account deletion legal-hold lookup requires a uid")
-    client = firestore_client or get_firestore_client()
+    client = account_deletion_firestore_client(firestore_client=firestore_client)
     try:
         snapshot = _document(client, f"{LEGAL_HOLDS_COLLECTION}/{uid}").get()
</file context>


def _control_ref(uid: str, *, firestore_client: Any = None):
client = firestore_client if firestore_client is not None else _client.get_firestore_client()
client = firestore_client if firestore_client is not None else _client.get_data_plane_firestore_client()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: When the data-plane client cannot be resolved, this new default raises RuntimeError before the cutover callers can map the state to 503. Handle data-plane resolution failures as the same typed unavailable state at the database/HTTP boundary so /v1/account/cutover/control and the cutover auth fence return a retryable 503 rather than an unhandled 500.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/database/account_cutover.py, line 25:

<comment>When the data-plane client cannot be resolved, this new default raises `RuntimeError` before the cutover callers can map the state to 503. Handle data-plane resolution failures as the same typed unavailable state at the database/HTTP boundary so `/v1/account/cutover/control` and the cutover auth fence return a retryable 503 rather than an unhandled 500.</comment>

<file context>
@@ -22,7 +22,7 @@ def __init__(self, message: str = 'cutover concurrency conflict', *, code: str =
 
 def _control_ref(uid: str, *, firestore_client: Any = None):
-    client = firestore_client if firestore_client is not None else _client.get_firestore_client()
+    client = firestore_client if firestore_client is not None else _client.get_data_plane_firestore_client()
     return client.collection('users').document(uid).collection(CONTROL_COLLECTION).document(CONTROL_DOCUMENT)
 
</file context>

def wrapped(uid: str, *args: Any, **kwargs: Any) -> Any:
database = _get_db(kwargs.get("firestore_client"))
with external_write_fence(uid, firestore_client=database):
with external_write_fence(uid, firestore_client=kwargs.get("firestore_client")):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: In _account_write_gated/_destination_account_write_gated, the fence now resolves to the data plane (via account_deletion_firestore_client -> get_data_plane_firestore_client) while the wrapped memory write still resolves its own client via _get_db -> get_firestore_client (compute plane) when no firestore_client is injected. The deletion-marker fence and the write it guards now run on different planes by default, which is the same read/write plane seam the PR is meant to close. Resolve one shared client in the decorator and pass it to both the fence and the wrapped write so they stay on the same plane.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/database/memories.py, line 45:

<comment>In _account_write_gated/_destination_account_write_gated, the fence now resolves to the data plane (via account_deletion_firestore_client -> get_data_plane_firestore_client) while the wrapped memory write still resolves its own client via _get_db -> get_firestore_client (compute plane) when no firestore_client is injected. The deletion-marker fence and the write it guards now run on different planes by default, which is the same read/write plane seam the PR is meant to close. Resolve one shared client in the decorator and pass it to both the fence and the wrapped write so they stay on the same plane.</comment>

<file context>
@@ -42,8 +42,7 @@ class FirestoreNotFound(Exception):
     def wrapped(uid: str, *args: Any, **kwargs: Any) -> Any:
-        database = _get_db(kwargs.get("firestore_client"))
-        with external_write_fence(uid, firestore_client=database):
+        with external_write_fence(uid, firestore_client=kwargs.get("firestore_client")):
             return function(uid, *args, **kwargs)
 
</file context>

account_deletion.purge_canonical_derived_user_data.assert_called_once()
purge_args, purge_kwargs = account_deletion.purge_canonical_derived_user_data.call_args
assert purge_args == ('uid1',)
assert 'db_client' in purge_kwargs

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 regression guard only asserts that a db_client kwarg is present, not that it is the data-plane client. Because the PR's fix is specifically about pinning deletion reads/writes to get_data_plane_firestore_client(), this assertion would still pass if the call regressed to the compute-plane get_firestore_client(). Verify the kwarg value equals database_client.get_data_plane_firestore_client() (mocking that accessor in the test) so the test actually guards the seam it is meant to protect.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/tests/services/users/test_account_deletion.py, line 1522:

<comment>The regression guard only asserts that a `db_client` kwarg is present, not that it is the data-plane client. Because the PR's fix is specifically about pinning deletion reads/writes to `get_data_plane_firestore_client()`, this assertion would still pass if the call regressed to the compute-plane `get_firestore_client()`. Verify the kwarg value equals `database_client.get_data_plane_firestore_client()` (mocking that accessor in the test) so the test actually guards the seam it is meant to protect.</comment>

<file context>
@@ -1516,7 +1516,10 @@ def test_purge_derived_user_data_continues_after_each_failure(monkeypatch):
+    account_deletion.purge_canonical_derived_user_data.assert_called_once()
+    purge_args, purge_kwargs = account_deletion.purge_canonical_derived_user_data.call_args
+    assert purge_args == ('uid1',)
+    assert 'db_client' in purge_kwargs
     assert [failure['operation'] for failure in result['required_failures']] == [
         'conversation_vectors',
</file context>

@Git-on-my-level
Git-on-my-level merged commit 6d49b7c into main Sep 3, 2026
46 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/deletion-fence-plane branch September 3, 2026 08:19
Git-on-my-level added a commit that referenced this pull request Sep 3, 2026
… plane splits (#12674)

## 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 #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-#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 #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.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/12674?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
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