Repository navigation
harden(rollout): refuse flag raises that are not live (ramp preflight) - #24956
Conversation
Codex Review Summary: ✅ CompletedThis 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. |
…ch fake Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 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".
| 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'} |
There was a problem hiding this comment.
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 👍 / 👎.
| 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'} |
There was a problem hiding this comment.
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 👍 / 👎.
| if not result[0]: | ||
| if effects.accept_not_live is None: | ||
| item = Decision( | ||
| Action.HOLD, | ||
| item.name, |
There was a problem hiding this comment.
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 👍 / 👎.
| '-S' + key, | ||
| self.ref, | ||
| '--', | ||
| 'backend/database/rollout_cohorts.py' if ramp else 'backend/', |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| roster = runtime_roster(paths, inventory) | ||
| if not roster: | ||
| return False, 'key_unread', {'key': key} |
There was a problem hiding this comment.
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 👍 / 👎.
| 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 |
There was a problem hiding this comment.
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 👍 / 👎.
| if live_preflight.is_raise(current, rule, inactive=args.inactive): | ||
| live_preflight.require(args.key, rule['rollout_percentage'], args.accept_not_live) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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".
| for name, pct in change.get('percents', {}).items() | ||
| if live_preflight.widens_exposure(entry, {'percents': {name: pct}}) |
There was a problem hiding this comment.
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 👍 / 👎.
| (float((before.get('percents') or {}).get(name, 0)), float(percent)) | ||
| for name, percent in (change.get('percents') or {}).items() |
There was a problem hiding this comment.
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 👍 / 👎.
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]>
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_ramppercent raises, and controller ADVANCE. Runtime containment comes from reading sites andruntime_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, ormetric_dead(exit 3). Transport or malformed evidence emitsRAMP_PREFLIGHT UNREAD <what> reason=<fixed-token>(exit 4). Scrapes use the repository expected-targets inventory and require samples with everyupvalue 1 over 30 minutes. The first\bomi_[a-z0-9_]+\bmetric in ramp prose must have a nonzero series in 30 minutes; unparseable prose emitsRAMP_PREFLIGHT NOTE metric_unparsed key=<K>and skips that metric check.One shared
widens_exposurepredicate 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 withRAMP_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 REASONrequires at least 15 characters. It prints OVERRIDE and appendsaccept_not_live:<REASON>to the writer's existing durable audit reason._rampstores 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.pyand its test file exactly fromorigin/mainat6a03440964b9ecf21330cc87a8b2c30dcce712da, 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:
_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:
_rampincreases/decreases refuse with exit 2 andmixed_writebefore 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.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.shviaTZ=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.logandlive3-unit-receipt.jsonin the run directory. Targeted Pyright of all nine PR Python files throughomi-heavycompleted 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 headb1f33d58c6e3; the targeted command remains non-green on that existing debt. No diagnostic settings were relaxed. Evidence:live3-pyright-all.py,live3-pyright-all.logandlive3-pyright-all.json.Full
scripts/pr-preflight --lane local --pr-body-file .../live3-pr-body.mdthroughomi-heavypassed 38 checks, measured completion 2026-11-09T01:33:46Z (live3-preflight.log). The credential-scrubbedbash .../live3-push.shcompleted 2026-11-09T01:43:45Z on head391e70be7556c3d9e6e408eab7df400d999fde22: 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 unsetsGOOGLE_APPLICATION_CREDENTIALSand everyCLOUDSDK_*variable and exportsBACKEND_UNIT_FILE_BUDGET_SECONDS=900 TZ=UTC. Evidence:live3-push.logandlive3-push-receipt.json.No .github change. No prod calls in tests.
🤖 Generated with Claude Code.