Skip to content

harden(rollout): refuse flag raises that are not live (ramp preflight) - #24956

Merged
Git-on-my-level merged 14 commits into
mainfrom
lane/live-preflight
Nov 9, 2026
Merged

Git-on-my-level merged 14 commits into
mainfrom
lane/live-preflight

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Requested by David

Episode F reached 100% while backend-listen served an image without its code; listen/pusher were unscraped, so missing metric series looked clean. Production raises now require evidence from the serving code and its telemetry before writing.

All three writers share backend/scripts/rollout/live_preflight.py: flag-store set/import/delete writes, operator _ramp percent raises, and controller ADVANCE. Runtime containment comes from reading sites and runtime_images.json, deriving record-seal from the batch chart and excluding the uninstalled pilot. The registry also drives direct deploy admission, so the child deployment is derived in code instead of adding an incompatible standalone service row. All nonterminated GKE replicas and the actual 100% Cloud Run traffic revision must contain every required code/registry commit, including introductions on parallel Git branches. Digest images bind through release SHA/tree labels.

Refusals are RAMP_PREFLIGHT REFUSE not_live, commit_unbound, key_unread, scrape_unknown runtime=<name>, scrape_dead, or metric_dead (exit 3). Transport or malformed evidence emits RAMP_PREFLIGHT UNREAD <what> reason=<fixed-token> (exit 4). Scrapes use the repository expected-targets inventory and require samples with every up value 1 over 30 minutes. The first \bomi_[a-z0-9_]+\b metric in ramp prose must have a nonzero series in 30 minutes; unparseable prose emits RAMP_PREFLIGHT NOTE metric_unparsed key=<K> and skips that metric check.

One shared widens_exposure predicate governs all writers: percent increases, activation, allow additions and deny removals widen; decreases, deactivation, allow removals and deny additions narrow. Deleting an Omi override returns control to PostHog and is widening unless the current rule is active at 100% with no deny UIDs; delete is gated against possible 100% exposure. Pure narrowing never runs preflight or its Git fetch. Mixed widening/narrowing writes refuse with RAMP_PREFLIGHT REFUSE mixed_write (exit 2) before liveness evidence; run the narrowing change alone first, then the raise. Overrides cannot accept a mixed write. A controller refusal HOLDs its advance; rollback remains available when evidence reads fail. Existing CAS, writer authority and quality-floor rules remain in force.

--accept-not-live REASON requires at least 15 characters. It prints OVERRIDE and appends accept_not_live:<REASON> to the writer's existing durable audit reason. _ramp stores the explanation in its transaction's history row while preserving the short serving reason token for deployed reader compatibility. No bus dependency or credential installation is introduced; reads use the write command's existing operator credentials.

Why isn't this a shared primitive instead? It is: one prover is imported by all three writers and is reusable by train readback. The real incident above is the regression case. The drift report and meta-repo ramp_apply gate are outside this PR.

Product invariants affected

none — operator admission and audit behavior only.

Failure class

Failure-Class: FC-unprovisioned-rollout-target

Exposure must not increase before the required reader code is deployed. The shared live preflight and its temporary-Git/cloud evidence regressions enforce that admission contract for these writers.

Verification prerequisite

Synced scripts/check_feature_flag_registry.py and its test file exactly from origin/main at 6a03440964b9ecf21330cc87a8b2c30dcce712da, incorporating the already-merged #24950 dated sweep exceptions/UTC-date fix. The lane's older checker began failing on the unchanged Nov 1 review date after UTC midnight. No new review decision, exception, registry value, local merge or force-push is introduced; these two files are byte-identical to current main.

Validation

Third-review fix:

  • Deleting an inactive or partial Omi override now preflights the PostHog handoff at 100%; a fully active 100% rule bypasses only when it has no deny UIDs. Regressions cover both decisions and exits 3/4 preserving the rule before any write. The shared predicate and runbook document the handoff. _ramp/controller writes merge percent patches and expose no delete/reset-to-another-source operation; clearing a lock does not remove percentages. Kill/deactivate/decrease/deny-add/allow-removal remain preflight-free.

Second-review fixes:

  • Mixed _ramp increases/decreases refuse with exit 2 and mixed_write before either evidence gate, Git fetch or write, including overrides and dry runs. The regression commits a standalone decrease with CAS, then proves a failed fetch blocks only the later raise.
  • Flag allow-add/percent-down and activation/percent-down combinations refuse as mixed; the expanded matrix also covers raises combined with deny additions, allow removals and kills. Pure narrowing remains independent of liveness reads.
  • Deny UID removal is widening and runs preflight even at zero percent or on an inactive rule; failure refuses before writing. The same predicate governs flag set/import, ramp_set and the controller; controller HOLD and rollback behavior remain covered.

Prior review regressions remain: fresh reader discovery after bounded origin fetch, job-template SHA/image containment with scrape-not-applicable NOTE, and source-projected Cloud Run evidence that excludes secret-looking env values.

Canonical five-file backend/test.sh via TZ=UTC BACKEND_UNIT_FILE_BUDGET_SECONDS=900 /Users/dazheng/workspace/omi/bin/omi-heavy run --wait 7200 -- bash .../verify-live.sh: 490 passed (live_preflight 27; omi_flags 71; ramp_controller/ramp_set 120; rollout_cohorts 29; runtime_percent 243), measured completion 2026-11-09T01:27:49Z. Evidence: live3-tests.log and live3-unit-receipt.json in the run directory. Targeted Pyright of all nine PR Python files through omi-heavy completed 2026-11-09T01:26:46Z: 61 pre-existing errors, 1547 warnings, zero new errors. Every current error maps to an unchanged line with the same message/rule/column in prior head b1f33d58c6e3; the targeted command remains non-green on that existing debt. No diagnostic settings were relaxed. Evidence: live3-pyright-all.py, live3-pyright-all.log and live3-pyright-all.json.

Full scripts/pr-preflight --lane local --pr-body-file .../live3-pr-body.md through omi-heavy passed 38 checks, measured completion 2026-11-09T01:33:46Z (live3-preflight.log). The credential-scrubbed bash .../live3-push.sh completed 2026-11-09T01:43:45Z on head 391e70be7556c3d9e6e408eab7df400d999fde22: all mandatory hooks passed, including 38 preflight checks, 218 selected unit tests (27 + 71 + 120), configured backend Pyright 0 errors, and pinned formatting. No check was skipped. The wrapper unsets GOOGLE_APPLICATION_CREDENTIALS and every CLOUDSDK_* variable and exports BACKEND_UNIT_FILE_BUDGET_SECONDS=900 TZ=UTC. Evidence: live3-push.log and live3-push-receipt.json.

No .github change. No prod calls in tests.

🤖 Generated with Claude Code.

View guided diff Turn on auto-fix

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T02:09:02.437520Z 3b0a636 New commits
ℹ️ 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 self-assigned this Nov 8, 2026

@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: 571fe097bc

ℹ️ 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".

Comment on lines +428 to +431
samples = self.metric('min(up{job=' + json.dumps(job) + '})')
flat = [v for series in samples for v in series]
if not flat or any(not points for points in samples) or any(v != 1 for v in flat):
return False, 'scrape_dead', {'key': key, 'job': job, 'up': min(flat) if flat else 'absent'}

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 Query scrape health using the matching Prometheus job names

With the checked-in production monitoring configuration, this queries GMP using job names belonging to the separate in-cluster Prometheus scrapers. For example, expected-targets.prod.yaml supplies cloud-run-application-metrics, whereas backend/deploy/cloud_run_gmp_sidecar.yaml names the managed job omi-cloud-run-application-metrics; gmp-shadow-mappings.json explicitly distinguishes these local and managed selectors. The GKE PodMonitoring resources likewise do not use the local *-metrics scraper names. Consequently, healthy deployments return no matching up samples and raises are refused as scrape_dead. Query the in-cluster endpoint for these inventory jobs, or translate them to the corresponding managed-monitoring selectors.

Useful? React with 👍 / 👎.

Comment on lines +447 to +450
samples = self.metric(selector)
series = sum(any(v != 0 for v in points) for points in samples)
if not series:
return False, 'metric_dead', {'key': key, 'metric': metric, 'window': '30m'}

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 Accept zero-valued runtime-percent samples as live evidence

When a ramp has been held at 0% for the last 30 minutes, this rejects its first increase even if every runtime is current and telemetry is healthy. For ramp names, the selected metric is omi_runtime_percent, and runtime_percent._export() deliberately sets that gauge to the currently served percentage, so zero is valid evidence of a live reader rather than a dead metric. This also prevents restarting a ramp after a sustained rollback without --accept-not-live. Check sample presence rather than nonzero values for this gauge, while retaining the nonzero requirement for metrics where that is appropriate.

Useful? React with 👍 / 👎.

Comment on lines +642 to +646
if not result[0]:
if effects.accept_not_live is None:
item = Decision(
Action.HOLD,
item.name,

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 Preserve controller lockstep when a follower fails preflight

When batch-pipeline and first-summary are seeded at the same percentage below 100, both can receive ADVANCE decisions, but these independent checks can HOLD only first-summary while allowing the lead to advance—for example, if the follower's evidence request encounters a transient transport failure. The resulting write leaves the follower below the lead. On subsequent ticks, _align_follower() classifies that state as follower_diverged, HOLDs it, and pages instead of allowing it to catch up, so a temporary evidence failure permanently stalls the follower until an operator intervenes. Preserve the lockstep invariant when applying preflight refusals, rather than committing the lead's advance independently of an aligned follower.

Useful? React with 👍 / 👎.

Comment on lines +346 to +349
'-S' + key,
self.ref,
'--',
'backend/database/rollout_cohorts.py' if ramp else 'backend/',

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 Exclude documentation and tests from reader-history requirements

When a documentation or test change adds an occurrence of an existing flag key, this whole-backend/ history search treats that commit as required serving code. Git's diff -h describes -S as “find filepair whose only one side contains the string”; it does not identify runtime-reader introductions. For example, the search for proactivity_v2 selects 45a3856ba, whose only backend change is the generated documentation file backend/docs/feature-flag-registry.md. I also reproduced a not_live refusal using the existing hermetic fixture after adding only a documentation mention while leaving the serving reader unchanged. Restrict the code-history requirement to actual runtime-reader source changes so documentation and tests do not force fleet redeployments before a flag can advance.

Useful? React with 👍 / 👎.

@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: 34a126901a

ℹ️ 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".

Comment on lines +370 to +372
roster = runtime_roster(paths, inventory)
if not roster:
return False, 'key_unread', {'key': key}

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 Account for client-only flags when deriving the reader roster

For valid client-only flags such as onboarding-setup-rating-prompt and mobile-chat-apps-all-channels, this always returns key_unread: repository-wide search finds their backend occurrences only in documentation, which runtime_roster() excludes, while their actual readers live in Flutter. These flags are served dynamically through backend/routers/omi_flags.py and utils.omi_flags.resolve_surface(), so no per-key Python literal is required. Because both set and import-posthog --apply now require this check, legitimate activation, percentage increases and allowlist additions cannot succeed without --accept-not-live, regardless of deployment health. Derive the relevant generic flag-serving runtimes from registry surfaces for client-only keys rather than requiring a literal backend reader.

Useful? React with 👍 / 👎.

Comment on lines +349 to +352
values = [[float(point[1]) for point in series['values']] for series in data['data']['result']]
if any(not math.isfinite(v) for series in values for v in series):
raise Unread('prometheus', 'invalid_sample')
return values

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 Verify scrape freshness before accepting historical samples

If a scraper or its ingestion pipeline stops publishing, the 30-minute range query can still return earlier up=1 samples followed by no data. Discarding every timestamp here makes that indistinguishable from current scrape coverage, and check() accepts any nonempty collection containing only ones. I reproduced a PASS with the last scrape sample 20 minutes old. This permits production raises while telemetry is currently unavailable, undermining the fail-closed evidence gate. Preserve timestamps and require sufficiently recent scrape evidence, rejecting missing coverage rather than accepting only the surviving historical points.

Useful? React with 👍 / 👎.

Comment thread backend/scripts/omi_flags.py Outdated
Comment on lines +209 to +210
if live_preflight.is_raise(current, rule, inactive=args.inactive):
live_preflight.require(args.key, rule['rollout_percentage'], args.accept_not_live)

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 Scope flag-store preflight to the target environment

When this CLI targets the separate development flag project documented in backend/docs/runbooks/omi-flags.md, raises still invoke the production preflight unconditionally. require() calls preflight() with its default project='based-hardware', and the prover selects the production GKE context; neither the flag-store target nor an environment is considered. Consequently, a feature already deployed in development cannot be enabled there until its code is also live in production, unless the operator supplies an override. The same problem affects import-posthog --apply. Make the flag writer environment-aware and restrict production evidence checks to production writes, as ramp_set.py already does.

Useful? React with 👍 / 👎.

Import the exact checker and fixture versions already merged by PR #24950 on origin/main. This incorporates the approved dated sweep exceptions without changing registry decisions or runtime values.

@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: b1f33d58c6

ℹ️ 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".

Comment on lines +154 to +155
for name, pct in change.get('percents', {}).items()
if live_preflight.widens_exposure(entry, {'percents': {name: pct}})

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 Check liveness when activating legacy retirement through its mode

When legacy-sync and batch-pipeline already have nonzero percentages but legacy_sync is on, changing the mode to draining or dark activates retirement for that cohort without increasing either percentage. widens_exposure() ignores the mode, and this comprehension only considers percentage changes, so the production write performs no live preflight—even if the same command explicitly supplies the unchanged legacy percentage. runtime_percent.legacy_sync_mode() immediately exposes the new mode to those users, and legacy_dark.legacy_admission_allowed() stops their legacy admission. Include mode activation in the classification and require evidence for legacy-sync, while keeping the rollback to on exempt.

Useful? React with 👍 / 👎.

Comment on lines +130 to +131
(float((before.get('percents') or {}).get(name, 0)), float(percent))
for name, percent in (change.get('percents') or {}).items()

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 Use serving defaults for unseeded ramp percentages

When first-summary is absent from _ramp, production serves the environment percentage, which the checked-in production runtime_env.yaml sets to 100; config/summary_guarantee.py passes that value through runtime_percent() as its fallback. Treating the absent entry as zero therefore classifies an operator's reduction to 50, with the required lock and --allow-quality-decrease, as an increase. ramp_set.py consequently invokes production preflight and can block this rollback when evidence is unavailable, contrary to the narrowing-write bypass. Compare against the effective serving baseline for an unseeded name rather than assuming every missing percentage is zero.

Useful? React with 👍 / 👎.

Git-on-my-level and others added 3 commits November 9, 2026 08:34
The CLI classified a set or delete (preflight needed or not) on a snapshot,
then wrote without checking the store still matched it. A concurrent kill
could be overwritten by a stale active rule, or a delete exempted as an
active 100% rule could hand the key back to PostHog after someone
deactivated it.

write_rule now takes the rule the caller read and refuses, inside the
transaction, when the stored rule's existence or version changed. set,
delete and import pass their snapshot; a conflict writes nothing and tells
the operator to rerun, which re-reads and reclassifies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A rule written outside write_rule may have no version, so (exists, None)
matched any other versionless rule. Compare such rules by full content;
versioned rules still compare by version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit b009573 into main Nov 9, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/live-preflight branch November 9, 2026 02:28
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.

2 participants