Skip to content

feat(codex): enable Ultrafast for supported models - #158703

Merged
sjf-oa merged 5 commits into
mainfrom
sjf/codex-service-tier-7
Sep 27, 2026
Merged

sjf-oa merged 5 commits into
mainfrom
sjf/codex-service-tier-7

Conversation

@sjf-oa

@sjf-oa sjf-oa commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Why

Users want to enable Ultrafast wherever their selected Codex model supports it while keeping their existing speed preference on other models.

What Problem This Solves

A requested but unsupported Codex tier can clear the override instead of preserving the current speed selection.

User Impact

Add plugins.entries.codex.config.appServer.enableUltrafast, defaulting to false. OpenClaw requests ultrafast only when the actual authenticated app-server catalog advertises it for the selected native model. Unsupported models, custom providers, and unavailable catalogs retain the current tier.

Why This Change Was Made

The optional upgrade runs at the turn boundary, after normal tier selection. The generated plugin configuration budget increases by exactly one for the explicitly requested opt-in boolean; core and channel budgets stay unchanged. Existing shared Fast behavior stays intact: on selects priority, off or inactive auto clears the override, and no shared control uses the configured or bound native preference. Active auto and standalone enablement can use Ultrafast when supported. Catalog discovery has a bounded budget and preserves cancellation and live ownership checks, without an additional entitlement cache.

Evidence

Final source head 64f0745b701ae4bc83b914326fc2b5e3f2ef4d29 merged as 9c2335a2d07e397ac2e30aa73f9412b77479a9e9. ClawSweeper reviewed that exact head with no code findings. The native verification below addresses its remaining signed-in app-server proof request.

  • 159 catalog/config cases and 21 registered turn-boundary cases passed for the unchanged runtime behavior, including advertised support, fallback, warm turns, retries, cancellation, and live ownership checks.
  • The final manual catalog type correction passed its affected compiler graphs, and the owning generated-configuration check passed. The required protected CI gates passed before merge.
  • Scoped formatting, type-aware lint, and git diff --check passed. Independent compatibility review found no actionable issues.
  • The existing-release backport separately passed 215 catalog/config cases and 22 registered turn-boundary cases, its owning production/test type graphs, generated configuration, scoped formatting, and type-aware lint.

No full image build or deployed Gateway/Slack E2E result is claimed.

Native service-tier verification

The remaining native-contract check was completed on 2026-09-26 at 19:03 PDT against a signed-in Codex 0.155.1 app-server. The probe imported the actual tier selector from the merged existing-release backport, 06b999fa4fcb3d6cc1d5c3836420ca7532845cca (OpenClaw 2026.9.4), and used the same authenticated client for catalog lookup and turn requests.

Each new test thread began at priority. The release selector received its actual selected model and the live catalog, with Ultrafast enabled. The following redacted trace summarizes the real model/list, thread/start, turn/start, and post-turn thread/resume responses. Model identifiers are consistently anonymized; both returned models were checked against the requested model.

Model Catalog service tiers Selected and requested turn tier Reported tier after turn Result
Supported model priority, ultrafast ultrafast ultrafast completed, OK
Unsupported model priority priority priority completed, OK

Both turns used text-only instructions, read-only sandboxing, and no approvals or tool calls. The two owned test threads were archived and the isolated probe process exited. The trace verifies native app-server acceptance and unsupported-model fallback. It does not measure backend processing-tier assignment or latency, and it is not a deployed Gateway or Slack E2E result.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: S labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 9:29 PM ET / September 27, 2026, 01:29 UTC (Revision 4).

ClawSweeper review

What this changes

The Codex plugin adds an opt-in setting that requests Ultrafast when the selected model's authenticated app-server catalog entry advertises it, with configuration, documentation, and tests.

Merge readiness

⛔ Blocked before merge - 2 items remain

Current main lacks model-aware Ultrafast selection, so this PR remains useful. The earlier Fast-mode and catalog-type findings are addressed in the current head, and this review found no new discrete code defect. A signed-in Codex turn is still needed to verify the native tier request.

Priority: P2
Reviewed head: 64f0745b701ae4bc83b914326fc2b5e3f2ef4d29

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and covers the prior findings; a native account trace would settle its remaining contract risk.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified maintain-access author is exempt from the external-contributor proof gate. The PR's mocked turn tests cover the new tier path, but no authenticated native turn is captured; existing stored config remains valid because the new setting is optional and false when absent.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified maintain-access author is exempt from the external-contributor proof gate. The PR's mocked turn tests cover the new tier path, but no authenticated native turn is captured; existing stored config remains valid because the new setting is optional and false when absent.
Evidence reviewed 10 items Introduced turn behavior: The PR resolves the tier from the selected model and active client immediately before turn/start, then rechecks turn ownership.
Current-main necessity: Current main builds the turn request without conditional Ultrafast catalog selection; its service-tier path is the existing configured or shared Fast value.
Previous finding resolved: The new head declares the catalog's serviceTiers field in the Codex model response type, addressing the prior review's TypeScript finding.
Findings None None.
Security None None.

How this fits together

The Codex plugin turns OpenClaw model requests into native Codex app-server turns. Plugin settings and the shared Fast control determine a service tier, which is sent with the selected model in the turn request.

flowchart LR
A[Plugin setting] --> C[Turn preparation]
B[Shared Fast control] --> C
C --> D[Selected native model]
D --> E[Authenticated model catalog]
E --> F{Ultrafast advertised?}
F -->|Yes| G[Ultrafast turn request]
F -->|No| H[Existing tier turn request]
Loading

Before merge

  • Resolve merge risk (P1) - The app-server source advertises Ultrafast, but the PR has no signed-in turn showing that the bundled Codex runtime accepts the selected tier and preserves the existing tier on an unsupported model.
  • Complete next step (P2) - Capture a redacted signed-in Codex 0.155.1 model/list and turn/start trace showing Ultrafast on a supported model and the retained tier on an unsupported model.
Agent review details

Security

None.

PR surface

Source +100, Tests +395, Docs +11, Generated 0. Total +506 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 9 104 4 +100
Tests 4 397 2 +395
Docs 2 11 0 +11
Config 0 0 0 0
Generated 2 3 3 0
Other 0 0 0 0
Total 17 515 9 +506

Review metrics

Metric Value Why it matters
New configuration 1 opt-in boolean; default false Existing configurations retain their tier behavior unless an operator enables the setting.
Production and test growth production +100, tests +395 lines The production growth is confined to the plugin's tier selection; most added lines cover turn and fallback behavior.

Merge-risk options

Maintainer options:

  1. Verify native tier selection (recommended)
    Capture a redacted authenticated Codex 0.155.1 catalog and turn trace showing Ultrafast on an advertised model and the existing tier on an unsupported model.

Technical review

Best possible solution:

Keep tier selection in the Codex plugin and verify a supported turn and an unsupported-model fallback against the bundled, authenticated app-server before landing.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR adds a conditional tier option. Current main's configured service tier does not select Ultrafast per model.

Is this the best way to solve the issue?

Yes, a Codex plugin setting is the narrow owner for model-aware tier selection; the existing serviceTier setting cannot preserve another tier selectively across models.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 030a6eca356e.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The verified maintain-access author is exempt from the external-contributor proof gate. The PR's mocked turn tests cover the new tier path, but no authenticated native turn is captured; existing stored config remains valid because the new setting is optional and false when absent.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review merge-risk labels are merge-risk: 🚨 auth-provider.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded, opt-in Codex plugin improvement with a native-contract validation gap.
  • merge-risk: 🚨 auth-provider: The opt-in changes the tier sent for an account-scoped model, and live provider acceptance has not yet been shown.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The verified maintain-access author is exempt from the external-contributor proof gate. The PR's mocked turn tests cover the new tier path, but no authenticated native turn is captured; existing stored config remains valid because the new setting is optional and false when absent.

Evidence

What I checked:

Likely related people:

  • sjf-oa: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record a redacted authenticated Codex model/list and turn/start trace for a supported model and an unsupported-model fallback.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed September 26, 2026, 2:58 AM ET / 06:58 UTC sha unknown :: blocked before merge. :: [P1] Preserve Fast-on behavior for existing flex configurations | [P2] Align the other Codex tier reference pages
  • reviewed 2026-09-26T23:58:41.455Z sha 662b846 :: blocked before merge. :: [P1] Preserve Fast-on priority for existing configured tiers
  • reviewed 2026-09-27T01:18:26.362Z sha a2ea0e5 :: blocked before merge. :: [P1] Declare serviceTiers on the Codex model response type

@sjf-oa sjf-oa changed the title fix: configured Codex service tiers are overwritten by Fast mode feat(codex): enable Ultrafast for supported models Sep 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 26, 2026
@sjf-oa
sjf-oa force-pushed the sjf/codex-service-tier-7 branch from 662b846 to f19af83 Compare September 27, 2026 00:59
@sjf-oa

sjf-oa commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

The updated commit preserves the existing shared Fast contract: on selects priority, off or inactive auto clears the override, and no shared control uses the configured baseline. The optional Ultrafast upgrade is applied afterward only when the actual selected native model advertises support in the authenticated catalog. Disabled or unsupported models therefore retain ordinary tier selection. Conflicts with current main are resolved, and fresh independent review found no actionable issues.

Commit: f19af83

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@sjf-oa

sjf-oa commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

The final revision adds warm-turn regressions for a previously accepted Ultrafast override followed by Fast off, inactive auto, or unsupported model support, plus configured retry baselines. The earlier Fast-off fixture now follows current main when no tier is inherited: it omits the override. Production behavior is unchanged from the reviewed correction; fresh independent review of the complete candidate found no actionable issues.

Commit: 442ff62

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@sjf-oa

sjf-oa commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

The requested supported-model opt-in and its default false are intentional. 64f0745b701ae4bc83b914326fc2b5e3f2ef4d29 fixes the manual catalog type declaration; the affected catalog suite and extension-test, scripts, and root-test compiler graphs pass, and hosted prod/test types are green.

The final review reports no code findings. The requested signed-in trace remains an acknowledged evidence gap, as stated in the PR body. Existing protocol validation and the registered turn fixtures establish the scoped catalog-to-turn contract, while live provider routing is not claimed. I accept that limitation for this default-off opt-in and am proceeding through the ordinary protected landing gates.

@sjf-oa
sjf-oa enabled auto-merge (squash) September 27, 2026 01:33
@sjf-oa
sjf-oa merged commit 9c2335a into main Sep 27, 2026
127 checks passed
@sjf-oa
sjf-oa deleted the sjf/codex-service-tier-7 branch September 27, 2026 01:35
sjf-oa added a commit that referenced this pull request Sep 27, 2026
## Why

Release users need the optional supported-model Ultrafast setting while preserving their existing tier and shared Fast preferences.

## What Problem This Solves

An unsupported requested native tier can clear the override instead of retaining the selected speed. This backports the reviewed conditional upgrade from [#158703](#158703).

## User Impact

`appServer.enableUltrafast` defaults to `false`. When enabled, the actual authenticated Codex catalog must advertise Ultrafast for the selected native model before OpenClaw upgrades the turn. Unsupported models, unavailable catalogs, and disabled opt-in preserve the existing tier. Shared Fast off and inactive auto remain off.

## Why This Change Was Made

Backport merged source commit `9c2335a2d07e397ac2e30aa73f9412b77479a9e9` onto the existing `sjf_openclaw_2026-09-04` branch. Package version stays `2026.9.4`. Compatibility changes retain this release's existing `openai` provider handling, schema and model normalization, and request owner. No newer protocol snapshot or provider modules are imported. The release's generated plugin budget increases only from 4141 to 4142 for the approved boolean; core and channel budgets stay unchanged.

## Evidence

Source proof and release proof are separate:

- Source PR completed exact-head ClawSweeper review with no code findings and passed its protected CI gates before merging.
- Fresh independent review of the complete release candidate found no actionable P0–P2 findings. The final export-only correction also received clean independent review.
- Release catalog/configuration tests: 215 passed. Registered turn-entry cohort: 22 passed, covering opt-out, unsupported native models, retained warm turns, inactive auto, and restoration of the original configured tier on retries.
- Owning extension production and test type graphs passed. Scoped formatting passed. The generated configuration baseline check passed with only the approved plugin setting added.
- Scoped type-aware lint passed for every changed Codex TypeScript file. Hosted CI on the final candidate is pending; no required hosted checks are configured for this existing release branch.

No full build, live Gateway execution, or signed-in provider routing proof is claimed for this backport.

Backport-Of: #158703
Release-Target: sjf_openclaw_2026-09-04
@sjf-oa

sjf-oa commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

MarMarLabs added a commit to MarMarLabs/openclaw that referenced this pull request Sep 27, 2026
33 upstream commits, including two low-value test batches (d048, d049)
and Ultrafast for supported models (openclaw#158703). No file outside the
generated set changed on both sides.

Two conflicts, both generated: docs/.generated/config-baseline.counts.json
and docs/.generated/config-baseline.sha256. This time the two sides moved
different columns. This branch took the channel count from 3748 to 3750,
and upstream's openclaw#158703, the only upstream commit on those files, took the
plugin count from 4349 to 4350, so the combined count is channel 3750 and
plugin 4350. Both files came from upstream and were regenerated, along
with the channel metadata, which upstream did not touch.

build:docker ran in a separate detached checkout of this commit outside the
nested node_modules install. Regenerating there changed the counts and hash files and left
the channel metadata identical, giving core 2463, channel 3750, plugin
4350 as predicted, this branch's channel hash and upstream's plugin hash.
The three generated-file checks pass there. The lockfile did not move.
No test this branch moved was deleted upstream in this range. The one
test file upstream deleted outright (openclaw#159298) is one this branch never
touched.

Feishu: 105 files and 1850 tests in the extension project, 17 files and
319 tests in the database-workers project, all 122 Feishu test files on
disk. The forwarder test and the routing guards pass, 1964 tests.
tsgo:core, tsgo:extensions, tsgo:extensions:test, tsgo:test:root, the
line-cap, max-lines and assertion-safety ratchets against upstream/main,
oxlint and oxfmt on the 42 changed code files all pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
* feat(codex): enable Ultrafast for supported models

* test(codex): preserve unconfigured Fast off selection

* test(codex): cover Ultrafast persistence and retry baselines

* docs(codex): register optional Ultrafast config baseline

* fix(codex): type advertised model service tiers

---------

Co-authored-by: Sarah Fortune <[email protected]>
obviyus added a commit that referenced this pull request Nov 1, 2026
…olicies (#190036)

## Summary

- **Problem:** `modelPolicy.allow` had two grammars under one name. Operator roles accepted a model-name prefix such as `openai/gpt-*`; agent policies rejected it. Role matching used a separate glob matcher, and five other callers detected wildcards by hand (`endsWith("/*")`, `slice(0, -2)`, `startsWith`). The copies agreed today but could drift, for example on padded refs like `"openai / *"`.
- **Fix:** `src/config/model-policy-ref.ts` now owns one parser (`parseModelPolicyWildcardRef`: `provider/*`, `provider/namespace/*`, `provider/family-*`) and one matcher (`modelPolicyWildcardMatches`). Role policy matching, config validation, `isModelKeyAllowedBySet`, configured model entries, alias candidates, `models status` and the legacy Codex wildcard migration use them. The role-only parser, the role glob matcher and the role-only validation branch are deleted.
- **User impact:** agent policies now also accept model-name prefixes such as `openai/gpt-*`. Existing agent and role configs keep their meaning; no config is invalidated.

## Evidence

**Live Gateway, real operator-role identity.** Setup:
- Candidate Gateway (`openclaw.mjs gateway run` from this branch) on an isolated HOME, state and loopback port.
- `gateway.auth.mode: "trusted-proxy"` with a loopback proxy that sets `x-forwarded-user: [email protected]`.
- `gateway.roles.default: "limited"`, with `modelPolicy: { allow: ["fixture/echo-*"], deny: ["fixture/echo-restricted*"] }`.
- A loopback fake OpenAI-completions provider that logs every request.
- The client is the real `GatewayClient` (webchat mode, device identity, no token), so the proxy-verified user is its only credential.

```text
(1)+(2) sessions.patch fixture/echo-restricted       -> FORBIDDEN "Your operator role cannot use this model…"
        sessions.patch fixture/echo-restricted-mini  -> FORBIDDEN
        sessions.patch fixture/other-x               -> FORBIDDEN (outside allow)
        sessions.patch fixture/echo-main             -> ok
        agent run on that session                    -> status ok
        provider log: POST /v1/chat/completions model=echo-main   (only request; no echo-restricted* or other-x call)
(3)     live reload narrows the role: deny += "fixture/echo-main*"
        [reload] config change detected; evaluating reload (gateway.roles.definitions.limited.modelPolicy.deny)
        next agent run on the pinned echo-main session -> status error "Your operator role cannot use this model…"
        provider requests before=2 after=2 (no new provider call)
(4)     upgrade cell, same state directory:
        published [email protected] Gateway writes and serves the role config:
          echo-restricted / echo-restricted-mini / other-x -> FORBIDDEN, echo-main -> ok, provider called with echo-main
        stop; candidate `doctor --fix` (agent DB schema 25 -> 39, role config untouched); candidate Gateway on that state:
          identical sessions.patch decisions (diff: IDENTICAL), provider called only with echo-main
```

**Role policy compatibility (main vs this PR, real owner code).** One script prepared role policies through `prepareOperatorModelPolicy` on an `origin/main` checkout and on this branch. It evaluated `allows()` for 12 models under 5 policies (family deny `vendor/restricted-v1*`, family allow `vendor/gpt-*`, nested `router/anthropic/*`, padded ` VENDOR / gpt-* ` with deny `vendor/gpt-5.5*`, inherited-source deny `vendor/restricted-*`). It also captured the `main` snapshots with `captureOperatorModelPolicySnapshot` and restored them on this branch with `restoreOperatorModelPolicySnapshot`.

```text
prepared decisions, main vs PR:           0 differences / 60
main snapshots restored on PR vs main:    0 differences / 60
familyDeny on PR: vendor/restricted-v1 false, vendor/restricted-v1-mini false, vendor/restricted-v2 true, vendor/primary true
```

**Admission proof.** New case in `src/gateway/sessions-patch.operator-model-policy.test.ts` drives `projectSessionsPatchEntry` (the `sessions.patch` owner that admits a model before any run or provider request) with role policy `allow: ["fixture/*"]`, `deny: ["fixture/restricted-v1*"]`, once with the freshly prepared policy and once with a policy restored from its captured snapshot:

```text
fixture/restricted-v1       -> FORBIDDEN "operator role cannot use this model"
fixture/restricted-v1-mini  -> FORBIDDEN
fixture/allowed             -> ok; after the operator source is revoked, its commit guard -> FORBIDDEN
```

It fails with this PR's first matcher (strict length check) and passes now. Rebased onto #190019; `pnpm check:changed` and the auth-model-policy suites pass on the rebased head.

Role admission suites that consume this predicate before provider calls also pass on this branch: model fallback, CLI runner, isolated completion and image fallback operator-policy suites, plus `operator-model-policy.test.ts` (65 tests).

- New regression in `model-visibility-policy.test.ts` (agent policy `openai/gpt-5.6-*` allows `gpt-5.6-sol`, not `gpt-5.5`) fails on `origin/main` and passes here.
- Validation table adds `openai/gpt-*` (valid for agents) and rejects `openai/gpt *` and `*`.
- Focused suites pass: model visibility, config model-ref validation, operator model policy, role mutation authority, `models status`, legacy Codex model migration, configured model entries, model selection.
- Role compatibility: `modelPolicyWildcardMatches` is a plain prefix test, the same set the old role glob (`^prefix.*$`) accepted, because the parser forbids any other `*`. A new operator-policy regression (`allow: ["vendor/*"]`, `deny: ["vendor/restricted-v1*"]` must deny `vendor/restricted-v1` itself) fails on the first head of this PR and passes now. Stored role snapshots keep the same canonical wildcard keys, so restored policies match as before.
- `pnpm check:changed` (dead-code step skipped) passes; config docs baseline regenerated.

## Merge danger

Two-way door: no stored state or migration; a revert restores the narrower agent grammar. Blast radius: model policy matching for agents and operator roles. Role semantics are unchanged (same prefix rule, same normalized `provider/model` key).

Pash/Sarah check: Sarah's commits on these files (#161609, #162335, #161048, #161004, #159363, #158307, #158703, #151176, #123875) touch Agents API, Codex and Slack config help/validation entries. This PR edits only model-policy wildcard parsing, matching and help text, so their behavior is unchanged.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
…olicies (openclaw#190036)

## Summary

- **Problem:** `modelPolicy.allow` had two grammars under one name. Operator roles accepted a model-name prefix such as `openai/gpt-*`; agent policies rejected it. Role matching used a separate glob matcher, and five other callers detected wildcards by hand (`endsWith("/*")`, `slice(0, -2)`, `startsWith`). The copies agreed today but could drift, for example on padded refs like `"openai / *"`.
- **Fix:** `src/config/model-policy-ref.ts` now owns one parser (`parseModelPolicyWildcardRef`: `provider/*`, `provider/namespace/*`, `provider/family-*`) and one matcher (`modelPolicyWildcardMatches`). Role policy matching, config validation, `isModelKeyAllowedBySet`, configured model entries, alias candidates, `models status` and the legacy Codex wildcard migration use them. The role-only parser, the role glob matcher and the role-only validation branch are deleted.
- **User impact:** agent policies now also accept model-name prefixes such as `openai/gpt-*`. Existing agent and role configs keep their meaning; no config is invalidated.

## Evidence

**Live Gateway, real operator-role identity.** Setup:
- Candidate Gateway (`openclaw.mjs gateway run` from this branch) on an isolated HOME, state and loopback port.
- `gateway.auth.mode: "trusted-proxy"` with a loopback proxy that sets `x-forwarded-user: [email protected]`.
- `gateway.roles.default: "limited"`, with `modelPolicy: { allow: ["fixture/echo-*"], deny: ["fixture/echo-restricted*"] }`.
- A loopback fake OpenAI-completions provider that logs every request.
- The client is the real `GatewayClient` (webchat mode, device identity, no token), so the proxy-verified user is its only credential.

```text
(1)+(2) sessions.patch fixture/echo-restricted       -> FORBIDDEN "Your operator role cannot use this model…"
        sessions.patch fixture/echo-restricted-mini  -> FORBIDDEN
        sessions.patch fixture/other-x               -> FORBIDDEN (outside allow)
        sessions.patch fixture/echo-main             -> ok
        agent run on that session                    -> status ok
        provider log: POST /v1/chat/completions model=echo-main   (only request; no echo-restricted* or other-x call)
(3)     live reload narrows the role: deny += "fixture/echo-main*"
        [reload] config change detected; evaluating reload (gateway.roles.definitions.limited.modelPolicy.deny)
        next agent run on the pinned echo-main session -> status error "Your operator role cannot use this model…"
        provider requests before=2 after=2 (no new provider call)
(4)     upgrade cell, same state directory:
        published [email protected] Gateway writes and serves the role config:
          echo-restricted / echo-restricted-mini / other-x -> FORBIDDEN, echo-main -> ok, provider called with echo-main
        stop; candidate `doctor --fix` (agent DB schema 25 -> 39, role config untouched); candidate Gateway on that state:
          identical sessions.patch decisions (diff: IDENTICAL), provider called only with echo-main
```

**Role policy compatibility (main vs this PR, real owner code).** One script prepared role policies through `prepareOperatorModelPolicy` on an `origin/main` checkout and on this branch. It evaluated `allows()` for 12 models under 5 policies (family deny `vendor/restricted-v1*`, family allow `vendor/gpt-*`, nested `router/anthropic/*`, padded ` VENDOR / gpt-* ` with deny `vendor/gpt-5.5*`, inherited-source deny `vendor/restricted-*`). It also captured the `main` snapshots with `captureOperatorModelPolicySnapshot` and restored them on this branch with `restoreOperatorModelPolicySnapshot`.

```text
prepared decisions, main vs PR:           0 differences / 60
main snapshots restored on PR vs main:    0 differences / 60
familyDeny on PR: vendor/restricted-v1 false, vendor/restricted-v1-mini false, vendor/restricted-v2 true, vendor/primary true
```

**Admission proof.** New case in `src/gateway/sessions-patch.operator-model-policy.test.ts` drives `projectSessionsPatchEntry` (the `sessions.patch` owner that admits a model before any run or provider request) with role policy `allow: ["fixture/*"]`, `deny: ["fixture/restricted-v1*"]`, once with the freshly prepared policy and once with a policy restored from its captured snapshot:

```text
fixture/restricted-v1       -> FORBIDDEN "operator role cannot use this model"
fixture/restricted-v1-mini  -> FORBIDDEN
fixture/allowed             -> ok; after the operator source is revoked, its commit guard -> FORBIDDEN
```

It fails with this PR's first matcher (strict length check) and passes now. Rebased onto openclaw#190019; `pnpm check:changed` and the auth-model-policy suites pass on the rebased head.

Role admission suites that consume this predicate before provider calls also pass on this branch: model fallback, CLI runner, isolated completion and image fallback operator-policy suites, plus `operator-model-policy.test.ts` (65 tests).

- New regression in `model-visibility-policy.test.ts` (agent policy `openai/gpt-5.6-*` allows `gpt-5.6-sol`, not `gpt-5.5`) fails on `origin/main` and passes here.
- Validation table adds `openai/gpt-*` (valid for agents) and rejects `openai/gpt *` and `*`.
- Focused suites pass: model visibility, config model-ref validation, operator model policy, role mutation authority, `models status`, legacy Codex model migration, configured model entries, model selection.
- Role compatibility: `modelPolicyWildcardMatches` is a plain prefix test, the same set the old role glob (`^prefix.*$`) accepted, because the parser forbids any other `*`. A new operator-policy regression (`allow: ["vendor/*"]`, `deny: ["vendor/restricted-v1*"]` must deny `vendor/restricted-v1` itself) fails on the first head of this PR and passes now. Stored role snapshots keep the same canonical wildcard keys, so restored policies match as before.
- `pnpm check:changed` (dead-code step skipped) passes; config docs baseline regenerated.

## Merge danger

Two-way door: no stored state or migration; a revert restores the narrower agent grammar. Blast radius: model policy matching for agents and operator roles. Role semantics are unchanged (same prefix rule, same normalized `provider/model` key).

Pash/Sarah check: Sarah's commits on these files (openclaw#161609, openclaw#162335, openclaw#161048, openclaw#161004, openclaw#159363, openclaw#158307, openclaw#158703, openclaw#151176, openclaw#123875) touch Agents API, Codex and Slack config help/validation entries. This PR edits only model-policy wildcard parsing, matching and help text, so their behavior is unchanged.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants