Repository navigation
[codex] Extract user data services - #8393
Conversation
There was a problem hiding this comment.
4 issues found across 10 files
Confidence score: 2/5
- In
backend/services/users/account_deletion.py, running deletion cleanup in a daemon thread means shutdown/redeploy can kill the wipe mid-flight, leaving accounts only partially deleted after users are told deletion began; move this to a durable non-daemon worker/job (or block until completion) before merging. - In
backend/services/users/data_export.py, the hard 10,000-row cap for memories/action_items can produce incomplete GDPR/CCPA exports for heavy users, which is a clear user/compliance risk; remove the silent truncation and paginate/stream all records before merge. - In
backend/services/users/data_export.py, doing large DB reads before the firstyielddefeats streaming and can spike latency/memory or trigger timeouts on large accounts; restructure to fetch in chunks and yield early to restore true streaming behavior. - In
backend/tests/unit/test_delete_account_stripe_cancel.py, the free-user and Stripe-error tests don’t assertthread.start(), so regressions in launching cleanup could slip through; add explicitstart()assertions in those paths before merging to lock in expected behavior.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Addressed the user-data service review feedback:
Verification run locally: |
There was a problem hiding this comment.
2 issues found across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
df3d959 to
12cfdad
Compare
|
Follow-up fixes for the second Cubic pass:
Verification run locally: |
kodjima33
left a comment
There was a problem hiding this comment.
Backend refactor: extract user data services (account deletion/export) — refactor, approve only
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12cfdade2b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Add the router-level delegation/error/header test to test.sh so it runs in CI alongside the service-level tests it complements. Addresses Codex review comment (P2): the new test file was added but never exercised by the repository CI runner.
|
Wired Verification:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7af787a28d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Add a dedicated bounded cleanup executor for long-running account deletion wipes and enqueue background_wipe_user_data there instead of the shared postprocess pool. This keeps bursts of account deletions from starving normal conversation post-processing work. Update account deletion tests to assert the wipe is enqueued on the cleanup executor.
|
Addressed the new Codex P2 about account deletion wipes consuming the shared postprocess pool. What changed:
Verification passed locally:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7bb537995
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codex review (discussion_r3482677110) flagged that the test asserts users_service.postprocess_executor, which no longer exists on the module. account_deletion.py imports and submits work with cleanup_executor (the dedicated long-running account-deletion pool). Update all three submit.assert_called_once_with assertions to reference cleanup_executor. Verification: pytest tests/unit/test_delete_account_stripe_cancel.py (3 passed) and tests/services/users/test_account_deletion.py (7 passed).
|
Fixed in
Updated all three assertions to reference Verification:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3253151c13
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Addresses P1 review feedback (Codex): the new cleanup_executor was added to _ALL_EXECUTORS but test_get_executor_metrics_returns_all_pools still asserted the old 7-element set. Update the expected set to include 'cleanup'.
Fixed: include
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1ee3ac15e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Address P1 review feedback from chatgpt-codex-connector: - test_llm_usage_endpoints.py: add get_people/get_user_profile to the database.users stub so services.users.data_export's module-level import succeeds when routers.users is imported under lightweight stubs. - test_lock_bypass_fixes.py: re-point gdpr export test patches from routers.users.* to services.users.data_export.* and use get_non_filtered_memories (the actual helper the service calls).
Addressed P1 review feedbackFixed both P1 items raised by @chatgpt-codex-connector about the backend test runner breaking after the service extraction. Thread 1 —
|
|
To use Codex here, create an environment for this repo. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d63a330822
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…port to module scope
- P1 (account_deletion.py:106): persist wipe_status pending/completed markers
in the account_deletions Firestore collection before enqueueing the wipe.
A deploy/restart that cancels a queued cleanup_executor future no longer
leaves the deletion silently incomplete — a reconciliation worker can query
for wipe_status='pending' and re-enqueue. mark_user_deletion_wipe_started
is written before enqueue; mark_user_deletion_wipe_completed in finally.
- P2 (routers/users.py:148): move start_account_deletion import to module
scope per backend AGENTS.md Import Rules ('All imports at module top level').
- Update tests to assert wipe-status persistence and module-level import patching.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Review feedback addressed
P1: Persist account-deletion wipes before returning OK (account_deletion.py:106)
Added persistent wipe-status markers in the existing account_deletions Firestore collection so a deploy/pod restart that cancels a queued cleanup_executor future no longer leaves the deletion silently incomplete.
What changed:
database/users.py: addedmark_user_deletion_wipe_started(uid)andmark_user_deletion_wipe_completed(uid). Both writewipe_statusto the top-levelaccount_deletionsdocument (same collection that already stores deletion feedback, survives the user-record wipe).account_deletion.py:mark_user_deletion_wipe_startedis called right beforesubmit_with_context(line 117).mark_user_deletion_wipe_completedis called in afinallyblock at the end ofbackground_wipe_user_dataso it runs even when the wipe fails.- A reconciliation worker can query
where wipe_status == 'pending'to find and re-enqueue wipes that were cancelled before they started. The marker write itself is best-effort (logged on failure, never blocks deletion).
This is a lighter-weight fix than a full durable queue + drain worker, which would be a separate infrastructure change. The pending marker gives the same reconciliation capability.
P2: Move account-deletion import to module scope (routers/users.py:148)
Moved from services.users.account_deletion import start_account_deletion to the module-level imports (line 25), alongside the existing from services.users.data_export import iter_user_data_export. Verified no circular dependency — account_deletion.py imports only from database/ and utils/, never from routers/.
Verification
tests/services/users/test_account_deletion.py: 7 passed — updated to assert wipe-status persistence ordering andfinally-block behaviortests/routers/test_users.py: 3 passed — updated to patch the module-level reference viapatch.objectinstead ofsys.modulesinjectiontests/unit/test_delete_account_*+test_executors.py: 32 passedblack --check --line-length 120: all files clean
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 630944cbb6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Address Codex P1 review feedback: a crash or deploy after auth.delete_account() succeeds but before the marker transitions to 'pending' left a 'deleting_auth' record outside the reconciler's recovery query, permanently stranding the Firestore/GCS/vector wipe. Changes: - get_pending_deletion_wipes() now also fetches stale 'deleting_auth' records (age-gated in Python, same over-fetch pattern as 'pending') - _claim_deletion_wipe_txn() handles 'deleting_auth' status with the same transactional age re-validation as 'pending' - reconcile_pending_deletion_wipes() verifies the Firebase auth user is actually gone via _is_auth_user_gone() before recovering a 'deleting_auth' record — fails safe on indeterminate errors so a transient Firebase outage cannot trigger a premature data wipe - Updated docstrings/comments throughout to reflect the new recovery guarantee Tests: 5 new tests covering recovery (user gone), skip (user exists), skip (indeterminate error), and _is_auth_user_gone helper (both paths). All 19 account_deletion tests + 9 claim_deletion_wipe_txn tests pass.
P1 fix: Recover stranded
|
|
This is already handled in the squashed commit. The recovery path for stale
So the crash scenario described — backend dies after Verified by running
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d2a902e60
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Addresses chatgpt-codex-connector P2: the stubbed database.users module stayed cached in sys.modules after import against the fake _client.db, leaking into later unit tests in a multi-file pytest run. Record its prior sys.modules entry alongside the transitive stubs so the autouse fixture restores/removes it after this module's tests finish.
|
Addressed P2: Remove the stubbed database.users module after import in commit 998710b. What changed Fix: record Verification 9 passed, 0 failed. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 998710be1a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Addresses chatgpt-codex-connector P2 (discussion_r3484122470): the imported services.users.account_deletion and services.users.data_export modules stayed cached in sys.modules with MagicMock globals (users_db, stripe_utils, cleanup_executor, etc.) after being loaded via the _StubFinder. In a multi-file pytest run, a later test importing the real service would reuse this mock-backed copy instead of reloading production dependencies. Both test files now pop the service module and its parent packages from sys.modules in the finally block, alongside the existing stub cleanup.
|
Two fixes pushed (commit ec8323c) plus a design assessment for the third comment. Fixed — P2: Remove stubbed service modules after import ( The imported Fix: pop Verification: 32 tests pass across all three affected test modules: 32 passed, 0 failed. Assessment — P2: Don't reclaim pending wipes solely by age ( This is a valid robustness observation but not a correctness bug in the current design. Walking through the concurrent-double-enqueue scenario:
The concern would become a real bug if the wipe operations were non-idempotent or if the stale_after window were shorter than realistic wipe durations. The current |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec8323ccb3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Address review feedback (chatgpt-codex-connector P2): the reconciler previously reclaimed 'pending' wipe markers solely by age, which meant a slow but live wipe (queued behind other cleanup jobs) could be duplicate-claimed after the short 10-min stale window, and a later duplicate failure could overwrite a successful completion. Introduce a 'running' state that background_wipe_user_data transitions to at the start of execution. The reconciler now distinguishes: - stale 'pending' (queued but never started → genuinely orphaned → reclaim after 10 min) - 'running' (actively executing → only reclaim after 30 min to account for legitimately slow wipes that sit behind other jobs) Added mark_user_deletion_wipe_running(), updated get_pending_deletion_wipes and _claim_deletion_wipe_txn to handle 'running' with its own stale window, and added 6 new tests covering the running-state behavior.
The running-state fix in the prior commit (b742b47) uses mark_user_deletion_wipe_running() directly in the worker and guards concurrent execution via _claim_deletion_wipe_txn(). The _claim_running_wipe_txn/claim_running_wipe helpers were an unused alternative approach — remove them.
Review feedback addressed
Running state prevents duplicate wipe reclaim (#3484183349)The core concern was that a slow but live wipe could be reclaimed as orphaned after the 10-minute Fix: Introduced a
Changes:
VerificationNew tests added:
|
Fixed: Don't reclaim pending wipes solely by ageAddressed the P2 feedback from What changedIntroduced a
This prevents a slow but live wipe from being duplicate-claimed after the short 10-min Files changed
Verification
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d78f6fd7b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
2 issues found across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
… restore router
Address 3 review threads from chatgpt-codex-connector:
P1 — set_user_deletion_feedback() used a non-merge set() on
account_deletions/{uid}, which could erase a durable wipe marker
(pending/failed/retrying) on a retried delete request. Now uses
merge=True so existing wipe_status fields are preserved.
P2 — retrying claims were reclaimed using the short stale_after (10 min)
window. If the executor backlog was full, a queued retrying future could
be re-claimed before it started running. Now uses running_stale_after
(30 min) for both get_pending_deletion_wipes and _claim_deletion_wipe_txn.
P2 — tests/routers/test_users.py leaked the stub-loaded routers.users
module into sys.modules. Now pops routers.users and service modules after
collection, and restores in the module-scope fixture.
Round 2: Fixed 3 review threadsP1 — Preserve wipe state when storing deletion feedback
P2 — Avoid reclaiming queued retrying wipes
P2 — Restore the stub-loaded users router
Verification
|
Round 3: Fixed typo + note on retrying claim
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a17947d7fc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
2 issues found across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Addresses review feedback from Codex (P2) and Cubic (P1/P2): test_users.py: - Capture _prior_routers_users and service module priors BEFORE stubbed import runs, so teardown restores the real modules instead of the stub-loaded versions - Add services.users.data_export to the cleanup pop loop (was missing) - Clear parent package attributes (routers.users, services.users.*) so from-imports don't resolve to stub-loaded modules via attr lookup test_claim_deletion_wipe_txn.py: - Clear database.users attribute on the parent database package during teardown so from database import users doesn't resolve to the half-stubbed module via attribute lookup All 17 tests across both files pass.
sys.modules cleanup — addressed all 4 review threadsAll four unresolved threads flagged incomplete Changes
Verification
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7edbf9b0c1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
pytest collects later test modules before any module-scoped fixture teardown runs, so restoring sys.modules in fixture teardown leaves half-stubbed entries (database._client, database.redis_db, utils.subscription, utils.other.endpoints) in sys.modules while later tests are imported. Move all sys.modules restoration to module level, immediately after capturing the needed references. This eliminates cross-module stub leakage: running test_users.py + test_claim_deletion_wipe_txn.py + test_rate_limiting.py together now passes all 70 tests (previously 9 test_rate_limiting tests failed due to leaked stubs).
Re: "Restore stubs before collection continues" — fixedValid concern. Module-scoped fixture teardown runs after pytest has already collected (imported) later test modules, so the half-stubbed FixMoved all This was applied to both stub-based test files:
VerificationRunning all three files together now passes with zero leakage: Previously this combination had 9 failures in |
Summary
backend/routers/users.pyintobackend/services/users/account_deletion.py.backend/services/users/data_export.pywhile keeping router response headers unchanged.Validation
python -m pytest -q backend/tests/services/users/test_account_deletion.py backend/tests/services/users/test_data_export.py backend/tests/routers/test_users.pypython -m pytest -q backend/tests/routers -k userspython -m pytest -q backend/tests/unit/test_delete_account_stripe_cancel.py backend/tests/unit/test_delete_account_purge_storage.pypython -m compileall backend/routers/users.py backend/services/users/account_deletion.py backend/services/users/data_export.pyblack --line-length 120 --skip-string-normalizationon changed Python files