Skip to content

feat(backend): host bounded jobstore retirement in serving maintenance - #25630

Merged
Git-on-my-level merged 15 commits into
mainfrom
lane/jobstore-fast-path
Nov 19, 2026
Merged

Git-on-my-level merged 15 commits into
mainfrom
lane/jobstore-fast-path

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Run retained jobstore-copy retirement from the existing Cloud Run backend-integration Serving supervisor. Migration 0010 stores target-bound cursors in Postgres; page mutations and locked version/cursor compare-and-set advancement commit together. One table/source runs per bounded round-robin tick after critical maintenance, with a kill switch, shared normal pool, and counts-only retirement/rotation telemetry.

Prepare the production target/context on the retirement host and every source deletion executor: Cloud Run backend, backend-sync, backend-sync-backfill and backend-integration; GKE backend-listen uses its own backend-listen-runtime DB principal. The GPU batch-pipeline-worker target uses batch-pipeline-worker, but that process runs Pump, not Serving. Staging retains its own post-render bindings without duplicate env names. The co-host env-diff guard documents the production erasure bindings as listen-only: pusher mounts no deletion routes or jobstore purge caller. The production-mirror doc contains the exact caller/deploy inventory and CLI fallback.

Activation and rollback

Copy and recovery-hint activation remain off by default: JOBSTORE_PRODUCTION_MIRROR=off and BATCH_JOBSTORE_MODE=firestore. Retirement defaults on only with a complete PG target and valid data-plane context; it remains independent of copy kills. Mode-off cohort exclusion can retire all retained copies during rotation. Primary backfill requires the production mirror configuration. Missing migration 0010 skips safely with a metric; no boot migration occurs.

Release must apply/verify the schema and runtime DML grants separately, verify actual executor identities/routing and mode-off erasure, measure a complete rotation/lag and fleet connection budget, then approve mirror and hint policy cohorts. In particular, verify the backend-listen-runtime SQL user/grants. No production data/API access, GCP tier, IAM change, gcloud write, deploy or merge was performed.

Rollback retirement with JOBSTORE_RETIREMENT_ENABLED=off; retain JOBSTORE_PG_* and synchronous erasure until copies retire. The fallback reconcile-page CLI keeps private checkpoints. The parked operator track and PRs #25613/#25215 are unchanged.

Budgets and state exits

Initial JOBSTORE_RETIREMENT_MAX_ROWS=10, MAX_PRIMARY_READS=20, MAX_STATEMENTS=500, PAGE_SECONDS=3, INTERVAL_SECONDS=20; total tick budget is 10 seconds. Before: no in-serving rotation or durable PG cursor. After: one bounded table/source per supervised leader tick, with normal-pool warmup outside the page budget and inside the total allowance. Maximum page time is 3 seconds, well below the 60-second advisory maintenance lease. Two normal sessions plus the existing reserved erasure session remain the per-process ceiling; the erasure connector retains its existing setup behavior.

The new cursor's terminal path is end-of-pass reset to NULL plus passes/version increments and rotation_completed_at in the page transaction. Errors roll back page and checkpoint. A failed table rotates out so it cannot starve other tables. Rows are retired only after a fresh authoritative absence/cohort exclusion, never by a clock/lease TTL. Rotation lag is current time minus cursor last-pass completion (creation before first pass), computed from bounded cursor-row observations without copy-table scans.

Product invariants affected

INV-MEM-4: canonical memory admission/promotion authority is unchanged; the bounded copy and retirement worker never writes Firestore documents or promotes canonical memory. Firestore remains the sole job writer/claimant and privacy authority; no customer-facing wire contract changes.

Verification

All tests and type checks run through /Users/dazheng/workspace/omi/bin/omi-heavy with GOOGLE_APPLICATION_CREDENTIALS and CLOUDSDK_* unset. Local Postgres uses a disposable Unix-socket test cluster and a synthetic primary.

  • Focused pytest selection: 355 passed, including 7 real-Postgres tests covering atomic page/cursor rollback, two overlapping leaders, CAS refusal, budget rollback and migration idempotency/rollback.
  • Unit: cursor scope/CAS/regression, same-transaction callback and SQL accounting, target/context/kill/backfill gates, one-table fairness, schema-missing no-op, warm/total budgets, supervisor-only leader scheduling, private-registry metrics and rotation lag.
  • Regression: copy-pool ceilings, production copy/cohort, CLI, admission, staging fence, source env/flag budgets, query shapes and deployment rendering.
  • backend/scripts/pre-deploy-check.sh: 632 tests passed plus source-only deploy validations.
  • Feature registry, deployment secret boundary and cross-service deploy contract passed (34 passed, 3 skipped in that source-contract suite). Full Pyright: 0 errors across 2317 files (existing warning output retained). The seven-file Firestore guard set passed, including 608 query-shape tests; worker runtime 56 passed and co-host env diff 92 passed. scripts/pr-preflight --pr-body-file passed all 52 checks before push.

Representative exact commands (all wrapped in omi-heavy; paths from the task worktree):

backend/.venv/bin/python -m pytest -q backend/tests/unit/test_jobstore_retirement_cursor.py backend/tests/unit/test_jobstore_retirement.py backend/tests/unit/test_jobstore_retirement_deploy.py backend/tests/unit/test_jobstore_connection_deadline.py backend/tests/unit/test_jobstore_reconcile.py backend/tests/unit/test_jobstore_reconcile_operator.py backend/tests/unit/test_jobstore_copy_connections.py backend/tests/unit/test_jobstore_production_copy.py backend/tests/unit/test_jobstore_migrations.py backend/tests/unit/test_jobstore_production_mirror_admission.py backend/tests/unit/test_staging_fence.py backend/tests/unit/test_runtime_env_sources.py backend/tests/unit/test_batch_stage_env_ratchet.py backend/tests/unit/test_flag_budget.py backend/tests/unit/test_jobstore_index_selection.py backend/tests/unit/test_batch_pipeline_recovery_metrics.py backend/tests/integration/test_jobstore_retirement_postgres.py backend/tests/integration/test_jobstore_migrations_postgres.py
backend/.venv/bin/python -m pytest -q backend/tests/unit/test_batch_pipeline_runtime.py
backend/.venv/bin/python -m pytest -q backend/tests/unit/test_verify_pusher_cohost_env_diff.py
backend/.venv/bin/python -m pyright -p backend/pyrightconfig.json --pythonpath backend/.venv/bin/python --outputjson
# From backend/ with its .venv/bin first on PATH:
bash scripts/pre-deploy-check.sh
# From repository root, using this body file:
scripts/pr-preflight --pr-body-file <body-file>

Failure-Class: none

This is a new maintenance/configuration capability, with no incident failure class claimed.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-17T19:14:27.279500Z
We couldn’t complete this review. Comment @codex review to try again.
5b5c016 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Git-on-my-level and others added 4 commits November 18, 2026 02:28
…ions

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, align tests

Retirement on backend-integration needs the production context check to pass
on a Cloud Run service that does not set OMI_FIRESTORE_DATA_PLANE_PROJECT; a
present value must still name based-hardware. Cursor statements no longer
build SQL with f-strings. Page ValueErrors are reported as operation failures.
Strict mock assertions now expect the new retire_copies/supervised/request
arguments; review findings F1-F3 and F6-F8 from panel review-20261117t191629-b508.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ent deploy test

The pure-Python loader took 1.05s CPU on CI, over the fast-unit guard.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Primary-source pages read Firestore; schedule them only when the production
mirror is configured and shadow mode and shadow writes are on. Page errors
log the exception type and SQLSTATE, never values. A future cursor timestamp
reports unknown (NaN) lag. The statement floor admits a one-row page.
Review review-20261117t201455-d221 F1-F3, F6, F7.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Status at cfd406a: all 64 checks green. Two panel reviews triaged (review-20261117t191629-b508, review-20261117t201455-d221); accepted findings fixed, rejections recorded with reasons.

Deploy ordering (do not deploy before this): with JOBSTORE_PG_* configured, erasure raises and retries when the target is unreachable or unauthorized. backend-listen-runtime@ currently has no Cloud SQL roles and no IAM DB user on prod-jobs, so this PR must not roll until:

  1. backend-listen-runtime@ gets roles/cloudsql.client + roles/cloudsql.instanceUser and an IAM DB user on prod-jobs (approval pending with David);
  2. the release executor applies expand-only migration 0010 and grants table DML (listen: all jobstore tables; backend-runtime and batch-pipeline-worker: the new cursor table).

Mirror and index reads stay off in this PR (JOBSTORE_PRODUCTION_MIRROR=off, BATCH_JOBSTORE_MODE=firestore). The batch-custody lane owner's ack is needed before merge; merge belongs to the release owner.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Deploy gate met (2026-11-18T06:16Z): backend-listen-runtime@ now has roles/cloudsql.client + instanceUser, an IAM DB user on prod-jobs, and full DML on all 6 jobstore tables plus default privileges (read back as the owner batch-pipeline-worker@). After merge, migration 0010 must be applied as batch-pipeline-worker@ so the default privileges cover the new cursor table. Remaining before merge: batch-custody lane owner ack; merge by the release owner.

# Conflicts:
#	backend/deploy/runtime_env.yaml
#	backend/deploy/runtime_env/prod.overlay.yaml
…rsor remediation

0010 adds (namespace, key COLLATE "C") indexes on jobs, results and control and
(namespace, tbl, key COLLATE "C") on docs, matching reconcile._copy_keys order.
The stuck-cursor comment no longer claims automatic clearing; the mirror doc
gives the operator step. Review review-20261118t064740-ffd1 F1, F3.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level and others added 4 commits November 18, 2026 17:35
# Conflicts:
#	backend/deploy/runtime_env.yaml
#	backend/deploy/runtime_env/prod.overlay.yaml
Panel review-20261118t200019-ac88 F1: the cursor table's tbl CHECK is an
independent copy of MIRRORED_TABLES; a mirrored table added in Python without
a migration would make that scope's cursor INSERT fail. Parse the CHECK from
the migration and require set equality.

Failure-Class: none
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	backend/deploy/runtime_env/prod.overlay.yaml
@Git-on-my-level

Copy link
Copy Markdown
Member Author

TRIAGE review-20261118t204901-23ff (exact head 86b03f3): SHIP (luna + glm-flash). Deferred follow-ups, none change behaviour while retirement is unconfigured in prod: F1 stable metric labels for schema/config refusal reasons; F2 tests pinning INVALID_CONFIG vs OPERATION_FAILED per refusal gate and a ValueError page case; F3 treat the post-commit deadline check as advisory so a committed page is not reported as timeout; F4 share the 20 s interval floor as a named constant. Earlier panel review-20261118t200019-ac88 F1 (0010 tbl CHECK == MIRRORED_TABLES) is fixed in db8cdd0.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Correction to the triage comment for review-20261118t204901-23ff: retirement is not inert after this PR. It configures the PG target, the prod worker matches the production context, and JOBSTORE_RETIREMENT_ENABLED defaults on, so the worker leader starts retirement ticks after the roll. Before migration 0010 a tick only checks the cursor table and emits page_error{reason=schema_missing} (labels rotate over the 11 tables, which is F1); after 0010 it runs copy-source pages only (mirror off, so no Firestore reads) against empty copy tables, deleting nothing. F1-F4 stay deferred; alerting should sum page_error by reason. Kill switch: JOBSTORE_RETIREMENT_ENABLED=off on the worker.

# Conflicts:
#	backend/scripts/verify_pusher_cohost_env_diff.py
@Git-on-my-level
Git-on-my-level merged commit f159cce into main Nov 19, 2026
73 of 76 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/jobstore-fast-path branch November 19, 2026 00:54
Git-on-my-level added a commit that referenced this pull request Nov 19, 2026
…d-integration (#25744)

## Summary

Stage the #25630 roll with jobstore copy retirement off. This sets
`JOBSTORE_RETIREMENT_ENABLED=off` on the **backend-integration** Cloud
Run service only. That is the one prod service where retirement ticks
run (`BATCH_PIPELINE_SERVING_ENABLED=true`).

Why: #25630 (merged f159cce) adds the jobstore PG target env to all four
Cloud Run services. With the target set, retirement defaults on, so a
roll before migration 0010 would tick `schema_missing` on
backend-integration. lead2 holds the roll (b592a8) and ruled this
staging delta (a392ec). It lets the roll carry no retirement work.
Release applies and reads back 0010 inside the canary. A separate later
config step removes this line.

Unchanged: the PG target, mode `firestore`, mirror `off`, and erasure.
`purge_jobstore_owner` still reaches the target, because erasure does
not read this switch.

## Rendered role-env diff (prod, `render_backend_runtime_env.py --env
prod`, origin/main 7c7b491 vs this head)

```
backend_integration_env_vars
+ JOBSTORE_RETIREMENT_ENABLED=off
```

No other service, secret, flag or identity output changes. The entry
uses `category: ops_kill`, matching the flag's lifecycle.

Staging composes the prod overlay before its own, so the staging overlay
pins `JOBSTORE_RETIREMENT_ENABLED: 'on'` in `env_all`. Staging keeps its
current default behavior (panel review-20261119t021451-a721 F2).

## Rollback

Revert this PR, or delete the one overlay line. Retirement then returns
to default on.

## Product invariants affected

- INV-MEM-4: path match only (`runtime_env.yaml`). The change adds one
jobstore retirement switch on backend-integration and touches no memory
intake, promotion or projection behavior.

## Checks

- `compose_runtime_env.py --check`: up to date.
`check_runtime_env_compose.sh`: OK.
- `check_feature_flag_registry.py`: OK (registry re-rendered).
- Deploy contract:
`test_prod_retirement_stays_off_on_the_serving_leader_until_0010_readback`
pins the staged value (delete it with the overlay line).
- Unit tests: 961 passed, 3 skipped across 22 files, including staging
and compose. Files include: render_backend_runtime_env,
check_cloud_run_env_drift, runtime_env_sources,
runtime_env_manifest_compat, backend_runtime_env_validator,
jobstore_retirement{,_cursor,_deploy}, cross_service_deploy_contract,
jobstore_production_copy, jobstore_shadow_seams.

Not a roll GO. Release on SCA-2283 admits the runtime.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
shubhxho pushed a commit to shubhxho/omi that referenced this pull request Nov 19, 2026
…off on backend-integration

Sets JOBSTORE_RETIREMENT_ENABLED=off on backend-integration only, so the
roll carries no copy-retirement ticks before migration 0010 is read back
(lead2 a392ec). Target, mode, mirror and erasure unchanged. Re-enable by
deleting the overlay line in a separate config step.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Nov 19, 2026
The revert of #25630 also removed 172.25.29.2/32 from PROD_NETWORKS and its
regression cases. The instance still exists and staging still configures the
job-store shadow path, so staging must keep refusing that address.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Nov 19, 2026
… so trains from main are clean (#25778)

## What

Reverts two merged, not-yet-serving changes:
- #25744 `deploy(jobstore): stage the #25630 roll with retirement off on
backend-integration`
- #25630 jobstore retained-copy retirement, migration
`0010_retirement_cursor.sql`, and the Postgres target env on all four
Cloud Run services and the listen and worker charts

Both are plain `git revert -m 1` of the merge commits (`d5329c70597d`,
`f159cceccac0`). They applied with no conflicts, and no reference to the
removed modules, env keys or migration remains on the branch.

One deliberate deviation from a pure revert (commit `214a8955`): the
`prod-jobs` private address `172.25.29.2/32` stays in the staging
isolation fence (`PROD_NETWORKS`) with its regression cases. The
instance still exists and staging still configures the job-store shadow
path, so staging must keep refusing that address. Found by the panel
review.

## Why

David paused the Postgres job-store port on 2026-11-19 (Multica
SCA-1959). With #25630 on main, every Cloud Run train from main adds the
`JOBSTORE_*` target env. That makes account and conversation erasure
connect to the idle `prod-jobs` instance before `finish_privacy_purge`,
so a Postgres outage would make purges raise and retry, for no benefit
while the port is paused. lead2 holds all trains for that reason
(b592a8), which also blocks the conversations v3 Cloud Run trains.

After this revert, the files these two PRs touched carry no jobstore
target env, and a train from main no longer changes erasure.

## Risk and rollback

- Nothing here is serving, so no running behaviour changes. Serving is
still the `a6824b8` revisions.
- Migration 0010 was never applied in prod (ledger is 1..8) and the copy
tables were empty at the last count (2026-11-19 01:15:53Z), so no data
depends on the removed code.
- Rollback: revert this PR.

## Product invariants affected

- INV-MEM-4: the change set touches a path under this invariant's globs
only because it restores that file to its pre-#25630 content. No
memory-promotion behaviour changes.

## Verification

- CI green on `214a8955` (64 checks, 0 failed).
- Panel reviews `review-20261119t104759-a779` (one major, fixed) and
`review-20261119t112157-f094` (minor and nit findings, triaged).

- Pre-push preflight on this branch.
- `git grep` for `retirement_cursor`, `jobstore.retirement`,
`JOBSTORE_RETIREMENT`, `0010_retirement`, `JOBSTORE_PG_HOST` in prod
overlays and charts: no matches.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Git-on-my-level added a commit to Git-on-my-level/omi that referenced this pull request Nov 19, 2026
…irement off on backend-integration (BasedHardware#25744)"

This reverts commit d5329c7, reversing
changes made to 1bdf17c.
Git-on-my-level added a commit to Git-on-my-level/omi that referenced this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant