Repository navigation
refactor: thermo-nuclear quality repayment (macOS + backend) - #9327
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 025db77a1f
ℹ️ 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.
1 issue found across 4 files (changes from recent commits).
You’re at about 97% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
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/testing/e2e/test_core_flow_expansion.py">
<violation number="1" location="backend/testing/e2e/test_core_flow_expansion.py:168">
P0: The monkeypatches in this test may not actually override the targeted functions. `routers/sync.py` imports `retrieve_vad_segments`, `process_segment`, `_reprocess_merged_conversations`, `build_person_embeddings_cache`, `decode_files_to_wav`, `get_wav_duration`, and `FAIR_USE_ENABLED` via `from ... import` style, which binds them as local names in `routers.sync`'s namespace. When Python's `from X import Y` is used, patching `X.Y` after import does not update the local `Y` reference in the importing module—so the real functions will still execute instead of the fakes. This means the test could silently exercise real logic, making it unreliable. To fix this, either revert to patching `sync_router` (the importing module) for functions used locally in `routers/sync.py`, or update the imports in `routers/sync.py` to use `import utils.sync.pipeline as sync_pipeline` and call functions as `sync_pipeline.retrieve_vad_segments(...)` etc.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Confidence score: 2/5
- In
desktop/macos/Desktop/Sources/OmiHTTPTransport.swift, the transport helpers defaultincludeBYOKtotrue, so BYOK API keys can be attached to unrelated requests; merging as-is risks leaking external credentials to endpoints that should never receive them. Flip the default to opt-in (or gate key injection to explicit LLM/provider calls only) and add a targeted test to verify non-LLM requests never carry BYOK headers before merging.
You’re at about 97% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
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="desktop/macos/Desktop/Sources/OmiHTTPTransport.swift">
<violation number="1" location="desktop/macos/Desktop/Sources/OmiHTTPTransport.swift:57">
P2: BYOK provider API keys are attached by default to every request because `includeBYOK` defaults to `true` in the transport helpers. This causes raw external credentials to be sent to endpoints that do not trigger LLM/STT work (conversation CRUD, goals, user profile, etc.) unless each call site remembers to opt out. Consider changing the default to `false` so callers must explicitly opt in when an endpoint actually needs BYOK keys; this closes the secret-propagation gap at the transport level instead of relying on every future call site to remember the opt-out.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
043318e to
e9dd8f8
Compare
Monitor review-fix summaryAddressed 13 of 19 trusted bot review threads (Codex/Cubic). 6 threads intentionally left unresolved as out-of-scope or false positives (see below). Fixed (13 threads)Backend —
Backend —
Backend —
Backend tests
Desktop —
Desktop —
Desktop —
Not addressed (6 threads)
Verification
|
…wift hardening Addresses trusted bot review comments on PR #9327: Backend (task_integrations_ops.py): - Change connected check to is False so legacy records missing the key fall through to access_token validation instead of being blocked (T3) - Set connected=True after successful token refresh (T3) - Wrap Asana/Google Tasks POST calls with perform_request_with_token_retry so 401 during task creation is recovered (T4) - Narrow broad except Exception in ensure_valid_oauth_token to ValueError/TypeError; refresh failures propagate instead of retrying with a stale token (T5) - Use narrow update payloads for Firestore writes (T11) Backend (sync/pipeline.py): - Sanitize exception text in process_segment error handler (T7) Backend (listen_session_bootstrap.py): - Replace set-based vocabulary dedup with order-preserving dict.fromkeys (T17) Backend tests: - Fix 5 structural tests in test_sync_v2.py boundary markers (T12) - Add canonical-path failure-preservation test (T18) Desktop (OmiHTTPTransport.swift -> Services/): - Move to Sources/Services/ to pass root-layout ratchet (T1/T19) - Cache ISO8601DateFormatter instances statically (T13) - Add makeEncoder() with matching date strategy (T15) - Replace force-unwrap URL with guard let (T16) Desktop (STTSessionState.swift): - Clear sessionForceLocal in beginLocalToCloudFallback (T6) Desktop (RewindStorageTestIsolation.swift): - Use typed DefaultsKey.authUserId (T9)
Extract task integration ops (create + OAuth helpers) from routers to utils/task_integrations_ops.py so task_sync no longer imports routers. Add import-boundary ratchet and Todoist characterization tests. Verification: pytest tests/unit/test_utils_import_boundary.py tests/unit/test_task_integrations_ops.py tests/unit/test_task_sync_async.py Co-authored-by: Cursor <[email protected]>
Extract-first legacy/canonical re-extract so LLM failures cannot wipe conversation memories. Cascade delete removes memories and action items before the conversation document. Add memory replace policy tests. Verification: pytest tests/unit/test_ws_i_write_convergence.py tests/unit/test_ws_j_delete_privacy.py tests/unit/test_memory_replace_policy.py Co-authored-by: Cursor <[email protected]>
Extract connect-time Firestore reads into listen_session_bootstrap with run_blocking offload. Register listen_ws_session workflow contract and add characterization tests (#9239). Verification: check_workflow_contracts.py + listen bootstrap test suite Co-authored-by: Cursor <[email protected]>
RecurringTaskScheduler no longer constructs a shadow ChatProvider; it receives the canonical TaskChatCoordinator from ViewModelContainer. Add INV-6 tripwire ensuring production Sources only call ChatProvider() in ViewModelContainer (previews excluded). Verified: xcrun swift test --filter ChatTimelineContinuityTests (20/20), StartupWarmupPolicyTests.testRecurringTaskScheduler (1/1). Co-authored-by: Cursor <[email protected]>
Move decode→VAD→STT→merge pipeline from routers/sync.py into utils/sync/pipeline.py so the router stays thin and utils never imports routers. Update workflow contract sources and test anchors. Verification: pytest tests/unit/test_sync_v2.py tests/unit/test_sync_cloud_tasks.py tests/unit/test_sync_ordered_assignment.py tests/unit/test_sync_silent_failure.py tests/unit/test_workflow_contracts.py tests/unit/test_utils_import_boundary.py (248 passed) Co-authored-by: Cursor <[email protected]>
Replace five scattered STT booleans with a pure STTSessionState type that encodes cloud↔local resolution, sticky flags, and fallback mutex rules. Hermetic STTSessionStateTests cover BLE/Intel paths, debug force-cloud, one-shot cloud→local fallback, app-run cloud stickiness, and reentry. Verified: xcrun swift test --package-path Desktop --filter STTSessionStateTests (9/9 passed) Co-authored-by: Cursor <[email protected]>
Add RewindStorageTestIsolation helper and migrate the three leaky memory suites to close() before user-dir delete. Includes a single-process combined-memory regression script for #9029. Verified: bash scripts/swift-test-combined-memory.sh (12/12 pass); per-suite filters for all three suites pass in isolation. Co-authored-by: Cursor <[email protected]>
Move URLSession setup, header assembly, GET/POST/DELETE verbs, 401 retry, and JSON decode/error handling from APIClient into OmiHTTPTransport; APIClient delegates with unchanged public surface. Add APIClient.swift line-count ratchet. Verified: pytest test_app_client_swift_generator + test_desktop_rest_inventory; xcrun swift test --filter APIClient (1 pre-existing routing assertion failure). Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Allowlist slow import-boundary tests; fix file_paths test to load utils.sync.pipeline instead of a MagicMock after wave 4 extract. Co-authored-by: Cursor <[email protected]>
Point sync pipeline and task-integration mocks at utils.sync.pipeline and utils.task_integrations_ops, and assert lazy storage client init. Co-authored-by: Cursor <[email protected]>
Map STTSessionState, OmiHTTPTransport, RecurringTaskScheduler, and ViewModelContainer to existing tier-1/2 harness flows. Co-authored-by: Cursor <[email protected]>
Point structural and patch targets at utils.sync.pipeline, listen_session_bootstrap, and task_integrations_ops after the thermo-nuclear refactor. Co-authored-by: Cursor <[email protected]>
…wift hardening Addresses trusted bot review comments on PR #9327: Backend (task_integrations_ops.py): - Change connected check to is False so legacy records missing the key fall through to access_token validation instead of being blocked (T3) - Set connected=True after successful token refresh (T3) - Wrap Asana/Google Tasks POST calls with perform_request_with_token_retry so 401 during task creation is recovered (T4) - Narrow broad except Exception in ensure_valid_oauth_token to ValueError/TypeError; refresh failures propagate instead of retrying with a stale token (T5) - Use narrow update payloads for Firestore writes (T11) Backend (sync/pipeline.py): - Sanitize exception text in process_segment error handler (T7) Backend (listen_session_bootstrap.py): - Replace set-based vocabulary dedup with order-preserving dict.fromkeys (T17) Backend tests: - Fix 5 structural tests in test_sync_v2.py boundary markers (T12) - Add canonical-path failure-preservation test (T18) Desktop (OmiHTTPTransport.swift -> Services/): - Move to Sources/Services/ to pass root-layout ratchet (T1/T19) - Cache ISO8601DateFormatter instances statically (T13) - Add makeEncoder() with matching date strategy (T15) - Replace force-unwrap URL with guard let (T16) Desktop (STTSessionState.swift): - Clear sessionForceLocal in beginLocalToCloudFallback (T6) Desktop (RewindStorageTestIsolation.swift): - Use typed DefaultsKey.authUserId (T9)
2077824 to
e78c93f
Compare
Monitor review-fix summaryAddressed 13 of 19 trusted bot review threads (Codex/Cubic). 6 threads intentionally left unresolved as out-of-scope or false positives (see below). Fixed (13 threads)Backend —
Backend —
Backend —
Backend tests
Desktop —
Desktop —
Desktop —
Not addressed (6 threads)
Verification
|
|
@cursor address merge conflicts and give me an assessment of how we did and what the major risk areas are |
Merge conflicts resolvedMerged latest
Assessment: how we didOverall: strong refactor PR with good discipline. ~52 files, +3.6k / −2.1k lines across 8 waves, with characterization tests and workflow contracts at most move points. That's the right shape for a repayment branch. What went well
Where it's thinner
Major risk areas (ranked)1. Sync pipeline extraction (
|
- Keep both listen_ws_session and canonical_memory_pipeline workflow contracts - Union fast-unit duration allowlist entries from both branches - Reconcile APIClient: retain OmiHTTPTransport for headers/codec/session while preserving main's RequestAuthPolicy 401 recovery (ghost-session fix #9324) Co-authored-by: David Zhang <[email protected]>
Restore compact APIClient.delete shape so INV-AUTH-1 source ratchet still sees performVoidRequest; raise APIClient line-count high-water for the auth-recovery merge; allowlist prompt-cache kwargs CPU duration. Co-authored-by: Cursor <[email protected]>
Monitor review-fix pass — no code changes neededRe-verified the 3 remaining unresolved trusted bot review threads. All are correctly classified as out-of-scope for this refactor PR (pre-existing patterns preserved verbatim during extraction). No code changes warranted. Threads reviewed (all cubic-dev-ai)
CI statusAll checks pass on
|
# Conflicts: # desktop/macos/Desktop/Sources/AppState/AppState+Transcription.swift
…t formatting Merge conflict left bare 'useLocalSTT' at line 66 (added by #9349 in main). Migrated to 'sttSession.useLocalSTT' per the PR's W6 STTSessionState refactor. Also restored Dart files to origin/main formatting (pre-commit hook had reformatted them during merge).
Monitor summary — conflict resolution + merge fixWhat changedResolved the DIRTY/CONFLICTING merge state by merging latest
Unresolved review threads (3, all previously triaged)All 3 remaining cubic-dev-ai threads were independently re-verified against current code. Each is a pre-existing pattern extracted verbatim during the refactor, not a new issue introduced by this PR:
Verification
|
…covers) Conflicts resolved across 3 files: - backend/routers/sync.py: combined client_device import with pipeline imports; kept HEAD (pipeline-extracted) versions of inline functions; device params already threaded by main's #9364 endpoint changes - backend/utils/sync/pipeline.py: added client_device_id/client_platform params to process_segment and _run_full_pipeline_background_async; pass through to CreateConversation (main's #9364 device provenance) - backend/tests/unit/test_sync_v2.py: kept both log_sanitizer and client_device mock stubs from both sides - desktop/macos/e2e/flows/capture-lifecycle.yaml: kept both STTSessionState and TranscriptionService cover paths
Main's #9364 added X-App-Platform/X-Device-Id-Hash Header() params to the v2 sync endpoint, but the merge resolution dropped the Header import from fastapi.
- test_device_provenance: read process_segment from pipeline.py (W4 extract) - client_device mocks: use MagicMock instead of types.SimpleNamespace (avoids UnboundLocalError when 'import types' appears later in method)
Prevent detached sync workers from mutating finalized jobs, keep injected OAuth clients through retries, avoid stale Todoist writes, default low-level BYOK headers off, and serialize Rewind singleton fixtures. Verified: 182 focused backend tests; backend isolation/import/async/workflow scanners; 127 focused Swift tests; combined memory suite; parallel Rewind suites; desktop source-layout and auth-session checks.
Route the merged automation action through ConversationRepository once, avoiding both the async MainActor compile error and duplicate PATCH requests. Verified: xcrun swift test --package-path Desktop --filter 'DesktopAutomationSecondaryActionTests|BYOKPaywallTests|STTSessionStateTests|ChatTimelineContinuityTests' (63 tests).
# Conflicts: # desktop/macos/Desktop/Sources/DesktopAutomationBridge.swift


Summary
Single-branch thermo-nuclear quality repayment across backend and macOS desktop (waves 1–8):
utils/task_integrations_ops.py; fixutils→routersimport violation intask_sync.py; import-boundary ratchet + Todoist characterization testslisten_session_bootstrap.py) offloads Firestore reads; registerlisten_ws_sessionworkflow contract (Listen WebSocket blocks event loop on synchronous Firestore preference read at connect #9239)utils/sync/pipeline.py; thinrouters/sync.pyTaskChatCoordinatorwithRecurringTaskScheduler; INV-6 tripwire for shadowChatProvider()STTSessionState+ transition tests; replace five STT booleans in AppStateRewindStorageTestIsolationharness + migrate three leaky memory suites (Swift test suite: shared-singleton contamination causes scheduling-dependent xctest worker crash #9029)OmiHTTPTransportfromAPIClient.swift([desktop/macos] APIClient.swift is a 5,750-line god actor with hand-duplicated server models #8844); line-count ratchetRelated: #8844, #9029, #9239
Product invariants affected
Characterization / coverage additions
test_utils_import_boundary.py,test_task_integrations_ops.pytest_memory_replace_policy.pytest_listen_session_bootstrap.pySTTSessionStateTests, combined-memory scriptVerification (local)
Out of scope (deferred Wave 9+)
MemoryWritePolicy/ListenReceiveLooppeel / sync v1/v2 unify / Chat models extract / ConversationsRepositoryMade with Cursor