Repository navigation
lr/06: runtime _ramp percents and ramp controller (contracts f, g) - #22425
Conversation
… M1) Contract (f): rollout_cohorts/_ramp holds per-env percents and legacy_sync. utils/rollout/runtime_percent.py reads it with a 30s process cache on the rollout executor, serves last-known-good on error, and falls back to the env value on a cold start or a missing document, so with no document behaviour is unchanged. config/ reaches it through a resolver seam in config/rollout_cohorts.py, bound by configure_rollout_runtime(). Unbound processes keep env values. summary_guarantee and batch_live_preview now read their percent through the seam. valid_uid rejects _ramp* ids. CAS writes create a history row in the same transaction and refuse range or nesting violations. Contract (g): scripts/rollout/ramp_controller.py has a pure decide() and a thin runner. The runner writes only the batch-pipeline/first-summary percents and acts only while legacy_sync=on. It moves one step at a time, at most once per 10 minutes, and never past 100. It uses the fleet gate's data-loss tokens for ROLLBACK_ZERO and stops after two rollbacks in 24h until a human lock_cleared write. Every decision goes to STATE and every action to anx. After a sleep or restart gap, the first tick only holds (S9). scripts/rollout/ramp_set.py is the operator CLI. inject_gate.py is the staging-only rehearsal wrapper. config/batch_pipeline.py is untouched (frozen until #22362/#22373 reach integration). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
…kage __init__ files Snapshot source 'firestore' and revision int (0 = no document) match lr/01-stubs. RAMP_DOC_ID re-exported. utils/rollout and scripts/rollout are namespace packages, because the dead-code ratchet blocks __init__.py there. LIFECYCLE headers are now on line 1. 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: 6697f118bb
ℹ️ 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".
| wrote = False | ||
| if writes and apply: | ||
| lead = next((item for item in writes if item.name == LEAD_NAME), writes[0]) | ||
| change = {'percents': {item.name: item.to_percent for item in writes}} |
There was a problem hiding this comment.
Keep safety rollbacks valid when retire is nonzero
Once batch-live-stt-retire is above a rollback target, this change lowers only batch-pipeline and first-summary; write_ramp() then rejects the transaction because check_ramp_nesting() requires the retire percentage not to exceed the pipeline percentage. Consequently, an ordinary rollback—and especially a data-loss/privacy rollback to zero—can fail and leave the unsafe rollout active. Coordinate the retire percentage or otherwise preserve the nesting invariant during rollback.
Useful? React with 👍 / 👎.
| except Exception: | ||
| # SDK errors can carry paths and payloads; keep the line content-free. | ||
| logger.warning('event=runtime_percent_read outcome=error served=lkg_or_env_default') |
There was a problem hiding this comment.
Report ramp fallback through shared telemetry
When the Firestore read fails or returns a malformed document, this branch changes serving mode to LKG or environment defaults but only emits a local log and gauges, so the repository-wide fallback telemetry cannot account for the degraded rollout-control path. Record this transition with utils.observability.fallback.record_fallback in addition to the domain metrics.
AGENTS.md reference: backend/AGENTS.md:L314-L314
Useful? React with 👍 / 👎.
| for name in RAMP_NAMES: | ||
| if name in snapshot.percents: | ||
| RUNTIME_PERCENT_VALUE.labels(name=name).set(snapshot.percents[name]) |
There was a problem hiding this comment.
Remove stale percent metrics when an override disappears
If a name was previously present and a later snapshot omits it—for example after deleting the control document to restore environment defaults—this loop neither removes nor updates the existing labeled Gauge child. Prometheus therefore continues exporting the old runtime percentage indefinitely even though serving has switched to the environment default, which can mislead rollout dashboards and rollback verification.
Useful? React with 👍 / 👎.
Keep lane 6's runtime_percent implementation (the stub was handed over per swarm-plan §3). The controller now uses utils.observability.reasons.RampReason. 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: f2d7380af1
ℹ️ 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".
| Decision( | ||
| Action.HOLD, item.name, item.from_percent, item.from_percent, RampReason.UNKNOWN, 'cas_conflict' | ||
| ) |
There was a problem hiding this comment.
Preserve rollback paging after CAS conflicts
When a data-loss or privacy rollback loses the CAS race, this replacement discards the original decision's page=True; because wrote remains false, the notification loop then emits no page. A concurrent revision update can therefore leave the unsafe percentage active until a later tick without alerting the lead; preserve the paging flag or explicitly notify on a failed safety rollback.
Useful? React with 👍 / 👎.
| if entry is not None and entry['locked_by'] is None and entry['percents']: | ||
| return 'percent_write_requires_operator_lock' | ||
| return {'percents': dict(args.percent)}, args.reason or 'unknown' |
There was a problem hiding this comment.
Verify the percent writer owns the operator lock
When a seeded environment is locked by one operator, this check permits a percent write from any other --actor merely because locked_by is non-null. For example, locked_by='lead-a' does not prevent --actor lead-b --percent ... from changing the rollout, defeating the coordination lock; require the lock value to identify the current actor before allowing the write.
Useful? React with 👍 / 👎.
|
|
||
|
|
||
| EXPECTED_TIER = {'prod': 'prod-operator', 'staging': 'dev-operator'} | ||
| DEFAULT_TARGET = {'prod': ('based-hardware', '(default)'), 'staging': ('based-hardware-dev', 'staging')} |
There was a problem hiding this comment.
Point staging readers at the staging database
With the documented default for --env staging, both controller CLIs write _ramp to the named based-hardware-dev/staging database, while serving reads go through get_data_plane_firestore_client(). That client uses the default database and _firestore_database_id() explicitly rejects named database overrides outside the emulator, so a normal staging backend cannot observe the controller's writes and the rehearsal gates an unchanged fleet. Use the same Firestore database target on both the writer and runtime reader.
Useful? React with 👍 / 👎.
| # Runtime percents and legacy_sync (`rollout_cohorts/_ramp`, contract (f)) bind with the cohorts. | ||
| configure_runtime_percent() |
There was a problem hiding this comment.
Warm runtime percents before async admission
This binds the runtime-percent resolver but leaves the existing async warm_rollout_cohorts() hook warming only membership data, while the newly added warm_ramp() has no callers. On an empty process cache, runtime_percent() called on the event loop schedules the Firestore read and immediately returns the environment default; this is especially visible in capture_batch_preview(), which then pins that fallback decision for the whole session. It can also briefly restore the production FIRST_SUMMARY_DEADLINE_PERCENT=100 default after a runtime rollback, so include the ramp read in the pre-admission warm hook.
Useful? React with 👍 / 👎.
…est's 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: 722ab2a349
ℹ️ 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".
| wrote = False | ||
| if writes and apply: | ||
| lead = next((item for item in writes if item.name == LEAD_NAME), writes[0]) | ||
| change = {'percents': {item.name: item.to_percent for item in writes}} |
There was a problem hiding this comment.
Keep first-summary coverage during batch rollback
When an ordinary, data-loss, or privacy failure triggers a rollback, writes contains both controlled names, so this change lowers first-summary together with batch admission. Owners between the old and new percentages then lose the short dispatch/repair/lease policy for existing summary debt unless the separate preserve flag is enabled; backend/docs/listen_pusher_pipeline.mdx:5338-5340 explicitly requires first-summary eligibility to remain enabled during batch rollback. Keep the first-summary percentage unchanged for rollback actions rather than including every rollback decision in this write.
Useful? React with 👍 / 👎.
| if args.apply and not args.train_lock_cmd: | ||
| return 'prod_apply_requires_train_lock_cmd' |
There was a problem hiding this comment.
Reject an empty production train-lock command
For a production --apply run, a whitespace-only --train-lock-cmd passes this raw-string check, but main() later converts it with shlex.split() to an empty list, which train_lock_probe() treats as “not held.” A misconfigured invocation can therefore write production ramp changes without checking the required prod-train coordination lock; validate that the parsed command contains at least one token.
Useful? React with 👍 / 👎.
| gate_verdict={ | ||
| 'status': verdict.status, | ||
| 'reason': verdict.reason, | ||
| 'percent': verdict.percent, | ||
| **dict(verdict.raw), |
There was a problem hiding this comment.
Preserve terminal verdict fields in ramp history
If the gate's aggregate JSON contains a status, reason, or percent key, expanding verdict.raw last silently overwrites the canonical values derived from the terminal gate line and the active cohort. The decision still uses the real GateVerdict, but the durable history row can report a different verdict or percentage, corrupting the audit trail used to investigate a rollout or rollback. Merge aggregate fields first or reject these reserved keys.
Useful? React with 👍 / 👎.
…spatch C1 (lead ruling): a gate that cannot run (ro_prod_unavailable, timeout_incomplete, parity_not_run, ...) holds. After 3 consecutive such ticks (~30 min) the controller pages the lead, then pages again every 3 ticks. The streak lives in the heartbeat file, so it survives a restart; a pause gap resets it. admission.authorize: admission decides funding once (contract (c)). A unit whose admission policy snapshot records provider_reason=byok skips the dispatch-time funded re-check, which runs without the user's keys or BYOK consent and would re-hold a BYOK owner on every lease (David: BYOK routes like everyone). A missing or other policy keeps today's re-check, so this stays behaviour-neutral until E1 writes binding.policy. 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: cbb4b26e6a
ℹ️ 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".
| CONTROLLED_NAMES = ('batch-pipeline', 'first-summary') | ||
| LEAD_NAME = 'batch-pipeline' |
There was a problem hiding this comment.
Feed the runtime percent into batch admission
When the controller advances or rolls back batch-pipeline, the serving admission path never reads that value: config/batch_pipeline.py:26-35 still derives its percentage exclusively from BATCH_PIPELINE_PERCENT, while the new runtime resolver is called only for first-summary and batch-live-stt-retire. Consequently, controller writes can be reported as successful while actual batch admission remains at the deployment's environment percentage, including during a safety rollback; wire runtime_percent('batch-pipeline', ...) into enabled_for().
Useful? React with 👍 / 👎.
| transaction.create( | ||
| ref.collection(RAMP_HISTORY_COLLECTION).document(f'{revision:010d}'), |
There was a problem hiding this comment.
Keep ramp history reseedable after deleting the root document
If _ramp has previously been written and its root document is later deleted to restore environment defaults, Firestore leaves the history subcollection intact. The next seed treats the missing root as revision 0, computes revision 1, and this create() collides with the existing history/0000000001, aborting the whole transaction and preventing the control document from being recreated. Preserve or tombstone the root document, clean the subcollection explicitly, or otherwise choose a noncolliding revision.
Useful? React with 👍 / 👎.
| parser.add_argument('--train-lock-cmd', help='B5 prod-train lock probe: exit 0 free, 1 held') | ||
| parser.add_argument('--state-file', default=STATE_FILE_DEFAULT) | ||
| parser.add_argument('--anx-card', default=ANX_CARD_DEFAULT) | ||
| parser.add_argument('--no-anx', action='store_true', help='Skip anx notes (rehearsal on a host without anx)') |
There was a problem hiding this comment.
Reject disabled notifications for production applies
When the production controller is invoked with --apply --no-anx, validate_args() accepts the combination and main() installs a no-op notifier. Real advances and even data-loss/privacy rollback pages then occur without the lead notification that the controller otherwise emits. Since this option is documented as a rehearsal escape hatch, restrict it to staging or dry-run executions.
Useful? React with 👍 / 👎.
| if args.actor is None or args.actor == CONTROLLER_ACTOR or args.expected_revision is None: | ||
| print('writes need --actor (not ramp-controller) and --expected-revision', file=sys.stderr) | ||
| return 2 |
There was a problem hiding this comment.
Make the documented legacy transitions executable
The canonical transition and rollback commands in backend/docs/runbooks/legacy-dark.md:31-35 invoke ramp_set.py with only --env and --legacy-sync, but this new check rejects both commands because they omit --actor and --expected-revision; even after adding those arguments, the documented commands still omit --apply and therefore only dry-run. An operator following the runbook cannot enter draining/dark or execute the documented one-write rollback to on, so update the procedure to show the revision and supply all required write arguments, or make the CLI workflow match the runbook.
Useful? React with 👍 / 👎.
| if reason == 'parity_not_run': | ||
| return replace(verdict, status='FAIL', reason='parity_not_run') | ||
| token = 'parity_' + reason if reason.startswith('row_') else 'parity_fail' | ||
| return replace(verdict, status='FAIL', reason=token, raw={**verdict.raw, 'prod_shadow': 'FAIL'}) |
There was a problem hiding this comment.
Preserve zero rollback for actual parity loss verdicts
The real parity gate emits reason tokens such as lost_recordings and privacy_violation because scripts/parity/report_schema.py:191-207 returns the failing row's ParityReason; it does not emit row_5 or row_7. This branch therefore converts an actual parity data-loss/privacy failure to the generic parity_fail, which classify_fail() treats as an ordinary one-step rollback rather than ROLLBACK_ZERO. Map the real fixed reason tokens or propagate the report's data_loss field so confirmed loss and privacy failures take the required zero rollback.
Useful? React with 👍 / 👎.
| if is_fail: | ||
| action, reason = classify_fail(verdict.reason) | ||
| if action is None: | ||
| return hold(reason, 'gate_fail_not_a_verdict:' + verdict.reason) |
There was a problem hiding this comment.
Page when the fleet gate cannot produce a verdict
When the fleet gate returns an execution failure such as ro_prod_unavailable, gate_not_run, gate_timeout, or parity_not_run, classify_fail() returns no action and this hold leaves page=False. The notification loop consequently emits nothing even though the controller is blind and cannot determine whether the active cohort is losing data; the unsafe percentage can remain active indefinitely with only local state/log output. Mark these non-verdict failures for paging while continuing to hold.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a49288fa15
ℹ️ 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".
| policy = binding.get('policy') if isinstance(binding, dict) else None # pyright: ignore[reportUnknownMemberType] | ||
| return isinstance(policy, dict) and policy.get('provider_reason') == 'byok' |
There was a problem hiding this comment.
Persist BYOK policy before checking it at dispatch
When dispatch enforcement is enabled for a BYOK admission, this exemption is unreachable in production: jobs serialize ProjectionBinding into projection_binding, but that dataclass has no policy field and neither batch intake path adds one. Consequently admitted_as_byok() always returns false for real jobs, so dispatch calls sync_allowed() without the user's BYOK credentials and can defer the unit indefinitely. Persist the admission-time funding decision in the durable binding or read it from a field that intake actually stores.
Useful? React with 👍 / 👎.
| except Exception as error: # noqa: BLE001 - a failed tick writes nothing; log the class only | ||
| logger.warning('event=ramp_controller_tick outcome=error error=%s', type(error).__name__) |
There was a problem hiding this comment.
Escalate controller tick exceptions
When a Firestore document/history read, non-CAS write, state-file append, or other tick operation raises in loop mode, this catch only writes a local log and silently retries forever. The controller can therefore remain unable to observe or roll back an active unsafe cohort without notifying the lead; emit a page and the shared fallback event before continuing the loop.
AGENTS.md reference: backend/AGENTS.md:L313-L314
Useful? React with 👍 / 👎.
Lane 6 (legacy-sync retirement swarm) M1 slice: contracts (f) and (g).
Runtime percents (f).
rollout_cohorts/_rampholds per-env percents,legacy_syncandlocked_by.utils/rollout/runtime_percent.pyreads it with a single 30s process cache on the rollout executor. It never waits on the event loop.config/rollout_cohorts.py, bound byconfigure_rollout_runtime(). Unbound processes keep their env values.summary_guaranteeandbatch_live_previewnow read their percent through the seam.valid_uidrejects_ramp*._ramp/historyrow. They refuse range, name and nesting violations.omi_runtime_percent_source{source},omi_runtime_percent_read_error_seconds,omi_runtime_percent{name}.Ramp controller (g).
scripts/rollout/ramp_controller.pyis a puredecide()plus a thin runner.legacy_sync=on.locked_byor the prod-train lock is set.lock_clearedwrite.Also included:
ramp_set.py(operator CLI; refuses percent writes while the controller owns the ladder) andinject_gate.py(staging-only rehearsal wrapper).config/batch_pipeline.pyis untouched; it stays frozen until #22362/#22373 reach integration.Verification:
tests/unit/test_runtime_percent.pyandtests/unit/test_ramp_controller.py. These include a hermetic full-ladder rehearsal with real CAS writes on StrictFirestore, both injected rollbacks, the two-rollbacks stop, the acknowledgement, a climb to 100, and a hold at the ceiling.Contract notes for captain sign-off (C1–C8) are in
swarm/status/lane06.md.Follow-ups in this PR:
admission.authorizeskips the dispatch-time funded re-check for units whose admission policy recordsprovider_reason=byok. Withoutbinding.policy(E1), behaviour is unchanged.Product invariants affected
_ramplives in the existingrollout_cohortscollection on the data-plane client already in use. The integrationgcp_*.ymllock lines (feat(deploy): lane 7 slice 1: ops file + config-train (B4), prod-train lock (B5), worker digest promotion, OMI_ROLE map (B8) #22430) arrive by merge only.Failure-Class: none
(The only
fix:commit in range is lane 1's integration fixdb45689b, which re-keys the callback-pending retry after a module move. Lane 6 adds no fix commits.)🤖 Generated with Claude Code