Skip to content

lr/06: runtime _ramp percents and ramp controller (contracts f, g) - #22425

Merged
Git-on-my-level merged 7 commits into
integration/legacy-retirefrom
lr/06-ramp
Oct 19, 2026
Merged

Git-on-my-level merged 7 commits into
integration/legacy-retirefrom
lr/06-ramp

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Lane 6 (legacy-sync retirement swarm) M1 slice: contracts (f) and (g).

Runtime percents (f).

  • rollout_cohorts/_ramp holds per-env percents, legacy_sync and locked_by.
  • utils/rollout/runtime_percent.py reads it with a single 30s process cache on the rollout executor. It never waits on the event loop.
  • On a read error it serves the last-known-good value indefinitely. On a cold start or a missing document it serves the caller's env value. With no document, behaviour is unchanged.
  • Config modules reach it through a stdlib-only seam in config/rollout_cohorts.py, bound by configure_rollout_runtime(). Unbound processes keep their env values.
  • summary_guarantee and batch_live_preview now read their percent through the seam.
  • valid_uid rejects _ramp*.
  • Writes are a CAS transaction that also creates a _ramp/history row. They refuse range, name and nesting violations.
  • New metrics: omi_runtime_percent_source{source}, omi_runtime_percent_read_error_seconds, omi_runtime_percent{name}.

Ramp controller (g). scripts/rollout/ramp_controller.py is a pure decide() plus a thin runner.

  • It writes only the batch-pipeline/first-summary percents, and acts only while legacy_sync=on.
  • It refuses while locked_by or the prod-train lock is set.
  • 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 to decide ROLLBACK_ZERO.
  • It stops after two rollbacks in 24h until a human lock_cleared write.
  • After a sleep or restart gap, the first tick only holds (decision S9: it runs on m5 under the lead's prod-operator tier).
  • It logs every decision to STATE.md and every action to anx.

Also included: ramp_set.py (operator CLI; refuses percent writes while the controller owns the ladder) and inject_gate.py (staging-only rehearsal wrapper).

config/batch_pipeline.py is untouched; it stays frozen until #22362/#22373 reach integration.

Verification:

  • tests/unit/test_runtime_percent.py and tests/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.
  • Neighbouring cohort, summary and live-preview tests pass.
  • pyright (pinned config) reports 0 errors. The lifecycle, flag-registry, import-side-effect and dead-code checks pass.
  • No cloud access was used.

Contract notes for captain sign-off (C1–C8) are in swarm/status/lane06.md.

Follow-ups in this PR:

  • The controller escalates after 3 consecutive gate-unavailable ticks (C1 ruling).
  • admission.authorize skips the dispatch-time funded re-check for units whose admission policy records provider_reason=byok. Without binding.policy (E1), behaviour is unchanged.

Product invariants affected

Failure-Class: none
(The only fix: commit in range is lane 1's integration fix db45689b, which re-keys the callback-pending retry after a module move. Lane 6 adds no fix commits.)

🤖 Generated with Claude Code

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

chatgpt-codex-connector Bot commented Oct 19, 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-19T08:45:23.579844Z a49288f 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.

…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]>

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

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

Comment on lines +125 to +127
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')

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

Comment on lines +231 to +233
for name in RAMP_NAMES:
if name in snapshot.percents:
RUNTIME_PERCENT_VALUE.labels(name=name).set(snapshot.percents[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 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]>

@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: 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".

Comment on lines +555 to +557
Decision(
Action.HOLD, item.name, item.from_percent, item.from_percent, RampReason.UNKNOWN, 'cas_conflict'
)

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

Comment on lines +63 to +65
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'

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 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')}

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

Comment on lines +173 to +174
# Runtime percents and legacy_sync (`rollout_cohorts/_ramp`, contract (f)) bind with the cohorts.
configure_runtime_percent()

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

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

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

Comment on lines +637 to +638
if args.apply and not args.train_lock_cmd:
return 'prod_apply_requires_train_lock_cmd'

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

Comment on lines +531 to +535
gate_verdict={
'status': verdict.status,
'reason': verdict.reason,
'percent': verdict.percent,
**dict(verdict.raw),

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

Git-on-my-level and others added 3 commits October 19, 2026 15:12
…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]>

@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: 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".

Comment on lines +51 to +52
CONTROLLED_NAMES = ('batch-pipeline', 'first-summary')
LEAD_NAME = 'batch-pipeline'

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

Comment on lines +245 to +246
transaction.create(
ref.collection(RAMP_HISTORY_COLLECTION).document(f'{revision:010d}'),

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

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

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

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

Comment on lines +435 to +438
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'})

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

Comment on lines +193 to +196
if is_fail:
action, reason = classify_fail(verdict.reason)
if action is None:
return hold(reason, 'gate_fail_not_a_verdict:' + verdict.reason)

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

@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: 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".

Comment on lines +21 to +22
policy = binding.get('policy') if isinstance(binding, dict) else None # pyright: ignore[reportUnknownMemberType]
return isinstance(policy, dict) and policy.get('provider_reason') == 'byok'

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

Comment on lines +734 to +735
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__)

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

@Git-on-my-level
Git-on-my-level merged commit 023410c into integration/legacy-retire Oct 19, 2026
24 checks passed
@Git-on-my-level
Git-on-my-level deleted the lr/06-ramp branch October 19, 2026 09:01
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