Add general Codex router and usage controls - #23
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 485e3114e4
ℹ️ 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".
| if(route.storageRole==="hard"&&prefs.hardRoute.status!=="runtime-pending"&&prefs.hardRoute.status!=="ready")return blocked("hard route is pending four-role preview consent"); | ||
| if(!pref.effort)return blocked("configured effort is unavailable"); | ||
| const expectedTier=machineTier==="fast"?"priority":"default"; | ||
| const exact=(e:RuntimeEvidence|TargetRuntimeEvidence,targetEvidence=false)=>e.evidenceSource==="codex-rollout-inspector"&&e.executionContext===(targetEvidence?"agent":"parent")&&e.agentIdentifier===(targetEvidence?identifier:null)&&e.model===pref.model&&e.effort===pref.effort&&(machineTier!=="fast"||e.observedRuntimeTier==="priority")&&(machineTier==="fast"||e.observedRuntimeTier===null||e.observedRuntimeTier===expectedTier)&&(pref.readonly?e.sandboxPolicyType==="read-only":e.sandboxPolicyType!=="read-only"); |
There was a problem hiding this comment.
Bind target proof to the freshly spawned agent
When any older rollout exists for the same configured role, its evidence satisfies exact because the check compares only the shared role identifier, model, effort, tier, and sandbox; the inspector's unique thread_id is not accepted by TargetRuntimeEvidence. Consequently a review or changed route can be marked verified using stale evidence without proving that the required fresh agent was spawned or that the evidence belongs to it. Include and validate the expected rollout/thread identity (or an equivalent per-spawn binding) before accepting target proof.
Useful? React with 👍 / 👎.
| if(current.evidenceSource!=="codex-rollout-inspector"||current.executionContext!=="parent"||current.agentIdentifier!==null)return blocked("current runtime evidence provenance must be the parent inspector record"); | ||
| if(target&&(target.evidenceSource!=="codex-rollout-inspector"||target.executionContext!=="agent"))return blocked("target runtime evidence provenance must be the agent inspector record","fresh_agent"); |
There was a problem hiding this comment.
Accept runtime evidence from configured non-Codex clients
For a Cursor profile with persisted effort, every general route still requires evidenceSource === "codex-rollout-inspector", even though that inspector reads Codex rollout sessions and cannot produce evidence for Cursor. The inspected Cursor smoke workflow expects orchestration to use the configured routine and advisor roles, while orchestration mandates resolve_route for every general route, so a truthful Cursor caller must always block (or falsely label Cursor metadata as Codex evidence). Evidence provenance needs to be client-specific or support validated host-native details.
Useful? React with 👍 / 👎.
| def consistent($values; $label): | ||
| ($values | map(select(type == "string" and length > 0)) | unique) as $unique | | ||
| if ($unique | length) == 1 then $unique[0] else error("inconsistent " + $label) end; |
There was a problem hiding this comment.
Reject incomplete turn-context evidence
When a rollout contains one valid turn_context followed by another that omits model, effort, or the sandbox type, consistent filters the missing value out and reports the older value as authoritative. This regresses the previous fail-closed behavior and lets resolve_route verify a current route even though one of its turns lacks required routing evidence. Reject every non-string or empty entry rather than discarding it before checking uniqueness.
Useful? React with 👍 / 👎.
| [ .[] | select(.type == "event_msg" and .payload.type == "token_count") | .payload.info ] as $token_infos | | ||
| [ $token_infos[]?.total_token_usage?.total_tokens | select(type == "number" and . >= 0 and floor == .) ] as $raw_tokens | | ||
| [ $token_infos[]?.last_token_usage?.input_tokens | select(type == "number" and . >= 0 and floor == .) ] as $input_rounds | |
There was a problem hiding this comment.
Do not report missing token usage as zero
If a rollout has no usable total_token_usage.total_tokens values—for example because a token_count record is incomplete or its shape changes—the inspector emits raw_tokens: 0 rather than unavailable/error. That makes an unobservable session indistinguishable from a zero-token session and causes the new raw-token budget control to fail open. Require a valid cumulative counter once runtime activity exists, or return an explicit unavailable value that blocks budget acceptance.
Useful? React with 👍 / 👎.
| if(route.storageRole==="hard"&&prefs.hardRoute.status!=="runtime-pending"&&prefs.hardRoute.status!=="ready")return blocked("hard route is pending four-role preview consent"); | ||
| if(!pref.effort)return blocked("configured effort is unavailable"); | ||
| const expectedTier=machineTier==="fast"?"priority":"default"; | ||
| const exact=(e:RuntimeEvidence|TargetRuntimeEvidence,targetEvidence=false)=>e.evidenceSource==="codex-rollout-inspector"&&e.executionContext===(targetEvidence?"agent":"parent")&&e.agentIdentifier===(targetEvidence?identifier:null)&&e.model===pref.model&&e.effort===pref.effort&&(machineTier!=="fast"||e.observedRuntimeTier==="priority")&&(machineTier==="fast"||e.observedRuntimeTier===null||e.observedRuntimeTier===expectedTier)&&(pref.readonly?e.sandboxPolicyType==="read-only":e.sandboxPolicyType!=="read-only"); |
There was a problem hiding this comment.
Require recognized writable sandbox evidence
For routine, medium, and hard routes, the sandbox predicate treats every value other than the exact string read-only as proof of writability. Because the server does not enforce the advertised JSON schema itself, omitted, empty, or unknown sandboxPolicyType values all make an otherwise matching route verified; the same applies to target evidence. This violates the fail-closed evidence gate and can dispatch implementation without any observed writable sandbox, so require a nonempty allowlisted writable policy rather than using a negative comparison.
Useful? React with 👍 / 👎.
Summary
Verification
Rollout
The live plugin and Codex defaults are unchanged in this PR. MBP backup, install, and canaries remain a separate rollout step after review.