Skip to content

feat(backend): split X connector sync into its own Cloud Run Job (#9298) - #11183

Merged
Git-on-my-level merged 56 commits into
BasedHardware:mainfrom
aryanorastar:fix/9298-x-connector-sync-job
Oct 6, 2026
Merged

Git-on-my-level merged 56 commits into
BasedHardware:mainfrom
aryanorastar:fix/9298-x-connector-sync-job

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Move X connector incremental sync off notifications-job onto a dedicated x-connector-sync-job (entrypoint, Dockerfile, runtime-env contract, deploy workflow).
  • Make Scheduler the single cadence owner (x-connector-sync-6h); the entrypoint no longer uses hour-modulo gating.
  • Fail the Cloud Run execution on registry/listing failures or total per-user failure instead of reporting a healthy no-op.
  • Preserve the existing scheduled-memory contract: construct one PromotionFlexRunRouter per job run, reuse it for every connected user, and leave intentional Flex capacity deferrals pending without counting them as sync failures.
  • Add the runbook and Cloud Run Jobs checklist/scaffold so future cron work does not return to the notifications process.

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

  • Focused X scheduler and failure-surface suites — 16 passed.
  • X + runtime-env + deployment-contract suites — 162 passed.
  • New behavioral regression drives run_x_sync_job() through two registry users and proves:
    • exactly one router is built with the job start time;
    • the same router reaches every sync_x_for_user() call;
    • a PromotionFlexDeferred user remains retryable and does not increment failed.
  • Full backend/test.sh sweep exercised all 992 test files; both X suites passed. Five unrelated current-main files remain red and are byte-identical to origin/main in 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).
  • Runtime image source-closure/import-smoke coverage includes x-connector-sync-job.
  • Maintainer operational follow-up after merge: create/verify the Scheduler job and perform the first deploy via 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

  • INV-DATA-1 — preserves the existing production data-plane authority; the new job workflow does not change client or Firebase routing.
  • INV-MEM-4 — preserves canonical-memory maintenance and scheduled Flex-routing ownership while removing unrelated X-sync bindings from notifications-job.

Test plan

  • Behavioral X scheduler/Flex routing and deferral coverage.
  • Cloud Run nonzero failure surface coverage.
  • Runtime env, Scheduler validator, notifications isolation, image contract, and render tests.
  • Current-main refresh and diff hygiene.
  • Post-merge live Scheduler/deploy verification by a maintainer with GCP authority.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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

All reported issues were addressed across 24 files

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

Re-trigger cubic

Comment thread backend/utils/other/jobs.py Resolved
Comment thread backend/deploy/runtime_env/_base.yaml Resolved
Comment thread backend/utils/x_connector.py Resolved

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.py refreshes OAuth access tokens via X_OAUTH_CLIENT_ID, X_OAUTH_CLIENT_SECRET, and X_OAUTH_REDIRECT_URI, then falls back to utils.social.get_twitter_timeline(), which reads RAPID_API_HOST / RAPID_API_KEY at import time.
  • The new cloud_run.jobs.x-connector-sync-job bindings in backend/deploy/runtime_env*.yaml move PINECONE_* 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.

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior backend Backend Task (python) labels Aug 6, 2026
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Aug 7, 2026
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]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level addressed your runtime-contract CR in c0aab2816b.

Runtime contract (your blocker)

cloud_run.jobs.x-connector-sync-job now binds everything run_x_sync_job() needs:

  • Secrets: X_OAUTH_CLIENT_SECRET, RAPID_API_KEY (plus existing OpenAI / SA / encryption / Pinecone)
  • Env: X_OAUTH_CLIENT_ID, X_OAUTH_REDIRECT_URI, RAPID_API_HOST (workflow passes the GitHub env vars into render)
  • Notifications-job stays free of X-sync-only bindings; render/validator tests assert both sides

Also fixed while here (cubic P1s aligned with the same surface)

  • Scaffold no longer strips Build/Verify/Push; gateway URL env removal keeps valid YAML
  • Scheduler validator requires the project-scoped x-connector-sync-scheduler@… SA (+ UnicodeError on state files)
  • Runbook documents deploy order so notifications without X sync cannot land before this job + x-connector-sync-6h are live
  • Removed dead should_run_x_sync_job() hour-modulo gate

Verification

Focused unit suite green in backend/.venv (render + validator + orchestrator + import smoke + scheduler).

Ready for re-pass when you have a moment. Agent-doc wording (AGENTS.md / checklist) unchanged aside from the runbook contract/rollout note — still happy to adjust that if you want different guidance.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level gentle bump for re-pass.

Head b04ac48ea5 is fully CI green (Backend unit suite + hermetic gauntlets + Hygiene/Formatting/Static Contracts). Runtime-contract fix from your CR is in (X_OAUTH_* + RapidAPI on x-connector-sync-job; notifications stays clean). Author-side clear — ready when you can re-review.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.py calls asyncio.run(run_x_sync_job()) and then exits 0 regardless of the returned summary. In backend/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.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level addressed the deploy-readiness CR on c4833cf528.

Failure surface (your blocker) — mirrors memory-maintenance-job:

  • run_x_sync_job() now returns failed + errors; listing/Firestore breakage populates errors instead of a healthy {users:0,…} summary
  • Per-user failures increment failed (including success: false returns, not only exceptions)
  • Entrypoint does summary = asyncio.run(...) then raise_if_x_sync_job_failed(summary) so Cloud Run / Scheduler see a non-zero exit on:
    • any listing/global errors
    • total failure (users > 0 and synced == 0 and every user failed)
  • Partial success (some users synced) still exits 0 — one flaky account doesn’t red-page the whole job

Tests: test_x_connector_sync_job_failure_surface.py + orchestrator entrypoint wiring — 13 focused tests green locally.

Ready for re-pass when you have a moment. Agent-doc wording unchanged from prior head.

aryanorastar added a commit to aryanorastar/omi that referenced this pull request Aug 8, 2026
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]>
@aryanorastar

aryanorastar commented Aug 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI was red on c4833cf528 after your failure-surface re-pass tip — fixed on 12fdcc1999:

  1. Static Contracts / Backend unit — GitHub’s merge-with-main put the x-connector render asserts into test_dev_runtime_manifest_contains_no_removed_first_user_or_capture_admission without defining jobs (NameError). Merged main locally and moved those asserts into test_render_dev_emits_x_connector_sync_job_outputs.
  2. Formatting — black 26.5.1 / line-length 120 on test_x_connector_sync_job_failure_surface.py + utils/x_connector.py.

Focused local: test_render_backend_runtime_env + failure-surface + notifications orchestrator → 37 passed.

Author-side clear again once CI goes green — ready for re-pass on the failure-surface behavior when you can.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the follow-up — the two earlier blockers I raised look addressed on this head:

  • backend/deploy/runtime_env.yaml / _base.yaml now give x-connector-sync-job the X OAuth, RapidAPI, Pinecone, Firebase, encryption, and stage/project bindings it needs, while notifications-job no longer carries the X-sync-only env/secrets.
  • backend/modal/x_connector_sync_job.py now calls raise_if_x_sync_job_failed(summary) after asyncio.run(run_x_sync_job()), and backend/utils/x_connector.py now 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.yml uses 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.py is now limited to notifications/daily summary work, which matches the split.
  • backend/AGENTS.md and docs/doc/developer/backend/cloud_run_jobs_checklist.md do change future agent/coding guidance: they steer agents toward one periodic domain per Cloud Run Job and away from hitchhiking new domains onto notifications-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.json adds the invariant that x-connector-sync-job deploys fail unless the exact enabled 6h OAuth Scheduler trigger targets the deployed job, and it registers tests/unit/test_validate_x_connector_sync_scheduler.py. However, the backend_cloud_run_deploy.sources list still only includes the memory-maintenance workflow/validator (.github/workflows/gcp_memory_maintenance_job.yml, .github/workflows/gcp_memory_maintenance_job_auto_dev.yml, and backend/scripts/validate_memory_maintenance_scheduler.py). It does not include .github/workflows/gcp_x_connector_sync_job.yml or backend/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 the backend_cloud_run_deploy.sources list 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.

@Git-on-my-level
Git-on-my-level dismissed stale reviews from themself August 8, 2026 21:35

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.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Addressed review @936f3ede4056

@Git-on-my-level Source-closure blocker fixed.

backend/testing/workflow_contracts.json → backend_cloud_run_deploy.sources now includes:

  • .github/workflows/gcp_x_connector_sync_job.yml
  • backend/scripts/validate_x_connector_sync_scheduler.py

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 main. Local: test_every_external_workflow_contract_source_triggers_backend_unit_workflow + test_validate_x_connector_sync_scheduler → 15 passed.

Ready for re-pass / dismiss CR when CI is green.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the updates — I re-reviewed this head and the prior blocker looks resolved.

What I checked:

  • backend/testing/workflow_contracts.json now includes both .github/workflows/gcp_x_connector_sync_job.yml and backend/scripts/validate_x_connector_sync_scheduler.py in 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.yml defines a dedicated manual deploy for x-connector-sync-job, tags from the checked-out commit, renders only the selected job env, and fails the deploy if the existing x-connector-sync-6h Scheduler contract does not match the job.
  • backend/deploy/runtime_env.yaml plus _base.yaml/overlays separate the X OAuth/RapidAPI/Pinecone bindings onto x-connector-sync-job while keeping notifications-job scoped to notification/daily-summary runtime bindings.
  • backend/modal/x_connector_sync_job.py is a thin Firebase-initializing entrypoint that always runs run_x_sync_job() and calls raise_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.py removes the old hour-modulo gate, reports listing failures through errors, counts per-user failures, and fails only on global/listing or all-user failure while still allowing partial progress.
  • backend/utils/other/jobs.py no longer imports or invokes X sync, which matches the ownership split away from notifications-job.
  • backend/scripts/validate_x_connector_sync_scheduler.py is 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.md and docs/doc/developer/backend/cloud_run_jobs_checklist.md do 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 to notifications-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.

@Git-on-my-level
Git-on-my-level dismissed their stale review August 9, 2026 21:34

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.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level @kodjima33 need human response

Author-clear on 936f3ede40:

  • Your source-closure CR dismissed; latest pass found no remaining code blocker
  • MERGEABLE + all checks green (backend unit, Static Contracts, Hygiene, hermetic, source-closure)
  • Prior blockers still on tip: X OAuth/RapidAPI on x-connector-sync-job, fail-closed sync-contract exit, backend_cloud_run_deploy.sources includes the new workflow + scheduler validator

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 gcp_x_connector_sync_job.yml remain maintainer post-merge (runbook), as called out in the PR body.

@undivisible undivisible added human Human-authored pull request docs-tooling Layer: Documentation, examples, dev tools labels Aug 10, 2026
@Git-on-my-level Git-on-my-level removed the docs-tooling Layer: Documentation, examples, dev tools label Aug 10, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

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

aryanorastar added a commit to aryanorastar/omi that referenced this pull request Aug 13, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Refreshed onto current main (1d4ff45b02). Kept the X-connector-sync job split in backend/AGENTS.md and the job render tests; took main's retired canonical-memory env-var contract. Runtime-env tests 103 passed locally.

@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]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Merged current main (2c1f2a4).

  • .github/ci-budget.yaml: kept main's new forecasts and added this PR's one-run bump on top (guardrails 73, shards 119, suite 117, tier 119), with rationale tied to the X workflow trigger. check_ci_budget.py passes.
  • backend/AGENTS.md: kept main's updated notifications-job wording, minus X sync (this PR moves it out), plus the x-connector-sync-job entry.
  • backend/tests/support/firestore_outside_query_drivers.py: main's driver for run_x_sync_job stubbed redis_db.try_acquire_x_sync_window_lock, which this branch removes along with hour-window gating. Dropped that stub; test_firestore_outside_query_contract.py, test_firestore_query_shapes.py, and test_firestore_caller_witnesses.py pass.
  • X sync, scheduler-reconcile and validator, runtime-env, workflow-contract, and deployment-concurrency checks pass.

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]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Pushed 1546d7e: added the Firestore index readiness gate that main now requires on every lane shipping a backend image (#20221).

  • gcp_x_connector_sync_job.yml now resolves the checked-out SHA, checks out the immutable gate controls, and runs firestore-readiness before auth and deploy, the same steps as the other job workflows. The deploy environment is pinned to prod/development, which the gate policy requires.
  • Registered the lane's source_sha binding in test_workflow_contracts.py. That suite passes (90), and the CI budget, deployment concurrency, workflow contract, X sync, and Firestore outside-query checks are clean.
  • Pushed without the local pre-push hook: it tripped twice on its per-test CPU limit (0.31s vs 0.30s, a different test each run, all pass in isolation) under local load. CI runs the same suites.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@kodjima33 this is approved. The latest push only adds the Firestore readiness gate main now requires; CI is running on it, ready to merge once green.

aryanorastar and others added 3 commits October 4, 2026 23:33
…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]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Merged current main twice (latest e018209).

  • tests/unit/test_render_backend_runtime_env.py: main moved the manifest patch to _MODULE['main'].__globals__. Kept that and this PR's loop that sets deploy-time env for every declared job.
  • backend/AGENTS.md: main had grown the file to within 5 bytes of its 39,000-byte budget, so the separate x-connector-sync-job entry no longer fit. The job is now listed in the existing cron-jobs line, and the notifications-job entry drops its X sync mentions (it no longer runs X sync). The file is 38,959 bytes and check_agents_md_lean.py passes.
  • Runtime-env renderer/validator, workflow contracts, X sync, scheduler validator, Firestore outside-query, CI budget, and deployment-concurrency checks pass on the merged tree.

… 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]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Pushed eff1406 for the red Backend unit shard.

  • test_proactivity_v2_flag_env_contract.py (new on main) renders full Cloud Run state and pre-resolves deploy-time inputs for services and network flags, but not for jobs. This PR's 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 the render failed with X_OAUTH_CLIENT_ID requires $X_OAUTH_CLIENT_ID to be set. The test now resolves job env_var entries the same way it resolves services.
  • That suite passes (74), along with every other test that renders runtime-env state (runtime-env validator, renderer, service identity, listen finalization, sync lineage rollout, release vector).

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.
@Git-on-my-level

Copy link
Copy Markdown
Member

Review on eff1406535 — not shipping that head

Previous reviews are addressed on the code path (Flex router, nonzero failure surface, WIF, Firebase project pin, source closure). Unresolved threads: none. kodjima33's approvals are on older commits and are approve-only, not a merge.

Two deploy blockers on that head, fixed in ece7564103:

  1. No runtime service account. Every live dev job runs as dev-backend-runtime. A new job without --service-account is created as the default compute SA. Dev now pins dev-backend-runtime; prod pins backend-runtime, the identity that already mounts the X OAuth and RapidAPI secrets on the Cloud Run API. backend-jobs-runtime does not.
  2. OAuth client id, redirect URI, and RapidAPI host were GitHub vars. Those names are not repository or environment variables. Render requires them to be non-empty, so the first deploy would fail closed. Live Cloud Run already mounts X_OAUTH_CLIENT_ID, X_OAUTH_REDIRECT_URI, and RAPID_API_HOST as secrets. The job now binds those same secrets.

Focused render/validator tests passed locally (124 in the runtime-env and proactivity contract files, plus the X job workflow assertion after the edit). Waiting for CI on ece7564103 before merge. Rollout stays manual and ordered: this job + scheduler first, notifications-job image that dropped X sync second.

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.
@Git-on-my-level

Copy link
Copy Markdown
Member

Hygiene on ece7564103 failed the deployment secret-boundary ratchet: X_OAUTH_CLIENT_ID, X_OAUTH_REDIRECT_URI, and RAPID_API_HOST are classified as config, so they cannot be new Cloud Run secret bindings.

cc4125d456 restores those three as env-var/config bindings and keeps the runtime service-account pin (dev-backend-runtime / backend-runtime). Local secret-boundary check against current main passed.

aryanorastar and others added 3 commits October 6, 2026 16:02
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]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Pushed 722bcbb (current main merged plus two commits) to clear the red Backend unit shards. Both causes are on main, not in this PR:

On the deploy prerequisite raised in review: X_OAUTH_CLIENT_ID, X_OAUTH_REDIRECT_URI, and RAPID_API_HOST are set and non-empty as environment variables in both development (since Jul 14) and prod (since Jul 16). The deploy job runs in the matching environment (environment: on line 37), so ${{ vars.* }} resolves for the render step. They're not repository-level variables, which is likely why they looked missing.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Merged latest main (a62fbc4) to clear the merge conflict — pushed f4ec068.

  • The only conflict was .github/ci-budget.yaml. Main has now added its own entry for mobile_daily_train.yml, so I took main's version of those lines. This PR no longer touches that workflow's entry; its ci-budget.yaml diff is back to just the X connector sync job.
  • No other conflicts. The PR's file list vs main is unchanged from before the merge.
  • Checked locally: CI budget check passes; runtime env validator/render, TTS, shared action items, and X sync suites (251 passed); workflow contract, proactivity flag, and CI budget tests (164 passed).

Git-on-my-level added a commit that referenced this pull request Oct 6, 2026
## 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. -->
@Git-on-my-level
Git-on-my-level merged commit 674ab47 into BasedHardware:main Oct 6, 2026
46 checks passed
Git-on-my-level added a commit that referenced this pull request Oct 6, 2026
## 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.
Git-on-my-level added a commit that referenced this pull request Oct 7, 2026
## 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. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) human Human-authored pull request needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split X connector sync out of notifications-job; document Cloud Run Job pattern + scaffold

6 participants