Repository navigation
feat(backend): split X connector sync into its own Cloud Run Job (#9298) - #11183
Git-on-my-level merged 56 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
All reported issues were addressed across 24 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for pulling the X connector sync out into its own Cloud Run Job. The direction is good: the new entrypoint keeps the job single-purpose, the workflow includes a read-only Scheduler contract check, and the tests cover the notifications-job isolation and selected-job runtime-env rendering.
I do think this needs changes before merge because the new job does not appear to receive the full runtime contract needed by run_x_sync_job():
backend/utils/x_connector.pyrefreshes OAuth access tokens viaX_OAUTH_CLIENT_ID,X_OAUTH_CLIENT_SECRET, andX_OAUTH_REDIRECT_URI, then falls back toutils.social.get_twitter_timeline(), which readsRAPID_API_HOST/RAPID_API_KEYat import time.- The new
cloud_run.jobs.x-connector-sync-jobbindings inbackend/deploy/runtime_env*.yamlmovePINECONE_*over, but do not bind the X OAuth or RapidAPI env/secrets to the new job. - That means the dedicated job can refresh neither expired OAuth tokens nor the RapidAPI fallback path; connected users whose access tokens expire would silently degrade to failed/stale X syncs even though the Scheduler and Cloud Run Job are healthy.
Please add the X OAuth and RapidAPI bindings needed by the code path to x-connector-sync-job (and keep any secrets off notifications-job if it no longer needs them), then extend the runtime-env/render tests to assert the new job carries those values and the notifications job does not retain X-sync-only bindings.
Agent-instruction impact: this PR also updates backend/AGENTS.md and adds docs/doc/developer/backend/cloud_run_jobs_checklist.md, both of which guide coding/review agents working in this repo. The guidance is directionally safe and useful (one periodic domain per Cloud Run Job; do not hitchhike unrelated work onto notifications-job), but because it changes future agent behavior and deploy scaffolding expectations, I’d still want maintainer review on the final wording once the runtime contract issue above is fixed.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Address David CR on BasedHardware#11183: the dedicated sync job must refresh OAuth tokens and use RapidAPI fallback. Also tighten scaffold/scheduler gates. Co-authored-by: Cursor <[email protected]>
|
@Git-on-my-level addressed your runtime-contract CR in Runtime contract (your blocker)
Also fixed while here (cubic P1s aligned with the same surface)
VerificationFocused unit suite green in Ready for re-pass when you have a moment. Agent-doc wording ( |
|
@Git-on-my-level gentle bump for re-pass. Head |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. The original runtime-contract blocker is addressed now: x-connector-sync-job receives the X OAuth/RapidAPI bindings needed by run_x_sync_job(), and the tests now assert those bindings stay off notifications-job.
I still need to request one deploy-readiness change before this can merge:
backend/modal/x_connector_sync_job.pycallsasyncio.run(run_x_sync_job())and then exits 0 regardless of the returned summary. Inbackend/utils/x_connector.py, the job catches a global user-listing failure and returns{'users': 0, 'synced': 0, 'new_posts': 0}, and per-user failures are logged/ignored. As a standalone Cloud Run Job triggered every 6h, that means credential/firestore/network breakage can look like a successful Scheduler execution, so the new dedicated sync job can silently stop syncing users while Cloud Run/Scheduler appear healthy.
Please make the job surface failure to Cloud Run for at least global/listing failures, and preferably include enough failed-user accounting in the runner/entrypoint to raise when the scheduled run could not complete its sync contract. The nearby memory-maintenance-job pattern of inspecting the summary and raising on errors is a good reference.
Agent-instruction impact: this PR updates backend/AGENTS.md and adds docs/doc/developer/backend/cloud_run_jobs_checklist.md, which will guide future coding/review agents toward one periodic domain per Cloud Run Job and away from adding unrelated work to notifications-job. That guidance looks safe and useful, but because it changes future agent behavior and deploy scaffolding expectations, it should still get human maintainer sign-off with the workflow/deploy changes.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
@Git-on-my-level addressed the deploy-readiness CR on Failure surface (your blocker) — mirrors memory-maintenance-job:
Tests: Ready for re-pass when you have a moment. Agent-doc wording unchanged from prior head. |
Split mangled x-connector render assertions into their own test (NameError on jobs), and black-format the failure-surface files at line-length 120. Failure-Class: none Co-authored-by: Cursor <[email protected]>
|
CI was red on
Focused local: Author-side clear again once CI goes green — ready for re-pass on the failure-surface behavior when you can. |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the follow-up — the two earlier blockers I raised look addressed on this head:
backend/deploy/runtime_env.yaml/_base.yamlnow givex-connector-sync-jobthe X OAuth, RapidAPI, Pinecone, Firebase, encryption, and stage/project bindings it needs, whilenotifications-jobno longer carries the X-sync-only env/secrets.backend/modal/x_connector_sync_job.pynow callsraise_if_x_sync_job_failed(summary)afterasyncio.run(run_x_sync_job()), andbackend/utils/x_connector.pynow reports listing errors and all-user failures through the summary instead of letting Cloud Run/Scheduler see a healthy no-op..github/workflows/gcp_x_connector_sync_job.ymluses the checked-out SHA for image tags, deploys the dedicated job, and gates success on a read-only Scheduler describe + validator.backend/utils/other/jobs.pyis now limited to notifications/daily summary work, which matches the split.backend/AGENTS.mdanddocs/doc/developer/backend/cloud_run_jobs_checklist.mddo change future agent/coding guidance: they steer agents toward one periodic domain per Cloud Run Job and away from hitchhiking new domains ontonotifications-job. That guidance looks safe and aligned with this fix, but it is agent-behavior/deploy guidance and should still get maintainer sign-off with the workflow change.
I found one remaining deploy-contract issue that should be fixed before merge:
backend/testing/workflow_contracts.jsonadds the invariant thatx-connector-sync-jobdeploys fail unless the exact enabled 6h OAuth Scheduler trigger targets the deployed job, and it registerstests/unit/test_validate_x_connector_sync_scheduler.py. However, thebackend_cloud_run_deploy.sourceslist still only includes the memory-maintenance workflow/validator (.github/workflows/gcp_memory_maintenance_job.yml,.github/workflows/gcp_memory_maintenance_job_auto_dev.yml, andbackend/scripts/validate_memory_maintenance_scheduler.py). It does not include.github/workflows/gcp_x_connector_sync_job.ymlorbackend/scripts/validate_x_connector_sync_scheduler.py, which are the actual enforcement files for the new invariant. That leaves the source-closure/diff-scoped contract mapping blind to future edits of this deploy-critical gate. Please add those two files to thebackend_cloud_run_deploy.sourceslist alongside the existing memory-maintenance entries.
Given this touches workflow/deploy behavior and agent-facing docs, I’m leaving the existing workflow-review / needs-maintainer-review labels in place for maintainer sign-off after the source-closure fix.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Resolved on current head: the X connector job now has the required runtime bindings and surfaces sync failures to Cloud Run; current review tracks a separate workflow-contract source-closure issue.
Addressed review @936f3ede4056@Git-on-my-level Source-closure blocker fixed.
alongside the existing memory-maintenance entries, so diff-scoped/source-closure mapping tracks the 6h Scheduler invariant enforcement files (not only the registered test). Also merged latest Ready for re-pass / dismiss CR when CI is green. |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the updates — I re-reviewed this head and the prior blocker looks resolved.
What I checked:
backend/testing/workflow_contracts.jsonnow includes both.github/workflows/gcp_x_connector_sync_job.ymlandbackend/scripts/validate_x_connector_sync_scheduler.pyin the backend Cloud Run deploy source closure, so the new Scheduler/deploy invariant is no longer blind to the actual enforcement files..github/workflows/gcp_x_connector_sync_job.ymldefines a dedicated manual deploy forx-connector-sync-job, tags from the checked-out commit, renders only the selected job env, and fails the deploy if the existingx-connector-sync-6hScheduler contract does not match the job.backend/deploy/runtime_env.yamlplus_base.yaml/overlays separate the X OAuth/RapidAPI/Pinecone bindings ontox-connector-sync-jobwhile keepingnotifications-jobscoped to notification/daily-summary runtime bindings.backend/modal/x_connector_sync_job.pyis a thin Firebase-initializing entrypoint that always runsrun_x_sync_job()and callsraise_if_x_sync_job_failed(summary), so Cloud Run/Scheduler see a non-zero failure when the sync contract is broken.backend/utils/x_connector.pyremoves the old hour-modulo gate, reports listing failures througherrors, counts per-user failures, and fails only on global/listing or all-user failure while still allowing partial progress.backend/utils/other/jobs.pyno longer imports or invokes X sync, which matches the ownership split away fromnotifications-job.backend/scripts/validate_x_connector_sync_scheduler.pyis read-only and validates the exact Scheduler name, 6h cadence, target URI, OAuth service account, and enabled state without creating or mutating cloud resources.backend/AGENTS.mdanddocs/doc/developer/backend/cloud_run_jobs_checklist.mddo change agent-facing repo guidance: future coding/review agents will be steered toward one periodic domain per Cloud Run Job and away from adding unrelated jobs tonotifications-job. That guidance looks safe and consistent with this PR, but it is still maintainer-facing agent/deploy guidance.
Given the workflow/deploy surface and the agent-instruction docs, I’m not formally approving; this should still get human maintainer sign-off for the rollout plan and Scheduler resource creation. Technically, I do not see a remaining code blocker on this head, and I’m dismissing my older change request because the source-closure concern is now addressed.
by AI on behalf of David — leaving this for human maintainer review because it changes deploy workflow behavior and agent-facing backend guidance.
Resolved on 936f3ed: backend_cloud_run_deploy now includes gcp_x_connector_sync_job.yml and validate_x_connector_sync_scheduler.py in source closure.
|
@Git-on-my-level @kodjima33 need human response Author-clear on
Branch protection still waits on code-owner review from @Git-on-my-level (workflow/deploy) plus write-access APPROVE. Please APPROVE when the rollout plan is acceptable; Scheduler job creation + first deploy via |
|
@Git-on-my-level @kodjima33 workflow-review ping: current head is MERGEABLE with all checks green; the only remaining gate is write-access/code-owner approval for the X connector Cloud Run Job workflow. Please approve or state an explicit blocker. |
Co-authored-by: Cursor <[email protected]>
|
Refreshed onto current @Git-on-my-level workflow CO when ready. |
…ller driver main's outside-query driver for run_x_sync_job stubs redis_db.try_acquire_x_sync_window_lock, but this branch moves X sync to its own Scheduler-owned Cloud Run Job and removes that hour-window lock, so the patch target no longer exists. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged current
|
main (BasedHardware#20221) requires every lane that ships a backend image to verify serving Firestore indexes first. Add the same checked-out-SHA resolution, immutable gate-control checkout, and readiness step the other job workflows use, pin the deploy environment to prod/development, and register the lane's source binding in the workflow contract test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Pushed 1546d7e: added the Firestore index readiness gate that
|
|
@kodjima33 this is approved. The latest push only adds the Firestore readiness gate |
…sync-job # Conflicts: # backend/tests/unit/test_render_backend_runtime_env.py
main grew backend/AGENTS.md to 38995 of its 39000-byte budget, so the separate x-connector-sync-job entry no longer fit. List the job in the existing cron-jobs line instead and drop the X sync mentions from the notifications-job entry, which no longer runs it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sync-job # Conflicts: # backend/AGENTS.md
|
Merged current
|
… v2 env contract test The test renders full Cloud Run state and pre-resolves deploy-time inputs for services and network flags, but not jobs. x-connector-sync-job binds X_OAUTH_CLIENT_ID, X_OAUTH_REDIRECT_URI and RAPID_API_HOST as required deploy inputs with no default, so rendering failed with "X_OAUTH_CLIENT_ID requires $X_OAUTH_CLIENT_ID to be set". Resolve job env_var entries the same way as services. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Pushed eff1406 for the red Backend unit shard.
|
A new Cloud Run job without --service-account lands on the default compute SA. The client id, redirect URI, and RapidAPI host were rendered from GitHub vars that are not defined for these environments; the live Cloud Run API already mounts those names as secrets. Bind them the same way and run as the identity that already has those mounts.
Review on
|
X_OAUTH_CLIENT_ID, X_OAUTH_REDIRECT_URI, and RAPID_API_HOST are classified as config. Binding them as Cloud Run secrets fails the deployment secret-boundary ratchet. Restore the env-var contract and keep the runtime service-account pin.
|
Hygiene on
|
Both fail on main itself and red every branch's Backend unit shards: - BasedHardware#15171 moved the TTS routes to redis_db.check_tts_rate_limit_for_user, but test_desktop_tts_updates.py still matched check_tts_rate_limit. - BasedHardware#20665 removed routers.action_items._wake_task_changes, which test_accept_shared_tasks_unavailable_claim_returns_503 still patched. Byte-identical to BasedHardware#20748, so whichever merges first leaves the other a no-op. Co-Authored-By: Claude Opus 5.5 <[email protected]>
BasedHardware#20797 added .github/workflows/mobile_daily_train.yml without a ci-budget entry, so check_ci_budget.py fails on main and on every branch whose diff selects the ci-budget gate. Entries come from `check_ci_budget.py --refresh`, with rationales taken from the workflow itself: a daily 14:00 UTC schedule plus manual dispatch, one ubuntu job that only calls the Codemagic API, and no pull_request or push trigger. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Pushed 722bcbb (current
On the deploy prerequisite raised in review: |
# Conflicts: # .github/ci-budget.yaml
|
Merged latest main (a62fbc4) to clear the merge conflict — pushed f4ec068.
|
## Summary - Point the desktop TTS unit helper at `check_tts_rate_limit_for_user`, which is what the route calls. - Drop the shared-task 503 test's patch of `routers.action_items._wake_task_changes`. Accept no longer calls that symbol, so the patch raises before the assertion. These two failures are already red on main and are blocking #11183's required unit shards. The files are not part of that PR. ## Failure class Failure-Class: none ## Test plan - [x] `tests/unit/test_desktop_tts_updates.py` - [x] `tests/unit/test_shared_action_items.py::test_accept_shared_tasks_unavailable_claim_returns_503` <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/20759?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. -->
## Summary - First dev execution of x-connector-sync-job (#11183): `users: 250, synced: 39, failed: 211` — every failure was `Error 111 connecting to None:6379`. The job never received its Redis env. - Bind `REDIS_DB_HOST` / `REDIS_DB_PORT` (config literals) and `REDIS_DB_PASSWORD` (secret-classified, so a Cloud Run secret binding) on the job for dev and prod. - Composed runtime_env.yaml regenerated. Follow-up to #11183. The dev Cloud Run job is already patched live with the same values; this PR makes it survive the next workflow deploy. ## Failure class Failure-Class: none ## Product invariants affected - INV-MEM-4 — deployment binding only: the new job gains the same Redis runtime bindings the notifications-job already carries; no canonical-memory ownership or routing change. ## Test plan - [x] `python3 backend/deploy/compose_runtime_env.py` — composed output matches overlays - [x] `.github/scripts/check_deployment_secret_boundary.py --base main` — passes - [x] `tests/unit/test_render_backend_runtime_env.py` — 50 passed - [x] Live dev verification after applying the same values: second execution `users: 250, synced: 43, failed: 91` (was 39/211). Remaining failures are per-user provider_5xx/oauth buckets, not infra.
## Summary - Move the X connector sync cadence from every 6h to every 12h (`0 3,15 * * *`). - The registry averages ~0.1 new posts per user per day (251 users → ~25-30 posts/day), so 6h sweeps were ~97% empty. 12h halves X API + RapidAPI footprint with no meaningful freshness loss for memory context. - Scheduler resource keeps its name `x-connector-sync-6h` (renaming churns IAM for zero value); only the schedule contract changes. - Runbook updated to match. Follow-up to #11183/#20852. Operator step after merge: two `gcloud scheduler jobs update` calls (dev + prod) — the deploy workflow only validates, never mutates, the schedule. ## Failure class Failure-Class: none ## Product invariants affected - INV-MEM-4 — scheduling cadence only; no ownership, routing, or data-plane change. ## Test plan - [x] `tests/unit/test_validate_x_connector_sync_scheduler.py` — 14 passed (contract fixture pinned to `0 3,15 * * *`) - [x] `black --check` on touched files - [ ] Post-merge: `gcloud scheduler jobs update http x-connector-sync-6h --location=us-central1 --schedule="0 3,15 * * *"` in both projects, then one deploy dispatch per env so the validator passes against the new schedule <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/20880?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> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/20880?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F20880&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Summary
notifications-jobonto a dedicatedx-connector-sync-job(entrypoint, Dockerfile, runtime-env contract, deploy workflow).x-connector-sync-6h); the entrypoint no longer uses hour-modulo gating.PromotionFlexRunRouterper job run, reuse it for every connected user, and leave intentional Flex capacity deferrals pending without counting them as sync failures.Fixes #9298
Why the Flex follow-up matters
While this PR was open, main added the shared Flex router to scheduled X memory extraction. The job split retained the Flex-aware per-user implementation but its rewritten scheduler boundary stopped passing the router, which made scheduled extraction silently use the legacy standard lane. The latest commit restores the current production routing contract without weakening this PR's new Cloud Run failure surface.
Verification
run_x_sync_job()through two registry users and proves:sync_x_for_user()call;PromotionFlexDeferreduser remains retryable and does not incrementfailed.backend/test.shsweep exercised all 992 test files; both X suites passed. Five unrelated current-main files remain red and are byte-identical toorigin/mainin this branch (test_legacy_memory_surface_inventory.py,test_modulate_stt.py,test_streaming_deepgram_backoff.py,test_async_app_integrations.py,test_async_realtime_integrations_offload.py).x-connector-sync-job.gcp_x_connector_sync_job.yml.Failure class
Failure-Class: none
The change is an ownership split plus a review-time regression repair; it is not a shipped recurring failure-class instance.
Product invariants affected
notifications-job.Test plan