Skip to content

feat(backend): fleet driver for the summary-vector backfill - #21135

Merged
Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
Git-on-my-level:lane/fleet-vector-backfill
Oct 10, 2026
Merged

Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
Git-on-my-level:lane/fleet-vector-backfill

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

What

Adds scripts/fleet_backfill_summary_vectors.py: a retry-safe fleet driver for the per-user backfill_summary_vectors.py operator tool, plus --all-users enumeration from conversation_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

  • Dry-run by default; --apply refuses without a configured vector index.
  • Per conversation: one embedding + the existing metadata-extraction LLM call. Fleet-scale cost was estimated at ~$40-230 for 50k-300k conversations before execution is authorized.
  • Designed to run inside the production backend environment (Cloud Run job or an attended operator shell); no secrets are read by this repo change.

Tests

  • Offline behavioral test of the driver: dry-run totals, resume skips done uids, error-budget stop marks the uid failed and continues, --retry-failed recovers only failed uids (writes verified per uid).
  • tests/unit/test_backfill_summary_vectors.py still green (16 passed).
  • --all-users enumeration verified against an independent REST enumeration of conversation_finalization_jobs since 2026-08-25 (27,595 vs 27,596, +1 from boundary drift; missing=0).

Failure-Class: none

View guided diff

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T13:07:14.791177Z 9717bbe 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.

@Git-on-my-level
Git-on-my-level merged commit c515ec6 into BasedHardware:main Oct 10, 2026
43 checks passed

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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'])]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +90 to +94
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}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +80 to +82
cursor = docs[-1].get('created_at') or cursor
# guard against a pathological single-timestamp page
cursor = cursor + timedelta(milliseconds=1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject a zero batch limit

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 👍 / 👎.

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