Repository navigation
refactor(models): use one wildcard grammar for agent and role model policies - #190036
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR shares wildcard parsing and matching between agent and operator-role model policies and adds family-prefix wildcards to agent policies. Example: An agent policy allows openai/gpt-*.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it provides a useful, maintainer-directed consolidation with no actionable code defects found in the reviewed head. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherConfigured model references enter the shared parser; validation, catalog visibility, session selection, and operator-role enforcement consume its canonical keys and matching decisions. flowchart TD
A[Agent and role configuration] --> B[Shared wildcard parser]
B --> C[Config validation]
B --> D[Shared wildcard matcher]
D --> E[Catalog and CLI visibility]
D --> F[Operator model ceiling]
F --> G[Session admission and provider execution]
Technical reviewBest possible solution: Use the existing policy-reference owner for both grammars while preserving namespace boundaries, role ceilings, and stored snapshot meanings. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows agent policies rejecting family prefixes while the separate operator-role parser accepts them; no target code was executed during this read-only review. Is this the best way to solve the issue? The consolidation uses the existing owner, removes the separate role parser and glob preparation, and retains distinct validation, visibility, snapshot, and admission coverage. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 72ba78c0b93d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -11, Tests +75, Docs 0, Generated 0. Total +64 across 15 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed November 1, 2026, 4:49 AM ET / 09:49 UTC (Revision 6). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…olicies Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
7736343 to
c7d99cf
Compare
…sion Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 3636291. Agent and operator-role model policies now share one wildcard grammar ( |
…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]>
Summary
modelPolicy.allowhad two grammars under one name. Operator roles accepted a model-name prefix such asopenai/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 / *".src/config/model-policy-ref.tsnow 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 statusand the legacy Codex wildcard migration use them. The role-only parser, the role glob matcher and the role-only validation branch are deleted.openai/gpt-*. Existing agent and role configs keep their meaning; no config is invalidated.Evidence
Live Gateway, real operator-role identity. Setup:
openclaw.mjs gateway runfrom this branch) on an isolated HOME, state and loopback port.gateway.auth.mode: "trusted-proxy"with a loopback proxy that setsx-forwarded-user: [email protected].gateway.roles.default: "limited", withmodelPolicy: { allow: ["fixture/echo-*"], deny: ["fixture/echo-restricted*"] }.GatewayClient(webchat mode, device identity, no token), so the proxy-verified user is its only credential.Role policy compatibility (main vs this PR, real owner code). One script prepared role policies through
prepareOperatorModelPolicyon anorigin/maincheckout and on this branch. It evaluatedallows()for 12 models under 5 policies (family denyvendor/restricted-v1*, family allowvendor/gpt-*, nestedrouter/anthropic/*, paddedVENDOR / gpt-*with denyvendor/gpt-5.5*, inherited-source denyvendor/restricted-*). It also captured themainsnapshots withcaptureOperatorModelPolicySnapshotand restored them on this branch withrestoreOperatorModelPolicySnapshot.Admission proof. New case in
src/gateway/sessions-patch.operator-model-policy.test.tsdrivesprojectSessionsPatchEntry(thesessions.patchowner that admits a model before any run or provider request) with role policyallow: ["fixture/*"],deny: ["fixture/restricted-v1*"], once with the freshly prepared policy and once with a policy restored from its captured snapshot:It fails with this PR's first matcher (strict length check) and passes now. Rebased onto #190019;
pnpm check:changedand 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).model-visibility-policy.test.ts(agent policyopenai/gpt-5.6-*allowsgpt-5.6-sol, notgpt-5.5) fails onorigin/mainand passes here.openai/gpt-*(valid for agents) and rejectsopenai/gpt *and*.models status, legacy Codex model migration, configured model entries, model selection.modelPolicyWildcardMatchesis 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 denyvendor/restricted-v1itself) 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/modelkey).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