Repository navigation
feat(backend): fleet driver for the summary-vector backfill - #21135
Git-on-my-level merged 3 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9717bbe025
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if state.get('started_at') is None: | ||
| state['started_at'] = datetime.now(timezone.utc).isoformat() | ||
|
|
||
| pending_uids = [u for u in uids if u not in state['done'] and (args.retry_failed or u not in state['failed'])] |
There was a problem hiding this comment.
Separate preview progress from applied progress
When an operator follows the documented cost-signoff workflow and reuses the required state file for a dry run followed by --apply, the preview has already written every successful UID into state['done'] with apply: false; this filter nevertheless drops them, so the apply invocation reports to_run: 0, exits successfully, and creates no vectors. Scope completion by mode, or only treat records with apply: true as done for an apply run.
Useful? React with 👍 / 👎.
| args = parser.parse_args(argv) | ||
|
|
||
| state_path = Path(args.state_file) | ||
| if args.all_users: |
There was a problem hiding this comment.
Reject simultaneous UID source flags
When an invocation includes both --uid-file and --all-users, argparse accepts it and this branch silently discards the targeted file, so adding --apply can turn a targeted production repair into an entire-fleet run with whole-fleet writes and cost. Put the source flags in a required mutually exclusive group.
Useful? React with 👍 / 👎.
| except json.JSONDecodeError: | ||
| backup = path.with_suffix(".corrupt") | ||
| path.rename(backup) | ||
| print(f"state file corrupt; moved to {backup}", file=sys.stderr) | ||
| return {"done": {}, "failed": {}, "started_at": None, "updated_at": None} |
There was a problem hiding this comment.
Fail closed when progress state is corrupt
If a partially completed apply's JSON is truncated or corrupt, this fallback renames the active progress record and resumes from a blank done map, causing all previously completed UIDs to be embedded and upserted again rather than stopping for operator recovery. Fail closed on invalid durable state; if recovery remains a fallback, instrument it through the shared fallback helper.
AGENTS.md reference: backend/AGENTS.md:L312-L312
Useful? React with 👍 / 👎.
| Pages the finalization-jobs collection ascending on created_at (the only | ||
| indexed order), selecting only created_at and uid. Read-only. | ||
| """ | ||
| from database._client import get_firestore_client |
There was a problem hiding this comment.
Move function-local imports to module scope
Because the dependency first imported here, along with the imports in main, _writer, and _asdict, is loaded only after a mode starts executing, import checks can pass while production --all-users or --apply dependencies remain unavailable and fail during a fleet run. The backend import contract requires imports at module scope, so move or refactor these dependency seams accordingly.
AGENTS.md reference: backend/AGENTS.md:L161-L161
Useful? React with 👍 / 👎.
| cursor = docs[-1].get('created_at') or cursor | ||
| # guard against a pathological single-timestamp page | ||
| cursor = cursor + timedelta(milliseconds=1) |
There was a problem hiding this comment.
Resume pages after the last snapshot
Once --all-users produces a full 9,999-document page, advancing the timestamp by 1 ms skips every job whose created_at equals the last timestamp or falls within the next millisecond; a UID represented only by one of those jobs is silently omitted from the fleet backfill. Page with start_after(docs[-1]), preserving document identity as the tie-breaker, instead of altering the timestamp.
Useful? React with 👍 / 👎.
| ) | ||
| parser.add_argument('--state-file', required=True, help='durable progress JSON (created if missing)') | ||
| parser.add_argument('--since', type=iso_timestamp, default=DEFAULT_SINCE) | ||
| parser.add_argument('--limit', type=int, default=500, help='max eligible rows per uid') |
There was a problem hiding this comment.
With --limit 0, metadata_rows and backfill_user select no rows, but each UID is still recorded as done and future resumes skip it, yielding a successful no-op for the whole fleet. Mirror the per-user CLI's positive-limit validation before processing any UID.
Useful? React with 👍 / 👎.
What
Adds
scripts/fleet_backfill_summary_vectors.py: a retry-safe fleet driver for the per-userbackfill_summary_vectors.pyoperator tool, plus--all-usersenumeration fromconversation_finalization_jobs(created_at ascending, uid+created_at projection only).Why
The chat-vector freshness repair (#21111) fixed new conversations; the pre-repair backlog needs the per-user backfill run for every affected account. Doing that by hand for ~27.6k uids is error-prone; the driver adds durable per-uid state (atomic tmp+rename), resume-on-rerun, failed-uid quarantine with
--retry-failed, and a 10%-per-batch error budget inherited from the per-user script.Cost/execution notes
--applyrefuses without a configured vector index.Tests
--retry-failedrecovers only failed uids (writes verified per uid).tests/unit/test_backfill_summary_vectors.pystill green (16 passed).--all-usersenumeration verified against an independent REST enumeration ofconversation_finalization_jobssince 2026-08-25 (27,595 vs 27,596, +1 from boundary drift; missing=0).Failure-Class: none