Repository navigation
Description
Summary
notifications-job became a multi-domain hourly cron bag (daily notifications → X connector sync → canonical memory maintenance). Memory maintenance is moving to a dedicated Cloud Run Job (memory-maintenance-job). This issue tracks the same ownership cleanup for X sync, plus a small docs/checklist + agent scaffold so the next scheduled job does not get hitchhiked again.
Context
Today backend/utils/other/jobs.py runs three gated tasks from one Cloud Run Job entrypoint (backend/modal/job.py):
- Daily notifications / daily summary (original owner — keep here)
- X connector incremental sync (
utils/x_connector.py, every 6h via hour-modulo) - Canonical ST→LT maintenance (moving off this host)
Pain we already hit with memory on this host:
- Manual
workflow_dispatch-only deploy → code/env can merge while the job image never redeploys - Mixed secrets/env across domains in one
runtime_env.yamljob block - Scheduler not defined in-repo → unclear whether hourly execute exists
- Unrelated failure/deploy blast radius
X has the same structural mismatch: different cadence (6h), enumerates all connected X users, different failure mode than push/daily summary.
Goals
1. Extract X sync to its own Cloud Run Job
- New job name suggestion:
x-connector-sync-job - Thin entrypoint that only calls
run_x_sync_job()(Firebase init + that runner) - Own Dockerfile (clone notifications / memory-maintenance job image pattern)
- Own
cloud_run.jobs.x-connector-sync-jobblock inbackend/deploy/runtime_env.yaml(dev + prod) - Own workflow
.github/workflows/gcp_x_connector_sync_job.yml(workflow_dispatch; port VPC render vars + checkout-SHA image tag fixes) - Remove X block from
backend/utils/other/jobs.py - Cloud Scheduler every 6h →
gcloud run jobs execute x-connector-sync-job(document exact commands; create/update in GCP as part of rollout) - Update AGENTS.md Backend Service Map
2. Document the Cloud Run Job pattern (checklist, not a framework)
Add a short agent/human-facing note (AGENTS.md and/or docs/doc/developer/backend/):
One domain → one Cloud Run Job. Do not add unrelated work to an existing job.
Checklist for adding a job:
- Thin
*_job.pyentrypoint calling one module - Dockerfile +
CMD runtime_env.yamlcloud_run.jobs.<name>+ list workflow inworkflow_filesgcp_<name>_job.yml(render/validate env, deploy withjob:)- Unit coverage for render outputs (
*_env_vars/*_secrets) - Runbook: first deploy,
gcloud run jobs execute, Cloud Scheduler create/update - Service map update in AGENTS.md
Explicit non-goal: no shared Python BaseCronJob / plugin registry / multi-task bag. Keep existing host shapes separate:
| Shape | Use for |
|---|---|
| Cloud Run Job + Scheduler | Periodic batch (notifications, memory maintenance, X sync) |
| Cloud Tasks → Cloud Run Service | Durable request work (sync, audio-merge, account-deletion) |
| GKE CronJob | Infra shell (agent-vm-reaper) |
3. Agent scaffold script
Add something like backend/scripts/scaffold_cloud_run_job.sh (or .py) that an agent can run to bootstrap a new job from the canonical template:
- Copies entrypoint / Dockerfile / workflow stubs with
JOB_NAMEsubstitution - Prints the
runtime_env.yamlsnippet shape and checklist TODOs - Does not create GCP resources or enable schedulers
Prefer cloning the landed memory-maintenance-job (or notifications-job if memory is not merged yet) as the template source.
Non-goals
- Changing X sync algorithm, registry schema, or per-user spacing
- Moving daily notifications / daily summary off
notifications-job - Building a unified job platform or auto-deploy-on-push for all jobs (can be a later issue)
- Enabling vector-repair outbox on
notifications-job(that work has its own contract; do not hitchhike)
Acceptance criteria
-
jobs.pyno longer imports or runs X sync -
x-connector-sync-jobdeploys via its own workflow with rendered runtime env - Runbook documents execute + 6h Scheduler for dev (and prod when applicable)
- AGENTS.md service map lists X sync on the new job; notifications-job is notifications (+ daily summary) only
- Checklist doc exists and is linked from AGENTS.md
- Scaffold script exists and produces a usable stub set for a dummy job name in a dry-run
Suggested sequencing
- Land
memory-maintenance-job(establishes the copyable pattern) - Add checklist + scaffold using that pattern
- Extract X sync using the scaffold / checklist
Related
- Memory maintenance host move (dedicated
memory-maintenance-job; do not keep ST→LT on notifications-job) - Vector-repair outbox worker contract (
docs/epics/memory_vector_repair_outbox_cloud_deployment_contract.yaml) — separate host when enabled; same “don’t hitchhike” rule
Activity
feat(backend): split X connector sync into its own Cloud Run Job (Bas…
feat(backend): split X connector sync into its own Cloud Run Job (Bas…
feat(backend): split X connector sync into its own Cloud Run Job (Bas…