Skip to content

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

Closed

Description

@Git-on-my-level

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):

  1. Daily notifications / daily summary (original owner — keep here)
  2. X connector incremental sync (utils/x_connector.py, every 6h via hour-modulo)
  3. 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.yaml job 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-job block in backend/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:

  1. Thin *_job.py entrypoint calling one module
  2. Dockerfile + CMD
  3. runtime_env.yaml cloud_run.jobs.<name> + list workflow in workflow_files
  4. gcp_<name>_job.yml (render/validate env, deploy with job:)
  5. Unit coverage for render outputs (*_env_vars / *_secrets)
  6. Runbook: first deploy, gcloud run jobs execute, Cloud Scheduler create/update
  7. 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_NAME substitution
  • Prints the runtime_env.yaml snippet 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.py no longer imports or runs X sync
  • x-connector-sync-job deploys 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

  1. Land memory-maintenance-job (establishes the copyable pattern)
  2. Add checklist + scaffold using that pattern
  3. 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

  1. added
    docs-tooling
    p3
    and removed
    docs-tooling
    p3
    on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs-toolingp3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions