Gateway effective limits + Codex output-token semantics (D-058, #136) #152

Merged
adrian.tkacz merged 5 commits from gateway/effective-limits into develop 2026-09-28 13:23:20 +00:00
Member

Closes #136 (child D of program #132) when merged. Implements the D-056 effective-capability intersection end to end and records its settlement as D-058. (Decision id was originally recorded as D-057; renumbered to D-058 after PR #149 merged D-057 for the reasoning-effort serialization contract — see the rebase note in the comments.)

What changed

  1. Per-route effective ceilings (resource_state.py, gateway_coordinator.py):
    effective = min(known of: model hard, channel ceiling, administrator allowance); UNKNOWN when no capability input is known — an administrator allowance alone never certifies a capability. New channel facts: ExecutionCapabilities.output_limit_tokens and output_limit_control.
  2. Rejection-based, route-specific enforcement: after admission selects the exact target, a new coordinator gate enforces the selected route's effective context/output ceilings (context_length_exceeded / output_limit_exceeded, never clipping). The administrator global pre-check stays authoritative; capability shortfalls remain the routing core's no_eligible_target (routing core untouched, per the frozen complexity boundary).
  3. Codex output-token semantics (worker_codex_adapter.py backstop + coordinator rule): re-evidenced the CURRENT runtime first (2026-09-28, codex-cli 0.155.0-alpha.16.3): the app-server turn contract has no output-token control (stable or experimental — live probes: candidate fields are silently ignored, genuinely gated fields error positively). Consequence per the frozen scope: a requested explicit limit on that channel is normalized away ONLY when non-binding (≥ the model's proven hard_properties.output_tokens, audited output_limit_normalized); a binding request is rejected output_limit_unenforceable; UNKNOWN hard max is never normalized; generation_params stay refuse-not-drop.
  4. Context re-evidence: the current runtime exposes no context-ceiling discovery (model/list has no context members; modelProvider/capabilities/read is feature booleans; today's docs publish no number) and the original M06 citation never contained 272000 — provenance gap documented. The 272000 fact is RETAINED as the owner-reviewed registration fact; client-visible effective context is always the intersection.
  5. Limits visibility / aggregation (the D-056 pt 6 delegated settlement): GET /v1/models advertises the STRONGEST bound route's effective ceiling as the headline (effective_context_limit_tokens, max_output_tokens) plus an additive x_scarcity_router.routes per-route detail array (null when unknown) — never weakest-route constrained, never strongest-only claimed, never UNKNOWN as a number. Supersedes D-055's interim max_output_tokens reading as that decision anticipated. Child H consumes routes.
  6. Honest defaults (gateway_contracts.py): 4 MiB body / 272000 input context / 131072 output / 1200 s execution — evidence-documented in the class docstring and D-058; export honesty verified (non-default only; an explicit legacy 16384 stays explicit).

Tests

New tests/test_effective_limits.py pins the issue's test list at the HTTP boundary: default supported-model accepted; explicit lower administrator ceilings enforced (context + output); large-but-bounded accepted; over-limit rejections unchanged; channel < model → effective enforced and advertised (incl. per-route metadata); non-binding normalization above proven hard max (normalized + audited); binding-below-hard-max rejected closed; UNKNOWN hard max never normalized; body/limit boundaries; export honesty. Child-A output-limit pin (test_representative_client.py) flipped to the new contract; codex adapter pin updated to the typed backstop; security 413 boundary moved to the new default.

Docs

  • docs/decisions.md: D-058 (intersection, enforcement, normalization, aggregation, defaults, alternatives) — after the merged D-057.
  • docs/codex-adapter-stage1-evidence.md: 2026-09-28 re-evidence section (runtime version, probes, findings, provenance note).
  • docs/execution-surface.md: contract rows → Implemented; effective-capability section states the implemented rules.

Gate

Rebased onto develop @ 81b8e63 (PR #149's merge); head 9eec9a8; origin/develop..HEAD is exactly this one commit, no merge commit. Full gate green on the rebased head: make check (full suite, including #149's tests), uv run basedpyright (0 diagnostics), git diff --check clean. One full-suite failure observed during earlier development was the known pre-existing #143 flake (test_scenario_11_client_disconnect_propagates_cancel, cancel-assert race under load): passes in isolation, path untouched by this diff.

UX assessment: material positive — the supported workload's requests (explicit 128k output ceilings, agent-sized conversations, long reasoning turns) now succeed by default; rejections carry actionable typed codes; discovery shows honest per-model and per-route numbers. No removed limits; no unbounded values.

Non-goals honored: nothing removed, no unbounded values, no tool-call work (#137), no admin UI.

Closes #136 (child D of program #132) when merged. Implements the D-056 effective-capability intersection end to end and records its settlement as **D-058**. (Decision id was originally recorded as D-057; renumbered to D-058 after PR #149 merged D-057 for the reasoning-effort serialization contract — see the rebase note in the comments.) ## What changed 1. **Per-route effective ceilings** (`resource_state.py`, `gateway_coordinator.py`): `effective = min(known of: model hard, channel ceiling, administrator allowance)`; UNKNOWN when no capability input is known — an administrator allowance alone never certifies a capability. New channel facts: `ExecutionCapabilities.output_limit_tokens` and `output_limit_control`. 2. **Rejection-based, route-specific enforcement**: after admission selects the exact target, a new coordinator gate enforces the selected route's effective context/output ceilings (`context_length_exceeded` / `output_limit_exceeded`, never clipping). The administrator global pre-check stays authoritative; capability shortfalls remain the routing core's `no_eligible_target` (routing core untouched, per the frozen complexity boundary). 3. **Codex output-token semantics** (`worker_codex_adapter.py` backstop + coordinator rule): re-evidenced the CURRENT runtime first (2026-09-28, `codex-cli 0.155.0-alpha.16.3`): the app-server turn contract has **no** output-token control (stable or experimental — live probes: candidate fields are silently ignored, genuinely gated fields error positively). Consequence per the frozen scope: a requested explicit limit on that channel is normalized away ONLY when non-binding (≥ the model's proven `hard_properties.output_tokens`, audited `output_limit_normalized`); a binding request is rejected `output_limit_unenforceable`; UNKNOWN hard max is never normalized; `generation_params` stay refuse-not-drop. 4. **Context re-evidence**: the current runtime exposes no context-ceiling discovery (`model/list` has no context members; `modelProvider/capabilities/read` is feature booleans; today's docs publish no number) and the original M06 citation never contained 272000 — provenance gap documented. The 272000 fact is RETAINED as the owner-reviewed registration fact; client-visible effective context is always the intersection. 5. **Limits visibility / aggregation** (the D-056 pt 6 delegated settlement): `GET /v1/models` advertises the STRONGEST bound route's effective ceiling as the headline (`effective_context_limit_tokens`, `max_output_tokens`) plus an additive `x_scarcity_router.routes` per-route detail array (`null` when unknown) — never weakest-route constrained, never strongest-only claimed, never UNKNOWN as a number. Supersedes D-055's interim `max_output_tokens` reading as that decision anticipated. Child H consumes `routes`. 6. **Honest defaults** (`gateway_contracts.py`): 4 MiB body / 272000 input context / 131072 output / 1200 s execution — evidence-documented in the class docstring and D-058; export honesty verified (non-default only; an explicit legacy `16384` stays explicit). ## Tests New `tests/test_effective_limits.py` pins the issue's test list at the HTTP boundary: default supported-model accepted; explicit lower administrator ceilings enforced (context + output); large-but-bounded accepted; over-limit rejections unchanged; channel < model → effective enforced and advertised (incl. per-route metadata); non-binding normalization above proven hard max (normalized + audited); binding-below-hard-max rejected closed; UNKNOWN hard max never normalized; body/limit boundaries; export honesty. Child-A output-limit pin (`test_representative_client.py`) flipped to the new contract; codex adapter pin updated to the typed backstop; security 413 boundary moved to the new default. ## Docs - `docs/decisions.md`: **D-058** (intersection, enforcement, normalization, aggregation, defaults, alternatives) — after the merged D-057. - `docs/codex-adapter-stage1-evidence.md`: 2026-09-28 re-evidence section (runtime version, probes, findings, provenance note). - `docs/execution-surface.md`: contract rows → Implemented; effective-capability section states the implemented rules. ## Gate Rebased onto `develop` @ `81b8e63` (PR #149's merge); head `9eec9a8`; `origin/develop..HEAD` is exactly this one commit, no merge commit. Full gate green on the rebased head: `make check` (full suite, including #149's tests), `uv run basedpyright` (0 diagnostics), `git diff --check` clean. One full-suite failure observed during earlier development was the **known pre-existing #143 flake** (`test_scenario_11_client_disconnect_propagates_cancel`, cancel-assert race under load): passes in isolation, path untouched by this diff. UX assessment: material positive — the supported workload's requests (explicit 128k output ceilings, agent-sized conversations, long reasoning turns) now succeed by default; rejections carry actionable typed codes; discovery shows honest per-model and per-route numbers. No removed limits; no unbounded values. Non-goals honored: nothing removed, no unbounded values, no tool-call work (#137), no admin UI.
feat: gateway effective limits + Codex output-token semantics (D-057, #136)
All checks were successful
ci / check (pull_request) Successful in 7m49s
cdf4ac6aab
Implement the D-056 effective-capability intersection end to end and fix
the product problem where an invisible generic ceiling sat below evidenced
capability:

- Per-route effective ceilings: effective = min(known of: model hard,
  channel ceiling, administrator allowance); UNKNOWN when no capability
  input is known (admin alone never certifies). New ExecutionCapabilities
  facts: output_limit_tokens, output_limit_control.
- Route-specific, rejection-based enforcement after admission (typed
  context_length_exceeded / output_limit_exceeded); the administrator
  global pre-check stays authoritative; capability shortfalls remain the
  routing core's no_eligible_target.
- Codex output rule (channel without output-limit control, re-evidenced
  2026-09-28): a requested limit is normalized away only when non-binding
  (>= proven hard max, audited output_limit_normalized); binding requests
  are rejected output_limit_unenforceable; UNKNOWN hard max is never
  normalized; generation_params stay refuse-not-drop. The adapter
  preflight keeps the typed backstop.
- Model-level aggregation: GET /v1/models advertises the strongest bound
  route's effective ceiling as the headline plus a new x_scarcity_router
  .routes per-route detail array (null when unknown) - never weakest-
  route constrained, never strongest-only claimed, never UNKNOWN as a
  number. Supersedes D-055's interim max_output_tokens reading.
- Honest defaults: 4 MiB body / 272000 input context / 131072 output /
  1200 s execution, evidence-documented; non-default limits remain the
  only exported configuration.
- Context re-evidence recorded honestly: 272000 retained as the owner-
  reviewed registration fact, provenance gap documented, runtime exposes
  no context discovery.
- Docs: D-057 decision record; codex evidence re-evidence section;
  execution-surface contract rows + effective-capability section.
- Child-A output-limit pin flipped to the new contract; new
  tests/test_effective_limits.py pins the full #136 test list at the
  HTTP boundary.

Full gate green (make check + basedpyright + git diff --check); the one
full-suite failure observed was the known pre-existing #143 flake
(passing in isolation, path untouched by this diff).
Author
Member

Independent review round (bounded review lifecycle; reviewed head frozen at cdf4ac6):

VERDICT: APPROVED — no MERGE_BLOCKER findings. Reviewer model: GLM-5.3-Flash (independent session). Full gate re-verified green on the frozen head (2115 tests, basedpyright 0 diagnostics, git diff --check clean, origin/develop..HEAD = exactly the one scoped commit).

UX impact: assessed, no unnecessary friction — new deployments admit the supported workload out of the box; in-limit requests unchanged; two intentional typed-error surface changes (binding limit on a no-control channel → 400 output_limit_unenforceable; above-calibrated-output → 503 no_eligible_target), both test-pinned; upgrade is safe (no limits block → larger documented defaults; an explicit legacy 16384 stays enforced and exported).

DEFER findings (recorded for the owner; none block merge):

  1. Routing does not steer on the new channel output facts (routing core untouched by design; D-057 "Alternatives considered" records the deferral). An unpinned logical request with an explicit output limit may be routed to a route that then rejects with a typed 400 even though another bound route could execute it; the strongest-route headline is executable via that route or via sr-pin:. Fail-closed and honest; child H / a future routing-core change should own route-steering.
  2. _model_hard_limits takes the min across all calibrated variants of the identity rather than the exact selected variant's entry, so the normalization threshold uses the weakest variant's proven maximum — conservative direction only (can over-reject, never over-permit); fixture and real catalogs carry uniform hard properties across variants today. A tighter reading of "the exact selected model" would use the selected variant's entry.
  3. The output_limit_normalized audit note rides only the RESULT_COMPLETED record; if a normalized request subsequently fails/cancels/times out, that attempt's record does not carry the note. Minor audit-fidelity gap on a path the D-057 rule does not pin.

Non-findings confirmed by the reviewer: gateway_openai.py/gateway_server.py touches are required by scope item 5 and additive; the untracked litellm/ directory in the local worktree is unrelated to this commit and is not part of the PR.

Per the bounded lifecycle: no blockers → no remediation round; final verification = the gate above; the PR stays open at the human merge gate.

Independent review round (bounded review lifecycle; reviewed head frozen at `cdf4ac6`): **VERDICT: APPROVED** — no MERGE_BLOCKER findings. Reviewer model: GLM-5.3-Flash (independent session). Full gate re-verified green on the frozen head (2115 tests, basedpyright 0 diagnostics, `git diff --check` clean, `origin/develop..HEAD` = exactly the one scoped commit). **UX impact: assessed, no unnecessary friction** — new deployments admit the supported workload out of the box; in-limit requests unchanged; two intentional typed-error surface changes (binding limit on a no-control channel → 400 `output_limit_unenforceable`; above-calibrated-output → 503 `no_eligible_target`), both test-pinned; upgrade is safe (no limits block → larger documented defaults; an explicit legacy `16384` stays enforced and exported). **DEFER findings (recorded for the owner; none block merge):** 1. **Routing does not steer on the new channel output facts** (routing core untouched by design; D-057 "Alternatives considered" records the deferral). An unpinned logical request with an explicit output limit may be routed to a route that then rejects with a typed 400 even though another bound route could execute it; the strongest-route headline is executable via that route or via `sr-pin:`. Fail-closed and honest; child H / a future routing-core change should own route-steering. 2. **`_model_hard_limits` takes the min across all calibrated variants of the identity** rather than the exact selected variant's entry, so the normalization threshold uses the weakest variant's proven maximum — conservative direction only (can over-reject, never over-permit); fixture and real catalogs carry uniform hard properties across variants today. A tighter reading of "the exact selected model" would use the selected variant's entry. 3. **The `output_limit_normalized` audit note rides only the RESULT_COMPLETED record**; if a normalized request subsequently fails/cancels/times out, that attempt's record does not carry the note. Minor audit-fidelity gap on a path the D-057 rule does not pin. Non-findings confirmed by the reviewer: `gateway_openai.py`/`gateway_server.py` touches are required by scope item 5 and additive; the untracked `litellm/` directory in the local worktree is unrelated to this commit and is not part of the PR. Per the bounded lifecycle: no blockers → no remediation round; final verification = the gate above; the PR stays open at the human merge gate.
adrian.tkacz force-pushed gateway/effective-limits from cdf4ac6aab
All checks were successful
ci / check (pull_request) Successful in 7m49s
to 9eec9a8601
All checks were successful
ci / check (pull_request) Successful in 7m53s
2026-09-28 07:54:12 +00:00
Compare
kilo changed title from Gateway effective limits + Codex output-token semantics (D-057, #136) to Gateway effective limits + Codex output-token semantics (D-058, #136) 2026-09-28 07:54:55 +00:00
Author
Member

Rebase + decision renumber (owner-requested conflict fix).

PR #149 (reasoning-effort serialization, #148) merged its own D-057 to develop while this branch was in flight, so this PR's decision collided with it. Resolution, per the repository's no-sync-merge rule:

  • The in-progress git merge origin/develop was aborted (no synchronization merge commit enters this PR) and the single commit was rebased onto develop @ 81b8e63 with --force-with-lease.
  • Conflict: exactly one hunk — the tail of docs/decisions.md, where both branches appended their "D-057". Resolved by keeping the merged D-057 verbatim and renumbering this PR's decision to D-058.
  • All references adjusted: the decision record heading, docs/execution-surface.md (4), docs/codex-adapter-stage1-evidence.md (1), gateway_openai.py (2), gateway_contracts.py (1), gateway_coordinator.py (4), tests/test_effective_limits.py (2). The D-057 references in selector.py, docs/machine-interfaces.md, docs/selection-policy.md, docs/architecture.md and their tests belong to the merged #148 contract and were left untouched.
  • New reviewed head: 9eec9a8 (content identical to the reviewed cdf4ac6 except the rebase, the renumbering and the commit message). Full gate re-run green on the new head: make check (full suite incl. #149's tests), basedpyright 0 diagnostics, git diff --check clean; origin/develop..HEAD is exactly the one scoped commit, no merge commit. The earlier APPROVED review verdict and its three DEFERs carry over — the rebase introduced no logic changes.
**Rebase + decision renumber (owner-requested conflict fix).** PR #149 (reasoning-effort serialization, #148) merged its own **D-057** to `develop` while this branch was in flight, so this PR's decision collided with it. Resolution, per the repository's no-sync-merge rule: - The in-progress `git merge origin/develop` was aborted (no synchronization merge commit enters this PR) and the single commit was **rebased** onto `develop` @ `81b8e63` with `--force-with-lease`. - Conflict: exactly one hunk — the tail of `docs/decisions.md`, where both branches appended their "D-057". Resolved by keeping the merged D-057 verbatim and renumbering this PR's decision to **D-058**. - **All references adjusted**: the decision record heading, `docs/execution-surface.md` (4), `docs/codex-adapter-stage1-evidence.md` (1), `gateway_openai.py` (2), `gateway_contracts.py` (1), `gateway_coordinator.py` (4), `tests/test_effective_limits.py` (2). The D-057 references in `selector.py`, `docs/machine-interfaces.md`, `docs/selection-policy.md`, `docs/architecture.md` and their tests belong to the merged #148 contract and were left untouched. - New reviewed head: **`9eec9a8`** (content identical to the reviewed `cdf4ac6` except the rebase, the renumbering and the commit message). Full gate re-run green on the new head: `make check` (full suite incl. #149's tests), `basedpyright` 0 diagnostics, `git diff --check` clean; `origin/develop..HEAD` is exactly the one scoped commit, no merge commit. The earlier APPROVED review verdict and its three DEFERs carry over — the rebase introduced no logic changes.
fix: remediate the four exact-head review findings on #152 (D-058, #136)
All checks were successful
ci / check (pull_request) Successful in 7m57s
bc96c10788
Remediation of the independent exact-head review of PR #152; content
identical to the reviewed commit except the changes below. D-057 (merged
via PR #149) is untouched; D-058 is unchanged in number (no newer
develop decision existed).

Blocker 1 - output capability gates routes BEFORE ranking (correctness,
not optimization): the routing core's compatibility stage applies the
shared output rule per candidate, so a route whose evidenced output
capability cannot satisfy the request is ineligible before competitive
ranking (output_limit_unknown / _insufficient / _unenforceable, closed
additive reason codes); a request never routes to a weaker route when
another route serves the exact same identity. Pins evaluate exactly and
reject with mapped typed 400s. The administrator pre-check stays
authoritative and is deliberately not a ranking input (uniform across
routes).

Finding 3 - exact-variant hard properties: the rule consumes the EXACT
calibrated (provider, model, variant) entry's hard output (never a
sibling variant's calibration, never a minimum across variants);
profile-alias requests resolve the variant later and cannot claim the
non-binding normalization on control=False channels; discovery computes
each route's detail per exact bound variant (weakest reported so the
detail never over-advertises).

Blocker 2 - administrator policy separated from channel capability:
GatewayLimits defaults are bounded operational guards, not a channel's
registration fact - body 16 MiB (headroom above the largest evidenced
context, tokenization-independent), input 2^21 tokens (one binary order
above the strongest evidenced 1.05M catalog context), output 131072,
1200 s. The 272000 Codex fact stays a per-route channel capability; a
>272k request executes on an evidenced stronger route and stays
ineligible on the 272k channel; an explicit admin 272000 narrows all
routes. The 413 drain window follows the configured body bound so
rejections return a clean response.

Finding 4 - normalization provenance survives failure: the
output_limit_normalized note is appended to EVERY terminal audit record
written after normalization (completed, failed, failed-ambiguous, timed
out, cancelled, unexpected) and never to pre-normalization rejections;
it never replaces the primary failure reason.

Single source of truth: route_output_code() in resource_state.py is the
one reusable output rule, applied pre-ranking and post-admission alike.
D-058 + execution-surface docs reconciled (no 'deferred optimization',
no '272k as gateway default', no min-across-variants language).

New regressions: OutputSteeringTests (weak-preferred steering,
weak-only, pin-weak, pin-strong, UNKNOWN fail-closed), ExactVariantTests
(per-variant hard properties, discovery detail, exact-variant
normalization threshold), DefaultCapabilityTests (>272k executes on the
strong route / ineligible on the 272k channel / explicit admin
narrowing), NormalizationProvenanceTests (completed/failed/ambiguous/
timeout/cancelled carry the note; binding rejection carries none).

Gate on this head: 2144 tests OK, basedpyright 0 diagnostics,
git diff --check clean, guardrails 42 OK.
fix: map output-capability no-solution decisions to typed 400s (review blocker)
All checks were successful
ci / check (pull_request) Successful in 8m2s
35cc72b2dc
Remediation of the fresh exact-head review's MERGE_BLOCKER: with the
shipped output_limit_control=false Codex surface, an unpinned request
with an explicit binding sub-maximum output limit (e.g. 64000 of an
advertised 128000) is excluded at every route pre-ranking and surfaced
as a generic retry-suggesting 503 no_eligible_target - contradicting
the advertised headline contract added by this same branch.

Now _no_eligible_target_error inspects the decision's target
exclusions: when routes were excluded on the OUTPUT dimension, the
client gets the actionable typed 400 (priority insufficient >
unenforceable > unknown, matching the pinned path) - the limit itself
is the problem (omit it, raise it to the proven maximum, or lower it).
Any other exclusion shape keeps the honest 503.

Also: the D-058 point-4 and execution-surface headline wording now
states the no-control boundary explicitly; the exposed_logical_models
'Unreachable' comment is replaced with the true documented corner-case
rationale (review DEFER); regressions pin the unpinned typed mapping
(binding 64000 -> 400 output_limit_unenforceable; non-binding 128000
normalizes and executes; omitting the limit executes); the
weak-only-world and representative 128001 pins move from 503 to their
typed 400s.

Gate on this head: 2147 tests OK, basedpyright 0 diagnostics,
git diff --check clean, guardrails 42 OK.
Author
Member

Fresh independent exact-head review (reviewed head bc96c10 vs develop 81b8e63) — VERDICT: CHANGES_REQUESTED

Reviewer: GLM-5.3-Flash (independent session). The prior APPROVED was treated as invalid (head/base had changed). The reviewer verified all four earlier remediations against the code (pre-ranking output eligibility incl. the weak/strong steering scenario, exact-variant hard properties, defaults-vs-channel-capability separation, audit provenance across all six terminal states, D-057 untouched, D-056 exact-execution invariants, all gates green) and raised:

  • MERGE_BLOCKER — advertised headline vs unpinned error path: on the shipped output_limit_control: false Codex surface, an unpinned request with an explicit binding sub-maximum limit (e.g. max_completion_tokens: 64000 of an advertised 128000) is excluded at every route pre-ranking and surfaced as generic 503 no_eligible_target — contradicting this branch's own D-058 point 4 / execution-surface claims, and non-actionable (503 suggests transient).
  • DEFER — exposed_logical_models could hide a bound routable model in a mixed reviewed/floor-variant corner case, and its "Unreachable" comment gave wrong reasoning.

Remediation (head 35cc72b, per the bounded single-remediation lifecycle)

  • Blocker: _no_eligible_target_error now inspects the decision's target exclusions — when routes were excluded on the OUTPUT dimension, the client gets the actionable typed 400 (priority output_limit_insufficient > output_limit_unenforceable > output_limit_unknown, matching the pinned path); any other exclusion shape keeps the honest 503. The headline wording in D-058 pt 4 and execution-surface now states the no-control boundary explicitly (an explicit binding sub-max limit on such channels finds no eligible route; omit the limit or request at/above the maximum).
  • DEFER: the corner-case comment is replaced with the true, documented rationale (model stays unadvertised rather than guessed when no bound route evidences an output for its bound variants).
  • Regressions: unpinned binding 64000 on the no-control world → 400 output_limit_unenforceable (not 503); unpinned non-binding 128000 normalizes and executes with the audit note; omitting the limit executes; the weak-only-world and representative 128001 pins moved from 503 to their typed 400s.

Narrow final verification (blocker + obvious regressions only, per the lifecycle)

Full suite 2147 tests OK (the #143 flake did not fire), basedpyright 0 diagnostics, git diff --check clean, guardrails 42 OK. origin/develop..HEAD = exactly three scoped commits, no merge commit; D-057 untouched; D-058 unchanged in number.

Status: READY_FOR_REVIEW — PR open, unmerged, at the human gate. The reviewer's DEFER is resolved in the same commit; per the bounded budget no second full review was run after this contained remediation — the human gate holds the full record (verdict + remediation + verification) and decides.

## Fresh independent exact-head review (reviewed head `bc96c10` vs develop `81b8e63`) — VERDICT: CHANGES_REQUESTED Reviewer: GLM-5.3-Flash (independent session). The prior APPROVED was treated as invalid (head/base had changed). The reviewer verified all four earlier remediations against the code (pre-ranking output eligibility incl. the weak/strong steering scenario, exact-variant hard properties, defaults-vs-channel-capability separation, audit provenance across all six terminal states, D-057 untouched, D-056 exact-execution invariants, all gates green) and raised: - **MERGE_BLOCKER — advertised headline vs unpinned error path:** on the shipped `output_limit_control: false` Codex surface, an unpinned request with an explicit binding sub-maximum limit (e.g. `max_completion_tokens: 64000` of an advertised 128000) is excluded at every route pre-ranking and surfaced as generic `503 no_eligible_target` — contradicting this branch's own D-058 point 4 / execution-surface claims, and non-actionable (503 suggests transient). - **DEFER —** `exposed_logical_models` could hide a bound routable model in a mixed reviewed/floor-variant corner case, and its "Unreachable" comment gave wrong reasoning. ## Remediation (head `35cc72b`, per the bounded single-remediation lifecycle) - **Blocker:** `_no_eligible_target_error` now inspects the decision's target exclusions — when routes were excluded on the OUTPUT dimension, the client gets the actionable typed 400 (priority `output_limit_insufficient` > `output_limit_unenforceable` > `output_limit_unknown`, matching the pinned path); any other exclusion shape keeps the honest 503. The headline wording in D-058 pt 4 and execution-surface now states the no-control boundary explicitly (an explicit binding sub-max limit on such channels finds no eligible route; omit the limit or request at/above the maximum). - **DEFER:** the corner-case comment is replaced with the true, documented rationale (model stays unadvertised rather than guessed when no bound route evidences an output for its bound variants). - **Regressions:** unpinned binding 64000 on the no-control world → 400 `output_limit_unenforceable` (not 503); unpinned non-binding 128000 normalizes and executes with the audit note; omitting the limit executes; the weak-only-world and representative 128001 pins moved from 503 to their typed 400s. ## Narrow final verification (blocker + obvious regressions only, per the lifecycle) Full suite **2147 tests OK** (the #143 flake did not fire), `basedpyright` **0 diagnostics**, `git diff --check` clean, guardrails **42 OK**. `origin/develop..HEAD` = exactly three scoped commits, no merge commit; D-057 untouched; D-058 unchanged in number. **Status: READY_FOR_REVIEW — PR open, unmerged, at the human gate.** The reviewer's DEFER is resolved in the same commit; per the bounded budget no second full review was run after this contained remediation — the human gate holds the full record (verdict + remediation + verification) and decides.
Two contained merge blockers from the PR #152 head review.

1. control_api._registration_copy() hand-copied ExecutionCapabilities
   field-by-field and silently dropped the new output_limit_tokens /
   output_limit_control facts on every administrator mutation that
   rebuilds the resource record (enable/disable via _with_enabled,
   provider removal / endpoint detachment via _with_endpoint). The copy
   now uses the validated serializer round-trip
   (ExecutionCapabilities.from_dict(capabilities.to_dict())) - resistant
   to the next additive capability field by construction; this was the
   only field-by-field capability copy site in the package (all other
   paths already use from_dict). Regressions: disable -> re-enable,
   provider removal, and the persisted/exported configuration document
   all preserve the facts.

2. _no_eligible_target_error() returned a typed output 400 whenever ANY
   target exclusion carried an output code; its own contract reserves
   the mapping for decisions caused PURELY by the output dimension. Now
   every exclusion must be output-code-only (non-empty) for the 400;
   any earlier-stage or different-feature exclusion (availability,
   authorization, binding, another compatibility feature) keeps the
   ordinary 503 no_eligible_target, because the request could succeed
   unchanged once that other cause clears. Regression: available 32k
   route (output-insufficient) + never-observed 128k route, request 64k
   -> 503; after the strong route recovers the same request executes
   there unchanged. The intended pure cases remain pinned (single
   insufficient route, codex-only control=False binding sub-max, all-
   unknown capability).

Gate on this head: 2149 tests OK, basedpyright 0 diagnostics,
git diff --check clean, guardrails 42 OK. develop unchanged at 81b8e63;
D-058 remains the decision number.
Author
Member

Review round 2 (head 35cc72b vs develop 81b8e63) — REQUEST_CHANGES (2 contained blockers) → remediated in f1f191b → fresh narrow verification: both VERIFIED

Blocker 1 — D-058 capability facts erased by administrator mutations. control_api._registration_copy() hand-copied ExecutionCapabilities field-by-field and dropped output_limit_tokens / output_limit_control on every mutation that rebuilds the resource record (enable/disable via _with_enabled, provider removal / endpoint detachment via _with_endpoint). Fix: the copy now uses the validated serializer round-trip ExecutionCapabilities.from_dict(capabilities.to_dict()) — resistant to the next additive capability field by construction. A repo-wide audit found this was the ONLY field-by-field capability copy site (all other paths already use from_dict). Regressions (test_d058_capability_facts_survive_admin_mutations): disable → re-enable preserves the facts; provider removal (endpoint detached) preserves them; the persisted/exported configuration document is value-equivalent.

Blocker 2 — mixed-cause no-target misclassification. _no_eligible_target_error returned a typed output 400 whenever ANY exclusion carried an output code; its contract reserves the mapping for decisions caused PURELY by output semantics. Fix: the 400 now requires a non-empty exclusion set where EVERY exclusion's reason codes are purely output codes; any availability/authorization/binding/other-feature exclusion keeps the ordinary 503 no_eligible_target (the request could succeed unchanged once that cause clears). Regression (test_mixed_output_and_availability_stays_503): available 32k route (output-insufficient) + never-observed 128k route, request 64k → 503 with zero dispatches; after the strong route recovers, the same request executes there unchanged. The intended pure cases remain pinned: single insufficient route → 400 output_limit_insufficient; Codex-only control=False binding sub-max → 400 output_limit_unenforceable; all-UNKNOWN → 400 output_limit_unknown.

Fresh narrow verification (independent GLM-5.3-Flash session)

Base re-verified unmoved at 81b8e63. Scope: exactly 35cc72b..f1f191b (4 files). Fix 1 VERIFIED (copy path, no other hand-rolled copy, regression exercises both mutation paths through _registration_copy and would fail pre-fix, export equivalence). Fix 2 VERIFIED (pure-cause logic incl. priority order, all three intended 400 scenarios and the mixed 503 scenario classified as specified, regression includes the recovery half and fails on the pre-fix base). No findings. basedpyright 0 diagnostics, git diff --check clean, targeted suites 77 OK; full suite on this exact head: 2149 tests OK (the #143 flake did not fire); guardrails 42 OK.

Status: READY_FOR_REVIEW — PR #152 open, unmerged, at the human gate. D-058 unchanged (develop did not move); D-057 untouched; #137 not started.

## Review round 2 (head `35cc72b` vs develop `81b8e63`) — REQUEST_CHANGES (2 contained blockers) → remediated in `f1f191b` → fresh narrow verification: both VERIFIED **Blocker 1 — D-058 capability facts erased by administrator mutations.** `control_api._registration_copy()` hand-copied `ExecutionCapabilities` field-by-field and dropped `output_limit_tokens` / `output_limit_control` on every mutation that rebuilds the resource record (enable/disable via `_with_enabled`, provider removal / endpoint detachment via `_with_endpoint`). **Fix:** the copy now uses the validated serializer round-trip `ExecutionCapabilities.from_dict(capabilities.to_dict())` — resistant to the next additive capability field by construction. A repo-wide audit found this was the ONLY field-by-field capability copy site (all other paths already use `from_dict`). Regressions (`test_d058_capability_facts_survive_admin_mutations`): disable → re-enable preserves the facts; provider removal (endpoint detached) preserves them; the persisted/exported configuration document is value-equivalent. **Blocker 2 — mixed-cause no-target misclassification.** `_no_eligible_target_error` returned a typed output 400 whenever ANY exclusion carried an output code; its contract reserves the mapping for decisions caused PURELY by output semantics. **Fix:** the 400 now requires a non-empty exclusion set where EVERY exclusion's reason codes are purely output codes; any availability/authorization/binding/other-feature exclusion keeps the ordinary `503 no_eligible_target` (the request could succeed unchanged once that cause clears). Regression (`test_mixed_output_and_availability_stays_503`): available 32k route (output-insufficient) + never-observed 128k route, request 64k → 503 with zero dispatches; after the strong route recovers, the same request executes there unchanged. The intended pure cases remain pinned: single insufficient route → 400 `output_limit_insufficient`; Codex-only `control=False` binding sub-max → 400 `output_limit_unenforceable`; all-UNKNOWN → 400 `output_limit_unknown`. ## Fresh narrow verification (independent GLM-5.3-Flash session) Base re-verified unmoved at `81b8e63`. Scope: exactly `35cc72b..f1f191b` (4 files). **Fix 1 VERIFIED** (copy path, no other hand-rolled copy, regression exercises both mutation paths through `_registration_copy` and would fail pre-fix, export equivalence). **Fix 2 VERIFIED** (pure-cause logic incl. priority order, all three intended 400 scenarios and the mixed 503 scenario classified as specified, regression includes the recovery half and fails on the pre-fix base). No findings. `basedpyright` 0 diagnostics, `git diff --check` clean, targeted suites 77 OK; full suite on this exact head: **2149 tests OK** (the #143 flake did not fire); guardrails 42 OK. **Status: READY_FOR_REVIEW — PR #152 open, unmerged, at the human gate.** D-058 unchanged (develop did not move); D-057 untouched; #137 not started.
adrian.tkacz force-pushed gateway/effective-limits from f1f191b45e
All checks were successful
ci / check (pull_request) Successful in 8m7s
to e2f1624c66
All checks were successful
ci / check (pull_request) Successful in 8m4s
2026-09-28 12:21:33 +00:00
Compare
Author
Member

Rebase onto the advanced merge gate — develop e25de16 (merged PR #153) — fresh exact-head integration review: APPROVED

PR #152's branch was rebased onto the new canonical develop (reset-aware quota state + Z.ai reset plausibility, #153/#151). No merge commit; no new PR; conflicts resolved semantically.

Conflicts encountered: none textual — the rebase auto-merged because the two PRs occupy disjoint axes of the overlapping files. The reviewer then verified the merge is semantically sound, not just textual:

  • 422b04d..e2f1624 on scarcity_router/resource_state.py is purely additive (0 deletions): #153's reset-aware freshness (_window_reset_instants, _reset_crossed, classify_freshness, refresh_due) is byte-identical at HEAD, and D-058's capability axis (output_limit_tokens/output_limit_control, route_output_code, OUTPUT_LIMIT_*) is intact — exactly one definition of each symbol, no dropped or duplicated hunks.
  • No leakage either direction: reset-crossing logic reads only quota_facts window instants and sets freshness/refresh-due; route_output_code takes only capability/variant/request facts; gate ordering (binding → authorization → availability → compatibility) is untouched except for argument threading, so a route made stale across a quota-window reset still fails at the availability stage with its registration-owned capabilities untouched, and the output-eligibility check is never consulted for it.
  • docs/codex-adapter-stage1-evidence.md: both the #150 Revalidation block and the #136 2026-09-28 re-evidence section coexist, non-contradictory.
  • control_api._registration_copy still uses the additive-safe serializer round-trip and preserves every field (checked post-rebase; #153 added no capability fields).
  • D-058 verified still correct: docs/decisions.md at base e25de16 ends at D-057; #153's merge added no decision record; exactly one ### D-058 heading at HEAD.

Gates on the frozen HEAD e2f1624: full suite 2173 tests OK (now including #153's test_resource_state/test_zai_parser suites alongside all D-058 suites; the #143 flake did not fire), basedpyright 0 diagnostics, git diff --check clean, guardrails 42 OK.

Integration review verdict (independent GLM-5.3-Flash session): APPROVED — "the textual clean rebase is also semantically sound… integration approved." One DEFER (non-blocking, left for the human gate): D-058's provenance line could optionally note the #153 in-flight merge and this rebase; the two decisions are provably orthogonal (capability facts vs freshness semantics, zero shared state).

Status: READY_FOR_REVIEW — PR #152 open, unmerged, at the human gate. D-058 unchanged; D-057 untouched; #137 not started.

## Rebase onto the advanced merge gate — develop `e25de16` (merged PR #153) — fresh exact-head integration review: APPROVED PR #152's branch was rebased onto the new canonical develop (reset-aware quota state + Z.ai reset plausibility, #153/#151). No merge commit; no new PR; conflicts resolved semantically. **Conflicts encountered:** none textual — the rebase auto-merged because the two PRs occupy disjoint axes of the overlapping files. The reviewer then verified the merge is *semantically* sound, not just textual: - `422b04d..e2f1624` on `scarcity_router/resource_state.py` is **purely additive (0 deletions)**: #153's reset-aware freshness (`_window_reset_instants`, `_reset_crossed`, `classify_freshness`, `refresh_due`) is byte-identical at HEAD, and D-058's capability axis (`output_limit_tokens`/`output_limit_control`, `route_output_code`, `OUTPUT_LIMIT_*`) is intact — exactly one definition of each symbol, no dropped or duplicated hunks. - **No leakage either direction:** reset-crossing logic reads only `quota_facts` window instants and sets freshness/refresh-due; `route_output_code` takes only capability/variant/request facts; gate ordering (binding → authorization → availability → compatibility) is untouched except for argument threading, so a route made stale across a quota-window reset still fails at the availability stage with its registration-owned capabilities untouched, and the output-eligibility check is never consulted for it. - `docs/codex-adapter-stage1-evidence.md`: both the #150 Revalidation block and the #136 2026-09-28 re-evidence section coexist, non-contradictory. - **`control_api._registration_copy` still uses the additive-safe serializer round-trip** and preserves every field (checked post-rebase; #153 added no capability fields). - **D-058 verified still correct:** `docs/decisions.md` at base `e25de16` ends at D-057; #153's merge added no decision record; exactly one `### D-058` heading at HEAD. **Gates on the frozen HEAD `e2f1624`:** full suite **2173 tests OK** (now including #153's `test_resource_state`/`test_zai_parser` suites alongside all D-058 suites; the #143 flake did not fire), `basedpyright` **0 diagnostics**, `git diff --check` clean, guardrails **42 OK**. **Integration review verdict (independent GLM-5.3-Flash session): APPROVED** — "the textual clean rebase is also semantically sound… integration approved." One **DEFER** (non-blocking, left for the human gate): D-058's provenance line could optionally note the #153 in-flight merge and this rebase; the two decisions are provably orthogonal (capability facts vs freshness semantics, zero shared state). **Status: READY_FOR_REVIEW — PR #152 open, unmerged, at the human gate.** D-058 unchanged; D-057 untouched; #137 not started.
adrian.tkacz force-pushed gateway/effective-limits from e2f1624c66
All checks were successful
ci / check (pull_request) Successful in 8m4s
to fb5da15171
All checks were successful
ci / check (pull_request) Successful in 7m59s
2026-09-28 13:00:13 +00:00
Compare
Author
Member

Rebase onto develop 781bace (merged PR #155 / D-059) — fresh exact-head integration review (D-058 × D-059): APPROVED

The branch was rebased onto the advanced gate; no merge commit, no new issue/PR.

Conflicts and resolution: exactly one file conflicted — docs/decisions.md (both sides append at the tail). Resolved semantically, ledger order now D-057 → D-058 → D-059 with D-058 and D-059 both verbatim and unrenumbered (D-058 reserved for #152 as instructed; the merged D-059 untouched). A range-diff proves the approved PR #152 patch series survived byte-identically outside docs/decisions.md.

Semantic integration (verified by the independent reviewer with file:line evidence, not assumed from the auto-merge):

  1. D-058 capability filtering remains authoritative BEFORE competitive selection: the routing core's gate pipeline (incl. route_output_code in the compatibility stage) qualifies resources first; the narrowed catalog view contains only qualified identities; D-059 blackout/happy-hour policy runs inside select_model over survivors only.
  2. Policy can never revive a capability-failing route: blackout only excludes (eligible=False early-return); happy-hour is ranking-only and validation-enforced to apply to eligible candidates only; no policy path adds candidates or reopens gates.
  3. Distinguishability: D-058 = gate-level TargetExclusion codes (output_limit_*); D-059 = selector-level exclusion_stage="policy_blackout" + policy_blocked + BlackoutDecision in the embedded selection decision — disjoint vocabularies/layers, both serialized.
  4. Mixed-cause completeness (one new integration commit, fb5da15): D-059 blackout exclusions never reach the gate-level exclusion records, so a purely-output gate set could coexist with a blackout on a route that would satisfy the request. _no_eligible_target_error now also requires the embedded selection decision to show no blocked blackout candidate; any such candidate downgrades to the ordinary 503 no_eligible_target. New regression: available 32k route (output-insufficient) + 128k-capable route blocked by an active campaign blackout, request 64k → 503 with zero dispatches; control world without the blackout → 200 on the strong route. Blackout-only worlds stay 503 by the same mechanism.
  5. Exact model + reasoning-effort invariants intact (D-057 member untouched; no substitution path); D-059 did not alter D-058's admin-vs-channel separation, exact-variant hard properties, normalization or audit provenance (e25de16..781bace on the D-058 machinery files is empty).
  6. control_api serializer round-trip copy intact post-rebase.

Gates on the frozen HEAD fb5da15: full suite 2190 tests OK (incl. all #153/#155 suites; #143 did not fire), basedpyright 0 diagnostics, git diff --check clean, guardrails 42 OK; no merge commits in origin/develop..HEAD; working tree clean.

Findings: none. One non-finding observation recorded (the closest_candidates half of the downgrade scan is redundant with excluded — harmless and defensive).

Status: READY_FOR_REVIEW — PR #152 open, unmerged, at the human gate. D-058 and D-059 both correctly numbered; D-057 untouched; #137 not started.

## Rebase onto develop `781bace` (merged PR #155 / D-059) — fresh exact-head integration review (D-058 × D-059): APPROVED The branch was rebased onto the advanced gate; no merge commit, no new issue/PR. **Conflicts and resolution:** exactly one file conflicted — `docs/decisions.md` (both sides append at the tail). Resolved semantically, ledger order now **D-057 → D-058 → D-059** with **D-058 and D-059 both verbatim and unrenumbered** (D-058 reserved for #152 as instructed; the merged D-059 untouched). A range-diff proves the approved PR #152 patch series survived byte-identically outside `docs/decisions.md`. **Semantic integration (verified by the independent reviewer with file:line evidence, not assumed from the auto-merge):** 1. D-058 capability filtering remains authoritative BEFORE competitive selection: the routing core's gate pipeline (incl. `route_output_code` in the compatibility stage) qualifies resources first; the narrowed catalog view contains only qualified identities; D-059 blackout/happy-hour policy runs inside `select_model` over survivors only. 2. Policy can never revive a capability-failing route: blackout only excludes (`eligible=False` early-return); happy-hour is ranking-only and validation-enforced to apply to eligible candidates only; no policy path adds candidates or reopens gates. 3. Distinguishability: D-058 = gate-level `TargetExclusion` codes (`output_limit_*`); D-059 = selector-level `exclusion_stage="policy_blackout"` + `policy_blocked` + `BlackoutDecision` in the embedded selection decision — disjoint vocabularies/layers, both serialized. 4. **Mixed-cause completeness (one new integration commit, `fb5da15`):** D-059 blackout exclusions never reach the gate-level exclusion records, so a purely-output gate set could coexist with a blackout on a route that would satisfy the request. `_no_eligible_target_error` now also requires the embedded selection decision to show no blocked blackout candidate; any such candidate downgrades to the ordinary `503 no_eligible_target`. New regression: available 32k route (output-insufficient) + 128k-capable route blocked by an active campaign blackout, request 64k → 503 with zero dispatches; control world without the blackout → 200 on the strong route. Blackout-only worlds stay 503 by the same mechanism. 5. Exact model + reasoning-effort invariants intact (D-057 member untouched; no substitution path); D-059 did not alter D-058's admin-vs-channel separation, exact-variant hard properties, normalization or audit provenance (`e25de16..781bace` on the D-058 machinery files is empty). 6. `control_api` serializer round-trip copy intact post-rebase. **Gates on the frozen HEAD `fb5da15`:** full suite **2190 tests OK** (incl. all #153/#155 suites; #143 did not fire), `basedpyright` **0 diagnostics**, `git diff --check` clean, guardrails **42 OK**; no merge commits in `origin/develop..HEAD`; working tree clean. **Findings: none.** One non-finding observation recorded (the `closest_candidates` half of the downgrade scan is redundant with `excluded` — harmless and defensive). **Status: READY_FOR_REVIEW — PR #152 open, unmerged, at the human gate.** D-058 and D-059 both correctly numbered; D-057 untouched; #137 not started.
adrian.tkacz deleted branch gateway/effective-limits 2026-09-28 13:23:21 +00:00
Sign in to join this conversation.
No description provided.