Skip to content

feat: limit model use by operator role - #156346

Merged
shakkernerd merged 2 commits into
mainfrom
feat/operator-model-policy
Sep 23, 2026
Merged

shakkernerd merged 2 commits into
mainfrom
feat/operator-model-policy

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Shared Gateways can restrict which agents and operations a named role may use, but they cannot give that role a model ceiling that follows its accepted work. A role that should use an administrator's primary and fallback models can otherwise select a different model through session controls, retry paths, or auxiliary model tools.

This contribution introduces an optional model policy for named operator roles and carries it through the host and embedded execution paths. Related: #154893, which retains the native Codex integration and Visitor Access activation work.

User Impact

Administrators can set gateway.roles.definitions.<name>.modelPolicy to follow a source agent's configured primary and fallbacks, replace that membership with allow, and exclude resolved models or trailing family patterns with deny. Omitting the policy preserves existing model access. Unrestricted staff and shared-secret System behavior remain unchanged.

Accepted work must satisfy its original model ceiling and the current policy. With configuration reload enabled, model-only edits take effect on commit without reconnecting clients. Removing a model cancels its active requests while permitted sibling work remains active. Session selection, defaults, fallbacks, titles, decisions, image/PDF analysis, and plugin completion use the same ceiling.

Interactive plugin runtimes without exact model-policy support reject restricted attempts before starting, whether credentials are host-owned or native-owned. Adding a policy also cancels their previously unrestricted foreground and retained work. Codex interactive support is intentionally pending the separate native integration; the built-in runtime is available for these restricted attempts. Isolated prompt-only completion retains its existing exact-route, empty-tool contract and selected-model binding. This change does not require a policy on existing Visitor Access configurations or activate a live Gateway.

Why This Change Was Made

The Gateway issues the original operator source, so it owns the original/current policy intersection and notifications. Execution owners bind the actual selected model through dispatch and cleanup; callers do not reconstruct permission from model names or credential ownership. Same-source coalescing retains the original authority, and session writes revalidate their selection at the commit boundary.

The shared evaluator derives model choices from existing agent configuration and resolves aliases before exclusions. Automatic fallbacks filter their candidate chain before provider preparation. An empty permitted set produces an explicit error instead of widening access. Unsupported native execution is bound as an unknown model until a runtime implements the exact enforcement contract.

Evidence

The remote regression run exercised the actual registered harness entry point and retained-source capability. Before the repairs, five cases failed: fresh and host-auth restricted attempts executed, policy introduction did not cancel either foreground path, and retained work remained active. Fifteen controls passed, including ordinary no-policy behavior and native admission.

The corrected suites pass all 44 cases: 10 image-tool cases, 9 PDF-tool cases, 15 harness admission/finalization cases, and 10 retained-source cases. Direct and admitted tool callers both enforce denial, permitted fallback, and requester retirement, with source holds released after cleanup. The direct-media cases fail against the previous callers (five failures), then pass with the repair.

Independent review is complete with no unresolved actionable findings. Earlier source-bound proof covers role compilation, original/current intersection, registered Gateway dispatch, reload, coalescing, and the common execution consumers. The full remote package build, type-aware lint, production and affected test types, extension production/test types, config documentation, SDK exports/surface, and import-cycle checks passed. Hosted CI passed on a39c80e7554, including the corrected UI performance gate.

Standalone remote measurements use pnpm test <file> --maxWorkers=1:

Regression file Cases Command wall time
image-tool.runtime-abort.test.ts 10 30.85 s
pdf-tool.runtime-abort.test.ts 9 25.86 s
host-model-execution.test.ts 15 34.95 s
host-capability.source-lifetime.test.ts 10 30.56 s

Standalone wall time includes worker-artifact preparation and imports. These cases exercise the registered harness or real tool/capability boundary, where a helper-only test would miss the original failure. The role-parser correction also passes 44 schema cases (17.10 s standalone), 4 policy and 57 UI display cases (16.78 s combined), and 732 strict/role grammar comparisons. It restores the existing strict parser used by UI startup while keeping role prefix support in a separate export at the same owner. On the same fixed build identity, the untouched base measured 371,276 gzip bytes, the original integrated candidate measured 371,367 bytes, and the corrected candidate returned to 371,276 bytes, below the unchanged 371,332-byte limit. CI execution timings for the changed test files are recorded below.

Retained timing measurements for the existing policy tests

These are historical single-file command wall times using pnpm test <path> --maxWorkers=1, retained on matching test bytes. They include startup and cleanup and describe whole-suite cost, not the marginal cost added by this change or fresh execution of the current head. Slower Gateway/session cases exercise registered or persistent lifecycle boundaries that a helper-only assertion would bypass. Do not sum these measurements into CI duration.

Test Cases Wall seconds
src/acp/control-plane/manager.operator-model-policy.test.ts 7 16.395
src/agents/cli-runner.operator-model-policy.test.ts 1 15.667
src/agents/cli-runner/prepare.model-routing-authority.test.ts 5 26.352
src/agents/command/model-selection.configured.test.ts 21 40.127
src/agents/embedded-agent-runner/run-orchestrator.cleanup-resources.test.ts 6 34.920
src/agents/isolated-completion.operator-model-policy.test.ts 5 17.876
src/agents/model-fallback-image.operator-model-policy.test.ts 5 16.260
src/agents/model-fallback.operator-model-policy.test.ts 3 16.536
src/auto-reply/reply/conversation-label-generator.test.ts 22 29.701
src/auto-reply/reply/directive-handling.model-selection.test.ts 24 21.107
src/auto-reply/reply/get-reply-run-admission.session-file.test.ts 3 14.559
src/auto-reply/reply/model-selection.resolved-pin.test.ts 26 27.213
src/decisions/runtime.test.ts 51 15.129
src/gateway/chat-auth-readiness.integration.test.ts 1 42.600
src/gateway/operator-role-policy.test.ts 22 25.663
src/gateway/server-methods/sessions-title.test.ts 34 42.730
src/gateway/server-plugin-subagent-runtime.test.ts 26 28.890
src/gateway/server-reload-handlers.operator-model-policy.test.ts 1 39.100
src/gateway/server.sessions.create.resolved-model.test.ts 11 69.957
src/gateway/server/ws-connection/authenticated-request-dispatch.mutation-authority.test.ts 15 24.433
src/gateway/session-companion-rpc.test.ts 15 48.438
src/gateway/session-companion-runtime.test.ts 3 39.103
src/gateway/sessions-patch.operator-model-policy.test.ts 7 29.725
src/model-picker/apply-session-model-selection-placement.test.ts 5 30.649
src/model-picker/apply-session-model-selection.operator-context.test.ts 11 24.421
src/plugins/runtime/runtime-llm.operator-model-policy.test.ts 15 23.103

Additional retained measurements have narrower timing limits:

  • src/gateway/config-reload-plan.test.ts: 46 cases, 15.140 s wrapper wall (16.466 s including source verification).
  • src/model-picker/apply-session-model-selection.test.ts: 43 cases, 25.080 s wrapper wall (26.426 s including source verification).
  • src/agents/operator-model-policy.test.ts: 22.109 s combined with device-revocation coverage; 12 cases total, 4 belonging to the policy file. The current policy/UI sibling replay above supplies additional validation.
  • src/agents/openclaw-tools.session-status.model-policy.test.ts: 73.160 s combined with native-hook admission coverage; 13 cases total, one belonging to session status. Its assertion time was 5.680 s, not standalone wall time.
  • src/agents/harness/selection.test.ts: historical 161-case run in 41.680 s. Later main changes updated Agents API expectations, so this is a cost reference rather than an exact-current-source measurement.
Current-head CI test execution costs

These are summed case execution seconds from the passing Linux Node shard logs in the linked CI run. They exclude worker preparation, imports, and cleanup; the standalone wall measurements above include those costs. They are not additive CI job durations.

Test Cases reported CI execution seconds
src/acp/control-plane/manager.operator-model-policy.test.ts 7 0.035
src/agents/cli-runner.operator-model-policy.test.ts 1 0.005
src/agents/cli-runner/prepare.model-routing-authority.test.ts 5 1.165
src/agents/command/model-selection.configured.test.ts 21 1.021
src/agents/embedded-agent-runner/run-orchestrator.cleanup-resources.test.ts 6 0.605
src/agents/harness/host-capability.source-lifetime.test.ts 10 0.012
src/agents/harness/host-model-execution.test.ts 15 1.013
src/agents/harness/selection.test.ts 161 16.951
src/agents/isolated-completion.operator-model-policy.test.ts 5 0.036
src/agents/model-fallback-image.operator-model-policy.test.ts 5 0.008
src/agents/model-fallback.operator-model-policy.test.ts 3 0.131
src/agents/openclaw-tools.session-status.model-policy.test.ts 1 1.200
src/agents/operator-model-policy.test.ts 4 0.002
src/agents/tools/image-tool.runtime-abort.test.ts 10 1.928
src/agents/tools/pdf-tool.runtime-abort.test.ts 9 1.837
src/auto-reply/reply/conversation-label-generator.test.ts 22 0.131
src/auto-reply/reply/directive-handling.model-selection.test.ts 24 5.755
src/auto-reply/reply/get-reply-run-admission.session-file.test.ts 3 0.272
src/auto-reply/reply/model-selection.resolved-pin.test.ts 26 0.305
src/config/zod-schema.gateway-auth.test.ts 44 0.016
src/decisions/runtime.test.ts 51 0.279
src/gateway/chat-auth-readiness.integration.test.ts 1 1.548
src/gateway/config-reload-plan.test.ts 46 0.380
src/gateway/operator-role-policy.test.ts 22 1.120
src/gateway/server-methods/sessions-title.test.ts 34 3.595
src/gateway/server-plugin-subagent-runtime.test.ts 26 3.186
src/gateway/server-reload-handlers.operator-model-policy.test.ts 1 0.456
src/gateway/server.sessions.create.resolved-model.test.ts 11 11.000
src/gateway/server/ws-connection/authenticated-request-dispatch.mutation-authority.test.ts 15 0.216
src/gateway/session-companion-rpc.test.ts 15 0.700
src/gateway/session-companion-runtime.test.ts 3 10.434
src/gateway/sessions-patch.operator-model-policy.test.ts 7 1.366
src/model-picker/apply-session-model-selection-placement.test.ts 5 1.379
src/model-picker/apply-session-model-selection.operator-context.test.ts 11 2.109
src/model-picker/apply-session-model-selection.test.ts 43 8.893
src/plugins/runtime/runtime-llm.operator-model-policy.test.ts 15 1.620

@clawsweeper

clawsweeper Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@shakkernerd shakkernerd self-assigned this Sep 23, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Sep 23, 2026
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: a39c80e7554569cb41cc43f62f83da1442f85d85
  • Maintainer: @shakkernerd
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/harness/host-source-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/isolated-completion-model-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/auth-policy.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/device-revocation.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/operator-invocation-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/operator-role-source-policy.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/operator-run-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server/ws-connection/authenticated-request-dispatch.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@shakkernerd
shakkernerd merged commit 6b4ebc0 into main Sep 23, 2026
225 of 226 checks passed
@shakkernerd
shakkernerd deleted the feat/operator-model-policy branch September 23, 2026 09:57
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Added: optional operator-role model policies that follow model selection, accepted work, and model tools through execution and cleanup.

steipete added a commit that referenced this pull request Sep 23, 2026
…d-reasoning tests green (#156565)

Operator authority currency no longer folds the caller's own abort signal into
assertCurrent, so a caller-aborted direct completion settles through the
provider result again instead of rejecting after the stream ended (regressed
in #156346). The isolated reasoning validation fixture uses max, which stays
unsupported for the host-resolved model now that Ultra is a harness mode on
every runtime (#155393).

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
Add optional role-based model limits across Gateway selection, accepted execution, and model-consuming tools, preserving original and current permissions through cancellation and cleanup.

Refs openclaw#154893.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
…d-reasoning tests green (openclaw#156565)

Operator authority currency no longer folds the caller's own abort signal into
assertCurrent, so a caller-aborted direct completion settles through the
provider result again instead of rejecting after the stream ended (regressed
in openclaw#156346). The isolated reasoning validation fixture uses max, which stays
unsupported for the host-resolved model now that Ultra is a harness mode on
every runtime (openclaw#155393).

Co-authored-by: Peter Steinberger <[email protected]>
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
obviyus added a commit that referenced this pull request Nov 28, 2026
…07247)

## What problem this solves

`docs/gateway/operator-scopes.md` says that "bounded automatic metadata" keeps Gateway service authority, but does not say what that covers. #207070 bound progress narration to the turn's operator role and session observer digests to the session owner's role, so the sentence now reads as if those still bypass the role `modelPolicy`. Operators who restrict utility models cannot tell from the docs which automatic model calls their roles control.

## Change

Docs only. Replace the undefined term with the consumers and the authority each uses:

- Progress narration: the turn's role. Execution skips refused utility models; a role that refuses every utility model gets no narration.
- Session observer digests: the session owner's role, resolved once when a run's observation starts. A refusing owner role turns observation off for that run. Deleted owner profiles and sessions without an owner are observed on service authority.
- Automatically generated session and thread titles, inbound media preprocessing and host-owned execution approval keep service authority (unchanged; chat-send dashboard titles and channel thread titles pass no operator authority).

## Security note

Before #207070, progress narration and session observer digests ran the utility model even when the role's `modelPolicy` refused it (since #156346, 2026-09-23). The refused model ran on the Gateway's credentials and its short text was shown; main turns, tools and data access were not affected. #207070 fixed it on main. Backports are prepared for the active extended-stable line (narration) and the next stable (the #206962 + #207070 pair).

## Evidence

- Text checked against `src/auto-reply/reply/progress-narrator.ts`, `src/gateway/session-observer-completion.ts` and `src/gateway/server-methods/chat-send-background.ts` on main.
- `oxfmt --check`, `check-docs-mdx`, `docs:check-links` (0 broken), `git diff --check`: clean.
- Local review: patch is correct, 0 findings.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
…enclaw#207247)

## What problem this solves

`docs/gateway/operator-scopes.md` says that "bounded automatic metadata" keeps Gateway service authority, but does not say what that covers. openclaw#207070 bound progress narration to the turn's operator role and session observer digests to the session owner's role, so the sentence now reads as if those still bypass the role `modelPolicy`. Operators who restrict utility models cannot tell from the docs which automatic model calls their roles control.

## Change

Docs only. Replace the undefined term with the consumers and the authority each uses:

- Progress narration: the turn's role. Execution skips refused utility models; a role that refuses every utility model gets no narration.
- Session observer digests: the session owner's role, resolved once when a run's observation starts. A refusing owner role turns observation off for that run. Deleted owner profiles and sessions without an owner are observed on service authority.
- Automatically generated session and thread titles, inbound media preprocessing and host-owned execution approval keep service authority (unchanged; chat-send dashboard titles and channel thread titles pass no operator authority).

## Security note

Before openclaw#207070, progress narration and session observer digests ran the utility model even when the role's `modelPolicy` refused it (since openclaw#156346, 2026-09-23). The refused model ran on the Gateway's credentials and its short text was shown; main turns, tools and data access were not affected. openclaw#207070 fixed it on main. Backports are prepared for the active extended-stable line (narration) and the next stable (the openclaw#206962 + openclaw#207070 pair).

## Evidence

- Text checked against `src/auto-reply/reply/progress-narrator.ts`, `src/gateway/session-observer-completion.ts` and `src/gateway/server-methods/chat-send-background.ts` on main.
- `oxfmt --check`, `check-docs-mdx`, `docs:check-links` (0 broken), `git diff --check`: clean.
- Local review: patch is correct, 0 findings.

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

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime security-sensitive-changed size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant