|
| 1 | +# Lane E — output budgets, queue memory, per-key policy |
| 2 | + |
| 3 | +Status: OPEN. Branch `codex/260920-lane-e-budgets-key-policy` against `dev`, one pull request. |
| 4 | +Covers phase 2 bundles 10, 11 and 12 from [010_phase2.md](010_phase2.md). |
| 5 | + |
| 6 | +## What each bundle turned out to be |
| 7 | + |
| 8 | +### 10 — Devin output budget and the history ceiling |
| 9 | + |
| 10 | +Two defects, not one. The adapter forwarded only a caller-supplied |
| 11 | +`max_output_tokens`, and Codex never sends one, so every `devin/*` turn was capped at |
| 12 | +the cloud-direct encoder's 8192 fallback however the provider was configured. The |
| 13 | +escape hatch was closed too: no OAuth preset declares `defaultMaxOutputTokens` or |
| 14 | +`modelMaxOutputTokens`, so the delete-when-preset-undefined branch in |
| 15 | +`applyOAuthPresetCatalog` was the only branch either field ever took and a |
| 16 | +hand-edited value was gone before the next startup finished. Both had to move, or |
| 17 | +wiring the adapter alone would have been unreachable in practice. |
| 18 | + |
| 19 | +The resolver reads the caller's explicit value, then the configured per-model cap, |
| 20 | +then the provider default, then nothing — leaving the encoder fallback. It never |
| 21 | +reads `contextWindow` or `modelContextWindows`: CompletionConfiguration #2 is the |
| 22 | +output cap and #3 is the context window, and collapsing them would ask Cognition to |
| 23 | +generate a whole window of output. |
| 24 | + |
| 25 | +The history ceiling is the other half and stays a separate quantity. #5189 is |
| 26 | +carried with attribution: it derives the coding-agent projected-history bound from |
| 27 | +the declared context window in characters. That bounds replayed history memory; |
| 28 | +nothing there decides how long a reply may run. |
| 29 | + |
| 30 | +No retry change was needed. Source review of `stated-reset-retry.ts` and |
| 31 | +`upstream-retry.ts` confirms an upstream `incomplete / max_output_tokens` is a |
| 32 | +successful streaming response that has already emitted events, so it matches none |
| 33 | +of the replay conditions. The repeated identical attempts in #5190 are the client's. |
| 34 | + |
| 35 | +### 11 — adapter event queue memory |
| 36 | + |
| 37 | +PR #5182 had the right idea and the wrong number. Its 1 MiB aggregate default |
| 38 | +aborts a legitimate turn: a synchronous producer fills the queue before its |
| 39 | +consumer is scheduled, and the image loop does exactly that with over a million |
| 40 | +one-character deltas that coalesce into roughly 1.2 MB of retained text. Its own CI |
| 41 | +proved it, which is why it sits at `CHANGES_REQUESTED`. |
| 42 | + |
| 43 | +The work is carried with attribution and reshaped around two budgets rather than |
| 44 | +one, because a stalled consumer and a malformed event are different failures and an |
| 45 | +operator reading the terminal error should learn which happened. Accounting is now |
| 46 | +exact by construction: each queued item records what it was charged, so a merge |
| 47 | +pays only for appended text, a refused event is priced before anything is retained |
| 48 | +and never charged, and the terminal record explaining a refusal is admitted past |
| 49 | +the budget it reports but still charged and released. `retainedCodeUnits()` exposes |
| 50 | +the counter so the regressions assert it reaches zero rather than inferring it from |
| 51 | +an abort that happened to fire. |
| 52 | + |
| 53 | +Retention is measured by a bounded walk of own enumerable properties rather than a |
| 54 | +per-variant table. A table would be exhaustive over `AdapterEvent`, which is the |
| 55 | +union class `AGENTS.md` records: a member added on another branch would silently |
| 56 | +stop being counted. |
| 57 | + |
| 58 | +### 12 — per-admission-key model and provider scope |
| 59 | + |
| 60 | +The security question is where the check goes, not what it compares. A scope |
| 61 | +evaluated against the client's string authorizes one destination and reaches |
| 62 | +another, because alias resolution, policy and combo selection, subagent fallback |
| 63 | +and compaction override all rewrite that string. So the scope names destinations |
| 64 | +and is applied to the resolved route. |
| 65 | + |
| 66 | +On the Responses path every route produced by the request — direct name, alias, |
| 67 | +policy, combo child, shadow-intercept target and both subagent-fallback re-routes — |
| 68 | +passes through one capture point, which is where the check sits. Chat and Messages |
| 69 | +translate into that path; their native lanes and the compaction route send without |
| 70 | +re-entering it, so each applies the same predicate itself. `/v1/models` filters by |
| 71 | +the same predicate, and that filter is explicitly not the boundary. |
| 72 | + |
| 73 | +A malformed scope drops the key rather than degrading to `undefined` like every |
| 74 | +other field on the record, because degrading a permission field reads as "allowed |
| 75 | +everything". |
| 76 | + |
| 77 | +Out of scope and deliberately not started: Redis, a full multi-tenant conversion, |
| 78 | +and any budget or RPM/TPM system. |
| 79 | + |
| 80 | +#### What the scope does not cover, stated rather than implied |
| 81 | + |
| 82 | +An adversarial review of the branch found authenticated data-plane endpoints that |
| 83 | +spend provider quota without resolving a model through the router, so the scope |
| 84 | +does not reach them: |
| 85 | + |
| 86 | +- `/v1/images/generations` and `/v1/images/edits`, |
| 87 | +- `/v1/audio/transcriptions` and its streaming form, |
| 88 | +- `/v1/live`, `/v1/realtime/calls` and the standalone realtime sockets, |
| 89 | +- the non-account-qualified branch of `/v1/alpha/search`, which forwards the caller's |
| 90 | + model to a search sidecar without routing it. |
| 91 | + |
| 92 | +The account-qualified search branch does route a model and is checked. The rest |
| 93 | +need a destination definition this lane does not own — an image or audio endpoint |
| 94 | +has a fixed-purpose model rather than a routed one — and inventing one here would |
| 95 | +be the multi-tenant expansion this batch rules out. They are recorded so the |
| 96 | +contract is not read as broader than it is. |
| 97 | + |
| 98 | +The review also found that resolving an OpenAI virtual model rewrites |
| 99 | +`route.modelId` to the wire id after the initial check. That one was a real hole in |
| 100 | +the stated contract and is fixed: the settled route is re-checked after |
| 101 | +normalization, so the id that is billed is the id that was authorized. |
| 102 | + |
| 103 | +## Verification |
| 104 | + |
| 105 | +Static source review plus exact-head hosted CI. No local suite, individual test, |
| 106 | +typecheck, build, install or live `ocx` execution was run — those are NOT RUN, not |
| 107 | +passing. |
| 108 | + |
| 109 | +Union-defect classes checked before pushing. No file in the touched set carries a |
| 110 | +`file-size-baseline.json` cap; the largest, `src/oauth/index.ts` and |
| 111 | +`src/server/index/serve-options.ts`, stay under the 2000-line new-file threshold. |
| 112 | +The two new test files are registered in both `scripts/test-layout/layout.json` and |
| 113 | +`tests/fixtures/test-layout-expected.json`. Nothing here restates a count or |
| 114 | +enumerates a union. |
| 115 | + |
| 116 | +## Ownership |
| 117 | + |
| 118 | +Lane E owns the adapter event queue budget and the Devin and coding-agent limits. |
| 119 | +Retry classification — `sendCount`, the send budget, the stage and cause vocabulary — |
| 120 | +is lane C's and is untouched. |
| 121 | + |
| 122 | +## Carried work |
| 123 | + |
| 124 | +- #5182 (luvs01) — adapter event queue backlog budget. |
| 125 | +- #5189 (mdwsk88) — coding-agent projected-history ceiling. |
| 126 | + |
| 127 | +Both carry a `Co-authored-by` trailer in the branch commit. Neither original pull |
| 128 | +request is closed here; the coordinator handles that after this lane lands. |
0 commit comments